Skip to content

Commit

Permalink
Merge branch 'schismv2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdurrant committed Jan 11, 2024
2 parents 208fca4 + 6df370b commit 04555bd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion rompy/schism/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class SCHISMGrid(BaseGrid):
_pyschism_vgrid: Optional[Vgrid] = None

@model_validator(mode="after")
def validate_rough_drag_manning(v):
def validate_rough_drag_manning(cls, v):
fric_sum = sum([v.rough is not None, v.drag is not None, v.manning is not None])
if fric_sum > 1:
raise ValueError("Only one of rough, drag, manning can be set")
Expand Down
22 changes: 12 additions & 10 deletions tests/schism/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
from rompy.core.grid import BaseGrid
from rompy.schism import SCHISMGrid

here = Path(__file__).parent


def test_SCHISMGrid2D(tmpdir):
hgrid = DataBlob(source="test_data/hgrid.gr3")
drag = DataBlob(source="test_data/drag.gr3")
rough = DataBlob(source="test_data/rough.gr3")
manning = DataBlob(source="test_data/manning.gr3")
hgridll = DataBlob(source="test_data/hgrid.ll")
diffmin = DataBlob(source="test_data/diffmin.gr3")
diffmax = DataBlob(source="test_data/diffmax.gr3")
hgrid_WWM = DataBlob(source="test_data/hgrid_WWM.gr3")
wwmbnd = DataBlob(source="test_data/wwmbnd.gr3")
hgrid = DataBlob(source=here / "test_data/hgrid.gr3")
drag = DataBlob(source=here / "test_data/drag.gr3")
rough = DataBlob(source=here / "test_data/rough.gr3")
manning = DataBlob(source=here / "test_data/manning.gr3")
hgridll = DataBlob(source=here / "test_data/hgrid.ll")
diffmin = DataBlob(source=here / "test_data/diffmin.gr3")
diffmax = DataBlob(source=here / "test_data/diffmax.gr3")
hgrid_WWM = DataBlob(source=here / "test_data/hgrid_WWM.gr3")
wwmbnd = DataBlob(source=here / "test_data/wwmbnd.gr3")

grid = SCHISMGrid(
hgrid=hgrid,
# drag=drag,
drag=drag,
# rough=rough,
# manning=1.2,
# hgridll=hgridll,
Expand Down
3 changes: 0 additions & 3 deletions tests/schism/test_namelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def compare_nmls_values(nml1, nml2):
compare_nmls_values(value, nml2[key])
else:
if value != nml2[key]:
import ipdb

print(key, value, nml2[key])
ipdb.set_trace()


def compare_nmls(nml1, nml2):
Expand Down
7 changes: 2 additions & 5 deletions tests/schism/test_schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
from datetime import datetime
from pathlib import Path

import pytest
from utils import compare_files

from rompy.core import DataBlob, TimeRange
from rompy.model import ModelRun
from rompy.schism import Inputs, SchismCSIROConfig, SCHISMGrid

sys.path.append("../")


# from ..utils import compare_files

here = Path(__file__).parent


@pytest.mark.skip(reason="Needs to be updated")
def test_schism_render(tmpdir):
"""Test the swantemplate function."""
run_id = "test_schism"
Expand Down
26 changes: 8 additions & 18 deletions tests/schism/test_schism_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
import xarray as xr

from rompy.core import BaseGrid, DataBlob, DataGrid, TimeRange
from rompy.core.data import SourceDatamesh, SourceDataset, SourceFile, SourceIntake
from rompy.core.data import (SourceDatamesh, SourceDataset, SourceFile,
SourceIntake)
from rompy.schism import SCHISMGrid
from rompy.schism.data import (
SCHISMDataBoundary,
SCHISMDataOcean,
SCHISMDataSflux,
SCHISMDataTides,
SfluxAir,
TidalDataset,
)
from rompy.schism.data import (SCHISMDataBoundary, SCHISMDataOcean,
SCHISMDataSflux, SCHISMDataTides, SfluxAir,
TidalDataset)
from rompy.schism.namelists import Sflux_Inputs

HERE = Path(__file__).parent
Expand All @@ -28,7 +24,7 @@

@pytest.fixture
def grid2d():
return SCHISMGrid(hgrid=DataBlob(source="test_data/hgrid.gr3"), drag=1)
return SCHISMGrid(hgrid=DataBlob(source=HERE / "test_data/hgrid.gr3"), drag=1)


@pytest.fixture
Expand Down Expand Up @@ -88,14 +84,8 @@ def test_oceandata(tmp_path, grid2d, hycom_bnd):
def test_tidal_boundary(tmp_path, grid2d):
tides = SCHISMDataTides(
tidal_data=TidalDataset(
elevations=Path(__file__).parent
/ "test_data"
/ "tpxo9-test"
/ "h_m2s2n2.nc",
velocities=Path(__file__).parent
/ "test_data"
/ "tpxo9-test"
/ "u_m2s2n2.nc",
elevations=HERE / "test_data" / "tpxo9-test" / "h_m2s2n2.nc",
velocities=HERE / "test_data" / "tpxo9-test" / "u_m2s2n2.nc",
),
constituents=["M2", "S2", "N2"],
)
Expand Down
8 changes: 8 additions & 0 deletions tests/schism/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ def download_hycom(dest=Path("./"), hgrid=Path("./hgrid.gr3")):
)
for file in files:
file.unlink()


def compare_files(file1, file2):
with open(file1, "r") as f1:
with open(file2, "r") as f2:
for line1, line2 in zip(f1, f2):
if line1[0] != "$" and line2[0] != "$":
assert line1.rstrip() == line2.rstrip()

0 comments on commit 04555bd

Please sign in to comment.