Skip to content

Commit e877b1f

Browse files
committed
Quickfix to refactor field name (e.g, from invalid names like 'U (A grid)' to 'UAgrid'), to pass in the new assert variables name checks.
1 parent e74b84f commit e877b1f

File tree

7 files changed

+43
-42
lines changed

7 files changed

+43
-42
lines changed

src/parcels/_datasets/structured/generic.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def _rotated_curvilinear_grid():
2323
{
2424
"data_g": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
2525
"data_c": (["time", "ZC", "YC", "XC"], np.random.rand(T, Z, Y, X)),
26-
"U (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
27-
"V (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
28-
"U (C grid)": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
29-
"V (C grid)": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
26+
"UAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
27+
"VAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
28+
"UCgrid": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
29+
"VCgrid": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
3030
},
3131
coords={
3232
"XG": (["XG"], XG, {"axis": "X", "c_grid_axis_shift": -0.5}),
@@ -98,10 +98,10 @@ def _unrolled_cone_curvilinear_grid():
9898
{
9999
"data_g": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
100100
"data_c": (["time", "ZC", "YC", "XC"], np.random.rand(T, Z, Y, X)),
101-
"U (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
102-
"V (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
103-
"U (C grid)": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
104-
"V (C grid)": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
101+
"UAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
102+
"VAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
103+
"UCgrid": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
104+
"VCgrid": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
105105
},
106106
coords={
107107
"XG": (["XG"], XG, {"axis": "X", "c_grid_axis_shift": -0.5}),
@@ -140,10 +140,10 @@ def _unrolled_cone_curvilinear_grid():
140140
{
141141
"data_g": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
142142
"data_c": (["time", "ZC", "YC", "XC"], np.random.rand(T, Z, Y, X)),
143-
"U (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
144-
"V (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
145-
"U (C grid)": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
146-
"V (C grid)": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
143+
"UAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
144+
"VAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
145+
"UCgrid": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
146+
"VCgrid": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
147147
},
148148
coords={
149149
"XG": (
@@ -182,10 +182,10 @@ def _unrolled_cone_curvilinear_grid():
182182
{
183183
"data_g": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
184184
"data_c": (["time", "ZC", "YC", "XC"], np.random.rand(T, Z, Y, X)),
185-
"U (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
186-
"V (A grid)": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
187-
"U (C grid)": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
188-
"V (C grid)": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
185+
"UAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
186+
"VAgrid": (["time", "ZG", "YG", "XG"], np.random.rand(T, Z, Y, X)),
187+
"UCgrid": (["time", "ZG", "YC", "XG"], np.random.rand(T, Z, Y, X)),
188+
"VCgrid": (["time", "ZG", "YG", "XC"], np.random.rand(T, Z, Y, X)),
189189
},
190190
coords={
191191
"XG": (

tests/test_fieldset.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
def fieldset() -> FieldSet:
2121
"""Fixture to create a FieldSet object for testing."""
2222
grid = XGrid.from_dataset(ds, mesh="flat")
23-
U = Field("U", ds["U (A grid)"], grid)
24-
V = Field("V", ds["V (A grid)"], grid)
23+
U = Field("U", ds["UAgrid"], grid)
24+
V = Field("V", ds["VAgrid"], grid)
2525
UV = VectorField("UV", U, V)
2626

2727
return FieldSet(
@@ -42,6 +42,7 @@ def test_fieldset_add_constant_int_name(fieldset):
4242
with pytest.raises(TypeError, match="Expected a string for variable name, got int instead."):
4343
fieldset.add_constant(123, 1.0)
4444

45+
4546
@pytest.mark.parametrize("name", ["a b", "123", "while"])
4647
def test_fieldset_add_constant_invalid_name(fieldset, name):
4748
with pytest.raises(ValueError, match=r"Received invalid Python variable name.*"):
@@ -63,7 +64,7 @@ def test_fieldset_add_constant_field(fieldset):
6364

6465
def test_fieldset_add_field(fieldset):
6566
grid = XGrid.from_dataset(ds, mesh="flat")
66-
field = Field("test_field", ds["U (A grid)"], grid)
67+
field = Field("test_field", ds["UAgrid"], grid)
6768
fieldset.add_field(field)
6869
assert fieldset.test_field == field
6970

@@ -76,7 +77,7 @@ def test_fieldset_add_field_wrong_type(fieldset):
7677

7778
def test_fieldset_add_field_already_exists(fieldset):
7879
grid = XGrid.from_dataset(ds, mesh="flat")
79-
field = Field("test_field", ds["U (A grid)"], grid)
80+
field = Field("test_field", ds["UAgrid"], grid)
8081
fieldset.add_field(field, "test_field")
8182
with pytest.raises(ValueError, match="FieldSet already has a Field with name 'test_field'"):
8283
fieldset.add_field(field, "test_field")
@@ -113,12 +114,12 @@ def test_fieldset_gridset_multiple_grids(): ...
113114

114115
def test_fieldset_time_interval():
115116
grid1 = XGrid.from_dataset(ds, mesh="flat")
116-
field1 = Field("field1", ds["U (A grid)"], grid1)
117+
field1 = Field("field1", ds["UAgrid"], grid1)
117118

118119
ds2 = ds.copy()
119120
ds2["time"] = (ds2["time"].dims, ds2["time"].data + np.timedelta64(timedelta(days=1)), ds2["time"].attrs)
120121
grid2 = XGrid.from_dataset(ds2, mesh="flat")
121-
field2 = Field("field2", ds2["U (A grid)"], grid2)
122+
field2 = Field("field2", ds2["UAgrid"], grid2)
122123

123124
fieldset = FieldSet([field1, field2])
124125
fieldset.add_constant_field("constant_field", 1.0)
@@ -144,8 +145,8 @@ def test_fieldset_init_incompatible_calendars():
144145
)
145146

146147
grid = XGrid.from_dataset(ds1, mesh="flat")
147-
U = Field("U", ds1["U (A grid)"], grid)
148-
V = Field("V", ds1["V (A grid)"], grid)
148+
U = Field("U", ds1["UAgrid"], grid)
149+
V = Field("V", ds1["VAgrid"], grid)
149150
UV = VectorField("UV", U, V)
150151

151152
ds2 = ds.copy()

tests/test_kernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
def fieldset() -> FieldSet:
1919
ds = datasets_structured["ds_2d_left"]
2020
grid = XGrid.from_dataset(ds, mesh="flat")
21-
U = Field("U", ds["U (A grid)"], grid)
22-
V = Field("V", ds["V (A grid)"], grid)
21+
U = Field("U", ds["UAgrid"], grid)
22+
V = Field("V", ds["VAgrid"], grid)
2323
return FieldSet([U, V])
2424

2525

tests/test_particlefile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def fieldset() -> FieldSet: # TODO v4: Move into a `conftest.py` file and remov
2121
"""Fixture to create a FieldSet object for testing."""
2222
ds = datasets["ds_2d_left"]
2323
grid = XGrid.from_dataset(ds)
24-
U = Field("U", ds["U (A grid)"], grid)
25-
V = Field("V", ds["V (A grid)"], grid)
24+
U = Field("U", ds["UAgrid"], grid)
25+
V = Field("V", ds["VAgrid"], grid)
2626
UV = VectorField("UV", U, V)
2727

2828
return FieldSet(

tests/test_particleset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
def fieldset() -> FieldSet:
2525
ds = datasets_structured["ds_2d_left"]
2626
grid = XGrid.from_dataset(ds, mesh="flat")
27-
U = Field("U", ds["U (A grid)"], grid)
28-
V = Field("V", ds["V (A grid)"], grid)
27+
U = Field("U", ds["UAgrid"], grid)
28+
V = Field("V", ds["VAgrid"], grid)
2929
return FieldSet([U, V])
3030

3131

tests/test_particleset_execute.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
def fieldset() -> FieldSet:
3333
ds = datasets_structured["ds_2d_left"]
3434
grid = XGrid.from_dataset(ds, mesh="flat")
35-
U = Field("U", ds["U (A grid)"], grid)
36-
V = Field("V", ds["V (A grid)"], grid)
35+
U = Field("U", ds["UAgrid"], grid)
36+
V = Field("V", ds["VAgrid"], grid)
3737
UV = VectorField("UV", U, V)
3838
return FieldSet([U, V, UV])
3939

@@ -44,8 +44,8 @@ def fieldset_no_time_interval() -> FieldSet:
4444
ds = datasets_structured["ds_2d_left"].isel(time=0).drop_vars("time")
4545

4646
grid = XGrid.from_dataset(ds, mesh="flat")
47-
U = Field("U", ds["U (A grid)"], grid)
48-
V = Field("V", ds["V (A grid)"], grid)
47+
U = Field("U", ds["UAgrid"], grid)
48+
V = Field("V", ds["VAgrid"], grid)
4949
UV = VectorField("UV", U, V)
5050
return FieldSet([U, V, UV])
5151

tests/test_xgrid.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,43 +201,43 @@ def test_search_1d_array_some_out_of_bounds(array, x, expected_xi):
201201
[
202202
pytest.param(
203203
datasets["ds_2d_left"],
204-
"U (C grid)",
204+
"UCgrid",
205205
{
206206
"XG": (np.int64(0), np.float64(0.0)),
207207
"YC": (np.int64(-1), np.float64(0.5)),
208208
"ZG": (np.int64(0), np.float64(0.0)),
209209
},
210-
id="MITgcm indexing style U (C grid)",
210+
id="MITgcm indexing style UCgrid",
211211
),
212212
pytest.param(
213213
datasets["ds_2d_left"],
214-
"V (C grid)",
214+
"VCgrid",
215215
{
216216
"XC": (np.int64(-1), np.float64(0.5)),
217217
"YG": (np.int64(0), np.float64(0.0)),
218218
"ZG": (np.int64(0), np.float64(0.0)),
219219
},
220-
id="MITgcm indexing style V (C grid)",
220+
id="MITgcm indexing style VCgrid",
221221
),
222222
pytest.param(
223223
datasets["ds_2d_right"],
224-
"U (C grid)",
224+
"UCgrid",
225225
{
226226
"XG": (np.int64(0), np.float64(0.0)),
227227
"YC": (np.int64(0), np.float64(0.5)),
228228
"ZG": (np.int64(0), np.float64(0.0)),
229229
},
230-
id="NEMO indexing style U (C grid)",
230+
id="NEMO indexing style UCgrid",
231231
),
232232
pytest.param(
233233
datasets["ds_2d_right"],
234-
"V (C grid)",
234+
"VCgrid",
235235
{
236236
"XC": (np.int64(0), np.float64(0.5)),
237237
"YG": (np.int64(0), np.float64(0.0)),
238238
"ZG": (np.int64(0), np.float64(0.0)),
239239
},
240-
id="NEMO indexing style V (C grid)",
240+
id="NEMO indexing style VCgrid",
241241
),
242242
],
243243
)

0 commit comments

Comments
 (0)