Skip to content

Commit 853b84d

Browse files
Add test for constant in time/no time interval field
This test verifies that a field that has no time interval (is constant in time) evaluates to the same value. Additionally, this test is a minimal reproducer for the case that the patch in the search_time_indices function is meant to resolve. The search_time_indices function is called in the `Field.eval` method, which always expects a tuple output corresponding to the time index and the time interpolation weight. Previously, when there was no time interval, the search_time_indices function only returned a single value.
1 parent 38c2ded commit 853b84d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/v4/test_field.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ def test_field_unstructured_z_linear():
147147
assert np.isclose(W.eval(time=ds.time[0].values, z=900.0, y=30.0, x=30.0, applyConversion=False), 900.0)
148148

149149

150+
def test_field_constant_in_time():
151+
"""Tests field evaluation for a field with no time interval (i.e., constant in time)."""
152+
ds = datasets_unstructured["stommel_gyre_delaunay"]
153+
grid = UxGrid(ds.uxgrid, z=ds.coords["nz"])
154+
# Note that the vertical coordinate is required to be the position of the layer interfaces ("nz"), not the mid-layers ("nz1")
155+
P = Field(name="p", data=ds.p, grid=grid, interp_method=UXPiecewiseConstantFace)
156+
157+
# Assert that the field can be evaluated at any time, and returns the same value
158+
time = np.datetime64("2000-01-01T00:00:00")
159+
P1 = P.eval(time=time, z=10.0, y=30.0, x=30.0, applyConversion=False)
160+
P2 = P.eval(time=time + np.timedelta64(1, "D"), z=10.0, y=30.0, x=30.0, applyConversion=False)
161+
assert np.isclose(P1, P2)
162+
163+
150164
def test_field_unstructured_grid_creation(): ...
151165

152166

0 commit comments

Comments
 (0)