Skip to content

Commit

Permalink
Merge pull request #157 from raphaelquast/dev
Browse files Browse the repository at this point in the history
Merge for EOmaps v6.3
  • Loading branch information
raphaelquast authored Mar 23, 2023
2 parents 115375f + a1c1da5 commit ebc8de7
Show file tree
Hide file tree
Showing 18 changed files with 421 additions and 315 deletions.
46 changes: 33 additions & 13 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
| To start creating a new map (in this case a plot in ``epsg=4326``, e.g. lon/lat), simply use:
.. code-block:: python
:name: test_init_map_objects
from eomaps import Maps
m = Maps(crs=4326, layer="first layer", figsize=(10, 5)) # initialize a Maps-object
m.add_feature.preset.coastline() # add coastlines to the map
m = Maps(crs=4326, layer="first layer", figsize=(7, 5)) # initialize a Maps-object
m.set_extent((-25, 35, 25, 70)) # set the map extent
m.add_feature.preset.coastline() # add coastlines to the map
- ``crs`` represents the projection used for plotting
- ``layer`` represents the name of the layer associated with the Maps-object (see below)
Expand Down Expand Up @@ -44,8 +46,7 @@ Possible ways for specifying the ``crs`` for plotting are:

Maps
Maps.CRS


Maps.set_extent


▤ Layers
Expand Down Expand Up @@ -424,6 +425,7 @@ Possible shapes that can be used to quickly generate a plot for extremely large


.. code-block:: python
:name: test_set_shape
from eomaps import Maps
data, x, y = [.3,.64,.2,.5,1], [1,2,3,4,5], [2,5,3,7,5]
Expand Down Expand Up @@ -557,6 +559,7 @@ By default, the plot-extent of the axis is adjusted to the extent of the data **
To always keep the extent as-is, use ``m.plot_map(set_extent=False)``.

.. code-block:: python
:name: test_plot_data
from eomaps import Maps
m = Maps()
Expand Down Expand Up @@ -597,6 +600,7 @@ To adjust the margins of the subplots, use ``m.subplots_adjust()``, ``m.f.tight_
have a look at the :ref:`layout_editor`!

