Skip to content

Commit 7ad5d46

Browse files
Removing redundant depth and time dimensions from constant field creation
1 parent 6215839 commit 7ad5d46

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

src/parcels/_core/fieldset.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -136,44 +136,14 @@ def add_constant_field(self, name: str, value, mesh: Mesh = "spherical"):
136136
2. flat: No conversion, lat/lon are assumed to be in m.
137137
"""
138138
ds = xr.Dataset(
139-
{name: (["time", "depth", "lat", "lon"], np.full((1, 1, 1, 1), value))},
140-
coords={
141-
"time": (["time"], [np.timedelta64(0, "s")], {"axis": "T"}),
142-
"depth": (["depth"], [0], {"axis": "Z"}),
143-
"lat": (["lat"], [0], {"axis": "Y"}),
144-
"lon": (["lon"], [0], {"axis": "X"}),
145-
},
139+
{name: (["lat", "lon"], np.full((1, 1), value))},
140+
coords={"lat": (["lat"], [0], {"axis": "Y"}), "lon": (["lon"], [0], {"axis": "X"})},
146141
)
147-
grid = XGrid(
148-
xgcm.Grid(
149-
ds,
150-
coords={
151-
"X": {
152-
"left": "lon",
153-
},
154-
"Y": {
155-
"left": "lat",
156-
},
157-
"Z": {
158-
"left": "depth",
159-
},
160-
"T": {
161-
"center": "time",
162-
},
163-
},
164-
autoparse_metadata=False,
165-
**_DEFAULT_XGCM_KWARGS,
166-
),
167-
mesh=mesh,
168-
)
169-
self.add_field(
170-
Field(
171-
name,
172-
ds[name],
173-
grid,
174-
interp_method=XConstantField,
175-
)
142+
xgrid = xgcm.Grid(
143+
ds, coords={"X": {"left": "lon"}, "Y": {"left": "lat"}}, autoparse_metadata=False, **_DEFAULT_XGCM_KWARGS
176144
)
145+
grid = XGrid(xgrid, mesh=mesh)
146+
self.add_field(Field(name, ds[name], grid, interp_method=XConstantField))
177147

178148
def add_constant(self, name, value):
179149
"""Add a constant to the FieldSet. Note that all constants are

0 commit comments

Comments
 (0)