@@ -181,21 +181,15 @@ def __init__(
181
181
raise ValueError (
182
182
"Cannot combine Grid from defer_loaded Field with np.ndarray data. please specify lon, lat, depth and time dimensions separately"
183
183
)
184
- self .grid = grid
184
+ self ._grid = grid
185
185
else :
186
186
if (time is not None ) and isinstance (time [0 ], np .datetime64 ):
187
187
time_origin = TimeConverter (time [0 ])
188
188
time = np .array ([time_origin .reltime (t ) for t in time ])
189
189
else :
190
190
time_origin = TimeConverter (0 )
191
- self .grid = Grid .create_grid (lon , lat , depth , time , time_origin = time_origin , mesh = mesh )
191
+ self ._grid = Grid .create_grid (lon , lat , depth , time , time_origin = time_origin , mesh = mesh )
192
192
self .igrid = - 1
193
- # self.lon, self.lat, self.depth and self.time are not used any more in parcels.
194
- # self.grid should be used instead.
195
- # Those variables are still defined for backwards compatibility with users codes.
196
- self .lon = self .grid .lon
197
- self .lat = self .grid .lat
198
- self .depth = self .grid .depth
199
193
self .fieldtype = self .name if fieldtype is None else fieldtype
200
194
self .to_write = to_write
201
195
if self .grid .mesh == "flat" or (self .fieldtype not in unitconverters_map .keys ()):
@@ -207,12 +201,12 @@ def __init__(
207
201
self .timestamps = timestamps
208
202
if isinstance (interp_method , dict ):
209
203
if self .name in interp_method :
210
- self .interp_method = interp_method [self .name ]
204
+ self ._interp_method = interp_method [self .name ]
211
205
else :
212
206
raise RuntimeError (f"interp_method is a dictionary but { name } is not in it" )
213
207
else :
214
- self .interp_method = interp_method
215
- self .gridindexingtype = gridindexingtype
208
+ self ._interp_method = interp_method
209
+ self ._gridindexingtype = gridindexingtype
216
210
if self .interp_method in ["bgrid_velocity" , "bgrid_w_velocity" , "bgrid_tracer" ] and self .grid .gtype in [
217
211
GridType .RectilinearSGrid ,
218
212
GridType .CurvilinearSGrid ,
@@ -253,11 +247,11 @@ def __init__(
253
247
254
248
self .vmin = vmin
255
249
self .vmax = vmax
256
- self .cast_data_dtype = cast_data_dtype
250
+ self ._cast_data_dtype = cast_data_dtype
257
251
if self .cast_data_dtype == "float32" :
258
- self .cast_data_dtype = np .float32
252
+ self ._cast_data_dtype = np .float32
259
253
elif self .cast_data_dtype == "float64" :
260
- self .cast_data_dtype = np .float64
254
+ self ._cast_data_dtype = np .float64
261
255
262
256
if not self .grid .defer_load :
263
257
self .data = self .reshape (self .data , transpose )
@@ -307,6 +301,41 @@ def __init__(
307
301
if len (kwargs ) > 0 :
308
302
raise SyntaxError (f'Field received an unexpected keyword argument "{ list (kwargs .keys ())[0 ]} "' )
309
303
304
+ @property
305
+ def grid (self ):
306
+ return self ._grid
307
+
308
+ @property
309
+ def lon (self ):
310
+ """Lon defined on the Grid object"""
311
+ return self .grid .lon
312
+
313
+ @property
314
+ def lat (self ):
315
+ """Lat defined on the Grid object"""
316
+ return self .grid .lat
317
+
318
+ @property
319
+ def depth (self ):
320
+ """Depth defined on the Grid object"""
321
+ return self .grid .depth
322
+
323
+ @property
324
+ def cell_edge_sizes (self ):
325
+ return self .grid .cell_edge_sizes
326
+
327
+ @property
328
+ def interp_method (self ):
329
+ return self ._interp_method
330
+
331
+ @property
332
+ def gridindexingtype (self ):
333
+ return self ._gridindexingtype
334
+
335
+ @property
336
+ def cast_data_dtype (self ):
337
+ return self ._cast_data_dtype
338
+
310
339
@classmethod
311
340
def get_dim_filenames (cls , filenames , dim ):
312
341
if isinstance (filenames , str ) or not isinstance (filenames , collections .abc .Iterable ):
@@ -823,7 +852,6 @@ def calc_cell_edge_sizes(self):
823
852
for x , (lon , dx ) in enumerate (zip (self .grid .lon , np .gradient (self .grid .lon ), strict = False )):
824
853
self .grid .cell_edge_sizes ["x" ][y , x ] = x_conv .to_source (dx , lon , lat , self .grid .depth [0 ])
825
854
self .grid .cell_edge_sizes ["y" ][y , x ] = y_conv .to_source (dy , lon , lat , self .grid .depth [0 ])
826
- self .cell_edge_sizes = self .grid .cell_edge_sizes
827
855
else :
828
856
raise ValueError (
829
857
f"Field.cell_edge_sizes() not implemented for { self .grid .gtype } grids. "
@@ -1542,8 +1570,6 @@ def add_periodic_halo(self, zonal, meridional, halosize=5, data=None):
1542
1570
(data [:, :, :, - halosize :], data , data [:, :, :, 0 :halosize ]), axis = len (data .shape ) - 1
1543
1571
)
1544
1572
assert data .shape [3 ] == self .grid .xdim , "Fourth dim must be x."
1545
- self .lon = self .grid .lon
1546
- self .lat = self .grid .lat
1547
1573
if meridional :
1548
1574
if len (data .shape ) == 3 :
1549
1575
data = lib .concatenate ((data [:, - halosize :, :], data , data [:, 0 :halosize , :]), axis = len (data .shape ) - 2 )
@@ -1553,7 +1579,6 @@ def add_periodic_halo(self, zonal, meridional, halosize=5, data=None):
1553
1579
(data [:, :, - halosize :, :], data , data [:, :, 0 :halosize , :]), axis = len (data .shape ) - 2
1554
1580
)
1555
1581
assert data .shape [2 ] == self .grid .ydim , "Third dim must be y."
1556
- self .lat = self .grid .lat
1557
1582
if dataNone :
1558
1583
self .data = data
1559
1584
else :
0 commit comments