Skip to content

Commit

Permalink
Merge pull request #141 from Kitware/update-examples
Browse files Browse the repository at this point in the history
Update examples
  • Loading branch information
jourdain authored Nov 22, 2024
2 parents c933453 + 12ab9c4 commit fd92567
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 11 deletions.
53 changes: 50 additions & 3 deletions examples/example_config_esgf.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,59 @@
{
"data_origin": {
"source": "esgf",
"id": "CMIP6.PAMIP.MOHC.HadGEM3-GC31-MM.pdSST-futAntSIC.r102i1p1f2.day.sfcWind.gn.v20210311|eagle.alcf.anl.gov"
"id": "CMIP6.PAMIP.MOHC.HadGEM3-GC31-MM.pdSST-futAntSIC.r102i1p1f2.day.sfcWind.gn.v20210311|eagle.alcf.anl.gov",
"order": "C"
},
"dataset_config": {
"arrays": ["sfcWind"]
"x": "lon",
"y": "lat",
"z": null,
"t": "time",
"slices": {
"time": 355,
"lon": [
0,
432,
1
],
"lat": [
0,
324,
1
]
},
"t_index": 1,
"arrays": [
"sfcWind"
]
},
"preview": {
"color_by": "sfcWind"
"view_3d": true,
"color_by": "sfcWind",
"color_preset": "Cool to Warm",
"color_min": 0.19989013671875,
"color_max": 21.98614501953125,
"scale_x": 1,
"scale_y": 1,
"scale_z": 1
},
"camera": {
"position": [
179.9999898225069,
7.62939453125e-06,
775.6354152568821
],
"view_up": [
0.0,
1.0,
0.0
],
"focal_point": [
179.9999898225069,
7.62939453125e-06,
0.0
],
"parallel_projection": 0,
"parallel_scale": 200.74921752448336
}
}
58 changes: 55 additions & 3 deletions examples/example_config_pangeo.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
{
"data_origin": {
"source": "pangeo",
"id": "MITgcm_channel_flatbottom_02km_run01_phys_snap15D"
"id": "MITgcm_channel_flatbottom_02km_run01_phys_snap15D",
"order": "C"
},
"dataset_config": {
"arrays": ["T"]
"x": "XC",
"y": "YC",
"z": "Z",
"t": "time",
"slices": {
"time": 7,
"XC": [
0,
500,
1
],
"YC": [
0,
1000,
1
],
"Z": [
0,
76,
1
]
},
"t_index": 7,
"arrays": [
"T"
]
},
"preview": {
"color_by": "T"
"view_3d": true,
"color_by": "T",
"color_preset": "Cool to Warm",
"color_min": -0.5137946009635925,
"color_max": 7.957241058349609,
"scale_x": 1,
"scale_y": 1,
"scale_z": "200"
},
"camera": {
"position": [
3074329.439833259,
3574329.439833259,
2283012.935927009
],
"view_up": [
0.0,
0.0,
1.0
],
"focal_point": [
500000.0,
1000000.0,
-291316.50390625
],
"parallel_projection": 0,
"parallel_scale": 1154040.3165173125
}
}
44 changes: 42 additions & 2 deletions examples/jupyter/import_config_esgf.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3c5ed231-0166-4181-ad69-630f32eb9af5",
"metadata": {},
"source": [
"# Example: Climate model data (ESGF host)\n",
"\n",
"This dataset contains a model of near-surface wind speed computed on a daily basis for a 14 month\n",
"period from April 2000 through May 2001. The data is from the Coupled Model Intercomparison Project Phase 6\n",
"(CMIP6) and is hosted by the Earth System Grid Federation (ESGF).\n",
"\n",
"To setup your environment:\n",
"\n",
"```\n",
"> pip install pan3d[viewer,esgf]\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -37,7 +55,9 @@
"id": "84d23d39-2fad-4495-8701-b8fe69170639",
"metadata": {},
"source": [
"## Load dataset"
"## Load dataset - and please be patient!\n",
"\n",
"When you run the next code cell, it will load one time step and build the coordinates and data for that time step. Download times have been observed to take over 10 seconds, so after running the next code cell, check the kernel state in the status bar at the bottom of the notebook and wait for it to go from \"Busy\" to \"Idle\"."
]
},
{
Expand All @@ -56,7 +76,9 @@
"id": "4a15f7d2-faea-4aba-b4bc-653ac39e155f",
"metadata": {},
"source": [
"## Show UI"
"## Start the Viewer\n",
"\n",
"Run the next cell to open the pan3d viewer. In the \"Xarray Viewer\" panel, you can open the \"Rendering\" subpanel and update the time slider to load and view different days in the 14 month range. (To move 1 day at a time, click on the slider then use the left and right arrow keys.)"
]
},
{
Expand All @@ -68,6 +90,24 @@
"source": [
"viewer.ui"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42f73ae2-6f68-4cd0-942e-72d0a390223d",
"metadata": {},
"outputs": [],
"source": [
"viewer.source._input"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7c7d279-ef3b-4689-8400-e016378c3177",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
44 changes: 42 additions & 2 deletions examples/jupyter/import_config_pangeo.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c7a6e13f-537c-4c4c-90dd-c2bff2383ed2",
"metadata": {},
"source": [
"# Example: MITgcm Channel Simulation (Pangeo host)\n",
"\n",
"This dataset was produced from the MTI General Circulation Model (MITgcm), a numerical model combining both atmospheric and ocean physics. This particular dataset is a simulation of a flat bottom channel at 2km resolution with time snapshots every 15 days over the course of a year. The xyz coordinates are 500 x 1000 x 76 and the computed variables are temperature, pressure, and 3 components of velocity.\n",
"\n",
"The dataset is hosted on Pangeo at https://catalog.pangeo.io/browse/master/ocean/channel/MITgcm_channel_flatbottom_02km_run01_phys_snap15D/.\n",
"\n",
"To setup your environment:\n",
"\n",
"```\n",
"> pip install pan3d[viewer,pangeo]\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -37,7 +55,9 @@
"id": "7d9d844d-09bd-4727-a006-a616c2c459a3",
"metadata": {},
"source": [
"## Load dataset"
"## Load dataset - and please be patient!\n",
"\n",
"The configuration file is set set to read temperature data. When you run the next cell, it will load one time step and build a 152 MB array for the temperature at that time step. Download times for one time step have been observed on the order of 1 minute. (You can increase the download speed by using a Cloud Billing account to pay egress fees. See the [pangeo catalog page](https://catalog.pangeo.io/browse/master/ocean/channel/MITgcm_channel_flatbottom_02km_run01_phys_snap15D/) for more info) When you run the next cell, check the kernel state in the status bar at the bottom of the notebook and wait for it to go from \"Busy\" to \"Idle\"."
]
},
{
Expand All @@ -51,6 +71,16 @@
"viewer.import_state(config)"
]
},
{
"cell_type": "markdown",
"id": "22566858-fdee-4427-8487-b7b033a7fb65",
"metadata": {},
"source": [
"# Start the viewer\n",
"\n",
"Run the next cell to open the pan3d viewer."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -64,7 +94,17 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3efafa03-df99-4690-9ac9-2ed5920e7205",
"id": "7618fba2-798e-422c-b2ff-47d80c4b8ad0",
"metadata": {},
"outputs": [],
"source": [
"viewer.source._input"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22115863-c085-4b3e-bad0-a2573cb77b59",
"metadata": {},
"outputs": [],
"source": []
Expand Down
2 changes: 1 addition & 1 deletion pan3d/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os


def has_gpu_rendering():
def has_gpu():
# Detect known environments without gpu rendering
target_env_vars = ["BINDER_REQUEST"]
return not any(os.environ.get(k) for k in target_env_vars)
Expand Down
10 changes: 10 additions & 0 deletions pan3d/viewers/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

from trame.ui.vuetify3 import VAppLayout
from trame.widgets import vuetify3 as v3
from trame.widgets import vtk as vtkw, vtklocal as vtkwasm

from pan3d.xarray.algorithm import vtkXArrayRectilinearSource

from pan3d.utils.constants import has_gpu
from pan3d.utils.convert import update_camera, to_image, to_float
from pan3d.utils.presets import apply_preset

Expand Down Expand Up @@ -90,6 +92,14 @@ def __init__(self, server=None, local_rendering=None):
if args.vtkjs:
self.local_rendering = "vtkjs"

# If no GPU, use local rendering
if self.local_rendering is None and not has_gpu():
self.local_rendering = "wasm"

# Initialize conditional widgets
vtkw.initialize(self.server)
vtkwasm.initialize(self.server)

# Process CLI
self.ctrl.on_server_ready.add(self._process_cli)

Expand Down

0 comments on commit fd92567

Please sign in to comment.