Skip to content

Commit

Permalink
changes to use Cartopy in place of Basemap (#34)
Browse files Browse the repository at this point in the history
* changes to use Cartopy in place of Basemap
* reverting to coverage run for Travis
* commenting out Matplotlib.use for issue on Travis Linux
* removed all qt5agg usages
  • Loading branch information
giumas committed Apr 10, 2020
1 parent 7606f39 commit bac1275
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 140 deletions.
82 changes: 31 additions & 51 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,52 @@
language: cpp # Travis-CI does not currently support Python and Mac OS X

matrix:
include:
- os: linux
dist: xenial
env: PYTHON_VERSION=3.6
- os: linux
dist: trusty
env: PYTHON_VERSION=3.6
- os: linux
dist: xenial
env: PYTHON_VERSION=3.7
- os: osx
env: PYTHON_VERSION=3.6
os:
- linux
- osx

env:
- PYTHON_VERSION=3.8
- PYTHON_VERSION=3.6
- PYTHON_VERSION=3.7

matrix:
fast_finish: true
allow_failures:
- os: linux
dist: trusty
env: PYTHON_VERSION=3.6
- os: linux
dist: xenial
env: PYTHON_VERSION=3.7
- os: osx
env: PYTHON_VERSION=3.6
- os: osx
- env: PYTHON_VERSION=3.7

install:
- "export DISPLAY=:99.0"
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
( sudo Xvfb :99 -ac -screen 0 1024x768x8; echo ok )&
curl https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o miniconda.sh;
else
sudo apt-get update;
sudo apt-get install -y xvfb;
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1920x1200x24 -ac +extension GLX +render -noreset;
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then MINICONDA_OS=Linux; else MINICONDA_OS=MacOSX; fi
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-$MINICONDA_OS-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p "$HOME"/miniconda
- source "$HOME"/miniconda/etc/profile.d/conda.sh
- conda config --set always_yes yes --set changeps1 no --set auto_update_conda false --set notify_outdated_conda false
- conda config --add channels conda-forge
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a

- conda create -q -n test-environment python=$PYTHON_VERSION
- source activate test-environment
- conda activate test-environment
- python --version

- pip install coveralls PyYAML pytest pytest-cov wheel
# for hyo2.abc
- conda install appdirs bidict cartopy gdal matplotlib-base numpy psutil pyproj
- pip install PySide2
- conda install numpy matplotlib-base gdal pyproj scipy basemap netCDF4 pillow gsw
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then
conda remove --force PyQt Qt sip;
export LD_LIBRARY_PATH=$HOME/miniconda/envs/test-environment/lib:$LD_LIBRARY_PATH;
fi
- pip install cython
- pip install coveralls
- pip install https://github.com/hydroffice/hyo2_abc/archive/master.zip
# for hyo2.soundspeed
- conda install gsw netCDF4 pillow pyserial scipy

- pip install .
- rm -f $HOME/miniconda/envs/test-environment/qt.conf
- pip install pytest pytest-cov
- conda list --show-channel-urls

script:
- py.test --cov
- coverage run --source hyo2 setup.py test
- coverage report -m
- coveralls

after_script:
- coverage report -m
- python setup.py bdist_wheel

after_success:
- pip install PyYAML
- coveralls
- path: dist\*

8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
History
-------

2020.0.0
~~~~~~~~

2020-04-09

- Started migration from Basemap to Cartopy


2019.0.0
~~~~~~~~

Expand Down
12 changes: 0 additions & 12 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
Copyright Notice and License Terms for: hyo2.soundspeed - Sound Speed package for HydrOffice
Copyright (c) 2019, University of New Hampshire, Center for Coastal and Ocean Mapping. All rights reserved.
Portions of this project were developed under a cooperative agreement with NOAA Coast Survey Development
Laboratory, and contain NOAA-developed code in the public domain.

Released under a dual license:
- Community license (LGPL v2.1)
- Industrial Associate license

For more info, visit: http:https://www.hydroffice.org/license_lgpl21/

-----------------------------------------------------------------------------

GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Expand Down
19 changes: 9 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
version: 0.1.{build}-{branch}
version: 2020.0.{build}-{branch}

environment:

matrix:

- PYTHON_VERSION: 3.8
PYTHON_ARCH: x64
MINICONDA: C:\Miniconda36-x64

- PYTHON_VERSION: 3.6
PYTHON_ARCH: x64
MINICONDA: C:\Miniconda36-x64
Expand All @@ -30,33 +34,28 @@ install:
- conda config --add channels conda-forge
- conda create -q -n test-environment python=%PYTHON_VERSION%
- activate test-environment
- pip install wheel

# Check that we have the expected version of Python
- python --version

- pip install pytest pytest-cov
- pip install coveralls
- pip install PySide2
- pip install coveralls PyYAML pytest pytest-cov wheel
# for hyo2.abc
- conda install numpy matplotlib-base gdal pyproj appdirs bidict coverage psutil
- conda install appdirs bidict cartopy gdal matplotlib-base numpy psutil pyproj
- pip install PySide2
# for hyo2.soundspeed
- conda install scipy basemap netCDF4 pillow gsw cython pyproj
- conda install gsw netCDF4 pillow pyserial scipy
# --no-deps because of pip not detecting the installed GDAL
- pip install https://github.com/hydroffice/hyo2_abc/archive/master.zip

build: off
build_script:
- pip install .
# - conda remove --force PyQt Qt sip
- del /q %MINICONDA%\envs\test-environment\qt.conf
- conda list --show-channel-urls

test: off
test_script:
- py.test --cov
- coverage report -m
- pip install PyYAML
- coveralls

after_test:
Expand Down
5 changes: 3 additions & 2 deletions examples/soundspeed/ex_plot_export_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

from hyo2.abc.lib.gdal_aux import GdalAux
# noinspection PyUnresolvedReferences
from hyo2.soundspeedmanager import app_info
from hyo2.soundspeed.soundspeed import SoundSpeedLibrary

Expand All @@ -22,8 +23,8 @@
logger.info("Profiles: %s" % len(lst))

# plots/maps/exports
# - map
lib.map_db_profiles()
# - mapt
lib.map_db_profiles(show_plot=False)
lib.save_map_db_profiles()

# - aggregate plot
Expand Down
4 changes: 2 additions & 2 deletions hyo2/soundspeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed"
__version__ = '2019.2.6'
__version__ = '2020.0.0'
__copyright__ = 'Copyright 2020 University of New Hampshire, Center for Coastal and Ocean Mapping'

lib_info = LibInfo()
Expand Down Expand Up @@ -44,6 +44,6 @@
"numpy": "numpy",
"pyproj": "pyproj",
"matplotlib": "matplotlib",
"basemap": "mpl_toolkits.basemap",
"cartopy": "cartopy",
"PySide2": "PySide2"
}
75 changes: 28 additions & 47 deletions hyo2/soundspeed/db/plot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import os
import numpy as np

