def test_given_nz(self): e = np.array([0, 1, 1, 2, 1]) z = strat._determine_strat_coordinates(e, nz=50) assert len(z) == 50 + 1 assert z[-1] == 2.00 assert z[0] == 0 assert z[1] - z[0] == pytest.approx(2 / 50) # delta_Z / nz
def test_given_nz_negative_endpoint(self): e = np.array([0, 1, 1, 50, -1]) z = strat._determine_strat_coordinates(e, nz=50) assert len(z) == 50 + 1 assert z[-1] == pytest.approx(50) assert z[0] == -1 assert z[1] - z[0] == pytest.approx(51 / 50) # delta_Z / nz
def test_given_dz(self): e = np.array([0, 1, 1, 2, 1]) z = strat._determine_strat_coordinates(e, dz=0.05) assert len(z) == 41 assert z[-1] == 2.00 assert z[0] == 0 assert z[1] - z[0] == 0.05
def test_onedim_traj_upsanddowns_negatives(self): # e = np.array([0, 0, -1, -4, -2, 3, 3.5, 3, 3, 4, 4]) e = xr.DataArray([0, 0, -1, -4, -2, 3, 3.5, 3, 3, 4, 4]) z = strat._determine_strat_coordinates(e, dz=0.5) # vert coordinates s, p = strat._compute_elevation_to_preservation(e) sc, dc = strat._compute_preservation_to_cube(s, z) c = self.take_var_time(s, z, sc, dc) assert np.all(p.nonzero()[0] == (4, 5, 9))
def test_onedim_traj_drop_at_end_to_zero(self): e = np.array([0, 1, 1, 0]) # e = np.expand_dims(e, axis=(1,2)) z = strat._determine_strat_coordinates(e, dz=0.5) # vert coordinates s, p = strat._compute_elevation_to_preservation(e) sc, dc = strat._compute_preservation_to_cube(s, z) c = self.take_var_time(s, z, sc, dc) assert len(z) == 3 assert np.all(np.isnan(c[:])) assert np.all(p == np.array([False, False, False, False]))
def test_onedim_traj_upsanddowns(self): e = np.array([0, 0, 1, 4, 6, 5, 3.5, 5, 7, 5, 6]) # e = np.expand_dims(e, axis=(1,2)) z = strat._determine_strat_coordinates(e, dz=0.5) # vert coordinates s, p = strat._compute_elevation_to_preservation(e) sc, dc = strat._compute_preservation_to_cube(s, z) c = self.take_var_time(s, z, sc, dc) assert z[-1] == 7 assert s[-1] == 6 assert np.all(p.nonzero()[0] == (2, 3, 7, 10)) assert c[0] == 1
def test_onedim_traj_drop_at_end(self): e = np.array([0, 1, 2, 3, 1]) z = strat._determine_strat_coordinates(e, dz=0.5) # vert coordinates assert z[0] == 0 assert z[-1] == 3 assert len(z) == 7 s, p = strat._compute_elevation_to_preservation(e) sc, dc = strat._compute_preservation_to_cube(s, z) lst = np.argmin(s[:, ...] < s[-1, ...], axis=0) # last elevation idx c = self.take_var_time(s, z, sc, dc) assert s[-1] == e[-1] assert s[-1] == e[-1] assert np.all(np.isnan(c[2:])) # from z>=1 to z==3 assert np.all(c[:2] == 0) assert lst == 1
def test_given_dz_and_nz(self): e = np.array([0, 1, 1, 2, 1]) z = strat._determine_strat_coordinates(e, dz=0.1, nz=50000) assert z[0] == 0 assert z[-1] == 2 assert z[1] - z[0] == 0.1
def test_given_z_and_dz_and_nz(self): e = np.array([0, 1, 1, 2, 1]) z_in = np.arange(0, 10, step=0.2) z = strat._determine_strat_coordinates(e, z=z_in, dz=0.1, nz=50000) assert np.all(z == z_in) assert z[1] - z[0] == 0.2
def test_given_nz_negative(self): e = np.array([0, 1, 1, 2, 1]) with pytest.raises(ValueError, match=r'"dz" or "nz" cannot *.'): _ = strat._determine_strat_coordinates(e, nz=-5)
def test_given_dz_negative_endpoint(self): e = np.array([0, 1, 1, 50, -1]) z = strat._determine_strat_coordinates(e, dz=0.05) assert len(z) == 1021 assert z[-1] == pytest.approx(50) assert z[0] == -1
def test_given_z_scalar(self): e = np.array([0, 1, 1, 2, 1]) with pytest.raises(ValueError): _ = strat._determine_strat_coordinates(e, z=0.05)
def test_given_z(self): e = np.array([0, 1, 1, 2, 1]) z_in = np.arange(0, 10, step=0.2) z = strat._determine_strat_coordinates(e, z=z_in) assert np.all(z == z_in)
def test_given_none_chooses_default(self): e = np.array([0, 1, 1, 2, 1]) with pytest.warns(UserWarning, match=r'No specification *.'): _ = strat._determine_strat_coordinates(e)