-
Notifications
You must be signed in to change notification settings - Fork 168
Support for creating a ParticleSet with empty FieldSet #880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,7 +96,8 @@ class ParticleSet(object): | |
|
|
||
| Please note that this currently only supports fixed size particle sets. | ||
|
|
||
| :param fieldset: :mod:`parcels.fieldset.FieldSet` object from which to sample velocity | ||
| :param fieldset: :mod:`parcels.fieldset.FieldSet` object from which to sample velocity. | ||
| While fieldset=None is supported, this will throw a warning as it breaks most Parcels functionality | ||
| :param pclass: Optional :mod:`parcels.particle.JITParticle` or | ||
| :mod:`parcels.particle.ScipyParticle` object that defines custom particle | ||
| :param lon: List of initial longitude values for particles | ||
|
|
@@ -112,9 +113,13 @@ class ParticleSet(object): | |
| Other Variables can be initialised using further arguments (e.g. v=... for a Variable named 'v') | ||
| """ | ||
|
|
||
| def __init__(self, fieldset, pclass=JITParticle, lon=None, lat=None, depth=None, time=None, repeatdt=None, lonlatdepth_dtype=None, pid_orig=None, **kwargs): | ||
| def __init__(self, fieldset=None, pclass=JITParticle, lon=None, lat=None, depth=None, time=None, repeatdt=None, lonlatdepth_dtype=None, pid_orig=None, **kwargs): | ||
| self.fieldset = fieldset | ||
| self.fieldset.check_complete() | ||
| if self.fieldset is None: | ||
| logger.warning_once("No FieldSet provided in ParticleSet generation. " | ||
| "This breaks most Parcels functionality") | ||
|
Comment on lines
+119
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good to set a warning. The formulation is very user-centric, but that's probably how it should be. |
||
| else: | ||
| self.fieldset.check_complete() | ||
| partitions = kwargs.pop('partitions', None) | ||
|
|
||
| def convert_to_array(var): | ||
|
|
@@ -133,7 +138,7 @@ def convert_to_array(var): | |
| pid = pid_orig + pclass.lastID | ||
|
|
||
| if depth is None: | ||
| mindepth, _ = self.fieldset.gridset.dimrange('depth') | ||
| mindepth = self.fieldset.gridset.dimrange('depth')[0] if self.fieldset is not None else 0 | ||
| depth = np.ones(lon.size) * mindepth | ||
| else: | ||
| depth = convert_to_array(depth) | ||
|
|
@@ -150,7 +155,7 @@ def _convert_to_reltime(time): | |
|
|
||
| if time.size > 0 and type(time[0]) in [datetime, date]: | ||
| time = np.array([np.datetime64(t) for t in time]) | ||
| self.time_origin = fieldset.time_origin | ||
| self.time_origin = fieldset.time_origin if self.fieldset is not None else 0 | ||
| if time.size > 0 and isinstance(time[0], np.timedelta64) and not self.time_origin: | ||
| raise NotImplementedError('If fieldset.time_origin is not a date, time of a particle must be a double') | ||
| time = np.array([self.time_origin.reltime(t) if _convert_to_reltime(t) else t for t in time]) | ||
|
|
@@ -212,7 +217,10 @@ def _convert_to_reltime(time): | |
| pclass.setLastID(offset+1) | ||
|
|
||
| if lonlatdepth_dtype is None: | ||
| self.lonlatdepth_dtype = self.lonlatdepth_dtype_from_field_interp_method(fieldset.U) | ||
| if fieldset is not None: | ||
| self.lonlatdepth_dtype = self.lonlatdepth_dtype_from_field_interp_method(fieldset.U) | ||
| else: | ||
| self.lonlatdepth_dtype = np.float32 | ||
| else: | ||
| self.lonlatdepth_dtype = lonlatdepth_dtype | ||
| assert self.lonlatdepth_dtype in [np.float32, np.float64], \ | ||
|
|
@@ -227,7 +235,8 @@ def _convert_to_reltime(time): | |
| initialised = set() | ||
| for v in self.ptype.variables: | ||
| if v.name in ['xi', 'yi', 'zi', 'ti']: | ||
| self.particle_data[v.name] = np.empty((len(lon), fieldset.gridset.size), dtype=v.dtype) | ||
| ngrid = fieldset.gridset.size if fieldset is not None else 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't that be |
||
| self.particle_data[v.name] = np.empty((len(lon), ngrid), dtype=v.dtype) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, okay, now I see why 'ngrid' should not be 0 ... the variable naming semantic here is a bit misleading then, but I understand the purpose. |
||
| else: | ||
| self.particle_data[v.name] = np.empty(len(lon), dtype=v.dtype) | ||
|
|
||
|
|
@@ -608,7 +617,7 @@ def execute(self, pyfunc=AdvectionRK4, endtime=None, runtime=None, dt=1., | |
| assert outputdt is None or outputdt >= 0, 'outputdt must be positive' | ||
| assert moviedt is None or moviedt >= 0, 'moviedt must be positive' | ||
|
|
||
| mintime, maxtime = self.fieldset.gridset.dimrange('time_full') | ||
| mintime, maxtime = self.fieldset.gridset.dimrange('time_full') if self.fieldset is not None else (0, 1) | ||
| if np.any(np.isnan(self.particle_data['time'])): | ||
| self.particle_data['time'][np.isnan(self.particle_data['time'])] = mintime if dt >= 0 else maxtime | ||
|
|
||
|
|
@@ -656,7 +665,7 @@ def execute(self, pyfunc=AdvectionRK4, endtime=None, runtime=None, dt=1., | |
| next_output = time + outputdt if dt > 0 else time - outputdt | ||
| next_movie = time + moviedt if dt > 0 else time - moviedt | ||
| next_callback = time + callbackdt if dt > 0 else time - callbackdt | ||
| next_input = self.fieldset.computeTimeChunk(time, np.sign(dt)) | ||
| next_input = self.fieldset.computeTimeChunk(time, np.sign(dt)) if self.fieldset is not None else np.inf | ||
|
|
||
| tol = 1e-12 | ||
| if verbose_progress is None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, so you decided to keep this parameter order, and then also rather just define 'JITParticle' as ptype standard. Yeah, fine - relieves you from a lot of tiny adaptions in the other files, I agree.