Skip to content

Commit 93c945a

Browse files
authored
Merge pull request #761 from stkistner/bugfix_dfs2_y_ax
Bugfix: bug fix in spectral 2D grid y ax
2 parents 504d2ad + e24f3df commit 93c945a

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

mikeio/spatial/_grid_geometry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,10 @@ def y(self) -> np.ndarray:
700700

701701
y1 = y0 + self.dy * (self.ny - 1)
702702
y_local = np.linspace(y0, y1, self.ny)
703-
return y_local if self._is_rotated else y_local + self._origin[1]
703+
if self._is_rotated or self.is_spectral:
704+
return y_local
705+
else:
706+
return y_local + self._origin[1]
704707

705708
@property
706709
def nx(self) -> int:

tests/test_dfs2.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def dfs2_random_2items():
2525
return mikeio.open(filepath)
2626

2727

28+
@pytest.fixture
29+
def dfs2_pt_spectrum_geographical():
30+
filepath = Path("tests/testdata/spectra/pt_spectra_geographical.dfs2")
31+
return mikeio.open(filepath, type="spectral")
32+
33+
2834
@pytest.fixture
2935
def dfs2_pt_spectrum():
3036
filepath = Path("tests/testdata/spectra/pt_spectra.dfs2")
@@ -312,6 +318,31 @@ def test_properties_pt_spectrum(dfs2_pt_spectrum):
312318
assert g.orientation == 0
313319

314320

321+
def test_properties_pt_spectrum_geographical(dfs2_pt_spectrum_geographical):
322+
dfs = dfs2_pt_spectrum_geographical
323+
assert dfs.x0 == pytest.approx(0.055)
324+
assert dfs.y0 == 0
325+
assert dfs.dx == pytest.approx(1.1)
326+
assert dfs.dy == 22.5
327+
assert dfs.nx == 25
328+
assert dfs.ny == 16
329+
assert dfs.longitude == pytest.approx(0, abs=1e-6)
330+
assert dfs.latitude == 0
331+
assert dfs.orientation == 0
332+
assert dfs.n_items == 1
333+
assert dfs.n_timesteps == 31
334+
335+
g = dfs.geometry
336+
assert g.is_spectral
337+
assert g.x[0] == pytest.approx(0.055)
338+
# assert g.x[-1] > 25 # if considered linear
339+
assert g.x[-1] < 0.6 # logarithmic
340+
assert g.y[0] == 0
341+
assert g.dx == pytest.approx(1.1)
342+
assert g.dy == 22.5
343+
assert g.orientation == 0
344+
345+
315346
def test_properties_pt_spectrum_linearf(dfs2_pt_spectrum_linearf):
316347
dfs = dfs2_pt_spectrum_linearf
317348
# This file doesn't have a valid projection string
50 KB
Binary file not shown.

0 commit comments

Comments
 (0)