Skip to content

Commit

Permalink
Added CLI options to enable output requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jreniel committed Jan 17, 2020
1 parent 292ebf4 commit 00cf32f
Show file tree
Hide file tree
Showing 8 changed files with 2,384 additions and 150 deletions.
481 changes: 373 additions & 108 deletions pyschism/cmd/argument_parser.py

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions pyschism/cmd/tidal_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import logging
import argparse
from pyschism.cmd import argument_parser
from pyschism.cmd.basecmd import SchismBaseCommand

Expand All @@ -9,22 +8,19 @@ class TidalRunCommand(SchismBaseCommand):
""" Wrapper for SCHISM tidal only run CLI tool. """


def parse_args():
parser = argparse.ArgumentParser()
argument_parser.add_general_options(parser, 'tidal')
return parser.parse_args()


def main():
args = parse_args()
parser = argument_parser.get_parser(
'tidal',
description="SCHISM tidal only run."
)
args = parser.parse_args()
if len(args.constituents) == 0:
args.constituents = ['all']
logging.basicConfig(level=args.log_level)
logging.getLogger("matplotlib").setLevel(logging.WARNING)
logging.getLogger("paramiko").setLevel(logging.WARNING)
drv = TidalRunCommand(args)
retv = drv.run()
exit(retv)
exit(drv.run())


# https://medium.com/opsops/how-to-test-if-name-main-1928367290cb
Expand Down
88 changes: 74 additions & 14 deletions pyschism/driver/driver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import tempfile
from datetime import datetime, timedelta
import pathlib
from pyschism.mesh import Mesh
from pyschism.driver.param import Param
from pyschism.forcing import (
TidalForcing,
WindForcing,
)
from pyschism.mesh import Mesh


class SchismRun:
Expand All @@ -18,19 +20,21 @@ def __init__(
tidal_forcing=None,
wind_forcing=None,
wave_forcing=None,
tracers=None,
mode='barotropic',
use_transport=False,
transport=False,
netcdf=True,
):
self._mesh = mesh
self._tidal_forcing = tidal_forcing
self._wind_forcing = wind_forcing
self._wave_forcing = wave_forcing
self._start_date = start_date
self._end_date = end_date
self._spinup_time = spinup_time
self._tidal_forcing = tidal_forcing
self._wind_forcing = wind_forcing
self._wave_forcing = wave_forcing
self._tracers = tracers
self._mode = mode
self._use_transport = use_transport
self._transport = transport
self._netcdf = netcdf

def run(
Expand Down Expand Up @@ -114,8 +118,28 @@ def mode(self):
return self._mode

@property
def use_transport(self):
return self._use_transport
def transport(self):
return self._transport

@property
def param(self):
return Param(
self.start_date,
self.end_date,
self.spinup_time,
)

@property
def start_date(self):
return self._start_date

@property
def end_date(self):
return self._end_date

@property
def spinup_time(self):
return self._spinup_time

def _run_local(self, nproc, outdir, overwrite):
self.write(outdir, overwrite)
Expand All @@ -127,6 +151,18 @@ def _run_coldstart(self, nproc, wdir):
def _mesh(self):
return self.__mesh

@property
def _start_date(self):
return self.__start_date

@property
def _end_date(self):
return self.__end_date

@property
def _spinup_time(self):
return self.__spinup_time

@property
def _tidal_forcing(self):
return self.__tidal_forcing
Expand All @@ -140,25 +176,49 @@ def _mode(self):
return self.__mode

@property
def _use_transport(self):
return self.__use_transport
def _transport(self):
return self.__transport

@_mesh.setter
def _mesh(self, mesh):
msg = f"mesh argument must be of type {Mesh}."
assert isinstance(mesh, Mesh), msg
self.__mesh = mesh

@_start_date.setter
def _start_date(self, start_date):
msg = f"start_date must be a {datetime} instance."
assert isinstance(start_date, datetime), msg
self.__start_date = start_date

@_end_date.setter
def _end_date(self, end_date):
msg = f"end_date must be a {datetime} instance."
assert isinstance(end_date, datetime), msg
self.__end_date = end_date

@_spinup_time.setter
def _spinup_time(self, spinup_time):
msg = f"spinup_time must be a {datetime} instance."
assert isinstance(spinup_time, datetime), msg
self.__spinup_time = spinup_time

@_tidal_forcing.setter
def _tidal_forcing(self, tidal_forcing):
if tidal_forcing is not None:
assert isinstance(tidal_forcing, TidalForcing)
tidal_forcing.start_date = self.start_date
tidal_forcing.end_date = self.end_date
tidal_forcing.spinup_time = self.spinup_time
self.__tidal_forcing = tidal_forcing

@_wind_forcing.setter
def _wind_forcing(self, wind_forcing):
if wind_forcing is not None:
assert isinstance(wind_forcing, WindForcing)
wind_forcing.start_date = self.start_date
wind_forcing.end_date = self.end_date
wind_forcing.spinup_time = self.spinup_time
self.__wind_forcing = wind_forcing

@_mode.setter
Expand All @@ -167,7 +227,7 @@ def _mode(self, mode):
assert mode.lower() in ['barotropic', 'baroclinic'], msg
self.__mode = mode

@_use_transport.setter
def _use_transport(self, use_transport):
assert isinstance(use_transport, bool)
self.__use_transport = use_transport
@_transport.setter
def _transport(self, transport):
assert isinstance(transport, bool)
self.__transport = transport
Loading

0 comments on commit 00cf32f

Please sign in to comment.