Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/fesom2.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pset_execute(self, npart, integrator):
lat = np.linspace(32.0, 19.0, npart)

pset = ParticleSet(fieldset=fieldset, pclass=Particle, lon=lon, lat=lat)
pset.execute(runtime=runtime, dt=dt, pyfunc=integrator)
pset.execute(kernels=integrator, runtime=runtime, dt=dt)

def time_pset_execute(self, npart, integrator):
self.pset_execute(npart, integrator)
Expand Down
93 changes: 19 additions & 74 deletions benchmarks/moi_curvilinear.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,28 @@
from glob import glob

import numpy as np
import parcels
import xarray as xr
import xgcm
from parcels.interpolators import XLinear

from .catalogs import Catalogs

runtime = np.timedelta64(2, "D")
dt = np.timedelta64(15, "m")


PARCELS_DATADIR = ... # TODO: Replace with intake


def download_dataset(*args, **kwargs): ... # TODO: Replace with intake


def _load_ds(datapath, chunk):
"""Helper function to load xarray dataset from datapath with or without chunking"""

fileU = f"{datapath}/psy4v3r1-daily_U_2025-01-0[1-3].nc"
filenames = {
"U": glob(fileU),
"V": glob(fileU.replace("_U_", "_V_")),
"W": glob(fileU.replace("_U_", "_W_")),
}
mesh_mask = f"{datapath}/PSY4V3R1_mesh_hgr.nc"
fileargs = {
"concat_dim": "time_counter",
"combine": "nested",
"data_vars": "minimal",
"coords": "minimal",
"compat": "override",
}
if chunk:
fileargs["chunks"] = {"time_counter": 1, "depth": 2, "y": chunk, "x": chunk}
def _load_ds(chunk):
"""Helper function to load xarray dataset from catalog with or without chunking"""
cat = Catalogs.CAT_BENCHMARKS
chunks = {"time_counter": 1, "depth": 2, "y": chunk, "x": chunk} if chunk else None

