From 5131ca9b7899570f59596f28abedbe2d876a09a1 Mon Sep 17 00:00:00 2001 From: Caitlin O'Connor Date: Thu, 1 Aug 2024 16:31:25 -0700 Subject: [PATCH] check for active weathering before trying to calculate spreading --- py_gnome/gnome/model.py | 2 +- py_gnome/gnome/spill_container.py | 4 ++-- py_gnome/gnome/spills/spill.py | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/py_gnome/gnome/model.py b/py_gnome/gnome/model.py index aa6abf98c..0dc930f65 100644 --- a/py_gnome/gnome/model.py +++ b/py_gnome/gnome/model.py @@ -1229,7 +1229,7 @@ def release_elements(self, start_time, end_time): env = self.compile_env() for sc in self.spills.items(): # release particles - num_released = sc.release_elements(start_time, end_time, environment=env) + num_released = sc.release_elements(start_time, end_time, environment=env, weathering_active = self.has_weathering) # initialize data - currently only weatherers do this so cycle # over weatherers collection - in future, maybe movers can also do # this diff --git a/py_gnome/gnome/spill_container.py b/py_gnome/gnome/spill_container.py index 74e95fb63..25c49ded2 100644 --- a/py_gnome/gnome/spill_container.py +++ b/py_gnome/gnome/spill_container.py @@ -872,7 +872,7 @@ def _get_fate_mask(self, fate): w_mask = np.logical_and(w_mask, self['mass'] > 0.0) return w_mask - def release_elements(self, start_time, end_time, environment=None): + def release_elements(self, start_time, end_time, environment=None, weathering_active=True): """ :param start_time: -- beginning of the release :param end_time: -- end of the release. @@ -892,7 +892,7 @@ def release_elements(self, start_time, end_time, environment=None): if not spill.on: continue - num_rel = spill.release_elements(self, start_time, end_time, environment=environment) + num_rel = spill.release_elements(self, start_time, end_time, environment=environment, weathering_active=weathering_active) if num_rel > 0: # update 'spill_num' ArrayType's initial_value so it # corresponds with spill number for this set of released diff --git a/py_gnome/gnome/spills/spill.py b/py_gnome/gnome/spills/spill.py index e1545f034..d163d28dd 100644 --- a/py_gnome/gnome/spills/spill.py +++ b/py_gnome/gnome/spills/spill.py @@ -431,7 +431,7 @@ def prepare_for_model_run(self, timestep): ''' self.release.prepare_for_model_run(timestep) - def release_elements(self, sc, start_time, end_time, environment=None): + def release_elements(self, sc, start_time, end_time, environment=None, weathering_active=True): """ Releases and partially initializes new LEs Note: this will have to be updated if we allow backwards runs for continuous spills @@ -457,9 +457,10 @@ def release_elements(self, sc, start_time, end_time, environment=None): self.substance.initialize_LEs(to_rel, sc, environment=environment) - self.release.initialize_LEs_post_substance(to_rel, sc, - start_time, end_time, - environment=environment) + if weathering_active: + self.release.initialize_LEs_post_substance(to_rel, sc, + start_time, end_time, + environment=environment) return to_rel @@ -520,7 +521,7 @@ def _setup_spill(release, spill.substance.windage_persist = windage_persist return spill - + def point_line_spill(num_elements, start_position, release_time, @@ -584,7 +585,7 @@ def point_line_spill(num_elements, if len(start_position) == 2: start_position = *start_position[:2], 0 if end_position is not None and len(end_position) == 2: - end_position = (*end_position[:2], 0) + end_position = (*end_position[:2], 0) release = PointLineRelease(release_time=release_time, start_position=start_position, @@ -604,7 +605,7 @@ def point_line_spill(num_elements, ) - return spill + return spill def surface_point_line_spill(num_elements, start_position, @@ -907,7 +908,7 @@ def spatial_release_spill(start_positions, ) return spill - + def polygon_release_spill(filename, release_time=None, substance=None, @@ -926,7 +927,7 @@ def polygon_release_spill(filename, release = PolygonRelease(filename = filename, release_time=release_time, name=name) - + spill = _setup_spill(release=release, water=water, substance=substance,