1. Read TESEO’s domain files

Open In Colab

1.1. Install pyTESEO

  • If you are running this notebook from Google colab uncomment and run !pip install pyteseo && pyteseo-tests in the cell below. Doing this you will install pyteseo from pypi repository and run pyteseo-tests to check the installation (all tests have to succeed).

  • If you are using this notebook in your own local machine you need to install the library from the local repo pip install . or pypi pip install pyteseo.

# !pip install pyteseo && pyteseo-tests
import warnings
warnings.simplefilter(action="ignore")

1.1.1. Load TESEO domain

Teseo domain is composed by 2 files: grid.dat and costa.dat. These files has to be located in the same folder.

You only need to instance the class Domain() from pyteseo.models.domain passing the path to the folder where de domain files are located

from pathlib import Path
from pyteseo.models.domain import Domain

# path where example data needed by the use case is located
import pyteseo.tests as tests_
domain_path = Path(tests_.__file__).parent / "data/ibiza_domain"

domain = Domain(path = str(domain_path))
domain
Domain(path='/home/runner/.local/lib/python3.10/site-packages/pyteseo/tests/data/ibiza_domain', grid=Grid(path='/home/runner/.local/lib/python3.10/site-packages/pyteseo/tests/data/ibiza_domain/grid.dat', dx=0.016666, dy=0.016667, nx=62, ny=50, bbox=(0.891666667, 38.4916667, 1.90833333, 39.3083333), nan_value=-999), coastline=Coastline(path='/home/runner/.local/lib/python3.10/site-packages/pyteseo/tests/data/ibiza_domain/costa.dat', bbox=(1.1587, 38.6412, 1.6504, 39.1196), n_polygons=36), bbox=(0.891666667, 38.4916667, 1.90833333, 39.3083333))

Domain class read grid file and coastline files (if exists) and stores the main properties of the both in grid and coastline fields, plus the rest of general properties, like:

  • path: path to the folder where the domain is located

  • bbox: bounding box of the domain (should be the same than the bbox of the grid file)

  • grid: grid object

  • coastline: coastline object

print(f"path: {domain.path}\nbbox : {domain.bbox}\ngrid: {domain.grid}\ncoastline: {domain.coastline}\n")
path: /home/runner/.local/lib/python3.10/site-packages/pyteseo/tests/data/ibiza_domain
bbox : (0.891666667, 38.4916667, 1.90833333, 39.3083333)
grid: path='/home/runner/.local/lib/python3.10/site-packages/pyteseo/tests/data/ibiza_domain/grid.dat' dx=0.016666 dy=0.016667 nx=62 ny=50 bbox=(0.891666667, 38.4916667, 1.90833333, 39.3083333) nan_value=-999
coastline: path='/home/runner/.local/lib/python3.10/site-packages/pyteseo/tests/data/ibiza_domain/costa.dat' bbox=(1.1587, 38.6412, 1.6504, 39.1196) n_polygons=36

in domain.grid and domain.coastline other objects are instanciated, storing especifical propierties for each component, like:

  • Grid

    • path

    • bbox

    • dx, dy, nx, ny

    • nan_value

  • Coastline

    • path

    • bbox

    • n_polygons

print(f"Number of grid cells in longitude axis equals {domain.grid.nx}, and the number of polygons in the coastline is {domain.coastline.n_polygons}")
Number of grid cells in longitude axis equals 62, and the number of polygons in the coastline is 36

Also each object has implemented a .plot() method to provide a standard representation:

  • domain.plot()

  • domain.grid.plot()

  • domain.coastline.plot()

domain.plot()
../_images/ab14886b2d2593fcc3600b201f9f9fc4ed1c5b2b1bec425f8be74a933ccb1fcb.png ../_images/ab14886b2d2593fcc3600b201f9f9fc4ed1c5b2b1bec425f8be74a933ccb1fcb.png

Finally, access to data by means of pandas, geopandas or xarray libraries and datamodel (dataframe, geodataframe or dataset) can be obtained by means of the following methods:

  • .load_df()

  • .load_gdf()

  • .load_ds()

gdf = domain.coastline.load_gdf()
gdf.loc[[0]].plot(color="blue", edgecolor="red")
<Axes: >
../_images/4845978c8a7949d738343ee078ae0dd93c3ac41c6f814ea0b9d7812b5a53b9e5.png
df = domain.grid.load_df()
df.plot.scatter(x="lon", y="lat", c="depth", cmap="viridis")
<Axes: xlabel='lon', ylabel='lat'>
../_images/2c0895e8dfadbfa6b5b82f761778c59e5094d1b2632fc0538f92785fafa8040d.png
ds = domain.grid.load_ds()
ds.plot.scatter(x="lon", y="lat", hue="depth", cmap="viridis")
<matplotlib.collections.PathCollection at 0x7f6a0140e7d0>
../_images/e3a853f66ea2ab069ec9652f00789f36a9c82ba61b6d01a4c7c068137234e989.png