mosartwmpy
mosartwmpy: A Python implementation of the MOSART-WM coupled hydrologic routing and water management model - Published in JOSS (2021)
Science Score: 100.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org, zenodo.org -
✓Committers with academic emails
2 of 4 committers (50.0%) from academic institutions -
✓Institutional organization owner
Organization immm-sfa has institutional domain (im3.pnnl.gov) -
✓JOSS paper metadata
Published in Journal of Open Source Software
Repository
Python translation of MOSART-WM: a water routing and management model
Basic Info
- Host: GitHub
- Owner: IMMM-SFA
- License: other
- Language: Python
- Default Branch: main
- Homepage: https://mosartwmpy.readthedocs.io/
- Size: 113 MB
Statistics
- Stars: 23
- Watchers: 8
- Forks: 11
- Open Issues: 12
- Releases: 28
Metadata Files
README.md
mosartwmpy
mosartwmpy is a python translation of MOSART-WM, a model for water routing and reservoir management written in Fortran. The original code can be found at IWMM and E3SM, in which MOSART is the river routing component of a larger suite of earth-science models. The motivation for rewriting is largely for developer convenience -- running, debugging, and adding new capabilities were becoming increasingly difficult due to the complexity of the codebase and lack of familiarity with Fortran. This version aims to be intuitive, lightweight, and well documented, while still being highly interoperable.
For a quick start, check out the Jupyter notebook tutorial!
getting started
Ensure you have Python v3.9 - v3.12 (consider using a virtual environment, see the docs here for a brief tutorial), then install mosartwmpy with:
shell
pip install mosartwmpy
Alternatively, install via conda with:
shell
conda install -c conda-forge mosartwmpy
Download a sample input dataset spanning May 1981 by running the following and selecting option 1 for "tutorial". This will download and unpack the inputs to your current directory. Optionally specify a path to download and extract to instead of the current directory.
shell
python -m mosartwmpy.download
Settings are defined by the merger of the mosartwmpy/config_defaults.yaml and a user specified file which can override any of the default settings. Create a config.yaml file that defines your simulation (if you chose an alternate download directory in the step above, you will need to update the paths to point at your data):
config.yaml```yaml simulation: name: tutorial startdate: 1981-05-24 enddate: 1981-05-26grid: path: ./input/domains/mosartconusnldas_grid.nc
runoff: readfromfile: true path: ./input/runoff/runoff198105.nc
watermanagement: enabled: true demand: readfromfile: true path: ./input/demand/demand198105.nc reservoirs: enableistarf: true parameters: path: ./input/reservoirs/reservoirs.nc dependencies: path: ./input/reservoirs/dependencydatabase.parquet streamflow: path: ./input/reservoirs/meanmonthlyreservoirflow.parquet demand: path: ./input/reservoirs/meanmonthlyreservoir_demand.parquet ```
mosartwmpy implements the Basic Model Interface defined by the CSDMS, so driving it should be familiar to those accustomed to the BMI. To launch the simulation, open a python shell and run the following:
```python from mosartwmpy import Model
path to the configuration yaml file
config_file = 'config.yaml'
initialize the model
mosartwm = Model() mosartwm.initialize(config_file)
advance the model one timestep
mosart_wm.update()
advance until the simulation.end_date specified in config.yaml
mosartwm.updateuntil(mosartwm.getend_time()) ```
model input
Input for mosartwmpy consists of many files defining the characteristics of the discrete grid, the river network, surface and subsurface runoff, water demand, and dams/reservoirs.
Currently, the gridded data is expected to be provided at the same spatial resolution.
Runoff input can be provided at any time resolution; each timestep will select the runoff at the closest time in the past.
Currently, demand input is read monthly but will also pad to the closest time in the past.
Efforts are under way for more robust demand handling.
Dams/reservoirs require four different input files: the physical characteristics, the average monthly flow expected during the simulation period, the average monthly demand expected during the simulation period, and a database mapping each GRanD ID to grid cell IDs allowed to extract water from it.
These dam/reservoir input files can be generated from raw GRanD data, raw elevation data, and raw ISTARF data using the provided utility.
The best way to understand the expected format of the input files is to examine the sample inputs provided by the download utility: python -m mosartwmpy.download.
multi-file input
To use multi-file demand or runoff input, use year/month/day placeholders in the file path options like so:
* If your files look like runoff-1999.nc, use runoff-{Y}.nc as the path
* If your files look like runoff-1999-02.nc, use runoff-{Y}-{M}.nc as the path
* If your files look like runoff-1999-02-03, use runoff-{Y}-{M}-{D}.nc as the path, but be sure to provide files for leap days as well!
model output
By default, key model variables are output on a monthly basis at a daily averaged resolution to ./output/<simulation name>/<simulation name>_<year>_<month>.nc. See the configuration file for examples of how to modify the outputs, and the ./mosartwmpy/state/state.py file for state variable names.
Alternatively, certain model outputs deemed most important can be accessed using the BMI interface methods. For example: ```python from mosartwmpy import Model
mosartwm = Model() mosartwm.initialize()
get a list of model output variables
mosartwm.getoutputvarnames()
get the flattened numpy.ndarray of values for an output variable
supply = mosartwm.getvalueptr('supplywater_amount') ```
subdomains
To simulate only a subset of basins (defined here as a collection of grid cells that share the same outlet cell),
use the configuration option grid -> subdomain (see example below) and provide a list of latitude/longitude
coordinate pairs representing each basin of interest (any single coordinate pair within the basin). For example, to
simulate only the Columbia River basin and the Lake Washington regions, one could enter the coordinates for Portland and
Seattle:
config.yamlyaml grid: subdomain: - 47.6062,-122.3321 - 45.5152,-122.6784 unmask_output: true
By default, the output files will still store empty NaN-like values for grid cells outside the subdomain, but
for even faster simulations and smaller output files set the grid -> unmask_output option to false. Disabling
this option causes the output files to only store values for grid cells within the subdomain. These smaller files
will likely take extra processing to effectively interoperate with other models.
visualization
Model instances can plot the current value of certain input and output variables (those available from Model.get_output_var_name and Model.get_input_var_names):
```python from mosartwmpy import Model configfile = 'config.yaml' mosartwm = Model() mosartwm.initialize(configfile) for _ in range(8): mosart_wm.update()
mosartwm.plotvariable('outgoingwatervolumetransportalongriverchannel', log_scale=True)
```

