Skip to content

Commit

Permalink
grass.jupyter: add SeriesMap and tests (OSGeo#3036)
Browse files Browse the repository at this point in the history
SeriesMap creates a ipywidgets Slider for scrolling between a list of rasters and/or vectors.
  • Loading branch information
chaedri authored Nov 30, 2023
1 parent 9f0d838 commit 731cab3
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 32 deletions.
3 changes: 2 additions & 1 deletion python/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ disable=raw-checker-failed,
file-ignored,
suppressed-message,
deprecated-pragma,
use-symbolic-message-instead
use-symbolic-message-instead,
duplicate-code

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
1 change: 1 addition & 0 deletions python/grass/jupyter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MODULES = \
interactivemap \
region \
map3d \
seriesmap \
reprojection_renderer \
utils \
timeseriesmap
Expand Down
1 change: 1 addition & 0 deletions python/grass/jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@
from .map3d import Map3D
from .setup import init
from .timeseriesmap import TimeSeriesMap
from .seriesmap import SeriesMap
72 changes: 72 additions & 0 deletions python/grass/jupyter/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,78 @@ def set_region_from_command(self, module, **kwargs):
return


class RegionManagerForSeries:
"""Region manager for SeriesMap"""

def __init__(self, use_region, saved_region, width, height, env):
"""Manages region during rendering.
:param use_region: if True, use either current or provided saved region,
else derive region from rendered layers
:param saved_region: if name of saved_region is provided,
this region is then used for rendering
:param width: rendering width
:param height: rendering height
:param env: environment for rendering
"""
self._env = env
self._width = width
self._height = height
self._use_region = use_region
self._saved_region = saved_region
self._extent_set = False
self._resolution_set = False

def set_region_from_rasters(self, rasters):
"""Sets computational region for rendering from a series of rasters.
This function sets the region from a series of rasters. If the extent or
resolution has already been set by calling this function previously or by the
set_region_from vectors() function, this function will not modify it.
If user specified the name of saved region during object's initialization,
the provided region is used. If it's not specified
and use_region=True, current region is used.
"""
if self._saved_region:
self._env["GRASS_REGION"] = gs.region_env(
region=self._saved_region, env=self._env
)
return
if self._use_region:
# use current
return
if self._resolution_set and self._extent_set:
return
if not self._resolution_set and not self._extent_set:
self._env["GRASS_REGION"] = gs.region_env(raster=rasters, env=self._env)
self._extent_set = True
self._resolution_set = True
elif not self._resolution_set:
self._env["GRASS_REGION"] = gs.region_env(align=rasters[0], env=self._env)
self._resolution_set = True

def set_region_from_vectors(self, vectors):
"""Sets computational region extent for rendering from a series of vectors
If the extent and resolution has already been set by set_region_from_rasters,
or by using the saved_region or use_region arguments, the region is not modified
"""
if self._saved_region:
self._env["GRASS_REGION"] = gs.region_env(
region=self._saved_region, env=self._env
)
return
if self._use_region:
# use current
return
if self._resolution_set and self._extent_set:
return
if not self._resolution_set and not self._extent_set:
self._env["GRASS_REGION"] = gs.region_env(vector=vectors, env=self._env)
self._extent_set = True


class RegionManagerFor3D:
"""Region manager for 3D displays (gets region from m.nviz.image command)"""

Expand Down
Loading

0 comments on commit 731cab3

Please sign in to comment.