Skip to content

Commit

Permalink
fix to extrapolate for ossm wind
Browse files Browse the repository at this point in the history
  • Loading branch information
coconnor8 committed Jul 16, 2024
1 parent 3419c6d commit d3c0ab9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion py_gnome/gnome/environment/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,13 @@ def at(self, points, time, *, units=None, extrapolate=None, coord_sys='uv',_auto
else:
raise ValueError('invalid coordinate system {0}'.format(coord_sys))

# since extrapolation_is_allowed is not passed into the C code we need
# to temporarily set it if extrapolate is passed in, and then change it back
original_extrapolation = self.extrapolation_is_allowed # save value
if extrapolate is not None: # passed in a value, assume this is what we want
self.extrapolation_is_allowed = extrapolate
else: # otherwise probably set on the wind_mover
if self.extrapolation_is_allowed is None:
if self.extrapolation_is_allowed is None: # shouldn't happen
self.extrapolation_is_allowed = False
#print(f"{self.extrapolation_is_allowed=}")
try:
Expand All @@ -565,6 +568,8 @@ def at(self, points, time, *, units=None, extrapolate=None, coord_sys='uv',_auto
# CyTimeseries is raising an IndexError
raise ValueError(f'time specified ({time}) is not within the bounds of the time: '
f'({self.data_start} to {self.data_stop})')
self.extrapolation_is_allowed = original_extrapolation # put it back the way it was

if idx is None:
ret_data[:, 0] = data[0]
ret_data[:, 1] = data[1]
Expand Down
8 changes: 4 additions & 4 deletions py_gnome/tests/unit_tests/test_environment/test_wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def test_at_out_of_bounds(wind_circ):
result = wind.at([(0, 0, 0)], wind.data_stop)
assert np.array_equal(result, [[1., 0., 0.]])

# but should work if extrapolate=True
result = wind.at([(0, 0, 0)], wind.data_stop + gs.hours(1), extrapolate=True)
assert np.array_equal(result, [[1., 0., 0.]])

# after the data_stop
with pytest.raises(ValueError) as excinfo:
result = wind.at([(0, 0, 0)], wind.data_stop + gs.hours(1))
Expand All @@ -248,10 +252,6 @@ def test_at_out_of_bounds(wind_circ):
result = wind.at([(0, 0, 0)], wind.data_start - gs.hours(1))
assert "not within the bounds" in str(excinfo.value)

# but should work if extrapolate=True
result = wind.at([(0, 0, 0)], wind.data_stop + gs.hours(1), extrapolate=True)
assert np.array_equal(result, [[1., 0., 0.]])


@pytest.fixture(scope='module')
def wind_rand(rq_rand):
Expand Down

0 comments on commit d3c0ab9

Please sign in to comment.