Skip to content

Commit

Permalink
Merge branch 'develop' of https://gitlab.orr.noaa.gov/gnome/pygnome i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
ChrisBarker-NOAA committed Jul 17, 2024
2 parents 095ed28 + ab6ef6f commit 7889914
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion py_gnome/gnome/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 18 additions & 10 deletions py_gnome/gnome/environment/environment_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 13 additions & 8 deletions py_gnome/gnome/environment/gridded_objects_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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]))
Expand All @@ -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,
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 7889914

Please sign in to comment.