-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ericbarefoot/iss22
Adding command line interface to model
- Loading branch information
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pyDeltaRCM import command_line | ||
|
||
if __name__ == '__main__': | ||
command_line.run_model() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import argparse | ||
|
||
import pyDeltaRCM | ||
from . import deltaRCM_driver | ||
|
||
|
||
def run_model(): | ||
|
||
parser = argparse.ArgumentParser(description='Options for running pyDeltaRCM from command line') | ||
|
||
parser.add_argument('--config', help='Path to a config file that you would like to use.') | ||
parser.add_argument('--version', action='version', version='pyDeltaRCM ' + pyDeltaRCM.__version__, help='Prints the version of pyDeltaRCM.') | ||
|
||
args = parser.parse_args() | ||
|
||
cmdlineargs = vars(args) | ||
|
||
if cmdlineargs['config'] is not None: | ||
delta = deltaRCM_driver.pyDeltaRCM(input_file=cmdlineargs['config']) | ||
else: | ||
delta = deltaRCM_driver.pyDeltaRCM() | ||
|
||
for time in range(0, delta.timesteps): | ||
|
||
delta.update() | ||
|
||
delta.finalize() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
run_model() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,6 @@ coeff_U_ero_sand: | |
alpha: | ||
type: ['float', 'int'] | ||
default: 0.1 | ||
timesteps: | ||
type: ['float', 'int'] | ||
default: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ save_discharge_grids: False | |
save_velocity_grids: False | ||
save_dt: 50 | ||
save_strata: False | ||
timesteps: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import pytest | ||
|
||
import os | ||
import shutil | ||
import locale | ||
import numpy as np | ||
import subprocess | ||
|
||
import pyDeltaRCM as deltaModule | ||
from pyDeltaRCM import command_line | ||
|
||
|
||
def test_call(): | ||
""" | ||
test calling the command line feature with a config file. | ||
""" | ||
subprocess.run(['run_pyDeltaRCM', '--config', os.path.join(os.getcwd(), 'tests', 'test_output.yaml')]) | ||
assert os.path.isfile(os.path.join(os.getcwd(), 'test', 'eta_0.0.png')) | ||
shutil.rmtree(os.path.join(os.getcwd(), 'test')) | ||
|
||
|
||
def test_version_call(): | ||
""" | ||
test calling the command line feature to query the version. | ||
""" | ||
encoding = locale.getpreferredencoding() | ||
printed1 = subprocess.run(['run_pyDeltaRCM', '--version'], stdout=subprocess.PIPE, encoding=encoding) | ||
assert printed1.stdout == 'pyDeltaRCM ' + deltaModule.__version__ + '\n' | ||
printed2 = subprocess.run(['python', '-m', 'pyDeltaRCM', '--version'], stdout=subprocess.PIPE, encoding=encoding) | ||
assert printed2.stdout == 'pyDeltaRCM ' + deltaModule.__version__ + '\n' | ||
|
||
|
||
def test_python_call(): | ||
""" | ||
test calling the python hook command line feature with a config file. | ||
""" | ||
subprocess.run(['python', '-m', 'pyDeltaRCM', '--config', os.path.join(os.getcwd(), 'tests', 'test_output.yaml')]) | ||
assert os.path.isfile(os.path.join(os.getcwd(), 'test', 'eta_0.0.png')) | ||
shutil.rmtree(os.path.join(os.getcwd(), 'test')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
site_prefix: '' | ||
case_prefix: '' | ||
out_dir: test | ||
Length: 10.0 | ||
Width: 10.0 | ||
seed: 0 | ||
dx: 1.0 | ||
L0_meters: 1.0 | ||
S0: 0.0002 | ||
itermax: 1 | ||
Np_water: 10 | ||
u0: 1.0 | ||
N0_meters: 2.0 | ||
h0: 1.0 | ||
H_SL: 0.0 | ||
SLR: 0.001 | ||
Np_sed: 10 | ||
f_bedload: 0.5 | ||
C0_percent: 0.1 | ||
toggle_subsidence: False | ||
sigma_max: 0.0 | ||
start_subsidence: 50. | ||
save_eta_figs: True | ||
save_stage_figs: False | ||
save_depth_figs: False | ||
save_discharge_figs: False | ||
save_velocity_figs: False | ||
save_eta_grids: False | ||
save_stage_grids: False | ||
save_depth_grids: False | ||
save_discharge_grids: False | ||
save_velocity_grids: False | ||
save_dt: 50 | ||
save_strata: False | ||
timesteps: 1 |