Skip to content

Commit 9df2804

Browse files
Merge remote-tracking branch 'origin/v4-dev' into feature/uxgrid-morton-hashing
2 parents 7589bde + 5079236 commit 9df2804

15 files changed

Lines changed: 58 additions & 1381 deletions

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies: #! Keep in sync with [tool.pixi.dependencies] in pyproject.toml
1818
- scikit-learn
1919
- zarr>=2.11.0,!=2.18.0,<3
2020
- uxarray>=2025.3.0
21+
- xgcm>=0.9.0
2122
- pooch
2223

2324
# Notebooks

parcels/_index_search.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ def curvilinear_point_in_cell(grid, y: np.ndarray, x: np.ndarray, yi: np.ndarray
7777
def _search_indices_curvilinear_2d(
7878
grid: XGrid, y: np.ndarray, x: np.ndarray, yi: np.ndarray | None = None, xi: np.ndarray | None = None
7979
):
80+
"""Searches a grid for particle locations in 2D curvilinear coordinates.
81+
82+
Parameters
83+
----------
84+
grid : XGrid
85+
The curvilinear grid to search within.
86+
y : np.ndarray
87+
Array of latitude-coordinates of the points to locate.
88+
x : np.ndarray
89+
Array of longitude-coordinates of the points to locate.
90+
yi : np.ndarray | None, optional
91+
Array of initial guesses for the j indices of the points to locate.
92+
xi : np.ndarray | None, optional
93+
Array of initial guesses for the i indices of the points to locate.
94+
95+
Returns
96+
-------
97+
tuple
98+
A tuple containing four elements:
99+
- yi (np.ndarray): Array of found j-indices corresponding to the input coordinates.
100+
- eta (np.ndarray): Array of barycentric coordinates in the j-direction within the found grid cells.
101+
- xi (np.ndarray): Array of found i-indices corresponding to the input cooordinates.
102+
- xsi (np.ndarray): Array of barycentric coordinates in the i-direction within the found grid cells.
103+
"""
80104
if np.any(xi):
81105
# If an initial guess is provided, we first perform a point in cell check for all guessed indices
82106
is_in_cell, coords = curvilinear_point_in_cell(grid, y, x, yi, xi)

parcels/fieldset.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import numpy as np
88
import xarray as xr
9+
import xgcm
910

10-
from parcels import xgcm
1111
from parcels._core.utils.time import get_datetime_type_calendar
1212
from parcels._core.utils.time import is_compatible as datetime_is_compatible
1313
from parcels._typing import Mesh
@@ -130,14 +130,12 @@ def add_constant_field(self, name: str, value, mesh: Mesh = "flat"):
130130
correction for zonal velocity U near the poles.
131131
2. flat: No conversion, lat/lon are assumed to be in m.
132132
"""
133-
da = xr.DataArray(
134-
data=np.full((1, 1, 1, 1), value),
135-
)
136-
grid = XGrid(xgcm.Grid(da))
133+
ds = xr.Dataset({name: (["time", "lat", "lon", "depth"], np.full((1, 1, 1, 1), value))})
134+
grid = XGrid(xgcm.Grid(ds))
137135
self.add_field(
138136
Field(
139137
name,
140-
da,
138+
ds[name],
141139
grid,
142140
interp_method=None, # TODO : Need to define an interpolation method for constants
143141
)

parcels/xgcm/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

parcels/xgcm/comodo.py

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)