-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial preprocessor implementation #52
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5c97716
refactor naming and CLI api to new preprocessor
5288da4
change entry point name
d868e0b
changes to names of hooks, working on testing:
d3b0e40
minor renames, tests with explicit yamls
ed41b32
working preprocessor
353539e
add python api and tests
6400d81
convert all tests to use temp directories and files, except BMI tests.
d7193d5
switch timestep extraction order so no initialization of jobs if bad …
5df8600
documentation for changes made with preprocessor and the renaming models
c27a0e3
cleanup
1ca1cde
rename test file
70bda53
switch tests to use raises
9e522d2
add python api Preprocessor to top level imports
aef535f
update docs, cleanup, add another tests
6016668
add py high level api docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from .deltaRCM_tools import Tools | ||
from .deltaRCM_driver import pyDeltaRCM | ||
from .model import DeltaModel | ||
from .bmi_delta import BmiDelta | ||
from .shared_tools import _get_version | ||
|
||
__all__ = ['Tools', 'pyDeltaRCM', 'BmiDelta'] | ||
__all__ = ['DeltaModel', 'BmiDelta'] | ||
__version__ = _get_version() |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from pyDeltaRCM import command_line | ||
from . import preprocessor | ||
|
||
if __name__ == '__main__': | ||
command_line.run_model() | ||
preprocessor.preprocessor_wrapper() |
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 was deleted.
Oops, something went wrong.
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,6 +142,3 @@ 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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import os | ||
import argparse | ||
import abc | ||
|
||
import yaml | ||
|
||
from .shared_tools import _get_version | ||
from .model import DeltaModel | ||
|
||
_ver = _get_version() | ||
|
||
|
||
class BasePreprocessor(abc.ABC): | ||
"""Base preprocessor class. | ||
|
||
Defines a prelimiary yaml file parsing, the model instatiation, | ||
and timestep loop routine. | ||
|
||
Subclasses handle the high-level command line API | ||
and the python API. | ||
""" | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def preliminary_yaml_parsing(self): | ||
"""A very preliminiary yaml parsing step. | ||
|
||
Here, we check whether | ||
|
||
1) the file is valid yaml | ||
2) for a field named ``matrix`` in the yaml file | ||
3) for a field named ``timesteps`` in the yaml file, which is used | ||
for time looping if it is given. If ``timesteps`` is not given, | ||
an error is raised, and the user is directed to either fix the | ||
issue or use the low-level API. | ||
|
||
""" | ||
|
||
# open the file, an error will be thrown if invalid yaml? | ||
user_file = open(self.input_file, mode='r') | ||
user_dict = yaml.load(user_file, Loader=yaml.FullLoader) | ||
user_file.close() | ||
|
||
if 'matrix' in user_dict.keys(): | ||
raise NotImplementedError('Matrix expansion not yet implemented...') | ||
|
||
if 'timesteps' in user_dict.keys(): | ||
self.timesteps = user_dict['timesteps'] | ||
else: | ||
raise ValueError('You must specify timesteps to use the high-level API.') | ||
|
||
def instatiate_model(self): | ||
self.deltamodel = DeltaModel(input_file=self.input_file) | ||
|
||
def run_model(self): | ||
"""Loop the model. | ||
|
||
Iterate the timestep ``update`` routine for the specified number of | ||
iterations. | ||
""" | ||
|
||
for _t in range(0, self.timesteps): | ||
self.deltamodel.update() | ||
|
||
self.deltamodel.finalize() | ||
|
||
|
||
class CLI_API(BasePreprocessor): | ||
|
||
def __init__(self): | ||
|
||
super().__init__() | ||
|
||
self.process_arguments() | ||
|
||
if self.args['config']: | ||
self.input_file = self.args['config'] | ||
self.preliminary_yaml_parsing() | ||
else: | ||
self.input_file = None | ||
|
||
self.instatiate_model() | ||
|
||
self.run_model() | ||
|
||
def process_arguments(self): | ||
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=_ver, help='Print pyDeltaRCM version.') | ||
|
||
args = parser.parse_args() | ||
|
||
self.args = vars(args) | ||
|
||
|
||
class Python_API(BasePreprocessor): | ||
|
||
def __init__(self): | ||
raise NotImplementedError | ||
super().__init__(self) | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
CLI_API() |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we remove the notion of a default timestepping?