Reference¶
thalassa ¶
Thalassa is a library for visualizing unstructured mesh data with a focus on large scale sea level data
crop ¶
crop(ds: xr.Dataset, bbox: shapely.Polygon) -> xr.Dataset
Crop the dataset using the provided bbox
.
Examples:
import thalassa
import shapely
ds = thalassa.open_dataset("some_netcdf.nc")
bbox = shapely.box(0, 0, 1, 1)
ds = thalassa.crop(ds, bbox)
PARAMETER | DESCRIPTION |
---|---|
ds |
The dataset we want to crop.
TYPE:
|
bbox |
A Shapely polygon whose boundary will be used to crop
TYPE:
|
Source code in thalassa/utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
normalize ¶
normalize(ds: xr.Dataset) -> xr.Dataset
Normalize the dataset
i.e. convert it to the "Thalassa Schema".
Examples:
import thalassa
import xarray as xr
ds = xr.open_dataset("some_netcdf.nc")
ds = thalassa.normalize(ds)
print(ds)
PARAMETER | DESCRIPTION |
---|---|
ds |
The dataset we want to convert.
TYPE:
|
Source code in thalassa/normalization.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
open_dataset ¶
open_dataset(path: str | os.PathLike[str], normalize: bool = True, **kwargs: dict[str, typing.Any]) -> xr.Dataset
Open the file specified at path
using xarray
and return an xarray.Dataset
.
If normalize
is True
then convert the dataset to the "Thalassa schema", too.
Additional kwargs
are passed on to xarray.open_dataset()
.
Note
This function is just a wrapper around xarray.open_dataset()
. The reason we need
it is because the netcdfs files created by ADCIRC are not compatible with xarray
,
at least not when using the defaults. This function automatically detects the
problematic variables (e.g. neta
and nvel
) and drops them.
Examples:
import thalassa
ds = thalassa.open_dataset("some_netcdf.nc")
print(ds)
PARAMETER | DESCRIPTION |
---|---|
path |
The path to the dataset file (netCDF, zarr, grib)
TYPE:
|
normalize |
Boolean flag indicating whether the dataset should be converted/normalized to the "Thalassa schema".
Normalization is currently only supported for
TYPE:
|
kwargs |
The
TYPE:
|
Source code in thalassa/api.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
plot ¶
plot(ds: xr.Dataset, variable: str, bbox: shapely.Polygon | None = None, title: str = '', cmap: str = 'plasma', colorbar: bool = True, clabel: str = '', clim_min: float | None = None, clim_max: float | None = None, x_range: tuple[float, float] | None = None, y_range: tuple[float, float] | None = None, show_mesh: bool = False) -> gv.DynamicMap
Return the plot of the specified variable
.
Examples:
import thalassa
ds = thalassa.open_dataset("some_netcdf.nc")
thalassa.plot(ds, variable="zeta_max")
When we plot time dependent variables we need to filter the data
in such a way that time
is no longer a dimension.
For example to plot the map of the first timestamp of variable zeta
:
import thalassa
ds = thalassa.open_dataset("some_netcdf.nc")
thalassa.plot(ds.isel(time=0), variable="zeta")
Often, it is quite useful to limit the range of the colorbar:
import thalassa
ds = thalassa.open_dataset("some_netcdf.nc")
thalassa.plot(ds, variable="zeta", clim_min=1, clim_max=3, clabel="meter")
If we want to on-the-fly crop the dataset we can pass bbox
, too:
import shapely
import thalassa
bbox = shapely.box(0, 0, 1, 1)
ds = thalassa.open_dataset("some_netcdf.nc")
thalassa.plot(ds, variable="depth", bbox=bbox)
PARAMETER | DESCRIPTION |
---|---|
ds |
The dataset which will get visualized. It must adhere to the "thalassa schema".
TYPE:
|
variable |
The dataset's variable which we want to visualize.
TYPE:
|
bbox |
A Shapely polygon which will be used to (on-the-fly) crop the
TYPE:
|
title |
The title of the plot. Defaults to
TYPE:
|
cmap |
The colormap to use.
TYPE:
|
colorbar |
Boolean flag indicating whether the plot should have an integrated colorbar.
TYPE:
|
clabel |
A caption for the colorbar. Useful for indicating e.g. units
TYPE:
|
clim_min |
The lower limit for the colorbar.
TYPE:
|
clim_max |
The upper limit for the colorbar.
TYPE:
|
x_range |
A tuple indicating the minimum and maximum longitude to be displayed.
TYPE:
|
y_range |
A tuple indicating the minimum and maximum latitude to be displayed.
TYPE:
|
show_mesh |
A boolean flag indicating whether the mesh should be overlayed on the rendered variable. Enabling this makes rendering slower.
TYPE:
|
Source code in thalassa/plotting.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
plot_mesh ¶
plot_mesh(ds: xr.Dataset, bbox: shapely.Polygon | None = None, title: str = 'Mesh') -> gv.DynamicMap
Plot the mesh of the dataset
Examples:
import thalassa
ds = thalassa.open_dataset("some_netcdf.nc")
thalassa.plot_mesh(ds)
If we want to on-the-fly crop the dataset we can pass bbox
, too:
import shapely
import thalassa
bbox = shapely.box(0, 0, 1, 1)
ds = thalassa.open_dataset("some_netcdf.nc")
thalassa.plot_mesh(ds, bbox=bbox)
PARAMETER | DESCRIPTION |
---|---|
ds |
The dataset whose mesh we want to visualize. It must adhere to the "thalassa schema"
TYPE:
|
bbox |
A Shapely polygon which will be used to (on-the-fly) crop the
TYPE:
|
title |
The title of the plot.
TYPE:
|
Source code in thalassa/plotting.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
plot_ts ¶
plot_ts(ds: xr.Dataset, variable: str, source_plot: gv.DynamicMap) -> gv.DynamicMap
Return a plot with the full timeseries of a specific node.
The node that will be visualized is selected by clicking on source_plot
.
Examples:
import thalassa
ds = thalassa.open_dataset("some_netcdf.nc")
main_plot = thalassa.plot(ds, variable="zeta_max")
ts_plot = thalassa.plot_ts(ds, variable="zeta", source_plot=main_plot)
(main_plot.opts(width=600) + ts_plot.opts(width=600)).cols(1)
PARAMETER | DESCRIPTION |
---|---|
ds |
The dataset which will get visualized. It must adhere to the "thalassa schema"
TYPE:
|
variable |
The dataset's variable which we want to visualize.
TYPE:
|
source_plot |
The plot instance which be used to select the coordinates of the node.
Normally, you get this instance by calling
TYPE:
|
Source code in thalassa/plotting.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|