# noinspection PyUnresolvedReferences
from PySide2 import QtWidgets
import matplotlib
from matplotlib import rc_context

from mpl_toolkits.basemap import Basemap
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import logging

matplotlib.use('qt5agg')
# matplotlib.use('qt5agg')
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -48,7 +50,7 @@ def plots_folder(cls, output_folder):
os.makedirs(folder)
return folder

def map_profiles(self, pks=None, output_folder=None, save_fig=False):
def map_profiles(self, pks=None, output_folder=None, save_fig=False, show_plot=False):
"""plot all the ssp in the database"""

with rc_context(self.rc_context):
Expand Down Expand Up @@ -81,81 +83,60 @@ def map_profiles(self, pks=None, output_folder=None, save_fig=False):

# make the world map
plt.close("Profiles Map")
fig = plt.figure("Profiles Map")
# fig.patch.set_facecolor('#1464F4')
ax = plt.subplot(111, aspect='equal')
_ = plt.figure("Profiles Map")
ax = plt.subplot(111, projection=ccrs.PlateCarree())
plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
# plt.title("SSP Map (%s profiles)" % len(view_rows))
plt.ioff()

if rows:
wm = self._world_draw_polygons()
else:
wm = self._world_draw_map()
x, y = wm(ssp_x, ssp_y)
wm.scatter(x, y, marker='o', s=16, color='r')
wm.scatter(x, y, marker='.', s=1, color='k')
# noinspection PyUnresolvedReferences
ax.coastlines(resolution='50m')
# noinspection PyUnresolvedReferences
ax.add_feature(cfeature.OCEAN.with_scale('50m'))
# noinspection PyUnresolvedReferences
ax.add_feature(cfeature.LAND.with_scale('50m'), color='lightgray')
# noinspection PyUnresolvedReferences
ax.gridlines(color='#cccccc', linestyle='--')

