From ab6ef6f573da0469608b35d6270e0c69ccfc32a8 Mon Sep 17 00:00:00 2001 From: Caitlin O'Connor Date: Wed, 17 Jul 2024 13:17:02 -0700 Subject: [PATCH] changed extrapolate default to None in at functions --- py_gnome/gnome/environment/environment.py | 2 +- .../gnome/environment/environment_objects.py | 28 ++++++++++++------- .../gnome/environment/gridded_objects_base.py | 21 ++++++++------ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/py_gnome/gnome/environment/environment.py b/py_gnome/gnome/environment/environment.py index 31c7c973f..26d6c3009 100644 --- a/py_gnome/gnome/environment/environment.py +++ b/py_gnome/gnome/environment/environment.py @@ -56,7 +56,7 @@ def __init__(self, make_default_refs=True, **kwargs): self.array_types = {} super().__init__(**kwargs) - def at(self, points, time, *, units=None, extrapolate=False, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, **kwargs): """ Find the value of the property at positions P at time T diff --git a/py_gnome/gnome/environment/environment_objects.py b/py_gnome/gnome/environment/environment_objects.py index d7464bbd0..70a05ac09 100644 --- a/py_gnome/gnome/environment/environment_objects.py +++ b/py_gnome/gnome/environment/environment_objects.py @@ -119,7 +119,7 @@ def v(self): return self._v - def at(self, points, time, *, units=None, extrapolate=False, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, **kwargs): """ Find the value of the property at positions of points at time T @@ -486,7 +486,7 @@ class GridCurrent(VelocityGrid, Environment): # 'surface_northward_sea_water_velocity'], # 'w': ['upward_sea_water_velocity']} - def at(self, points, time, *, units=None, extrapolate=False, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, **kwargs): ''' Find the value of the property at positions P at time T @@ -516,7 +516,9 @@ def at(self, points, time, *, units=None, extrapolate=False, **kwargs): if res is not None: return res - extrapolate = self.extrapolation_is_allowed or extrapolate + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed + value = super(GridCurrent, self).at(points, time, units=units, @@ -580,7 +582,7 @@ def __init__(self, self.wet_dry_mask = wet_dry_mask - def at(self, points, time, *, units=None, extrapolate=False, coord_sys='uv', _auto_align=True, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, coord_sys='uv', _auto_align=True, **kwargs): ''' Find the value of the property at positions P at time T @@ -628,7 +630,8 @@ def at(self, points, time, *, units=None, extrapolate=False, coord_sys='uv', _au return self.transform_result(value, coord_sys) if value is None: - extrapolate = self.extrapolation_is_allowed or extrapolate + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed value = super(GridWind, self).at(pts, time, units=units, extrapolate=extrapolate, @@ -711,7 +714,7 @@ def __init__(self, *args, **kwargs): kwargs['data'] = data - def at(self, points, time, *, units=None, extrapolate=False, + def at(self, points, time, *, units=None, extrapolate=None, _hash=None, _mem=True, **kwargs): if _hash is None: @@ -728,6 +731,9 @@ def at(self, points, time, *, units=None, extrapolate=False, _time_idx = self.time.index_of(time) order = self.dimension_ordering + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed + if order[0] == 'time': value = self._time_interp(points, time, units=units, extrapolate=extrapolate, _mem=_mem, _hash=_hash, **kwargs) @@ -840,8 +846,9 @@ def init_from_netCDF(self, **kwargs ) - def at(self, points, time, *, units=None, extrapolate=False, **kwargs): - extrapolate = self.extrapolation_is_allowed or extrapolate + def at(self, points, time, *, units=None, extrapolate=None, **kwargs): + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed cctn = (self.ice_concentration.at(points, time, extrapolate=extrapolate, **kwargs) .copy()) @@ -907,13 +914,14 @@ def from_netCDF(cls, ice_velocity=ice_velocity, **kwargs)) - def at(self, points, time, *, units=None, extrapolate=False, min_val=0, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, min_val=0, **kwargs): """ :param min_val: Minimum value for wind speed. If computed wind speed is less than this value, it will be set to this value. :type min_val: float """ - extrapolate = self.extrapolation_is_allowed or extrapolate + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed cctn = self.ice_concentration.at(points, time, extrapolate=extrapolate, **kwargs) wind_v = super(IceAwareWind, self).at(points, time, diff --git a/py_gnome/gnome/environment/gridded_objects_base.py b/py_gnome/gnome/environment/gridded_objects_base.py index 8cc8e1f8d..f461b010f 100644 --- a/py_gnome/gnome/environment/gridded_objects_base.py +++ b/py_gnome/gnome/environment/gridded_objects_base.py @@ -589,7 +589,10 @@ def from_netCDF(cls, *args, **kwargs): return var @combine_signatures - def at(self, points, time, *, units=None, extrapolate=False, unmask=True, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, unmask=True, **kwargs): + + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed value = super(Variable, self).at(points, time, units=units, @@ -744,7 +747,7 @@ def __init__(self, **kwargs): super(VectorVariable, self).__init__(*args, **kwargs) self.extrapolation_is_allowed = extrapolation_is_allowed - + #Adding this so unit conversion happens properly in the components #I really don't think we will be doing mixed units in one of these #anytime soon. @@ -755,8 +758,8 @@ def __init__(self, warnings.warn("Variable {0} has units {1} which are not the same as the VectorVariable {2} units {3}.".format(var.name, var._gnome_unit, self.name, self._gnome_unit)) else: var._gnome_unit = self._gnome_unit - - + + def __repr__(self): try: @@ -939,7 +942,7 @@ def constant(cls, :param values: vector of values :type values: array-like ''' - + Grid = Grid_S Time = cls._default_component_types['time'] _node_lon = np.array(([-360, 0, 360], [-360, 0, 360], [-360, 0, 360])) @@ -952,9 +955,11 @@ def constant(cls, _vars = [Variable(grid=_grid, units=units[i], time=_time, data=d) for i, d in enumerate(_datas)] return cls(name=name, grid=_grid, time=_time, variables=_vars) - def at(self, points, time, *, units=None, extrapolate=False, unmask=True, **kwargs): + def at(self, points, time, *, units=None, extrapolate=None, unmask=True, **kwargs): units = units if units else self._gnome_unit #no need to convert here, its handled in the subcomponents - value = super(VectorVariable, self).at(points, time, + if extrapolate is None: + extrapolate = self.extrapolation_is_allowed + value = super(VectorVariable, self).at(points, time, units=units, extrapolate=extrapolate, unmask=unmask, @@ -1013,7 +1018,7 @@ def get_data_vectors(self): xt = x.shape[0] y = raw_v[:] yt = y.shape[0] - if raw_u.shape[-2:] == raw_v.shape[-2:] and raw_u.shape[-2:] == self.grid.center_mask.shape: + if raw_u.shape[-2:] == raw_v.shape[-2:] and raw_u.shape[-2:] == self.grid.center_mask.shape: #raw u/v are same shape and on center #need to padding_slice the variable since they are not interpolated from u/v x = x[(np.s_[:],) + ctr_padding_slice]