{ "cells": [ { "cell_type": "markdown", "id": "81931b00", "metadata": { "tags": [] }, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "id": "f98abedb", "metadata": { "tags": [] }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "from __future__ import annotations" ] }, { "cell_type": "code", "execution_count": null, "id": "1322ccdf", "metadata": { "tags": [] }, "outputs": [], "source": [ "# debug\n", "import sys\n", "\n", "print(sys.executable)\n", "print(sys.version_info)" ] }, { "cell_type": "code", "execution_count": null, "id": "4302062f", "metadata": { "tags": [] }, "outputs": [], "source": [ "# main imports\n", "import holoviews as hv\n", "import numpy as np\n", "import pandas as pd\n", "import xarray as xr\n", "\n", "hv.extension(\"bokeh\")" ] }, { "cell_type": "markdown", "id": "dc0e2d11", "metadata": { "tags": [] }, "source": [ "## Open a dataset\n", "\n", "Thalassa supports the output of several solvers (e.g. Schism, ADCIRC). \n", "In order to do so, it converts the output of these files to a common \"schema\".\n", "This process is called \"normalization\".\n", "\n", "> \"normalization\" == Renaming of dimensions and variables\n", "\n", "The most convenient way to apply this normalization process is to use the `api.open_dataset()` function which is a wrapper around `xr.open_dataset()`." ] }, { "cell_type": "code", "execution_count": null, "id": "ff903d5f", "metadata": { "tags": [] }, "outputs": [], "source": [ "from thalassa import api\n", "\n", "api.open_dataset?" ] }, { "cell_type": "code", "execution_count": null, "id": "d5178d63", "metadata": { "tags": [] }, "outputs": [], "source": [ "filename = \"../tests/data/fort.63.nc\"\n", "ds = api.open_dataset(filename)\n", "ds" ] }, { "cell_type": "markdown", "id": "bf6c402a", "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": "03d18c80", "metadata": { "tags": [] }, "outputs": [], "source": [ "#variable, layer, timestamp = \"salt\", 40, \n", "#variable, layer, timestamp = \"depth\", None, None\n", "variable, layer, timestamp = \"zeta\", None, ds.time.values[4]\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.sel(time=timestamp), variable=variable)\n", "\n", "# The wireframe is the representation of the mesh\n", "wireframe = api.get_wireframe(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)\n", "tap_dmap = api.get_tap_timeseries(ds=ds, variable=variable, source_raster=raster)" ] }, { "cell_type": "markdown", "id": "d408e8dc", "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": "61d335a4", "metadata": { "tags": [] }, "outputs": [], "source": [ "raster_layout = tiles * raster.opts(width=600, cmap=\"viridis\") \n", "raster_layout" ] }, { "cell_type": "code", "execution_count": null, "id": "cd80deda", "metadata": { "tags": [] }, "outputs": [], "source": [ "import warnings\n", "\n", "with warnings.catch_warnings():\n", " warnings.simplefilter(\"ignore\")\n", " \n", " tap_dmap" ] }, { "cell_type": "code", "execution_count": null, "id": "7d0e9454", "metadata": { "tags": [] }, "outputs": [], "source": [ "mesh_layout = tiles * wireframe.opts(width=600)\n", "mesh_layout" ] } ], "metadata": { "kernelspec": { "display_name": "thalassa", "language": "python", "name": "python3" }, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }