From 58b2d7e47db5d80f3f6714f8e6746892514d0956 Mon Sep 17 00:00:00 2001 From: Abhishek Yenpure Date: Mon, 6 Jan 2025 13:53:36 -0800 Subject: [PATCH] fix (explorer consistency): Making explorer name and constructor arguments consistent --- pan3d/explorers/globe.py | 4 ++-- pan3d/explorers/slicer.py | 26 ++++++++++++++++++++++---- pan3d/xarray/accessor.py | 10 +++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/pan3d/explorers/globe.py b/pan3d/explorers/globe.py index 2ab0842..8ba7c14 100644 --- a/pan3d/explorers/globe.py +++ b/pan3d/explorers/globe.py @@ -42,7 +42,7 @@ @TrameApp() -class GlobeViewer: +class GlobeExplorer: """ A Trame based pan3D explorer to visualize 3D geographic data projected onto a globe representing the earth or projected using various cartographic projections. @@ -591,7 +591,7 @@ def _ipython_display_(self): def main(): - app = GlobeViewer() + app = GlobeExplorer() app.start() diff --git a/pan3d/explorers/slicer.py b/pan3d/explorers/slicer.py index 141e42e..c6113ca 100644 --- a/pan3d/explorers/slicer.py +++ b/pan3d/explorers/slicer.py @@ -45,7 +45,7 @@ @TrameApp() -class XArraySlicer: +class SliceExplorer: """ A Trame based pan3D explorer to visualize 3D using slices along different dimensions @@ -54,7 +54,7 @@ class XArraySlicer: using VTK while interacting with the slice in 2D or 3D. """ - def __init__(self, xarray=None, source=None, server=None): + def __init__(self, xarray=None, source=None, server=None, local_rendering=None): # trame setup self.server = get_server(server) if self.server.hot_reload: @@ -67,9 +67,26 @@ def __init__(self, xarray=None, source=None, server=None): help="Pass a string with this argument to specify a startup configuration. This value must be a local path to a JSON file which adheres to the schema specified in the [Configuration Files documentation](../api/configuration.md).", required=(source is None and xarray is None), ) - args, _ = parser.parse_known_args() + # Local rendering setup + parser.add_argument( + "--wasm", + help="Use WASM for local rendering", + action="store_true", + ) + parser.add_argument( + "--vtkjs", + help="Use vtk.js for local rendering", + action="store_true", + ) + args, _ = parser.parse_known_args() + self.local_rendering = local_rendering + if args.wasm: + self.local_rendering = "wasm" + if args.vtkjs: + self.local_rendering = "vtkjs" # Check if we have what we need + config_file = Path(args.import_state) if args.import_state else None if ( (config_file is None or not config_file.exists()) @@ -703,6 +720,7 @@ def _build_ui(self, *args, **kwargs): # 3D view Pan3DView( self.render_window, + local_rendering=self.local_rendering, axis_names="slice_axes", style="position: absolute; left: 0; top: var(--v-layout-top); bottom: var(--v-layout-bottom); z-index: 0; width: 100%;", ) @@ -801,7 +819,7 @@ def _ipython_display_(self): def main(): - app = XArraySlicer() + app = SliceExplorer() app.start() diff --git a/pan3d/xarray/accessor.py b/pan3d/xarray/accessor.py index c3612fe..dec1c75 100644 --- a/pan3d/xarray/accessor.py +++ b/pan3d/xarray/accessor.py @@ -62,23 +62,23 @@ def preview(self): @property def slicer(self): - from pan3d.explorers.slicer import XArraySlicer + from pan3d.explorers.slicer import SliceExplorer if self._viewer_slicer is None: - self._viewer_slicer = XArraySlicer( + self._viewer_slicer = SliceExplorer( xarray=self.xarray, server=self.next_id(), - # local_rendering=self._local_rendering, # FIXME Abhishek + local_rendering=self._local_rendering, ) return self._viewer_slicer @property def globe(self): - from pan3d.explorers.globe import GlobeViewer + from pan3d.explorers.globe import GlobeExplorer if self._viewer_globe is None: - self._viewer_globe = GlobeViewer( + self._viewer_globe = GlobeExplorer( xarray=self.xarray, server=self.next_id(), local_rendering=self._local_rendering,