Skip to content

Commit e9c774b

Browse files
committed
Drop croco support from fieldfilebuffer
1 parent 66a58eb commit e9c774b

File tree

3 files changed

+23
-47
lines changed

3 files changed

+23
-47
lines changed

parcels/fieldfilebuffer.py

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,72 +71,40 @@ def zdim(self):
7171
zdim -= 1
7272
return zdim
7373

74-
@property
75-
def _lon_slice(self):
76-
return self._croco_slice
77-
78-
@property
79-
def _lat_slice(self):
80-
return self._croco_slice
81-
82-
@property
83-
def _depth_slice(self):
84-
return self._croco_slice
85-
86-
@property
87-
def _croco_slice(self):
88-
if self.gridindexingtype in ["croco"]:
89-
return slice(None, -1)
90-
return slice(None)
91-
9274
@property
9375
def latlon(self):
9476
lon = self.dataset[self.dimensions["lon"]]
9577
lat = self.dataset[self.dimensions["lat"]]
9678
if self.nolonlatindices and self.gridindexingtype not in ["croco"]:
97-
if len(lon.shape) < 3:
98-
lon_subset = lon
99-
lat_subset = lat
100-
elif len(lon.shape) == 3: # some lon, lat have a time dimension 1
101-
lon_subset = lon[0, :, :]
102-
lat_subset = lat[0, :, :]
79+
if len(lon.shape) == 3: # some lon, lat have a time dimension 1
80+
lon = lon[0, :, :]
81+
lat = lat[0, :, :]
10382
elif len(lon.shape) == 4: # some lon, lat have a time and depth dimension 1
104-
lon_subset = lon[0, 0, :, :]
105-
lat_subset = lat[0, 0, :, :]
83+
lon = lon[0, 0, :, :]
84+
lat = lat[0, 0, :, :]
10685
else:
10786
self.indices["lon"] = range(self.xdim)
10887
self.indices["lat"] = range(self.ydim)
109-
if len(lon.shape) == 1:
110-
lon_subset = lon[self._lon_slice]
111-
lat_subset = lat[self._lat_slice]
112-
elif len(lon.shape) == 2:
113-
lon_subset = lon[self._lat_slice, self._lon_slice]
114-
lat_subset = lat[self._lat_slice, self._lon_slice]
115-
elif len(lon.shape) == 3: # some lon, lat have a time dimension 1
116-
lon_subset = lon[0, self._lat_slice, self._lon_slice]
117-
lat_subset = lat[0, self._lat_slice, self._lon_slice]
88+
if len(lon.shape) == 3: # some lon, lat have a time dimension 1
89+
lon = lon[0, :, :]
90+
lat = lat[0, :, :]
11891
elif len(lon.shape) == 4: # some lon, lat have a time and depth dimension 1
119-
lon_subset = lon[0, 0, self._lat_slice, self._lon_slice]
120-
lat_subset = lat[0, 0, self._lat_slice, self._lon_slice]
92+
lon = lon[0, 0, :, :]
93+
lat = lat[0, 0, :, :]
12194

12295
if len(lon.shape) > 1:
123-
if is_rectilinear(lon_subset, lat_subset):
124-
lon_subset = lon_subset[0, :]
125-
lat_subset = lat_subset[:, 0]
126-
return lat_subset, lon_subset
96+
if is_rectilinear(lon, lat):
97+
lon = lon[0, :]
98+
lat = lat[:, 0]
99+
return lat, lon
127100

128101
@property
129102
def depth(self):
130103
if "depth" in self.dimensions:
131104
depth = self.dataset[self.dimensions["depth"]]
132105
self.data_full_zdim = self.zdim
133106
self.indices["depth"] = range(self.zdim)
134-
if len(depth.shape) == 1:
135-
return depth[self._depth_slice]
136-
elif len(depth.shape) == 3:
137-
return depth[self._depth_slice, self._lat_slice, self._lon_slice]
138-
elif len(depth.shape) == 4:
139-
return depth[:, self._depth_slice, self._lat_slice, self._lon_slice]
107+
return depth
140108
else:
141109
self.indices["depth"] = [0]
142110
return np.zeros(1)

tests/test_advection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ def test_advection_RK45(lon, lat, rk45_tol):
187187
print(fieldset.RK45_tol)
188188

189189

190+
@pytest.mark.v4alpha
191+
@pytest.mark.xfail(reason="When refactoring fieldfilebuffer croco support was dropped. This will be fixed in v4.")
190192
def test_conversion_3DCROCO():
191193
"""Test of the (SciPy) version of the conversion from depth to sigma in CROCO
192194
@@ -228,6 +230,8 @@ def test_conversion_3DCROCO():
228230
assert np.allclose(sigma, s_xroms, atol=1e-3)
229231

230232

233+
@pytest.mark.v4alpha
234+
@pytest.mark.xfail(reason="When refactoring fieldfilebuffer croco support was dropped. This will be fixed in v4.")
231235
def test_advection_3DCROCO():
232236
fieldset = FieldSet.from_modulefile(TEST_DATA / "fieldset_CROCO3D.py")
233237

@@ -246,6 +250,8 @@ def SampleW(particle, fieldset, time): # pragma: no cover
246250
assert np.allclose(pset.lon_nextloop, [x + runtime for x in X.flatten()], atol=1e-3)
247251

248252

253+
@pytest.mark.v4alpha
254+
@pytest.mark.xfail(reason="When refactoring fieldfilebuffer croco support was dropped. This will be fixed in v4.")
249255
def test_advection_2DCROCO():
250256
fieldset = FieldSet.from_modulefile(TEST_DATA / "fieldset_CROCO2D.py")
251257

tests/test_fieldset_sampling.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ def test_sampling_out_of_bounds_time(allow_time_extrapolation):
586586
pset.execute(SampleP, runtime=0.1, dt=0.1)
587587

588588

589+
@pytest.mark.v4alpha
590+
@pytest.mark.xfail(reason="When refactoring fieldfilebuffer croco support was dropped. This will be fixed in v4.")
589591
def test_sampling_3DCROCO():
590592
data_path = os.path.join(os.path.dirname(__file__), "test_data/")
591593
fieldset = FieldSet.from_modulefile(data_path + "fieldset_CROCO3D.py")

0 commit comments

Comments
 (0)