|
14 | 14 | Geographic, |
15 | 15 | Particle, |
16 | 16 | ParticleSet, |
17 | | - StatusCode, |
18 | 17 | Variable, |
19 | 18 | ) |
20 | 19 | from tests.utils import create_fieldset_global |
@@ -796,82 +795,6 @@ def test_multiple_grid_addlater_error(): |
796 | 795 | assert fail |
797 | 796 |
|
798 | 797 |
|
799 | | -@pytest.mark.v4alpha |
800 | | -@pytest.mark.xfail(reason="Implementation of NestedFields is being reconsidered in v4.") |
801 | | -def test_nestedfields(): |
802 | | - from parcels import NestedField |
803 | | - |
804 | | - xdim = 10 |
805 | | - ydim = 20 |
806 | | - |
807 | | - U1 = Field( |
808 | | - "U1", |
809 | | - 0.1 * np.ones((ydim, xdim), dtype=np.float32), |
810 | | - lon=np.linspace(0.0, 1.0, xdim, dtype=np.float32), |
811 | | - lat=np.linspace(0.0, 1.0, ydim, dtype=np.float32), |
812 | | - ) |
813 | | - V1 = Field( |
814 | | - "V1", |
815 | | - 0.2 * np.ones((ydim, xdim), dtype=np.float32), |
816 | | - lon=np.linspace(0.0, 1.0, xdim, dtype=np.float32), |
817 | | - lat=np.linspace(0.0, 1.0, ydim, dtype=np.float32), |
818 | | - ) |
819 | | - U2 = Field( |
820 | | - "U2", |
821 | | - 0.3 * np.ones((ydim, xdim), dtype=np.float32), |
822 | | - lon=np.linspace(0.0, 2.0, xdim, dtype=np.float32), |
823 | | - lat=np.linspace(0.0, 2.0, ydim, dtype=np.float32), |
824 | | - ) |
825 | | - V2 = Field( |
826 | | - "V2", |
827 | | - 0.4 * np.ones((ydim, xdim), dtype=np.float32), |
828 | | - lon=np.linspace(0.0, 2.0, xdim, dtype=np.float32), |
829 | | - lat=np.linspace(0.0, 2.0, ydim, dtype=np.float32), |
830 | | - ) |
831 | | - U = NestedField("U", [U1, U2]) |
832 | | - V = NestedField("V", [V1, V2]) |
833 | | - fieldset = FieldSet(U, V) |
834 | | - |
835 | | - P1 = Field( |
836 | | - "P1", |
837 | | - 0.1 * np.ones((ydim, xdim), dtype=np.float32), |
838 | | - lon=np.linspace(0.0, 1.0, xdim, dtype=np.float32), |
839 | | - lat=np.linspace(0.0, 1.0, ydim, dtype=np.float32), |
840 | | - ) |
841 | | - P2 = Field( |
842 | | - "P2", |
843 | | - 0.2 * np.ones((ydim, xdim), dtype=np.float32), |
844 | | - lon=np.linspace(0.0, 2.0, xdim, dtype=np.float32), |
845 | | - lat=np.linspace(0.0, 2.0, ydim, dtype=np.float32), |
846 | | - ) |
847 | | - P = NestedField("P", [P1, P2]) |
848 | | - fieldset.add_field(P) |
849 | | - |
850 | | - def Recover(particle, fieldset, time): # pragma: no cover |
851 | | - if particle.state == StatusCode.ErrorOutOfBounds: |
852 | | - particle.dlon = 0 |
853 | | - particle.dlat = 0 |
854 | | - particle.ddepth = 0 |
855 | | - particle.lon = 0 |
856 | | - particle.lat = 0 |
857 | | - particle.p = 999 |
858 | | - particle.state = StatusCode.Evaluate |
859 | | - |
860 | | - pset = ParticleSet(fieldset, pclass=pclass(), lon=[0], lat=[0.3]) |
861 | | - pset.execute(AdvectionRK4 + pset.Kernel(SampleP), runtime=2, dt=1) |
862 | | - assert np.isclose(pset.lat[0], 0.5) |
863 | | - assert np.isclose(pset.p[0], 0.1) |
864 | | - pset = ParticleSet(fieldset, pclass=pclass(), lon=[0], lat=[1.1]) |
865 | | - pset.execute(AdvectionRK4 + pset.Kernel(SampleP), runtime=2, dt=1) |
866 | | - assert np.isclose(pset.lat[0], 1.5) |
867 | | - assert np.isclose(pset.p[0], 0.2) |
868 | | - pset = ParticleSet(fieldset, pclass=pclass(), lon=[0], lat=[2.3]) |
869 | | - pset.execute(pset.Kernel(AdvectionRK4) + SampleP + Recover, runtime=1, dt=1) |
870 | | - assert np.isclose(pset.lat[0], 0) |
871 | | - assert np.isclose(pset.p[0], 999) |
872 | | - assert np.allclose(fieldset.UV[0][0, 0, 0, 0], [0.1, 0.2]) |
873 | | - |
874 | | - |
875 | 798 | def test_fieldset_sampling_updating_order(tmp_zarrfile): |
876 | 799 | def calc_p(t, y, x): |
877 | 800 | return 10 * t + x + 0.2 * y |
|
0 commit comments