diff --git a/mikeio/spatial/_grid_geometry.py b/mikeio/spatial/_grid_geometry.py index 734defb56..1ede1cccc 100644 --- a/mikeio/spatial/_grid_geometry.py +++ b/mikeio/spatial/_grid_geometry.py @@ -700,7 +700,10 @@ def y(self) -> np.ndarray: y1 = y0 + self.dy * (self.ny - 1) y_local = np.linspace(y0, y1, self.ny) - return y_local if self._is_rotated else y_local + self._origin[1] + if self._is_rotated or self.is_spectral: + return y_local + else: + return y_local + self._origin[1] @property def nx(self) -> int: diff --git a/tests/test_dfs2.py b/tests/test_dfs2.py index 41e4c7660..4e65629f8 100644 --- a/tests/test_dfs2.py +++ b/tests/test_dfs2.py @@ -25,6 +25,12 @@ def dfs2_random_2items(): return mikeio.open(filepath) +@pytest.fixture +def dfs2_pt_spectrum_geographical(): + filepath = Path("tests/testdata/spectra/pt_spectra_geographical.dfs2") + return mikeio.open(filepath, type="spectral") + + @pytest.fixture def dfs2_pt_spectrum(): filepath = Path("tests/testdata/spectra/pt_spectra.dfs2") @@ -312,6 +318,31 @@ def test_properties_pt_spectrum(dfs2_pt_spectrum): assert g.orientation == 0 +def test_properties_pt_spectrum_geographical(dfs2_pt_spectrum_geographical): + dfs = dfs2_pt_spectrum_geographical + assert dfs.x0 == pytest.approx(0.055) + assert dfs.y0 == 0 + assert dfs.dx == pytest.approx(1.1) + assert dfs.dy == 22.5 + assert dfs.nx == 25 + assert dfs.ny == 16 + assert dfs.longitude == pytest.approx(0, abs=1e-6) + assert dfs.latitude == 0 + assert dfs.orientation == 0 + assert dfs.n_items == 1 + assert dfs.n_timesteps == 31 + + g = dfs.geometry + assert g.is_spectral + assert g.x[0] == pytest.approx(0.055) + # assert g.x[-1] > 25 # if considered linear + assert g.x[-1] < 0.6 # logarithmic + assert g.y[0] == 0 + assert g.dx == pytest.approx(1.1) + assert g.dy == 22.5 + assert g.orientation == 0 + + def test_properties_pt_spectrum_linearf(dfs2_pt_spectrum_linearf): dfs = dfs2_pt_spectrum_linearf # This file doesn't have a valid projection string diff --git a/tests/testdata/spectra/pt_spectra_geographical.dfs2 b/tests/testdata/spectra/pt_spectra_geographical.dfs2 new file mode 100644 index 000000000..aae92718b Binary files /dev/null and b/tests/testdata/spectra/pt_spectra_geographical.dfs2 differ