Lazy Loading Tidal Data
This notebook demonstrates reading tide model data in chunks, which can help improve computational times for large models.
import pyTMD
import numpy as np
# get model parameters from the database
m = pyTMD.io.model().from_database("GOT4.10_nc")
# interpolation points
lon = np.arange(-180, -120, 0.25)
lat = np.arange(40, 80, 0.25)
# convert interpolation points to the projection of the model
x, y = pyTMD.io.dataset._coords(
lon, lat, type="grid", source_crs=4326, target_crs=m.projection
)
%%timeit
# read dataset without chunks
ds = m.open_dataset(group="z")
# interpolate the dataset to the points
local = ds.tmd.interp(x, y, method="linear")
445 ms ± 2.21 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%%timeit
# read dataset with chunks
ds = m.open_dataset(group="z", chunks="auto")
# interpolate the dataset to the points
local = ds.tmd.interp(x, y, method="linear")
269 ms ± 2.73 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)