|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 | import pytest |
3 | 5 | import uxarray as ux |
4 | 6 | import xarray as xr |
5 | 7 |
|
6 | | -from parcels import Field, UXPiecewiseConstantFace, UXPiecewiseLinearNode, xgcm |
| 8 | +from parcels import Field, UXPiecewiseConstantFace, UXPiecewiseLinearNode, VectorField, xgcm |
7 | 9 | from parcels._datasets.structured.generic import T as T_structured |
8 | 10 | from parcels._datasets.structured.generic import datasets as datasets_structured |
9 | 11 | from parcels._datasets.unstructured.generic import datasets as datasets_unstructured |
@@ -115,6 +117,38 @@ def test_vectorfield_init_different_time_intervals(): |
115 | 117 | ... |
116 | 118 |
|
117 | 119 |
|
| 120 | +def test_field_invalid_interpolator(): |
| 121 | + """Test that Field initialization fails with invalid interpolation methods.""" |
| 122 | + ds = datasets_structured["ds_2d_left"] |
| 123 | + grid = XGrid(xgcm.Grid(ds)) |
| 124 | + |
| 125 | + def invalid_interpolator_wrong_signature(self, ti, position, tau, t, z, y, invalid): |
| 126 | + return 0.0 |
| 127 | + |
| 128 | + # Test invalid interpolator with wrong signature |
| 129 | + with pytest.raises(ValueError, match=".*incorrect name.*"): |
| 130 | + Field(name="test", data=ds["data_g"], grid=grid, interp_method=invalid_interpolator_wrong_signature) |
| 131 | + |
| 132 | + |
| 133 | +@pytest.mark.xfail |
| 134 | +def test_vectorfield_invalid_interpolator(): |
| 135 | + """Test that VectorField initialization fails with invalid interpolation methods.""" |
| 136 | + ds = datasets_structured["ds_2d_left"] |
| 137 | + grid = XGrid(xgcm.Grid(ds)) |
| 138 | + |
| 139 | + def invalid_interpolator_wrong_signature(self): |
| 140 | + # Missing required parameters from _interp_template signature |
| 141 | + return 0.0 |
| 142 | + |
| 143 | + # Create component fields |
| 144 | + U = Field(name="U", data=ds["data_g"], grid=grid) |
| 145 | + V = Field(name="V", data=ds["data_g"], grid=grid) |
| 146 | + |
| 147 | + # Test invalid interpolator with wrong signature |
| 148 | + with pytest.raises(ValueError, match=".*incorrect name.*"): |
| 149 | + VectorField(name="UV", U=U, V=V, vector_interp_method=invalid_interpolator_wrong_signature) |
| 150 | + |
| 151 | + |
118 | 152 | def test_field_unstructured_z_linear(): |
119 | 153 | """Tests correctness of piecewise constant and piecewise linear interpolation methods on an unstructured grid with a vertical coordinate. |
120 | 154 | The example dataset is a FESOM2 square Delaunay grid with uniform z-coordinate. Cell centered and layer registered data are defined to be |
|
0 commit comments