diff --git a/src/e3sm_quickview/app.py b/src/e3sm_quickview/app.py index e8873a6..0cbe313 100644 --- a/src/e3sm_quickview/app.py +++ b/src/e3sm_quickview/app.py @@ -674,16 +674,14 @@ async def _on_projection(self, projection, **_): @change("spherical_center_lat", "spherical_center_lon", "projection") def _on_center(self, spherical_center_lat, spherical_center_lon, projection, **_): - if projection == ["Spherical"]: - if self.state.longitude_origin != -180: - self.state.longitude_origin = -180 + self.state.longitude_origin = (spherical_center_lon + 360) % 360 - 180 + if projection == ["Spherical"]: self.source.Clip(self.view_manager._clip_plane) self.view_manager.center_camera( float(spherical_center_lat), float(spherical_center_lon) ) else: - self.state.longitude_origin = (spherical_center_lon + 360) % 360 - 180 self.source.Clip() self.view_manager.camera_projection() @@ -693,6 +691,11 @@ def _on_grid_spacing(self, grid_interval, **_): # self.view_manager.reset_camera() self.view_manager.render() + @change("continent_level") + def _on_continent_res(self, continent_level, **_): + self.source.continent.update_resolution(continent_level) + self.view_manager.render() + def _on_slicing_change(self, var, ind_var, **_): with perf.timed(f"tick.{var}={self.state[ind_var]}.total"): with perf.timed("tick.pipeline"): diff --git a/src/e3sm_quickview/components/tools.py b/src/e3sm_quickview/components/tools.py index 0c1bbde..2d29b78 100644 --- a/src/e3sm_quickview/components/tools.py +++ b/src/e3sm_quickview/components/tools.py @@ -3,6 +3,7 @@ from trame.app import asynchronous from trame.decorators import trigger from trame.widgets import vuetify3 as v3 +from trame.widgets import html from e3sm_quickview import __version__ as quickview_version from e3sm_quickview.assets import ASSETS @@ -253,6 +254,7 @@ def __init__(self, compact="compact_drawer", title="Map Projection"): v_model=("grid_interval", 30), border=True, divided=True, + mandatory=True, ): v3.VBtn("1°", value=[1]) v3.VBtn("2°", value=[2]) @@ -261,6 +263,21 @@ def __init__(self, compact="compact_drawer", title="Map Projection"): v3.VBtn("15°", value=[15]) v3.VBtn("30°", value=[30]) + v3.VDivider(classes="mt-2") + with v3.VListItem(title="Continent resolution"): + with html.Div(classes="d-flex justify-center"): + with v3.VBtnToggle( + v_model=("continent_level", 0), + border=True, + divided=True, + mandatory=True, + ): + v3.VBtn("Low", value=[0], classes="text-none") + v3.VBtn( + "Medium", value=[1], classes="text-none" + ) + v3.VBtn("Large", value=[2], classes="text-none") + @property def options(self): return [ diff --git a/src/e3sm_quickview/data/coastlines.vtp b/src/e3sm_quickview/data/coastlines-high.vtp similarity index 100% rename from src/e3sm_quickview/data/coastlines.vtp rename to src/e3sm_quickview/data/coastlines-high.vtp diff --git a/src/e3sm_quickview/data/coastlines-low.vtp b/src/e3sm_quickview/data/coastlines-low.vtp new file mode 100644 index 0000000..4ac45fd Binary files /dev/null and b/src/e3sm_quickview/data/coastlines-low.vtp differ diff --git a/src/e3sm_quickview/data/coastlines-med.vtp b/src/e3sm_quickview/data/coastlines-med.vtp new file mode 100644 index 0000000..c8107f2 Binary files /dev/null and b/src/e3sm_quickview/data/coastlines-med.vtp differ diff --git a/src/e3sm_quickview/pipeline.py b/src/e3sm_quickview/pipeline.py index d2e8c60..abc7923 100644 --- a/src/e3sm_quickview/pipeline.py +++ b/src/e3sm_quickview/pipeline.py @@ -51,11 +51,16 @@ def clear(self): self.error_occurred = False +DATA_DIR = Path(__file__).with_name("data").resolve() +CONTINENT_SMALL = str(DATA_DIR / "coastlines-low.vtp") +CONTINENT_MEDIUM = str(DATA_DIR / "coastlines-med.vtp") +CONTINENT_LARGE = str(DATA_DIR / "coastlines-high.vtp") + + class Continent: def __init__(self, projection="Mollweide"): self._projection = projection - input_file = Path(__file__).with_name("data") / "coastlines.vtp" - self.reader = simple.XMLPolyDataReader(FileName=[str(input_file.resolve())]) + self.reader = simple.XMLPolyDataReader(FileName=[CONTINENT_SMALL]) self._crop = simple.EAMTransformAndExtract( Input=self.reader, LongitudeRange=[-180.0, 180.0], @@ -88,6 +93,12 @@ def crop(self, longitude_min_max, latitude_min_max): def longitude_origin(self): return self._longitude_origin + def update_resolution(self, level=0): + level = max(min(int(level), 2), 0) + file = [CONTINENT_SMALL, CONTINENT_MEDIUM, CONTINENT_LARGE][level] + self.reader.FileName = (file,) + self.geometry.UpdatePipeline() + @longitude_origin.setter def longitude_origin(self, origin): self._longitude_origin = origin