Skip to content

Commit

Permalink
Merge pull request #761 from stkistner/bugfix_dfs2_y_ax
Browse files Browse the repository at this point in the history
Bugfix: bug fix in spectral 2D grid y ax
  • Loading branch information
ecomodeller authored Nov 29, 2024
2 parents 504d2ad + e24f3df commit 93c945a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mikeio/spatial/_grid_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_dfs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.

0 comments on commit 93c945a

Please sign in to comment.