# noinspection PyUnresolvedReferences
ax.scatter(ssp_x, ssp_y, marker='o', s=14, color='r')
# noinspection PyUnresolvedReferences
ax.scatter(ssp_x, ssp_y, marker='.', s=1, color='k')
if pks is not None:
delta = 5.0
y_min = min(y)
y_min = min(ssp_y)
if (y_min - delta) < -90.0:
y_min = -90.0
else:
y_min -= delta
y_max = max(y)
y_max = max(ssp_y)
if (y_max + delta) > 90.0:
y_max = 90.0
else:
y_max += delta

x_min = min(x)
x_min = min(ssp_x)
if (x_min - delta) < -180.0:
x_min = -180.0
else:
x_min = x_min - delta
x_max = max(x)
x_max = max(ssp_x)
if (x_max + delta) > 180.0:
x_max = 180.0
else:
x_max += delta
# logger.debug("%s %s, %s %s" % (y_min, y_max, x_min, x_max))
# noinspection PyUnresolvedReferences
ax.set_ylim(y_min, y_max)
# noinspection PyUnresolvedReferences
ax.set_xlim(x_min, x_max)

if save_fig and (output_folder is not None):
plt.savefig(os.path.join(self.plots_folder(output_folder), 'ssp_map.png'),
bbox_inches='tight')
# else:
# plt.show()
elif show_plot:
plt.show()

return True

@staticmethod
def _world_draw_map():
logger.debug("drawing blue marble")
m = Basemap(resolution=None)
# resolution c, l, i, h, f in that order
img = m.bluemarble(zorder=0)
img.set_alpha(0.8)
return m

@staticmethod
def _world_draw_polygons():
logger.debug("drawing polygons")
m = None
try:
m = Basemap(resolution='i')
except OSError:
logger.debug("using low resolution for basemap")
m = Basemap(resolution='l')

m.drawcoastlines(zorder=1)
m.fillcontinents(color='lightgray', zorder=1)
m.drawparallels(np.arange(-90., 120., 10.), color="#cccccc", labels=[False, True, True, False])
m.drawmeridians(np.arange(0., 360., 20.), color="#cccccc", labels=[True, False, False, True])

return m

@staticmethod
def _set_inset_color(x, color):
for m in x:
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeed/profile/ray_tracing/plot_tracedprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from hyo2.soundspeed.profile.ray_tracing.diff_tracedprofiles import DiffTracedProfiles

matplotlib.use('qt5agg')
# matplotlib.use('qt5agg')
logger = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions hyo2/soundspeed/soundspeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,10 +1504,10 @@ def raise_plot_window(self) -> None:
_ = db.plot.raise_window()
db.disconnect()

def map_db_profiles(self, pks: Optional[list] = None) -> bool:
def map_db_profiles(self, pks: Optional[list] = None, show_plot: Optional[bool] = False) -> bool:
"""List the profile on the db"""
db = ProjectDb(projects_folder=self.projects_folder, project_name=self.current_project)
ret = db.plot.map_profiles(pks=pks)
ret = db.plot.map_profiles(pks=pks, show_plot=show_plot)
db.disconnect()
return ret

Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeed/temp/regex_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def ConvertFromSoundSpeedProfile(p):
p.data.num_samples = len(self)
col_types = []
prof_data = []
for data, name in ((p.data.pressure, 'pressure'), (p.data.depth, 'depth')
for data, name in ((p.data.pressure, 'pressure'), (p.data.depth, 'depth'),
(p.data.speed, 'soundspeed'), (p.data.temp, 'temperature'),
(p.data.sal, 'salinity'), (p.data.conductivity, 'conductivity')):
if data is not None:
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeedmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Manager"
__version__ = "2019.2.6"
__version__ = "2020.0.0"
__copyright__ = "Copyright 2020 University of New Hampshire, Center for Coastal and Ocean Mapping"

app_info = AppInfo()
Expand Down
Loading

0 comments on commit bac1275

Please sign in to comment.