Skip to content

Commit

Permalink
Merge pull request #181 from raphaelquast/dev
Browse files Browse the repository at this point in the history
Merge for EOmaps v7.1.1
  • Loading branch information
raphaelquast authored Sep 18, 2023
2 parents 22d039e + 9cdfb33 commit 1917715
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 48 deletions.
2 changes: 1 addition & 1 deletion eomaps/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "7.1"
__version__ = "7.1.1"
12 changes: 9 additions & 3 deletions eomaps/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ def annotate(
which is accessible via `m.cb.[click/pick].get.permanent_annotations`
If None, the artists will be permanent but NOT added to the
`permanent_annotations` list!
`permanent_annotations` list and NOT editable!
If "fixed" the artists will become invariable background artists that
are only re-drawn if necessary (useful if you want to draw many annotations)
The default is False
text : callable or str, optional
Expand Down Expand Up @@ -457,9 +460,12 @@ def annotate(
self._temporary_artists.append(annotation)
self.m.BM.add_artist(annotation, layer=layer)
else:
self.m.BM.add_artist(annotation, layer=layer)

if permanent is True:
if isinstance(permanent, str) and permanent == "fixed":
self.m.BM.add_bg_artist(annotation, layer=layer)
else:
self.m.BM.add_artist(annotation, layer=layer)

if not hasattr(self, "permanent_annotations"):
self.permanent_annotations = []

Expand Down
76 changes: 37 additions & 39 deletions eomaps/eomaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
_TransformedBoundsLocator,
_add_to_docstring,
register_modules,
_key_release_event,
)
from .shapes import Shapes
from .colorbar import ColorBar
Expand Down Expand Up @@ -2824,7 +2825,7 @@ def _calc_vmin_vmax(self, vmin=None, vmax=None):
# for details, see https://stackoverflow.com/a/934652/9703451

fill_value = self.data_specs.encoding.get("_FillValue", None)
if fill_value:
if fill_value and any([calc_min, calc_max]):
# find values that are not fill-values
use_vals = self._data_manager.z_data[
self._data_manager.z_data != fill_value
Expand Down Expand Up @@ -3836,49 +3837,45 @@ def cleanup(self):
ONLY execute this if you do not need to do anything with the layer
"""
# disconnect callback on xlim-change (only relevant for parent)
if not self._is_sublayer:
try:
if hasattr(self, "_cid_xlim"):
self.ax.callbacks.disconnect(self._cid_xlim)
del self._cid_xlim
except Exception:
_log.error("EOmaps-cleanup: Problem while clearing xlim-cid")

# clear data-specs and all cached properties of the data
try:
self._coll = None
self._data_manager.cleanup()

if hasattr(self, "tree"):
del self.tree
self.data_specs.delete()
except Exception:
_log.error("EOmaps-cleanup: Problem while clearing data specs")
# disconnect callback on xlim-change (only relevant for parent)
if not self._is_sublayer:
try:
if hasattr(self, "_cid_xlim"):
self.ax.callbacks.disconnect(self._cid_xlim)
del self._cid_xlim
except Exception:
_log.error("EOmaps-cleanup: Problem while clearing xlim-cid")

# clear data-specs and all cached properties of the data
try:
self._coll = None
self._data_manager.cleanup()

# disconnect all click, pick and keypress callbacks
try:
self.cb._reset_cids()
# cleanup callback-containers
self.cb._clear_callbacks()
except Exception:
_log.error("EOmaps-cleanup: Problem while clearing callbacks")
if hasattr(self, "tree"):
del self.tree
self.data_specs.delete()
except Exception:
_log.error("EOmaps-cleanup: Problem while clearing data specs")

# cleanup all artists and cached background-layers from the blit-manager
if not self._is_sublayer:
self.BM.cleanup_layer(self.layer)
# disconnect all click, pick and keypress callbacks
try:
self.cb._reset_cids()
# cleanup callback-containers
self.cb._clear_callbacks()
except Exception:
_log.error("EOmaps-cleanup: Problem while clearing callbacks")

# remove the child from the parent Maps object
if self in self.parent._children:
self.parent._children.remove(self)
# cleanup all artists and cached background-layers from the blit-manager
if not self._is_sublayer:
self.BM.cleanup_layer(self.layer)

# activate the base-layer (and re-initialize widgets)
try:
if self.parent != self:
self.show_layer(self.parent.layer)
# remove the child from the parent Maps object
if self in self.parent._children:
self.parent._children.remove(self)
except Exception:
_log.error(
"EOmaps-cleanup: Problem while updating map to reflect changes",
"EOmaps: Cleanup problem!",
exc_info=_log.getEffectiveLevel() <= logging.DEBUG,
)

Expand Down Expand Up @@ -5151,7 +5148,7 @@ def _get_nominatim_response(self, q, user_agent=None):
}

resp = requests.get(
rf"https://nominatim.openstreetmap.org/search/{q}?format=json&addressdetails=1&limit=1",
rf"https://nominatim.openstreetmap.org/search?q={q}&format=json&addressdetails=1&limit=1",
headers=headers,
).json()

Expand Down Expand Up @@ -5257,7 +5254,8 @@ def _open_companion_widget(self, xy=None):
# Activating the window during the callback steals focus and
# as a consequence the key-released-event is never triggered
# on the figure and "w" would remain activated permanently.
clicked_map.f.canvas.key_release_event("w")

_key_release_event(clicked_map.f.canvas, "w")
clicked_map._companion_widget.activateWindow()

def _init_companion_widget(self, show_hide_key="w"):
Expand Down
33 changes: 32 additions & 1 deletion eomaps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
_log = logging.getLogger(__name__)


from matplotlib.backend_bases import KeyEvent


def _key_release_event(canvas, key, guiEvent=None):
# copy of depreciated matplotlib functions for internal use
s = "key_release_event"
event = KeyEvent(s, canvas, key, guiEvent=guiEvent)
canvas.callbacks.process(s, event)
canvas._key = None


def _deprecated(message):
def deprecated_decorator(func):
def deprecated_func(*args, **kwargs):
Expand Down Expand Up @@ -962,6 +973,13 @@ def cb_move(self, event):
self.blit_artists()

def blit_artists(self):
# TODO the current colorbar implementation requires the parent colorbar
# to be drawn in order to change the inherited position.
# a full redraw takes care of that but it is slower than blitting...
if len(self._cb_picked) > 0:
self.m.redraw()
return

artists = [*self._ax_picked]
for cb in self._cb_picked:
artists.append(cb.ax_cb)
Expand Down Expand Up @@ -1156,6 +1174,8 @@ def _make_draggable(self, filepath=None):
# keep singular axes hidden
if not singularax:
ax.set_visible(True)
else:
ax.set_visible(False)

ax.set_animated(False)
ax.set_frame_on(True)
Expand Down Expand Up @@ -1201,6 +1221,11 @@ def _make_draggable(self, filepath=None):
child.set_visible(False)
child.set_animated(True)

# hide all colorbars that are not on the visible layer
for cb in self.cbs:
if cb._m.layer != self.m.BM.bg_layer:
cb.set_visible(False)

# only re-draw if info-text is None
if getattr(self, "_info_text", None) is None:
self._info_text = self.add_info_text()
Expand Down Expand Up @@ -1271,6 +1296,12 @@ def _undo_draggable(self):

self.modifier_pressed = False

# show all colorbars that are on the visible layer
active_layers = self.m.BM._get_layers_alphas()[0]
for cb in self.cbs:
if cb._m.layer in active_layers:
cb.set_visible(True)

# reset the histogram-size of all colorbars to make sure previously hidden
# axes (e.g. size=0) become visible if the size is now > 0.
for m in self.ms:
Expand Down Expand Up @@ -2421,7 +2452,7 @@ def _get_artist_zorder(self, a):
try:
return a.get_zorder()
except Exception:
_log.error(r"EOmaps: unalble to identify zorder of {a}... using 99")
_log.error(f"EOmaps: unalble to identify zorder of {a}... using 99")
return 99

def _draw_animated(self, layers=None, artists=None):
Expand Down
5 changes: 3 additions & 2 deletions eomaps/qtcompanion/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from matplotlib.colors import to_rgba_array

from ...inset_maps import InsetMaps
from ...helpers import _key_release_event
from ..common import iconpath
from ..base import BasicCheckableToolButton, NewWindow
from .wms import AddWMSMenuButton
Expand Down Expand Up @@ -1078,7 +1079,7 @@ def tabchanged(self, index):
)
# TODO this is a workaround since modifier-releases are not
# forwarded to the canvas if it is not in focus
self.m.f.canvas.key_release_event("control")
_key_release_event(self.m.f.canvas, "control")

elif modifiers == Qt.ShiftModifier:
# The all layer should not be combined with other layers...
Expand Down Expand Up @@ -1106,7 +1107,7 @@ def tabchanged(self, index):
)
# TODO this is a workaround since modifier-releases are not
# forwarded to the canvas if it is not in focus
self.m.f.canvas.key_release_event("shift")
_key_release_event(self.m.f.canvas, "shift")

# make sure to reflect the layer-changes in the tab-colors (and positions)
self.color_active_tab()
Expand Down
4 changes: 2 additions & 2 deletions eomaps/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ def __repr__(self):
def mask_radius(self):
r = Shapes._get_radius(self._m, self._mask_radius, "out")
if self._mask_radius is None:
return (i * 4 for i in r)
return [i * 4 for i in r]
else:
return r

Expand Down Expand Up @@ -1341,7 +1341,7 @@ def mask_radius(self):
if self.masked:
r = Shapes._get_radius(self._m, self._mask_radius, self.mask_radius_crs)
if self._mask_radius is None:
return (i * 4 for i in r)
return [i * 4 for i in r]
else:
return r
else:
Expand Down
4 changes: 4 additions & 0 deletions eomaps/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def __init__(
uselayers.append(l)
layers = uselayers

layers = [i for i in layers if not i.startswith("_")]

# assert (
# len(layers) > 0
# ), "EOmaps: There are no layers with artists available.. plot something first!"
Expand Down Expand Up @@ -441,6 +443,8 @@ def __init__(
uselayers.append(l)
layers = uselayers

layers = [i for i in layers if not i.startswith("_")]

if pos is None:
ax_slider = self._m.f.add_axes(
[
Expand Down

0 comments on commit 1917715

Please sign in to comment.