%load_ext autoreload
%autoreload 2
from __future__ import annotations
# debug
import sys
print(sys.executable)
print(sys.version_info)
# main imports
import holoviews as hv
import numpy as np
import pandas as pd
import xarray as xr
hv.extension("bokeh")
Thalassa supports the output of several solvers (e.g. Schism, ADCIRC). In order to do so, it converts the output of these files to a common "schema". This process is called "normalization".
"normalization" == Renaming of dimensions and variables
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()
.
from thalassa import api
api.open_dataset?
filename = "../tests/data/fort.63.nc"
ds = api.open_dataset(filename)
ds
thalassa
supports several types of graphs, including:
The following cell shows the basic usage:
#variable, layer, timestamp = "salt", 40,
#variable, layer, timestamp = "depth", None, None
variable, layer, timestamp = "zeta", None, ds.time.values[4]
# The trimesh is the most basic object. This is what you need to create all the others graphs
# It is on this object that you specify the timestamp and/or the layer.
trimesh = api.create_trimesh(ds.sel(time=timestamp), variable=variable)
# The wireframe is the representation of the mesh
wireframe = api.get_wireframe(trimesh)
# The tiles is using the tiling service from Open Street maps
tiles = api.get_tiles()
# The raster object is the basic Map that visualizes the variable.
# You can specify things like the colorbar limits and/or the extents
#raster = api.get_raster(trimesh, clim_min=0, clim_max=15)
raster = api.get_raster(trimesh)
# The pointer/tap timeseries extract the timeseries of a specific node from the xr.Dataset and visualize it.
pointer_dmap = api.get_pointer_timeseries(ds=ds, variable=variable, source_raster=raster)
tap_dmap = api.get_tap_timeseries(ds=ds, variable=variable, source_raster=raster)
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
.
raster_layout = tiles * raster.opts(width=600, cmap="viridis")
raster_layout
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
tap_dmap
mesh_layout = tiles * wireframe.opts(width=600)
mesh_layout