Commit 6ca42501 authored by Daniel Scheffler's avatar Daniel Scheffler

Fixed mpld3 exception. Revised availability checks for optional libs.

parent 54b4839b
Pipeline #1396 passed with stages
in 1 minute and 12 seconds
......@@ -2,6 +2,7 @@
import os
import warnings
from importlib import util
from collections import OrderedDict
import numpy as np
......@@ -1022,6 +1023,12 @@ class GeoArray(object):
palette.set_over('1')
palette.set_under('0')
# check availability of holoviews
if not util.find_spec('holoviews'):
warnings.warn("Interactive mode requires holoviews. Install it by running, e.g., "
"'conda install --yes -c ioam bokeh holoviews'. Using non-interactive mode.")
interactive = False
if interactive and image2plot.ndim == 3:
import holoviews as hv
from skimage.exposure import rescale_intensity
......@@ -1079,23 +1086,27 @@ class GeoArray(object):
:return:
"""
try:
from mpl_toolkits.basemap import Basemap
except ImportError:
warnings.warn('This function requires Basemap. You need to install basemap manually (see www./'
'matplotlib.org/basemap) if you want to plot maps. It is not automatically installed.')
raise
try:
# noinspection PyUnresolvedReferences
if not util.find_spec('mpl_toolkits.basemap'):
raise ImportError('This function requires Basemap. You need to install basemap manually (see www./'
'matplotlib.org/basemap) if you want to plot maps. It is not automatically installed.')
from mpl_toolkits.basemap import Basemap
mpld3_avl = util.find_spec('mpld3')
if not mpld3_avl:
warnings.warn('mpld3 is not available. Zooming disabled.')
zoomable = False
if zoomable:
import mpld3
if zoomable:
mpld3.enable_notebook()
else:
mpld3.enable_notebook()
elif mpld3_avl:
import mpld3
# noinspection PyBroadException
try:
mpld3.disable_notebook()
except ImportError:
if zoomable:
zoomable = False
warnings.warn('mpld3 is not available. Zooming disabled.')
except Exception:
pass
assert self.geotransform and tuple(self.geotransform) != (0, 1, 0, 0, 0, -1), \
'A valid geotransform is needed for a map visualization. Got %s.' % list(self.geotransform)
......@@ -1163,12 +1174,12 @@ class GeoArray(object):
def show_map_utm(self, xlim=None, ylim=None, band=0, figsize=None, interpolation='none', cmap=None,
nodataVal=None, vmin=None, vmax=None, res_factor=None, return_map=False):
try:
from mpl_toolkits.basemap import Basemap
except ImportError:
warnings.warn('This function requires Basemap. You need to install basemap manually (see www./'
'matplotlib.org/basemap) if you want to plot maps. It is not automatically installed.')
raise
if not util.find_spec('mpl_toolkits.basemap'):
raise ImportError('This function requires Basemap. You need to install basemap manually (see www./'
'matplotlib.org/basemap) if you want to plot maps. It is not automatically installed.')
from mpl_toolkits.basemap import Basemap
warnings.warn(UserWarning('This function is still under construction and may not work as expected!'))
# TODO debug this function
......@@ -1232,16 +1243,14 @@ class GeoArray(object):
footprint of GeoArray.
"""
try:
import folium
import geojson
except ImportError:
folium, geojson = None, None
if not folium or not geojson:
if not util.find_spec('folium') or not util.find_spec('geojson'):
raise ImportError(
"This method requires the libraries 'folium' and 'geojson'. They can be installed with "
"the shell command 'pip install folium geojson'.")
import folium
import geojson
lonlatPoly = reproject_shapelyGeometry(self.footprint_poly, self.epsg, 4326)
m = folium.Map(location=tuple(np.array(lonlatPoly.centroid.coords.xy).flatten())[::-1])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment