Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: bug fix in spectral 2D grid y ax #761

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.