1414from parcels .grid import GridType
1515from parcels .interaction .interactionkernel import InteractionKernel
1616from parcels .kernel import Kernel
17- from parcels .particle import Particle , Variable
17+ from parcels .particle import Particle
1818from parcels .particledata import ParticleData , ParticleDataIterator
1919from parcels .particlefile import ParticleFile
2020from parcels .tools .converters import _get_cftime_calendars , convert_to_flat_array
@@ -100,37 +100,6 @@ def __init__(
100100 if repeatdt :
101101 NotImplementedError ("ParticleSet.repeatdt is not implemented yet in v4" )
102102
103- # ==== first: create a new subclass of the pclass that includes the required variables ==== #
104- # ==== see dynamic-instantiation trick here: https://www.python-course.eu/python3_classes_and_type.php ==== #
105- class_name = pclass .__name__
106- array_class = None
107- if class_name not in dir ():
108-
109- def ArrayClass_init (self , * args , ** kwargs ):
110- fieldset = kwargs .get ("fieldset" , None )
111- ngrids = kwargs .get ("ngrids" , None )
112- if type (self ).ngrids .initial < 0 :
113- numgrids = ngrids
114- if numgrids is None and fieldset is not None :
115- numgrids = fieldset .gridset_size
116- assert numgrids is not None , "Neither fieldsets nor number of grids are specified - exiting."
117- type(self ).ngrids .initial = numgrids
118- self .ngrids = type (self ).ngrids .initial
119- if self .ngrids >= 0 :
120- self .ei = np .zeros (self .ngrids , dtype = np .int32 )
121- super (type (self ), self ).__init__ (* args , ** kwargs )
122-
123- array_class_vdict = {
124- "ngrids" : Variable ("ngrids" , dtype = np .int32 , to_write = False , initial = - 1 ),
125- "ei" : Variable ("ei" , dtype = np .int32 , to_write = False ),
126- "__init__" : ArrayClass_init ,
127- }
128- array_class = type (class_name , (pclass ,), array_class_vdict )
129- else :
130- array_class = locals ()[class_name ]
131- # ==== dynamic re-classing completed ==== #
132- _pclass = array_class
133-
134103 lon = np .empty (shape = 0 ) if lon is None else convert_to_flat_array (lon )
135104 lat = np .empty (shape = 0 ) if lat is None else convert_to_flat_array (lat )
136105
@@ -152,8 +121,8 @@ def ArrayClass_init(self, *args, **kwargs):
152121
153122 if time .size > 0 and type (time [0 ]) in [datetime , date ]:
154123 time = np .array ([np .datetime64 (t ) for t in time ])
155- if time . size > 0 and isinstance ( time [ 0 ], np . timedelta64 ) and not self . time_origin :
156- raise NotImplementedError ("If fieldset.time_origin is not a date, time of a particle must be a double " )
124+ else :
125+ raise NotImplementedError ("particle time must be a datetime or date object " )
157126
158127 time = np .array ([self .time_origin .reltime (t ) if _convert_to_reltime (t ) else t for t in time ])
159128 assert lon .size == time .size , "time and positions (lon, lat, depth) do not have the same lengths."
@@ -175,7 +144,7 @@ def ArrayClass_init(self, *args, **kwargs):
175144 ), f"{ kwvar } and positions (lon, lat, depth) don't have the same lengths."
176145
177146 self .particledata = ParticleData (
178- _pclass ,
147+ self . _pclass ,
179148 lon = lon ,
180149 lat = lat ,
181150 depth = depth ,
0 commit comments