Skip to content

Commit

Permalink
Merge pull request #92 from raphaelquast/dev
Browse files Browse the repository at this point in the history
merge for EOmaps v4.2.3
  • Loading branch information
raphaelquast authored Jun 24, 2022
2 parents ec25b5f + 0580adb commit df00e0e
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 55 deletions.
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ and ``< LAYER >`` indicates the actual layer-name.
| # ... for more advanced | |
| layer = mg.m_1_0.add_wms.ISRIC_SoilGrids.nitrogen.add_layer.nitrogen_0_5cm_mean | |
| layer.set_extent_to_bbox() # set the extent according to the boundingBox | |
| layer.info # the "info" property provides useful informations on the layer | |
| layer.info # the "info" property provides useful information on the layer | |
| layer() # call the layer to add it to the map | |
| layer.add_legend() # if a legend is provided, you can add it to the map! | |
| | |
Expand Down
10 changes: 8 additions & 2 deletions eomaps/_cb_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, m, cb_class=None, method="click"):
self._event = None

def _getobj(self, m):
"""get the equivalent callback container on anoter maps object"""
"""get the equivalent callback container on another maps object"""
return getattr(m.cb, self._method, None)

@property
Expand Down Expand Up @@ -730,7 +730,7 @@ class cb_pick_container(_click_container):
Note
----
you can set a treshold for the default picker via the `pick_distance`
you can set a threshold for the default picker via the `pick_distance`
`m.plot_map(pick_distance=20)` to specify the maximal distance (in pixels)
that is used to identify the closest datapoint
Expand Down Expand Up @@ -1120,6 +1120,12 @@ def __call__(self, f, key, **kwargs):
the ID of the attached callback
"""

if not isinstance(key, str):
raise TypeError(
"EOmaps: The 'key' for keypress-callbacks must be a string!"
)

return self._parent._add_callback(f, key, **kwargs)

class _get:
Expand Down
6 changes: 3 additions & 3 deletions eomaps/_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _estimate_radius(m, radius_crs, method=np.median):
radius = (radiusxy, radiusxy)

assert radius is not None, (
"EOmaps: Radius estimation failed... either there's somethign wrong with "
"EOmaps: Radius estimation failed... either there's something wrong with "
+ "the provided coordinates or you can try to increase the number of "
+ "datapoints used to evaluate the radius by increasing "
+ "`m.set_shape.radius_estimation_range`."
Expand Down Expand Up @@ -584,7 +584,7 @@ def getQ(x, xc):
# mask any point that is in a different quadrant than the center point
maskx = pts_quadrants != quadrants[:, np.newaxis]
# take care of points that are on the center line (e.g. don't mask them)
# (use a +- 10 degree around 0 as treshold)
# (use a +- 10 degree around 0 as threshold)
cpoints = np.broadcast_to(
np.isclose(xp, xc, atol=10)[:, np.newaxis], xs.shape
)
Expand Down Expand Up @@ -1411,7 +1411,7 @@ def __call__(self, radius="estimate", radius_crs="in"):
This considerably speeds up plotting of large datasets but it has the
disadvantage that only the vertices of the rectangles will be reprojected
to the plot-crs while the curvature of the edges is NOT considerd!
to the plot-crs while the curvature of the edges is NOT considered!
(e.g. the effective shape is a distorted rectangle with straight edges)
- use `m.set_shape.rectangles()` if you need "curved" edges!
Expand Down
2 changes: 1 addition & 1 deletion eomaps/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.2.2"
__version__ = "4.2.3"
73 changes: 48 additions & 25 deletions eomaps/_webmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
pass

def __call__(self, layer=None, zorder=0, **kwargs):
def __call__(self, layer=None, zorder=0, alpha=1, **kwargs):
"""
Add the WMTS layer to the map
Expand All @@ -324,31 +324,45 @@ def __call__(self, layer=None, zorder=0, **kwargs):
zorder : float
The zorder of the artist (e.g. the stacking level of overlapping artists)
The default is 0
alpha : float, optional
The alpha-transparency of the image.
NOTE: This changes the global transparency of the images... it does
not control whether the images are served with included transparency!
(check the "transparent" kwarg)
**kwargs :
additional kwargs passed to the WebMap service request.
(e.g. transparent=True, time='2020-02-05', etc.)
Additional Parameters
---------------------
transparent : bool, optional
Indicator if the WMS images should be read as RGB or RGBA
(e.g. with or without transparency). The default is False.
"""
from . import MapsGrid # do this here to avoid circular imports!

style = self._set_style(kwargs.get("styles", None))
self._style = self._set_style(kwargs.get("styles", None))
if self._style is not None:
kwargs["styles"] = [self._style]

self._zorder = zorder
self._kwargs = kwargs
self._alpha = alpha

for m in self._m if isinstance(self._m, MapsGrid) else [self._m]:
self._zorder = zorder
self._kwargs = kwargs
if layer is None:
self._layer = m.layer
else:
self._layer = layer

if self._layer == "all" or self._m.BM.bg_layer == self._layer:
# add the layer immediately if the layer is already active
self._do_add_layer(self._m, self._layer, zorder=zorder, kwargs=kwargs)
self._do_add_layer(self._m, self._layer)
else:
# delay adding the layer until it is effectively activated
self._m.BM.on_layer(
partial(self._do_add_layer, zorder=zorder, kwargs=kwargs),
partial(self._do_add_layer),
layer=self._layer,
persistent=False,
m=m,
Expand All @@ -372,7 +386,7 @@ def _add_wmts(ax, wms, layers, wms_kwargs=None, **kwargs):
ax.add_image(img)
return img

def _do_add_layer(self, m, l, zorder, kwargs):
def _do_add_layer(self, m, l):
# actually add the layer to the map.
print(f"EOmaps: Adding wmts-layer: {self.name}")

Expand All @@ -381,9 +395,10 @@ def _do_add_layer(self, m, l, zorder, kwargs):
m.ax,
self._wms,
self.name,
wms_kwargs=kwargs,
wms_kwargs=self._kwargs,
interpolation="spline36",
zorder=zorder,
zorder=self._zorder,
alpha=self._alpha,
)

# art = m.figure.ax.add_wmts(
Expand All @@ -401,7 +416,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
pass

def __call__(self, layer=None, zorder=0, **kwargs):
def __call__(self, layer=None, zorder=0, alpha=1, **kwargs):
"""
Add the WMS layer to the map
Expand All @@ -417,19 +432,33 @@ def __call__(self, layer=None, zorder=0, **kwargs):
zorder : float
The zorder of the artist (e.g. the stacking level of overlapping artists)
The default is 0
alpha : float, optional
The alpha-transparency of the image.
NOTE: This changes the global transparency of the images... it does
not control whether the images are served with included transparency!
(check the "transparent" kwarg)
**kwargs :
additional kwargs passed to the WebMap service request.
(e.g. transparent=True, time='2020-02-05', etc.)
Additional Parameters
---------------------
transparent : bool, optional
Indicator if the WMS images should be read as RGB or RGBA
(e.g. with or without transparency). The default is False.
"""
from . import MapsGrid # do this here to avoid circular imports!

style = self._set_style(kwargs.get("styles", None))
self._style = self._set_style(kwargs.get("styles", None))
if self._style is not None:
kwargs["styles"] = [self._style]

self._kwargs = kwargs
self._zorder = zorder
self._alpha = alpha

for m in self._m if isinstance(self._m, MapsGrid) else [self._m]:
self._kwargs = kwargs
self._zorder = zorder

if layer is None:
self._layer = m.layer
Expand All @@ -438,18 +467,11 @@ def __call__(self, layer=None, zorder=0, **kwargs):

if self._layer == "all" or m.BM.bg_layer == self._layer:
# add the layer immediately if the layer is already active
self._do_add_layer(m, self._layer, zorder=zorder, kwargs=kwargs)
self._do_add_layer(m, self._layer)
else:
# self._do_add_layer(m, self._layer)

# delay adding the layer until it is effectively activated

# m.BM.on_layer(
# func=self._do_add_layer, layer=self._layer, persistent=False, m=m
# )

m.BM.on_layer(
func=partial(self._do_add_layer, zorder=zorder, kwargs=kwargs),
func=partial(self._do_add_layer),
layer=layer,
persistent=False,
m=m,
Expand All @@ -475,7 +497,7 @@ def _add_wms(ax, wms, layers, wms_kwargs=None, **kwargs):

return img

def _do_add_layer(self, m, l, zorder, kwargs):
def _do_add_layer(self, m, l):
# actually add the layer to the map.
print(f"EOmaps: ... adding wms-layer {self.name}")

Expand All @@ -484,9 +506,10 @@ def _do_add_layer(self, m, l, zorder, kwargs):
m.ax,
self._wms,
self.name,
wms_kwargs=kwargs,
wms_kwargs=self._kwargs,
interpolation="spline36",
zorder=zorder,
zorder=self._zorder,
alpha=self._alpha,
)

# art = m.figure.ax.add_wms(
Expand Down
2 changes: 1 addition & 1 deletion eomaps/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def mark(
if self.m.figure.coll is not None:
radius = "pixel"
else:
# make a dot with 1/20 of the widht & height of the figure
# make a dot with 1/20 of the width & height of the figure
t = self.m.figure.ax.bbox.transformed(
self.m.figure.ax.transData.inverted()
)
Expand Down
Loading

0 comments on commit df00e0e

Please sign in to comment.