Skip to content

Commit c5f4429

Browse files
committed
Merge branch 'dev' into layouteditor_images
# Conflicts: # eomaps/helpers.py
2 parents b548fe6 + 759d1e9 commit c5f4429

File tree

6 files changed

+53
-36
lines changed

6 files changed

+53
-36
lines changed

eomaps/_data_manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,12 @@ def _select_vals(self, val, qs, slices=None):
652652
else:
653653
val = np.asanyarray(val)
654654

655-
if len(val.shape) == 2 and qx is not None and qy is not None:
655+
if (
656+
len(val.shape) == 2
657+
and qx is not None
658+
and qy is not None
659+
and slices is not None
660+
):
656661
(x0, x1, y0, y1) = slices
657662
ret = val[y0:y1, x0:x1]
658663
else:
@@ -895,6 +900,11 @@ def get_props(self, *args, **kwargs):
895900
else:
896901
slices, blocksize = None, None
897902

903+
# remember last selection and slices (required in case explicit
904+
# colors are provided since they must be selected accordingly)
905+
self._last_qs = qs
906+
self._last_slices = slices
907+
898908
self._current_data = dict(
899909
xorig=self._select_vals(self.xorig, qs, slices),
900910
yorig=self._select_vals(self.yorig, qs, slices),

eomaps/_webmap.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,15 @@ def _do_add_layer(self, m, layer, **kwargs):
584584

585585

586586
class _WebServiceCollection:
587-
def __init__(self, m, service_type="wmts", url=None):
587+
def __init__(self, m, service_type="wmts", url=None, **kwargs):
588588
self._m = m
589589
self._service_type = service_type
590590
if url is not None:
591591
self._url = url
592592

593+
# additional kwargs that will be passed to owslib.WebMapService()
594+
self._service_kwargs = kwargs.copy()
595+
593596
def __getitem__(self, key):
594597
return self.add_layer.__dict__[key]
595598

@@ -626,28 +629,28 @@ def findlayer(self, name):
626629
return [i for i in self.layers if name.lower() in i.lower()]
627630

628631
@staticmethod
629-
def _get_wmts(url):
632+
def _get_wmts(url, **kwargs):
630633
# TODO expose useragent
631634

632635
# lazy import used to avoid long import times
633636
from owslib.wmts import WebMapTileService
634637

635-
return WebMapTileService(url)
638+
return WebMapTileService(url, **kwargs)
636639

637640
@staticmethod
638-
def _get_wms(url):
641+
def _get_wms(url, **kwargs):
639642
# TODO expose useragent
640643

641644
# lazy import used to avoid long import times
642645
from owslib.wms import WebMapService
643646

644-
return WebMapService(url)
647+
return WebMapService(url, **kwargs)
645648

646649
@property
647650
@lru_cache()
648651
def add_layer(self):
649652
if self._service_type == "wmts":
650-
wmts = self._get_wmts(self._url)
653+
wmts = self._get_wmts(self._url, **self._service_kwargs)
651654
layers = dict()
652655
for key in wmts.contents.keys():
653656
layername = _sanitize(key)
@@ -665,7 +668,7 @@ def add_layer(self):
665668
layers[layername] = wmtslayer
666669

667670
elif self._service_type == "wms":
668-
wms = self._get_wms(self._url)
671+
wms = self._get_wms(self._url, **self._service_kwargs)
669672
layers = dict()
670673
for key in wms.contents.keys():
671674
layername = _sanitize(key)
@@ -821,14 +824,14 @@ def _fetch_layers(self):
821824
url = self._url
822825
if url is not None:
823826
if self._service_type == "wms":
824-
wms = self._get_wms(url)
827+
wms = self._get_wms(url, **self._service_kwargs)
825828
layer_names = list(wms.contents.keys())
826829
for lname in layer_names:
827830
self._layers["layer_" + _sanitize(lname)] = _WMSLayer(
828831
self._m, wms, lname
829832
)
830833
elif self._service_type == "wmts":
831-
wmts = self._get_wmts(url)
834+
wmts = self._get_wmts(url, **self._service_kwargs)
832835
layer_names = list(wmts.contents.keys())
833836
for lname in layer_names:
834837
self._layers["layer_" + _sanitize(lname)] = _WMTSLayer(

eomaps/eomaps.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,21 +3462,13 @@ def snapshot(self, *layer, transparent=False, clear=False):
34623462
else:
34633463
sn = self._get_snapshot()
34643464
try:
3465-
from IPython.display import display, Image as IpyImage
3466-
from io import BytesIO
3467-
3468-
# fix issues with PILLOW 10.0 and transparent snapshots
3469-
# in jupyter notebooks (TODO should be fixed in PILLOW 10.1.0)
3470-
# ...bug causes unwanted errors in _repr__jpeg_ for RGBA images
3471-
# the fix enforces png as format
3472-
temp = BytesIO()
3473-
Image.fromarray(sn, "RGBA").save(temp, format="png")
3474-
3475-
display(
3476-
IpyImage(temp.getvalue()),
3477-
display_id=True,
3478-
clear=clear,
3479-
)
3465+
from IPython.display import display_png, clear_output
3466+
3467+
if clear:
3468+
clear_output(wait=True)
3469+
# use display_png to avoid issues with transparent snapshots
3470+
display_png(Image.fromarray(sn, "RGBA"), raw=False)
3471+
34803472
except Exception:
34813473
_log.exception(
34823474
"Unable to display the snapshot... is the script "
@@ -4827,7 +4819,9 @@ def _plot_map(
48274819

48284820
def _sel_c_transp(self, c):
48294821
return self._data_manager._select_vals(
4830-
c.T if self._data_manager._z_transposed else c
4822+
c.T if self._data_manager._z_transposed else c,
4823+
qs=self._data_manager._last_qs,
4824+
slices=self._data_manager._last_slices,
48314825
)
48324826

48334827
def _handle_explicit_colors(self, color):

eomaps/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,11 +1587,12 @@ def apply_layout(self, layout):
15871587
valid_keys = set(self.get_layout())
15881588
active_keys = set(layout)
15891589

1590-
missing_keys = [
1591-
i for i in (valid_keys - active_keys) if not i.endswith("extent")
1592-
]
1593-
if len(missing_keys) > 0:
1594-
warnings.warn(
1590+
if valid_keys != set(layout):
1591+
missing_keys = [
1592+
i for i in (valid_keys - active_keys) if not i.endswith("extent")
1593+
]
1594+
1595+
_log.warning(
15951596
"EOmaps: The the layout does not match the expected structure! "
15961597
"Layout might not be properly restored. "
15971598
"Invalid or missing keys:\n"

eomaps/shapes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ def _get_colors_and_array(kwargs, mask):
326326
# identify colors and the array
327327
# special treatment of array input to properly mask values
328328
array = kwargs.pop("array", None)
329-
330329
if array is not None:
331330
if mask is not None:
332331
array = array[mask]
@@ -336,17 +335,18 @@ def _get_colors_and_array(kwargs, mask):
336335
color_vals = dict()
337336
for c_key in ["fc", "facecolor", "color"]:
338337
color = kwargs.pop(c_key, None)
338+
339339
if color is not None:
340340
# explicit treatment for recarrays (to avoid performance issues)
341341
# with matplotlib.colors.to_rgba_array()
342342
# (recarrays are used to convert 3/4 arrays into an rgb(a) array
343343
# in m._handle_explicit_colors() )
344344
if isinstance(color, np.recarray):
345-
color_vals[c_key] = color[mask].view(
345+
color_vals[c_key] = color[mask.reshape(color.shape)].view(
346346
(float, len(color.dtype.names))
347347
) # .ravel()
348348
elif isinstance(color, np.ndarray):
349-
color_vals[c_key] = color[mask]
349+
color_vals[c_key] = color[mask.reshape(color.shape)]
350350
else:
351351
color_vals[c_key] = color
352352

eomaps/webmap_containers.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,9 @@ def Austria(self):
24222422
WMS.__doc__ = type(self).Austria.__doc__
24232423
return WMS
24242424

2425-
def get_service(self, url, service_type="wms", rest_API=False, maxzoom=19):
2425+
def get_service(
2426+
self, url, service_type="wms", rest_API=False, maxzoom=19, **kwargs
2427+
):
24262428
"""
24272429
Get a object that can be used to add WMS, WMTS or XYZ services based on
24282430
a GetCapabilities-link or a link to a ArcGIS REST API
@@ -2470,6 +2472,11 @@ def get_service(self, url, service_type="wms", rest_API=False, maxzoom=19):
24702472
24712473
The maximum zoom-level available (to avoid http-request errors) for too
24722474
high zoom levels. The default is 19.
2475+
kwargs :
2476+
Additional keyword arguments passed to `owslib.WebMapService()`.
2477+
(only relevant if type is "wms" or "wmts")
2478+
2479+
For example: `version=1.3.0`
24732480
24742481
Returns
24752482
-------
@@ -2541,6 +2548,8 @@ def get_service(self, url, service_type="wms", rest_API=False, maxzoom=19):
25412548
service_type=service_type,
25422549
)
25432550
else:
2544-
service = _WebServiceCollection(self._m, service_type="wms", url=url)
2551+
service = _WebServiceCollection(
2552+
self._m, service_type="wms", url=url, **kwargs
2553+
)
25452554

25462555
return service

0 commit comments

Comments
 (0)