.. code-block:: python
:name: test_subplots_adjust
from eomaps import Maps
m = Maps()
Expand Down Expand Up @@ -680,6 +684,7 @@ To apply a uniform color to all datapoints, you can use `matpltolib's named colo
- ``m.plot_map(fc=(1, 0, 0.2, 0.5))``

.. code-block:: python
:name: test_uniform_colors
from eomaps import Maps
Expand Down Expand Up @@ -716,6 +721,7 @@ Explicit colors
To explicitly color each datapoint with a pre-defined color, simply provide a list or array of the aforementioned types.

.. code-block:: python
:name: test_explicit_colors
from eomaps import Maps
Expand Down Expand Up @@ -766,6 +772,7 @@ You can fix individual color channels by passing a list with 1 element, e.g.:
- ``m.plot_map(fc=(<R-array>, [0.12345], <B-array>, <A-array>))``

.. code-block:: python
:name: test_rgba_composites
from eomaps import Maps
import numpy as np
Expand Down Expand Up @@ -840,7 +847,8 @@ To position the map in a (virtual) grid, one of the following options are possib

+----------------------------------------------------+------------------------------------+
| .. code-block:: python | .. image:: _static/grids/grid1.png |
| | :align: center |
| :name: test_gridpos_1 | :align: center |
| | |
| from eomaps import Maps | |
| # ----- initialize a figure with an EOmaps map | |
| # position = item 1 of a 2x1 grid | |
Expand All @@ -854,7 +862,8 @@ To position the map in a (virtual) grid, one of the following options are possib

+----------------------------------------------------+------------------------------------+
| .. code-block:: python | .. image:: _static/grids/grid2.png |
| | :align: center |
| :name: test_gridpos_2 | :align: center |
| | |
| from eomaps import Maps | |
| # ----- initialize a figure with an EOmaps map | |
| # position = item 1 of a 2x2 grid | |
Expand All @@ -871,7 +880,8 @@ To position the map in a (virtual) grid, one of the following options are possib

+----------------------------------------------------+------------------------------------+
| .. code-block:: python | .. image:: _static/grids/grid3.png |
| | :align: center |
| :name: test_gridpos_3 | :align: center |
| | |
| from eomaps import Maps | |
| # ----- initialize a figure with an EOmaps map | |
| # position = span 2 rows of a 3x1 grid | |
Expand All @@ -890,7 +900,8 @@ To position the map in a (virtual) grid, one of the following options are possib

+----------------------------------------------------+------------------------------------+
| .. code-block:: python | .. image:: _static/grids/grid4.png |
| | :align: center |
| :name: test_gridpos_4 | :align: center |
| | |
| from eomaps import Maps | |
| # ----- initialize a figure with an EOmaps map | |
| m = Maps(ax=211) | |
Expand All @@ -902,7 +913,8 @@ To position the map in a (virtual) grid, one of the following options are possib

+----------------------------------------------------+------------------------------------+
| .. code-block:: python | .. image:: _static/grids/grid5.png |
| | :align: center |
| :name: test_gridpos_5 | :align: center |
| | |
| from eomaps import Maps | |
| # ----- initialize a figure with an EOmaps map | |
| m = Maps(ax=221) | |
Expand All @@ -920,7 +932,8 @@ To position the map in a (virtual) grid, one of the following options are possib

+----------------------------------------------+------------------------------------+
| .. code-block:: python | .. image:: _static/grids/grid6.png |
| | :align: center |
| :name: test_gridpos_6 | :align: center |
| | |
| from matplotlib.gridspec import GridSpec | |
| from eomaps import Maps | |
| | |
Expand Down Expand Up @@ -1921,6 +1934,7 @@ If you want to get a ``geopandas.GeoDataFrame`` containing all shapes and metada
(Have a look at :ref:`geodataframe` on how to add the obtained ``GeoDataFrame`` to the map)

.. code-block:: python
:name: test_get_gdf
from eomaps import Maps
m = Maps()
Expand Down Expand Up @@ -2467,8 +2481,14 @@ To label the colorbar with custom names for a given set of bins, use ``m.colorba
🌠 Using the colorbar as a "dynamic shade indicator"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you use ``shade_raster`` or ``shade_points`` as plot-shape, the colorbar can be used to indicate the
distribution of the shaded pixels within the current field of view by setting ``dynamic_shade_indicator=True``.

.. note::

This will only work if you use ``m.set_shape.shade_raster()`` or ``m.set_shape.shade_points()`` as plot-shape!


For shade shapes, the colorbar can be used to indicate the distribution of the shaded
pixels within the current field of view by setting ``dynamic_shade_indicator=True``.

+--------------------------------------------------------------------+--------------------------------------------------+
| .. code-block:: python | .. image:: _static/minigifs/dynamic_colorbar.gif |
Expand Down Expand Up @@ -3029,7 +3049,7 @@ Similar to ``Maps.from_file``, a new layer based on a file can be added to an ex

.. code-block:: python
m = Maps8()
m = Maps()
m.add_feature.preset.coastline()
m2 = m.new_layer_from_file(
Expand Down
21 changes: 10 additions & 11 deletions eomaps/_cb_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,18 @@ def _objs(self):
for m in [*self._m.parent._children, self._m.parent]:
# always execute keypress callbacks irrespective of the mouse-pos
obj = self._getobj(m)
if obj is not None:

# only include objects that are on the same layer
if obj is not None and self._execute_cb(obj._m.layer):
objs.append(obj)
else:
for m in [*self._m.parent._children, self._m.parent]:
# don't use "is" in here since Maps-children are proxies
# (and so are their attributes)!
if event.inaxes == m.ax:
obj = self._getobj(m)
if obj is not None:
# only include objects that are on the same layer
if obj is not None and self._execute_cb(obj._m.layer):
objs.append(obj)
return objs

Expand Down Expand Up @@ -1377,6 +1380,11 @@ def _onpick(self, event):
) and self._m.f.canvas.toolbar.mode != "":
return

# make sure temporary artists are cleared before executing new callbacks
# to avoid having old artists around when callbacks are triggered again
self._clear_temporary_artists()
self._m.BM._clear_temp_artists(self._method)

clickdict = self._get_pickdict(event)

if event.mouseevent.dblclick:
Expand Down Expand Up @@ -1440,22 +1448,14 @@ def pickcb(event):
if not self._artist is event.artist:
return

# make sure temporary artists are cleared before executing new callbacks
# to avoid having old artists around when callbacks are triggered again
self._m.BM._clear_temp_artists(self._method)

self._event = event
self._clear_temporary_artists()
# self._m.BM._clear_temp_artists(self._method)

# execute "_onpick" on the maps-object that belongs to the clicked axes
# and forward the event to all forwarded maps-objects
self._onpick(event)
# forward callbacks to the connected maps-objects
self._fwd_cb(event, self._picker_name)

self._m.BM._after_update_actions.append(self._clear_temporary_artists)
self._m.BM._clear_temp_artists(self._method)
# don't update here... the click-callback will take care of it!
except ReferenceError:
pass
Expand All @@ -1472,7 +1472,6 @@ def _fwd_cb(self, event, picker_name):
return
for key, m in self._fwd_cbs.items():
obj = self._getobj(m)
obj._clear_temporary_artists()
if obj is None:
continue

Expand Down
39 changes: 4 additions & 35 deletions eomaps/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def set_props(

# estimate the radius (used as margin on data selection)
try:
self._r = self.m._shapes._estimate_radius(self.m, "out")
self._r = self.m._shapes._estimate_radius(
self.m, radius_crs="out", method=np.nanmax
)
if self._r is not None and all(np.isfinite(i) for i in self._r):
self._radius_margin = [i * self._radius_margin_factor for i in self._r]
else:
Expand Down Expand Up @@ -283,7 +285,7 @@ def _set_cpos(self, x, y, radiusx, radiusy, cpos):

@property
def current_extent(self):
return self.m.ax.get_extent(self.m.ax.projection)
return self.m.get_extent(self.m.ax.projection)

@property
def extent_changed(self):
Expand Down Expand Up @@ -434,10 +436,8 @@ def on_fetch_bg(self, layer=None, bbox=None, check_redraw=True):
# fail-fast in case the data is completely outside the extent
return

# update the number of immediate points calculated for plot-shapes
s = self._get_datasize(props)
self._print_datasize_warnings(s)
self._set_n(s)

# stop here in case we are dealing with a pick-only dataset
if self._only_pick:
Expand Down Expand Up @@ -635,37 +635,6 @@ def get_props(self, *args, **kwargs):
def _get_datasize(self, props):
return np.size(props["z_data"])

def _set_n(self, s):
shape = self.m.shape

# in case an explicit n is provided, keep using it!
if getattr(shape, "_n", None) is not None:
return shape._n

if shape.name == "rectangles":
# mesh currently onls supports n=1
if shape.mesh is True:
shape.n = 1
return
# if plot crs is same as input-crs there is no need for
# intermediate points since the rectangles are not curved!
if self.m._crs_plot == self.m.data_specs.crs:
shape.n = 1
return

if s < 10:
n = 100
elif s < 100:
n = 75
elif s < 1000:
n = 50
elif s < 10000:
n = 20
else:
n = 12

shape.n = n

def _print_datasize_warnings(self, s):
if s < 1e5:
return
Expand Down
Loading

0 comments on commit ebc8de7

Please sign in to comment.