ds_u = xr.open_mfdataset(filenames["U"], **fileargs)[["vozocrtx"]].drop_vars(
["nav_lon", "nav_lat"]
ds_u = (
cat.moi_u(chunks=chunks).to_dask()[["vozocrtx"]].rename_vars({"vozocrtx": "U"})
)
ds_v = xr.open_mfdataset(filenames["V"], **fileargs)[["vomecrty"]].drop_vars(
["nav_lon", "nav_lat"]
ds_v = (
cat.moi_v(chunks=chunks).to_dask()[["vomecrty"]].rename_vars({"vomecrty": "V"})
)
ds_depth = xr.open_mfdataset(filenames["W"], **fileargs)[["depthw"]]
ds_mesh = xr.open_dataset(mesh_mask)[["glamf", "gphif"]].isel(t=0)

ds = xr.merge([ds_u, ds_v, ds_depth, ds_mesh], compat="identical")
ds = ds.rename(
{
"vozocrtx": "U",
"vomecrty": "V",
"glamf": "lon",
"gphif": "lat",
"time_counter": "time",
"depthw": "depth",
}
)
ds.deptht.attrs["c_grid_axis_shift"] = -0.5
da_depth = cat.moi_w(chunks=chunks).to_dask()["depthw"]
ds_mesh = cat.moi_mesh(chunks=None).read()[["glamf", "gphif"]].isel(t=0)
ds_mesh["depthw"] = da_depth
ds = parcels.convert.nemo_to_sgrid(fields=dict(U=ds_u, V=ds_v), coords=ds_mesh)

return ds

Expand All @@ -75,47 +41,26 @@ class MOICurvilinear:
"npart",
]

def setup(self, interpolator, chunk, npart):
self.datapath = download_dataset("MOi-curvilinear", data_home=PARCELS_DATADIR)

def time_load_data_3d(self, interpolator, chunk, npart):
"""Benchmark that times loading the 'U' and 'V' data arrays only for 3-D"""

# To have a reasonable runtime, we only consider the time it takes to load two time levels
# and two depth levels (at most)
ds = _load_ds(self.datapath, chunk)
ds = _load_ds(chunk)
for j in range(min(ds.coords["deptht"].size, 2)):
for i in range(min(ds.coords["time"].size, 2)):
_u = ds["U"].isel(deptht=j, time=i).compute()
_v = ds["V"].isel(deptht=j, time=i).compute()

def pset_execute_3d(self, interpolator, chunk, npart):
ds = _load_ds(self.datapath, chunk)
coords = {
"X": {"left": "x"},
"Y": {"left": "y"},
"Z": {"center": "deptht", "left": "depth"},
"T": {"center": "time"},
}

grid = parcels._core.xgrid.XGrid(
xgcm.Grid(ds, coords=coords, autoparse_metadata=False, periodic=False),
mesh="spherical",
)

ds = _load_ds(chunk)
fieldset = parcels.FieldSet.from_sgrid_conventions(ds)
if interpolator == "XLinear":
interp_method = XLinear
fieldset.U.interp_method = XLinear
fieldset.V.interp_method = XLinear
else:
raise ValueError(f"Unknown interpolator: {interpolator}")

U = parcels.Field("U", ds["U"], grid, interp_method=interp_method)
V = parcels.Field("V", ds["V"], grid, interp_method=interp_method)
U.units = parcels.GeographicPolar()
V.units = parcels.Geographic()
UV = parcels.VectorField("UV", U, V)

fieldset = parcels.FieldSet([U, V, UV])

pclass = parcels.Particle

lon = np.linspace(-10, 10, npart)
Expand Down
214 changes: 186 additions & 28 deletions catalogs/parcels-benchmarks/catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,219 @@
plugins:
source:
- module: intake_xarray
sources: #!TODO Update
croco:
description: CROCO_idealized
sources:
fesom_baroclinic_gyre_data:
description: FESOM baroclinic gyre velocity data (legacy)
driver: netcdf
#cache:
# - argkey: urlpath
# regex: ''
# type: file
args:
urlpath: "{{ CATALOG_DIR }}/data/CROCOidealized_data/CROCO_idealized.nc"
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_FESOM-baroclinic-gyre/data/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
GlobCurrent_example_data:
description: GlobCurrent_example_data
fesom_baroclinic_gyre_mesh:
description: FESOM baroclinic gyre mesh (legacy)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/GlobCurrent_example_data/*.nc"
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_FESOM-baroclinic-gyre/data/mesh/fesom.mesh.diag.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
MITgcm_example_data:
description: MITgcm_example_data
fesom_baroclinic_gyre_v2_data:
description: FESOM baroclinic gyre velocity data (v2025.10.2.2)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/MITgcm_example_data/*.nc"
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_FESOM-baroclinic-gyre_v2025.10.2.2/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
MovingEddies_data:
description: MovingEddies_data
fesom_baroclinic_gyre_v2_mesh:
description: FESOM baroclinic gyre mesh (v2025.10.2.2)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/MovingEddies_data/*.nc"
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_FESOM-baroclinic-gyre_v2025.10.2.2/mesh/fesom.mesh.diag.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"

# NemoCurvilinear_data:
# NemoNorthSeaORCA025-N006_data:
# OFAM_example_data
# Peninsula_data
SWASH_data:
description: SWASH_data
icon_data:
description: ICON ocean model data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/SWASH_data/*.nc"
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_ICON/epoc2_010_oce_ml_1d_mean_19900102T000000Z.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
WOA_data:
description: WOA_data
icon_grid:
description: ICON ocean grid
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/WOA_data/*.nc"
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_ICON/icon_grid_O.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
moi_u:
description: MOi curvilinear U velocity
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_MOi_data/psy4v3r1-daily_U_*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
concat_dim: "time_counter"
combine: "nested"
data_vars: "minimal"
coords: "minimal"
compat: "override"
moi_v:
description: MOi curvilinear V velocity
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_MOi_data/psy4v3r1-daily_V_*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
concat_dim: "time_counter"
combine: "nested"
data_vars: "minimal"
coords: "minimal"
compat: "override"
moi_w:
description: MOi curvilinear W velocity
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_MOi_data/psy4v3r1-daily_W_*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
concat_dim: "time_counter"
combine: "nested"
data_vars: "minimal"
coords: "minimal"
compat: "override"
moi_mesh:
description: MOi curvilinear horizontal grid
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_MOi_data/PSY4V3R1_mesh_hgr.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_regional:
description: Nested LOCATE regional IBI data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/regional/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_regional_resampled:
description: Nested LOCATE regional IBI data (resampled)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/regional_resampled/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_bcn_coastal:
description: Nested LOCATE BCN coastal data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/BCN/coastal/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_bcn_coastal_resampled:
description: Nested LOCATE BCN coastal data (resampled)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/BCN/coastal_resampled/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_bcn_harbour:
description: Nested LOCATE BCN harbour data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/BCN/harbour/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_bcn_harbour_resampled:
description: Nested LOCATE BCN harbour data (resampled)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/BCN/harbour_resampled/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_tar_coastal:
description: Nested LOCATE TAR coastal data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/TAR/coastal/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_tar_coastal_resampled:
description: Nested LOCATE TAR coastal data (resampled)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/TAR/coastal_resampled/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_tar_harbour:
description: Nested LOCATE TAR harbour data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/TAR/harbour/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
nested_locate_tar_harbour_resampled:
description: Nested LOCATE TAR harbour data (resampled)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_Nested_LOCATE/TAR/harbour_resampled/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
smoc:
description: SMOC ocean model data
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/Parcels_Benchmarks_SMOC_data/*.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
creg12_u:
description: CREG12 NEMO U velocity (parcels-2521)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/parcels-2521-data/data/CREG12.L75-REF12_y2001m02.1d_gridU.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
creg12_v:
description: CREG12 NEMO V velocity (parcels-2521)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/parcels-2521-data/data/CREG12.L75-REF12_y2001m02.1d_gridV.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
creg12_w:
description: CREG12 NEMO W velocity (parcels-2521)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/parcels-2521-data/data/CREG12.L75-REF12_y2001m02.1d_gridW.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
creg12_mesh:
description: CREG12 NEMO mesh (parcels-2521)
driver: netcdf
args:
urlpath: "{{ CATALOG_DIR }}/data/Parcelsv4_Benchmarking_data/parcels-2521-data/data/trimmed_mesh_file.nc"
chunks: {}
xarray_kwargs:
engine: "netcdf4"
Loading