Skip to content

Commit 5c474ae

Browse files
Adding unit test to show combining fields with and without time doesn't currently work
1 parent 11179ed commit 5c474ae

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tests/test_fieldset.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pandas as pd
88
import pytest
9+
import xarray as xr
910

1011
from parcels import Field, ParticleFile, ParticleSet, XGrid, convert
1112
from parcels._core.fieldset import FieldSet, _datetime_to_msg
@@ -359,6 +360,17 @@ def test_fieldset_add():
359360
assert set(fields_before) == set(fset.fields.keys())
360361

361362

363+
def test_vectorfields_without_time():
364+
"""Test that vector fields without a time dimension can be evaluated."""
365+
ds1 = datasets_structured["ds_2d_left"][["U_A_grid", "V_A_grid", "grid"]].rename({"U_A_grid": "U", "V_A_grid": "V"})
366+
ds2 = ds1.isel(time=0).drop_vars("time").rename({"U": "U_const", "V": "V_const"})
367+
ds = xr.merge([ds1, ds2])
368+
369+
fset = FieldSet.from_sgrid_conventions(ds, mesh="flat", vector_fields={"UV_const": ("U_const", "V_const")})
370+
fset.UV_const.eval(t=0, z=0, y=0, x=0)
371+
fset.U_const.eval(t=0, z=0, y=0, x=0)
372+
373+
362374
def test_fieldset_add_error_on_duplicate_context_values():
363375
"""Test that adding FieldSets with overlapping context value names raises a ValueError."""
364376
ds1 = datasets_structured["ds_2d_left"][["U_A_grid", "grid"]].rename({"U_A_grid": "U1"})

0 commit comments

Comments
 (0)