2626from parcels ._reprs import default_repr
2727from parcels ._typing import VectorType
2828from parcels .interpolators import (
29- UXPiecewiseConstantFace ,
30- UXPiecewiseLinearNode ,
31- XLinear ,
3229 ZeroInterpolator ,
3330 ZeroInterpolator_Vector ,
3431)
@@ -52,17 +49,11 @@ def _deal_with_errors(error, key, vector_type: VectorType):
5249 return 0
5350
5451
55- _DEFAULT_INTERPOLATOR_MAPPING = {
56- XGrid : XLinear ,
57- UxGrid : UXPiecewiseLinearNode ,
58- }
59-
60-
6152class Field :
6253 """The Field class that holds scalar field data.
6354 The `Field` object is a wrapper around a xarray.DataArray or uxarray.UxDataArray object.
6455 Additionally, it holds a dynamic Callable procedure that is used to interpolate the field data.
65- During initialization, the user can supply a custom interpolation method that is used to interpolate the field data,
56+ During initialization, the user is required to supply a custom interpolation method that is used to interpolate the field data,
6657 so long as the interpolation method has the correct signature.
6758
6859 Notes
@@ -97,7 +88,7 @@ def __init__(
9788 name : str ,
9889 data : xr .DataArray | ux .UxDataArray ,
9990 grid : UxGrid | XGrid ,
100- interp_method : Callable | None = None ,
91+ interp_method : Callable ,
10192 ):
10293 if not isinstance (data , (ux .UxDataArray , xr .DataArray )):
10394 raise ValueError (
@@ -137,14 +128,8 @@ def __init__(
137128 raise e
138129
139130 # Setting the interpolation method dynamically
140- if interp_method is None :
141- if isinstance (data , ux .UxDataArray ):
142- self ._interp_method = _select_uxinterpolator (data )
143- else :
144- self ._interp_method = _DEFAULT_INTERPOLATOR_MAPPING [type (self .grid )]
145- else :
146- assert_same_function_signature (interp_method , ref = ZeroInterpolator , context = "Interpolation" )
147- self ._interp_method = interp_method
131+ assert_same_function_signature (interp_method , ref = ZeroInterpolator , context = "Interpolation" )
132+ self ._interp_method = interp_method
148133
149134 self .igrid = - 1 # Default the grid index to -1
150135
@@ -487,34 +472,3 @@ def _get_positions(field: Field, time, z, y, x, particles, _ei) -> tuple[dict, d
487472 _update_particles_ei (particles , grid_positions , field )
488473 _update_particle_states_position (particles , grid_positions )
489474 return particle_positions , grid_positions
490-
491-
492- def _select_uxinterpolator (da : ux .UxDataArray ):
493- """Selects the appropriate uxarray interpolator for a given uxarray UxDataArray"""
494- supported_uxinterp_mapping = {
495- # (nz1,n_face): face-center laterally, layer centers vertically — piecewise constant
496- "nz1,n_face" : UXPiecewiseConstantFace ,
497- # (nz,n_node): node/corner laterally, layer interfaces vertically — barycentric lateral & linear vertical
498- "nz,n_node" : UXPiecewiseLinearNode ,
499- }
500- # Extract only spatial dimensions, neglecting time
501- da_spatial_dims = tuple (d for d in da .dims if d not in ("time" ,))
502- if len (da_spatial_dims ) < 2 :
503- return None
504-
505- # Construct key (string) for mapping to interpolator
506- # Find vertical and lateral tokens
507- vdim = None
508- ldim = None
509- for d in da_spatial_dims :
510- if d in ("nz" , "nz1" ):
511- vdim = d
512- if d in ("n_face" , "n_node" ):
513- ldim = d
514- # Map to supported interpolators
515- if vdim and ldim :
516- key = f"{ vdim } ,{ ldim } "
517- if key in supported_uxinterp_mapping .keys ():
518- return supported_uxinterp_mapping [key ]
519-
520- return None
0 commit comments