Using provided utility functions, the output of a simulation can be plotted as well.
Plot the storage, inflow, and outflow of a particular GRanD dam: ```python from mosartwmpy import Model from mosartwmpy.plotting.plot import plotreservoir configfile = 'config.yaml' mosartwm = Model() mosartwm.initialize(configfile) mosartwm.update_until()
plotreservoir(
model=mosartwm,
grand_id=310,
start='1981-05-01',
end='1981-05-31',
)
```

Plot a particular output variable (as defined in config.yaml) over time:
```python
from mosartwmpy import Model
from mosartwmpy.plotting.plot import plotvariable
configfile = 'config.yaml'
mosartwm = Model()
mosartwm.initialize(configfile)
mosartwm.update_until()
plotvariable(
model=mosartwm,
variable='RIVERDISCHARGEOVERLANDLIQ',
start='1981-05-01',
end='1981-05-31',
logscale=True,
cmap='winterr',
)
```

If cartopy, scipy, and geoviews are installed, tiles can be displayed along with the plot:
python
plot_variable(
model=mosart_wm,
variable='RIVER_DISCHARGE_OVER_LAND_LIQ',
start='1981-05-01',
end='1981-05-31',
log_scale=True,
cmap='winter_r',
tiles='StamenWatercolor'
)

model coupling
A common use case for mosartwmpy is to run coupled with output from the Community Land Model (CLM). To see an example of how to drive mosartwmpy with runoff from a coupled model, check out the Jupyter notebook tutorial!
testing and validation
Before running the tests or validation, make sure to download the "sample_input" and "validation" datasets using the download utility python -m mosartwmpy.download.
To execute the tests, run ./test.sh or python -m unittest discover mosartwmpy/tests from the repository root.
To execute the validation, run a model simulation that includes the years 1981 - 1982, note your output directory, and then run python -m mosartwmpy.validate from the repository root. This will ask you for the simulation output directory, think for a moment, and then open a figure with several plots representing the NMAE (Normalized Mean Absolute Error) as a percentage and the spatial sums of several key variables compared between your simulation and the validation scenario. Use these plots to assist you in determining if the changes you have made to the code have caused unintended deviation from the validation scenario. The NMAE should be 0% across time if you have caused no deviations. A non-zero NMAE indicates numerical difference between your simulation and the validation scenario. This might be caused by changes you have made to the code, or alternatively by running a simulation with different configuration or parameters (i.e. larger timestep, fewer iterations, etc). The plots of the spatial sums can assist you in determining what changed and the overall magnitude of the changes.
If you wish to merge code changes that intentionally cause significant deviation from the validation scenario, please work with the maintainers to create a new validation dataset.
Owner
- Name: Integrated Multisector Multiscale Modeling
- Login: IMMM-SFA
- Kind: organization
- Location: Richland, WA
- Website: https://im3.pnnl.gov/
- Repositories: 45
- Profile: https://github.com/IMMM-SFA
Models and code from the IM3 SFA
JOSS Publication
mosartwmpy: A Python implementation of the MOSART-WM coupled hydrologic routing and water management model
Authors
Tags
hydrology water management multisector dynamics reservoir modelingCitation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Thurber"
given-names: "Travis"
orcid: "https://orcid.org/0000-0002-4370-9971"
- family-names: "Rexer"
given-names: "Emily"
orcid: "https://orcid.org/0000-0002-0327-183X"
- family-names: "Vernon"
given-names: "Chris"
orcid: "https://orcid.org/0000-0002-3406-6214"
- family-names: "Sun"
given-names: "Ning"
orcid: "https://orcid.org/0000-0002-4094-4482"
- family-names: "Turner"
given-names: "Sean"
orcid: "https://orcid.org/0000-0003-4400-9800"
- family-names: "Yoon"
given-names: "Jim"
orcid: "https://orcid.org/0000-0002-8025-2587"
- family-names: "Broman"
given-names: "Daniel"
orcid: "https://orcid.org/0000-0001-8281-3299"
- family-names: "Voisin"
given-names: "Nathalie"
orcid: "https://orcid.org/0000-0002-6848-449X"
title: "mosartwmpy"
version: 0.2.7
date-released: "2022-02-03"
url: "https://github.com/IMMM-SFA/mosartwmpy"
identifiers:
- description: "mosartwmpy: A Python implementation of the MOSART-WM coupled hydrologic routing and water management model"
type: doi
value: "10.21105/joss.03221"
date-released: "2021-06-24"
GitHub Events
Total
- Issues event: 1
- Watch event: 4
- Delete event: 6
- Issue comment event: 2
- Push event: 13
- Pull request review comment event: 2
- Pull request review event: 6
- Pull request event: 9
- Fork event: 3
- Create event: 5
Last Year
- Issues event: 1
- Watch event: 4
- Delete event: 6
- Issue comment event: 2
- Push event: 13
- Pull request review comment event: 2
- Pull request review event: 6
- Pull request event: 9
- Fork event: 3
- Create event: 5
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| travis | t****r@p****v | 163 |
| crvernon | c****n@g****m | 29 |
| erexer | 1****r | 20 |
| nathalievoisin | n****n@p****v | 3 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 58
- Total pull requests: 59
- Average time to close issues: about 2 months
- Average time to close pull requests: 8 days
- Total issue authors: 7
- Total pull request authors: 3
- Average comments per issue: 1.09
- Average comments per pull request: 0.86
- Merged pull requests: 55
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 9
- Average time to close issues: N/A
- Average time to close pull requests: about 1 hour
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 0.0
- Average comments per pull request: 0.22
- Merged pull requests: 8
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- thurber (40)
- JannisHoch (5)
- crvernon (4)
- cheginit (4)
- angjuny (1)
- hkhorasani (1)
- erexer (1)
Pull Request Authors
- thurber (41)
- erexer (18)
- crvernon (4)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 4
-
Total downloads:
- pypi 119 last-month
-
Total dependent packages: 0
(may contain duplicates) -
Total dependent repositories: 1
(may contain duplicates) - Total versions: 98
- Total maintainers: 1
proxy.golang.org: github.com/IMMM-SFA/mosartwmpy
- Documentation: https://pkg.go.dev/github.com/IMMM-SFA/mosartwmpy#section-documentation
- License: other
-
Latest release: v0.6.2
published about 2 years ago
Rankings
proxy.golang.org: github.com/immm-sfa/mosartwmpy
- Documentation: https://pkg.go.dev/github.com/immm-sfa/mosartwmpy#section-documentation
- License: other
-
Latest release: v0.6.2
published about 2 years ago
Rankings
pypi.org: mosartwmpy
Python implementation of MOSART-WM: A water routing and management model
- Homepage: https://github.com/IMMM-SFA/mosartwmpy
- Documentation: https://mosartwmpy.readthedocs.io/
- License: BSD2-Simplified
-
Latest release: 0.6.2
published about 2 years ago
Rankings
Maintainers (1)
conda-forge.org: mosartwmpy
- Homepage: https://github.com/IMMM-SFA/mosartwmpy
- License: BSD-3-Clause
-
Latest release: 0.4.4
published over 3 years ago
Rankings
Dependencies
- actions/checkout v1 composite
- actions/setup-python master composite
- codecov/codecov-action v1 composite
- python 3.9-slim-bullseye build
- bmipy >=2.0
- click >=8.0.1
- contextily >=1.2.0
- dask *
