Skip to content

Commit

Permalink
Add NWM setup support for SCHISM
Browse files Browse the repository at this point in the history
National Water Model input for SCHISM can now be configured by adding `configure_nwm.json` file to the configuration files. `initialize_schism` will automatically create this file if `--forcing nwm` is included
  • Loading branch information
SorooshMani-NOAA authored Oct 17, 2022
2 parents 2656ca7 + 065a391 commit b052d3f
Show file tree
Hide file tree
Showing 28 changed files with 19,161 additions and 5 deletions.
2 changes: 2 additions & 0 deletions coupledmodeldriver/client/initialize_schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
OWIForcingJSON,
TidalForcingJSON,
WW3DATAForcingJSON,
NationalWaterModelFocringJSON,
)
from coupledmodeldriver.configure.base import NEMSCapJSON
from coupledmodeldriver.configure.forcings.base import (
Expand All @@ -36,6 +37,7 @@
class ForcingConfigurations(Enum):
tidal = TidalForcingJSON
besttrack = BestTrackForcingJSON
nwm = NationalWaterModelFocringJSON


FORCING_NAMES = list(entry.name for entry in ForcingConfigurations)
Expand Down
1 change: 1 addition & 0 deletions coupledmodeldriver/configure/forcings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
OWIForcingJSON,
TidalForcingJSON,
WW3DATAForcingJSON,
NationalWaterModelFocringJSON,
)
75 changes: 73 additions & 2 deletions coupledmodeldriver/configure/forcings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from pyschism.forcing.bctides.tides import TidalDatabase as PySCHISMTidalDatabase
from pyschism.forcing.nws import BestTrackForcing as PySCHISMBestTrackForcing
from pyschism.forcing.base import ModelForcing as PySCHISMForcing
from pyschism.forcing import NWM as PySCHISMNWM
from pyschism.forcing.source_sink.nwm import NWMElementPairings

from coupledmodeldriver.configure.base import (
AttributeJSON,
Expand All @@ -47,12 +49,13 @@
PYSCHISM_FORCINGS = {
'Tides': 'TidalForcingJSON',
'BestTrackForcing': 'BestTrackForcingJSON',
# 'GFS, etc.': 'ATMESHForcingJSON',
'NationalWaterModel': 'NationalWaterModelFocringJSON'
# 'NWM : ,
# 'GFS, etc.': 'ATMESHForcingJSON',
# 'AtmosphericMeshForcing': 'ATMESHForcingJSON',
}

PYSCHISM_FORCING_CLASSES = (PySCHISMTides, PySCHISMForcing)
PYSCHISM_FORCING_CLASSES = (PySCHISMTides, PySCHISMForcing, PySCHISMNWM)


class TidalSource(IntEnum):
Expand Down Expand Up @@ -785,3 +788,71 @@ def nemspy_entry(self) -> WaveWatch3ForcingEntry:
return WaveWatch3ForcingEntry(
filename=self['resource'], processors=self['processors'], **self['nems_parameters']
)


class HydrologyForcingJSON(ForcingJSON, ABC):
"""
abstraction of a hydrology forcing configuration
"""

field_types = {}

def __init__(self, **kwargs):
if 'fields' not in kwargs:
kwargs['fields'] = {}
kwargs['fields'].update(HydrologyForcingJSON.field_types)

ForcingJSON.__init__(self, **kwargs)


class NationalWaterModelFocringJSON(HydrologyForcingJSON, FileForcingJSON):
"""
National water model file configuration in ``configure_nwm.json``
.. code-block:: python
TODO
"""

name = 'NWM'
default_filename = f'configure_nwm.json'
default_aggregation_radius = None
defaul_cache = False
field_types = {
'aggregation_radius': float,
'cache': bool,
}

def __init__(
self, resource: PathLike, **kwargs,
):
if 'fields' not in kwargs:
kwargs['fields'] = {}
kwargs['fields'].update(NationalWaterModelFocringJSON.field_types)

HydrologyForcingJSON.__init__(self, **kwargs)
FileForcingJSON.__init__(self, resource=resource, **kwargs)

@property
def adcircpy_forcing(self) -> None:
raise NotImplementedError('ADCIRC does NOT support NWM forcing!')

@classmethod
def from_adcircpy(cls, forcing: None) -> 'None':
raise NotImplementedError('ADCIRC does NOT support NWM forcing!')

@property
def pyschism_forcing(self) -> PySCHISMNWM:
return PySCHISMNWM(
aggregation_radius=self['aggregation_radius'],
nwm_file=self['resource'],
cache=self['cache'],
)

@classmethod
def from_pyschism(cls, forcing: PySCHISMNWM) -> 'ForcingJSON':
return cls(
resource=forcing.nwm_file,
aggregation_radius=forcing.aggregation_radius,
cache=forcing.cache,
)
9 changes: 7 additions & 2 deletions coupledmodeldriver/generate/schism/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pyschism.forcing.base import ModelForcing
from pyschism.stations import Stations
from pyschism.forcing.nws.base import NWS
from pyschism.forcing import NWM

from coupledmodeldriver.configure import Model, ModelJSON, SlurmJSON
from coupledmodeldriver.configure.base import AttributeJSON, NEMSCapJSON
Expand Down Expand Up @@ -408,6 +409,7 @@ def pyschism_driver(self) -> ModelDriver:
tidal_elevation = None
tidal_velocity = None
meteo = None
hydrology = None
for pyschism_forcing in self.pyschism_forcings:
if isinstance(pyschism_forcing, Tides):

Expand All @@ -420,14 +422,17 @@ def pyschism_driver(self) -> ModelDriver:
elif isinstance(pyschism_forcing, NWS):
meteo = pyschism_forcing

elif isinstance(pyschism_forcing, NWM):
hydrology = pyschism_forcing

config = ModelConfig(
hgrid=self.pyschism_mesh,
vgrid=None,
fgrid=None, # TODO
fgrid=None, # pyschism writes linear with depth for 2D
iettype=tidal_elevation,
ifltype=tidal_velocity,
nws=meteo,
# source_sink=NWM()
source_sink=hydrology,
)

# TODO: What about other variable outputs?
Expand Down
4 changes: 3 additions & 1 deletion coupledmodeldriver/generate/schism/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ForcingJSON,
TidalForcingJSON,
BestTrackForcingJSON,
NationalWaterModelFocringJSON,
)
from coupledmodeldriver.generate.schism.base import SCHISMJSON
from coupledmodeldriver.platforms import Platform
Expand All @@ -40,6 +41,7 @@ class SCHISMRunConfiguration(RunConfiguration):
SUPPLEMENTARY = {
TidalForcingJSON,
BestTrackForcingJSON,
NationalWaterModelFocringJSON,
}

def __init__(
Expand Down Expand Up @@ -174,7 +176,7 @@ def files_exist(self, directory: PathLike) -> bool:
'bctides.in',
'hgrid.gr3',
'hgrid.ll',
# 'manning.gr3',
'manning.gr3',
'outputs',
'param.nml',
'vgrid.in',
Expand Down
Loading

0 comments on commit b052d3f

Please sign in to comment.