33import warnings
44from collections .abc import Iterable
55from pathlib import Path
6- from typing import TYPE_CHECKING , Literal
6+ from typing import TYPE_CHECKING , cast
77
88import dask .array as da
99import numpy as np
2020from parcels ._typing import (
2121 GridIndexingType ,
2222 InterpMethod ,
23+ InterpMethodOption ,
2324 Mesh ,
2425 VectorType ,
2526 assert_valid_gridindexingtype ,
@@ -140,8 +141,6 @@ class Field:
140141 Minimum allowed value on the field. Data below this value are set to zero
141142 vmax : float
142143 Maximum allowed value on the field. Data above this value are set to zero
143- cast_data_dtype : str
144- Cast Field data to dtype. Supported dtypes are "float32" (np.float32 (default)) and "float64 (np.float64).
145144 time_origin : parcels.tools.converters.TimeConverter
146145 Time origin of the time axis (only if grid is None)
147146 interp_method : str
@@ -162,7 +161,6 @@ class Field:
162161 """
163162
164163 allow_time_extrapolation : bool
165- _cast_data_dtype : type [np .float32 ] | type [np .float64 ]
166164
167165 def __init__ (
168166 self ,
@@ -179,7 +177,6 @@ def __init__(
179177 transpose : bool = False ,
180178 vmin : float | None = None ,
181179 vmax : float | None = None ,
182- cast_data_dtype : type [np .float32 ] | type [np .float64 ] | Literal ["float32" , "float64" ] = "float32" ,
183180 time_origin : TimeConverter | None = None ,
184181 interp_method : InterpMethod = "linear" ,
185182 allow_time_extrapolation : bool | None = None ,
@@ -246,19 +243,6 @@ def __init__(
246243 self .vmin = vmin
247244 self .vmax = vmax
248245
249- match cast_data_dtype :
250- case "float32" :
251- self ._cast_data_dtype = np .float32
252- case "float64" :
253- self ._cast_data_dtype = np .float64
254- case _:
255- self ._cast_data_dtype = cast_data_dtype
256-
257- if self .cast_data_dtype not in [np .float32 , np .float64 ]:
258- raise ValueError (
259- f"Unsupported cast_data_dtype { self .cast_data_dtype !r} . Choose either: 'float32' or 'float64'"
260- )
261-
262246 if not self .grid .defer_load :
263247 self .data = self ._reshape (self .data , transpose )
264248 self ._loaded_time_indices = range (self .grid .tdim )
@@ -332,10 +316,6 @@ def interp_method(self, value):
332316 def gridindexingtype (self ):
333317 return self ._gridindexingtype
334318
335- @property
336- def cast_data_dtype (self ):
337- return self ._cast_data_dtype
338-
339319 @property
340320 def netcdf_engine (self ):
341321 return self ._netcdf_engine
@@ -522,6 +502,7 @@ def from_netcdf(
522502 interp_method = interp_method [variable [0 ]]
523503 else :
524504 raise RuntimeError (f"interp_method is a dictionary but { variable [0 ]} is not in it" )
505+ interp_method = cast (InterpMethodOption , interp_method )
525506
526507 if "lon" in dimensions and "lat" in dimensions :
527508 with NetcdfFileBuffer (
@@ -719,10 +700,6 @@ def _reshape(self, data, transpose=False):
719700 # Ensure that field data is the right data type
720701 if not isinstance (data , (np .ndarray )):
721702 data = np .array (data )
722- if (self .cast_data_dtype == np .float32 ) and (data .dtype != np .float32 ):
723- data = data .astype (np .float32 )
724- elif (self .cast_data_dtype == np .float64 ) and (data .dtype != np .float64 ):
725- data = data .astype (np .float64 )
726703 if transpose :
727704 data = np .transpose (data )
728705 if self .grid ._lat_flipped :
@@ -1059,7 +1036,6 @@ def computeTimeChunk(self, data, tindex):
10591036 timestamp = timestamp ,
10601037 interp_method = self .interp_method ,
10611038 data_full_zdim = self .data_full_zdim ,
1062- cast_data_dtype = self .cast_data_dtype ,
10631039 )
10641040 filebuffer .__enter__ ()
10651041 time_data = filebuffer .time
0 commit comments