-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notebooks: Add notebooks/API.ipynb + fix some minor issues in BBox_Fi…
…ltering.
- Loading branch information
Showing
2 changed files
with
207 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f3e4d71b-357e-45e2-aa3e-9e89b1b662ab", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2\n", | ||
"\n", | ||
"from __future__ import annotations" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "15c46224-c0c6-4c7c-8c4b-fd1a0580398a", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"os.environ['USE_PYGEOS'] = '0' # remove geopandas warnings\n", | ||
"\n", | ||
"import holoviews as hv\n", | ||
"import numpy as np\n", | ||
"import numpy_indexed as npi\n", | ||
"import pandas as pd\n", | ||
"import xarray as xr\n", | ||
"\n", | ||
"hv.extension(\"bokeh\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1779d199-055f-47f6-a296-f823cec4329c", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%bash\n", | ||
"pushd /tmp\n", | ||
"wget --quiet https://github.com/ec-jrc/Thalassa/files/10867068/fort.63.zip \n", | ||
"unzip -o fort.63.zip\n", | ||
"popd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "73965237-0675-49d1-ae01-e45a67bd77d4", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from thalassa import api\n", | ||
"\n", | ||
"filename = \"/tmp/fort.63.nc\"\n", | ||
"ds = api.open_dataset(filename)\n", | ||
"ds" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d2957b88-7e35-47c4-be69-fc510b809572", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Main API\n", | ||
"\n", | ||
"`thalassa` supports several types of graphs, including:\n", | ||
" \n", | ||
"- A visualization of the variables at various timestamps and or layers.\n", | ||
"- A visualization of the mesh\n", | ||
"- Extraction of timeseries from specific points\n", | ||
"\n", | ||
"The following cell shows the basic usage:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f63f4df8-7160-47cd-b40b-322751b60e75", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#variable, layer, timestamp = \"salt\", 40, ds.time.values[4]\n", | ||
"#variable, layer, timestamp = \"depth\", None, None\n", | ||
"variable, layer, timestamp = \"zeta\", None, \"max\"\n", | ||
"\n", | ||
"# The trimesh is the most basic object. This is what you need to create all the others graphs\n", | ||
"# It is on this object that you specify the timestamp and/or the layer.\n", | ||
"trimesh = api.create_trimesh(ds=ds, variable=variable, timestamp=timestamp, layer=layer)\n", | ||
"\n", | ||
"# The wireframe is the representation of the mesh\n", | ||
"wireframe = api.get_wireframe(trimesh=trimesh)\n", | ||
"\n", | ||
"# The tiles is using the tiling service from Open Street maps\n", | ||
"tiles = api.get_tiles() \n", | ||
"\n", | ||
"# The raster object is the basic Map that visualizes the variable. \n", | ||
"# You can specify things like the colorbar limits and/or the extents\n", | ||
"#raster = api.get_raster(trimesh, clim_min=0, clim_max=15)\n", | ||
"raster = api.get_raster(trimesh)\n", | ||
"\n", | ||
"# The pointer/tap timeseries extract the timeseries of a specific node from the xr.Dataset and visualize it.\n", | ||
"pointer_dmap = api.get_pointer_timeseries(ds=ds, variable=variable, source_raster=raster, layer=layer)\n", | ||
"tap_dmap = api.get_tap_timeseries(ds=ds, variable=variable, source_raster=raster, layer=layer)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c1d58fec-9a9a-45c5-b408-780b9bdd01ed", | ||
"metadata": {}, | ||
"source": [ | ||
"### Let's visualize!\n", | ||
"\n", | ||
"After you render the layout, move the mouse over the map and click on it. This will fill in the `pointer_dmap` and the `tap_dmap`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f42fc4d5-37ff-4195-8cb2-03986c2bcfaa", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"layout = tiles * raster.opts(width=600, cmap=\"viridis\") \n", | ||
"layout\n", | ||
"(pointer_dmap + tap_dmap).opts(shared_axes=False)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "thalassa2", | ||
"language": "python", | ||
"name": "thalassa2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters