Skip to content

Commit

Permalink
tested write param with template
Browse files Browse the repository at this point in the history
  • Loading branch information
jreniel committed Mar 30, 2021
1 parent 5b3e897 commit bc8002d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyschism/cmd/forecast/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def add_forecast_init(actions):
"--skip-run", action="store_true",
help="Skips running the model.")
init.add_argument('--nproc', type=int, default=cpu_count(logical=False))
init.add_argument('--use-param-template', action='store_true')
_add_tidal_constituents(init)
_add_atmospheric_forcing(init)
_add_hydrologic_forcing(init)
Expand Down
3 changes: 2 additions & 1 deletion pyschism/cmd/forecast/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def __init__(self, args: Namespace):
vgrid=False,
fgrid=False,
wind_rot=False,
overwrite=self.args.overwrite
overwrite=self.args.overwrite,
use_param_template=self.args.use_param_template
)

if self.args.skip_run is False:
Expand Down
4 changes: 3 additions & 1 deletion pyschism/driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def write(
nws=True,
wind_rot=True,
stations=True,
use_param_template=False,
):
"""Writes to disk the full set of input files necessary to run SCHISM.
"""
Expand Down Expand Up @@ -132,7 +133,8 @@ def write(
self.model_domain.fgrid.write(outdir / fgrid, overwrite)
if param:
param = 'param.nml' if param is True else param
self.param.write(outdir / param, overwrite)
self.param.write(outdir / param, overwrite,
use_template=use_param_template)
if bctides:
bctides = 'bctides.in' if bctides is True else bctides
self.bctides.write(outdir / bctides, overwrite)
Expand Down
14 changes: 14 additions & 0 deletions pyschism/param/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,17 @@ def __str__(self):
data.append(f" {key}={str(current)}")
data = '\n'.join(data)
return f"&CORE\n{data}\n/"

def to_dict(self):
output = {}
for key, default in PARAM_DEFAULTS.items():
current = getattr(self, key)
if key == 'rnday':
current = current.total_seconds() / (60.*60.*24)
if key == 'dt':
current = current.total_seconds()
if key in self._mandatory:
output[key] = current
elif default != current:
output[key] = current
return output
17 changes: 17 additions & 0 deletions pyschism/param/opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,20 @@ def __str__(self):
current.append(f' {current}({i+1}) = 1')
data = '\n'.join(data)
return f"&OPT\n{data}\n/"

def to_dict(self):
data = {}
for key, default in PARAM_DEFAULTS.items():
current = getattr(self, key)
if key in ['dramp', 'drampbc']:
if current is not None:
current = current.total_seconds() / (60*60*24)
if current is not None:
if not isinstance(current, list):
data[key] = current
else:
data[key] = len(current) * [0]
for i, state in enumerate(current):
if state:
data[key][i] = 1
return data
2 changes: 1 addition & 1 deletion pyschism/param/param.nml.template
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@
! If USE_MARSH is on and isav=1, all .gr3 must have constant depths!
!----------------------------------------------------------------------
isav = 0 !on/off flag
sav_cd = 1.13 !only needed if isav=1. Drag coefficient
! sav_cd = 1.13 !only needed if isav=1. Drag coefficient

!----------------------------------------------------------------------
! Coupling step with ICE module.
Expand Down
6 changes: 3 additions & 3 deletions pyschism/param/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def write(self, path, overwrite=False, use_template=False):

def to_dict(self):
return {
'CORE': self.core.__dict__,
'OPT': self.opt.__dict__,
'SCHOUT': self.schout.__dict__
'CORE': self.core.to_dict(),
'OPT': self.opt.to_dict(),
'SCHOUT': self.schout.to_dict()
}

@property
Expand Down
26 changes: 26 additions & 0 deletions pyschism/param/schout.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,29 @@ def __str__(self):
schout.append(f' {var[1:]}({i+1})={state}')
schout.append('/')
return '\n'.join(schout)

def to_dict(self):
data = {}
if self.nhot_write is not None:
data['nhot'] = self._nhot
data['nhot_write'] = self.nhot_write
if self.nspool_sta is not None:
nspool_sta = self.nspool_sta
if isinstance(nspool_sta, timedelta):
nspool_sta = int(round(nspool_sta.total_seconds() / self._dt))
if isinstance(nspool_sta, float):
nspool_sta = int(
round(timedelta(hours=nspool_sta) / self._dt))
if isinstance(nspool_sta, (int, float)):
if nspool_sta <= 0:
raise ValueError("nspool_sta must be positive.")
data['iout_sta'] = self._iout_sta
data['nspool_sta'] = nspool_sta
for var in dir(self):
if var.startswith('_iof'):
_var = var[1:]
data[_var] = len(getattr(self, var)) * [0]
for i, state in enumerate(getattr(self, var)):
if state == 1:
data[_var][i] = state
return data

0 comments on commit bc8002d

Please sign in to comment.