From 2e86ec521a0d71438d84fc651518f0c573a27de2 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 18 Mar 2026 10:11:56 +0100 Subject: [PATCH 1/3] Update code --- benchmarks/fesom2.py | 2 +- benchmarks/moi_curvilinear.py | 4 ++-- results/benchmarks.json | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmarks/fesom2.py b/benchmarks/fesom2.py index e7bd735..b6a18cf 100644 --- a/benchmarks/fesom2.py +++ b/benchmarks/fesom2.py @@ -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) diff --git a/benchmarks/moi_curvilinear.py b/benchmarks/moi_curvilinear.py index dcc1f27..d4b00e8 100644 --- a/benchmarks/moi_curvilinear.py +++ b/benchmarks/moi_curvilinear.py @@ -108,8 +108,8 @@ def pset_execute_3d(self, interpolator, chunk, npart): 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() + # U.units = parcels.GeographicPolar() + # V.units = parcels.Geographic() UV = parcels.VectorField("UV", U, V) fieldset = parcels.FieldSet([U, V, UV]) diff --git a/results/benchmarks.json b/results/benchmarks.json index 2093eba..b531d8c 100644 --- a/results/benchmarks.json +++ b/results/benchmarks.json @@ -11,7 +11,7 @@ "10000" ], [ - "" + "" ] ], "type": "peakmemory", @@ -32,7 +32,7 @@ "10000" ], [ - "" + "" ] ], "repeat": 0, @@ -57,7 +57,7 @@ "10000" ], [ - "" + "" ] ], "repeat": 0, From d678e038d23f99c65da8998d8399a2fdede6a51b Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:16:14 +0100 Subject: [PATCH 2/3] Update fieldset ingestion --- benchmarks/moi_curvilinear.py | 50 ++++++----------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/benchmarks/moi_curvilinear.py b/benchmarks/moi_curvilinear.py index d4b00e8..b4ce7c9 100644 --- a/benchmarks/moi_curvilinear.py +++ b/benchmarks/moi_curvilinear.py @@ -14,7 +14,6 @@ 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), @@ -32,27 +31,12 @@ def _load_ds(datapath, chunk): if chunk: fileargs["chunks"] = {"time_counter": 1, "depth": 2, "y": chunk, "x": chunk} - ds_u = xr.open_mfdataset(filenames["U"], **fileargs)[["vozocrtx"]].drop_vars( - ["nav_lon", "nav_lat"] - ) - ds_v = xr.open_mfdataset(filenames["V"], **fileargs)[["vomecrty"]].drop_vars( - ["nav_lon", "nav_lat"] - ) - ds_depth = xr.open_mfdataset(filenames["W"], **fileargs)[["depthw"]] + ds_u = xr.open_mfdataset(filenames["U"], **fileargs)[["vozocrtx"]].rename_vars({"vozocrtx": "U"}) + ds_v = xr.open_mfdataset(filenames["V"], **fileargs)[["vomecrty"]].rename_vars({"vomecrty": "V"}) + da_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 + ds_mesh['depthw'] = da_depth + ds = parcels.convert.nemo_to_sgrid(fields=dict(U=ds_u, V=ds_v), coords=ds_mesh) return ds @@ -89,31 +73,13 @@ def time_load_data_3d(self, interpolator, chunk, npart): 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", - ) - + 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) From 6e84d4a00134957a5a2e65e1d677e65d5e9500e0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 15:37:19 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmarks/moi_curvilinear.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/benchmarks/moi_curvilinear.py b/benchmarks/moi_curvilinear.py index b4ce7c9..8e7848d 100644 --- a/benchmarks/moi_curvilinear.py +++ b/benchmarks/moi_curvilinear.py @@ -3,7 +3,6 @@ import numpy as np import parcels import xarray as xr -import xgcm from parcels.interpolators import XLinear from parcels_benchmarks.benchmark_setup import PARCELS_DATADIR, download_example_dataset @@ -31,11 +30,15 @@ def _load_ds(datapath, chunk): if chunk: fileargs["chunks"] = {"time_counter": 1, "depth": 2, "y": chunk, "x": chunk} - ds_u = xr.open_mfdataset(filenames["U"], **fileargs)[["vozocrtx"]].rename_vars({"vozocrtx": "U"}) - ds_v = xr.open_mfdataset(filenames["V"], **fileargs)[["vomecrty"]].rename_vars({"vomecrty": "V"}) + ds_u = xr.open_mfdataset(filenames["U"], **fileargs)[["vozocrtx"]].rename_vars( + {"vozocrtx": "U"} + ) + ds_v = xr.open_mfdataset(filenames["V"], **fileargs)[["vomecrty"]].rename_vars( + {"vomecrty": "V"} + ) da_depth = xr.open_mfdataset(filenames["W"], **fileargs)["depthw"] ds_mesh = xr.open_dataset(mesh_mask)[["glamf", "gphif"]].isel(t=0) - ds_mesh['depthw'] = da_depth + ds_mesh["depthw"] = da_depth ds = parcels.convert.nemo_to_sgrid(fields=dict(U=ds_u, V=ds_v), coords=ds_mesh) return ds