Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grass.jupyter: add SeriesMap and tests #3036

Merged
merged 26 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
270d511
add seriesmap with better code
chaedri Jun 6, 2023
be429ca
Merge branch 'main' of https://github.com/OSGeo/grass into SeriesMap-…
chaedri Jun 6, 2023
4215678
add tests for seriesmap
chaedri Jun 6, 2023
36ca222
fix using-layer-multiple-times bug
chaedri Jun 6, 2023
9cb45ae
fix play button
petrasovaa Aug 3, 2023
e259efb
Merge remote-tracking branch 'upstream/main' into SeriesMap-redo
Sep 8, 2023
3a51610
flake8
Sep 8, 2023
3470d3f
Add text label to SeriesMap save as GIF option
Sep 13, 2023
2466af8
remove unnecessary try-except
Sep 13, 2023
5015eb5
Fix SeriesMap tests
Sep 13, 2023
21abd46
Fix labels bug in TimeSeriesMap, reorganize duplicate code to utils.py
Sep 14, 2023
d3db4a7
pylint fixes
Sep 14, 2023
d943427
fix failing test
Sep 14, 2023
ff83dc1
move pylint disable duplicate-code
Sep 14, 2023
bee37bd
fix formatting (pylint C0209) and address pylint R0201 no-self-use
petrasovaa Oct 5, 2023
194c604
pylintrc: avoid checking duplicate code, can't be disabled locally
petrasovaa Oct 5, 2023
7b54757
Update utils.py with simpler font selection
chaedri Nov 20, 2023
517721b
Update utils.py with text_size for default font
chaedri Nov 20, 2023
07d76ac
Update utils.py, add exception for text_size with older PIL
chaedri Nov 20, 2023
cfd728b
Update utils.py with exception error type
chaedri Nov 20, 2023
4d351ad
add map_exists asserts
Nov 20, 2023
5c49974
minor fixes from PR comments
Nov 21, 2023
bfd833e
Merge branch 'main' of https://github.com/OSGeo/grass into SeriesMap-…
Nov 21, 2023
d51c86f
Update python/grass/jupyter/seriesmap.py
chaedri Nov 28, 2023
fcd93b4
Merge branch 'SeriesMap-redo' of https://github.com/chaedri/grass int…
Nov 28, 2023
456e00c
fix add_vectors bug
Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading