Skip to content

Commit

Permalink
Merge pull request #83 from UW-Hydro/develop
Browse files Browse the repository at this point in the history
RVIC 1.1.1
  • Loading branch information
Joe Hamman authored Feb 7, 2017
2 parents 622f45d + 40fc9a5 commit afde384
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 59 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ matrix:
- python: 2.7
- python: 3.4
- python: 3.5
- python: 3.6

# Setup anaconda
before_install:
Expand All @@ -23,13 +24,13 @@ before_install:
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a

# Install packages
install:
- conda create --yes --name=test python=$TRAVIS_PYTHON_VERSION numpy scipy pandas netcdf4 matplotlib pytest
- conda create --yes --name=test python=$TRAVIS_PYTHON_VERSION numpy scipy pandas netcdf4 matplotlib pytest -c conda-forge
- source activate test
# - conda install -c https://conda.anaconda.org/ioos cdo
# - pip install cdo
- python setup.py install

# Run test
script:
- py.test
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# RVIC Streamflow Routing Model



| VIC Links & Badges | |
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| VIC Documentation | [![Documentation Status](https://readthedocs.org/projects/rvic/badge/?version=latest)](https://readthedocs.org/projects/rvic/?badge=latest) |
| Travis Build | [![Build Status](https://travis-ci.org/UW-Hydro/RVIC.svg?branch=master)](https://travis-ci.org/UW-Hydro/RVIC) |
| Code Health | [![Code Health](https://landscape.io/github/UW-Hydro/RVIC/master/landscape.svg?style=flat)](https://landscape.io/github/UW-Hydro/RVIC/master) |
| License | [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg)](https://raw.githubusercontent.com/UW-Hydro/RVIC/master/LICENSE.txt) |
| Current Release DOI | [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.32620.svg)](http://dx.doi.org/10.5281/zenodo.32620) |

| Current Release DOI | [![DOI](https://zenodo.org/badge/11590212.svg)](https://zenodo.org/badge/latestdoi/11590212) |

The RVIC streamflow routing model is an adapted version of the model the model typically used as a post-processor with the Variable Infiltration Capacity (VIC) hydrology model. The routing model is a source-to-sink model that solves a linearized version of the Saint-Venant equations. This model, developed by Lohmann et al. (1996, 1998a, 1998b), has been used in many offline studies at a variety of spatial scales. Furthermore, the development of the impulse response functions (IRFs) is done as a preprocessing step, which considerably reduces the computation time in subsequent routing steps.

Expand Down
13 changes: 13 additions & 0 deletions docs/development/whats_new.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# What's New

v1.1.1 (7 February 2017

This release contains a number of bug and compatibility fixes.

### Enhancements

- Ability to pass a dictionary to top level RVIC functions (instead of only a file path). This allows for the generation of large ensembles of RVIC simulations in an interactive environment ([GH78](https://github.com/UW-Hydro/RVIC/pull/78)).

### Bug Fixes

- Fixed bug that in `tools/fraction2domain.bash` by using a temporary variable name ([GH88](https://github.com/UW-Hydro/RVIC/pull/88)).
- Fixed off-by-one error in `history.py` ([GH86](https://github.com/UW-Hydro/RVIC/pull/86)).

v1.1.0 (25 October 2015)

This release contains a number of bug and compatibility fixes.
Expand Down
2 changes: 2 additions & 0 deletions docs/user-guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Almost all of RVIC is available via a public API.
import rvic
```

`rvic.parameters.parameters` and `rvic.convolution.convolution` both support either a path (string) to an INI style configuration file or a dictionary including configuration options. This feature is quite useful when generating ensembles of RVIC simulations.

Most of the internals of RVIC are stored int the `rvic.core` module:

```Python
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
site_name: RVIC
site_description: RVIC Streamflow Routing Model
site_author: UW Hydro | Computational Hydrology
copyright: 'Copyright &copy; 2015, <a href="www.hydro.washington.edu/">University of Washington Computational Hydrology Group</a>.'
copyright: 'Copyright &copy; 2017, <a href="http://uw-hydro.github.io/">University of Washington Computational Hydrology Group</a>.'
repo_url: https://github.com/UW-Hydro/RVIC
theme: readthedocs

Expand Down
27 changes: 13 additions & 14 deletions rvic/convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,21 @@

# -------------------------------------------------------------------- #
# Top Level Driver
def convolution(config_file):
def convolution(config):
'''
Top level driver for RVIC convolution model.
Parameters
----------
config_file : str
Path to RVIC convolution configuration file.
config : str or dict.
Path to RVIC convolution configuration file or dictionary of
configuration options.
'''

# ---------------------------------------------------------------- #
# Initilize
hist_tapes, data_model, rout_var, \
time_handle, directories = convolution_init(config_file)
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
# Setup the pool of processors
# if numofproc > 1:
# pool = LoggingPool(processes=numofproc)
time_handle, directories = convolution_init(config)
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
Expand All @@ -69,7 +64,7 @@ def convolution(config_file):

# -------------------------------------------------------------------- #
# Initialize RVIC
def convolution_init(config_file):
def convolution_init(config):
'''
Initialize the RVIC convolution routine
Expand All @@ -85,8 +80,9 @@ def convolution_init(config_file):
Parameters
----------
config_file : str
Path to RVIC convolution configuration file.
config : str or dict
Path to RVIC convolution configuration file or dictionary of
configuration options.
Returns
----------
Expand All @@ -109,7 +105,10 @@ def convolution_init(config_file):

# ---------------------------------------------------------------- #
# Read Configuration files
config_dict = read_config(config_file)
if isinstance(config, dict):
config_dict = config
else:
config_dict = read_config(config)
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
Expand Down
6 changes: 3 additions & 3 deletions rvic/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def __write_grid(self):
f.createDimension('time', None)

time = f.createVariable('time', self._ncprec, ('time',))
time[:] = self._out_times[:self._out_data_i + 1]
time[:] = self._out_times[:self._out_data_i]
for key, val in iteritems(share.time):
if val:
setattr(time, key, val.encode())
Expand All @@ -531,7 +531,7 @@ def __write_grid(self):

time_bnds = f.createVariable('time_bnds', self._ncprec,
('time', 'nv',), **self.ncvaropts)
time_bnds[:, :] = self._out_time_bnds[:self._out_data_i + 1]
time_bnds[:, :] = self._out_time_bnds[:self._out_data_i]
# ------------------------------------------------------------ #

# ------------------------------------------------------------ #
Expand Down Expand Up @@ -585,7 +585,7 @@ def __write_grid(self):
for field in self._fincl:
var = f.createVariable(field, self._ncprec, tcoords,
**self.ncvaropts)
var[:, :] = self._out_data[field][:self._out_data_i + 1]
var[:, :] = self._out_data[field][:self._out_data_i]

for key, val in iteritems(getattr(share, field)):
if val:
Expand Down
6 changes: 3 additions & 3 deletions rvic/core/make_uh.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def read_direction(fdr, dy, dx):
'''
log.debug('Reading direction input and finding target row/columns')

to_y = np.zeros_like(fdr, dtype=np.int16)
to_x = np.zeros_like(fdr, dtype=np.int16)
to_y = np.zeros_like(fdr, dtype=np.int32)
to_x = np.zeros_like(fdr, dtype=np.int32)

valid_dirs = list(dy.keys())

Expand Down Expand Up @@ -238,7 +238,7 @@ def search_catchment(to_y, to_x, pour_point, basin_ids, basin_id):
# -1 - not in catchment
# 0 - unknown
# 1 - in catchment
in_catch = np.zeros_like(to_x, dtype=np.int16) - 1
in_catch = np.zeros_like(to_x, dtype=np.int32) - 1
in_catch[byinds, bxinds] = 0 # set basin inds as 0

# temporary variables for tracking flow path
Expand Down
28 changes: 16 additions & 12 deletions rvic/core/param_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def finish_params(outlets, dom_data, config_dict, directories):
'SUBSET_DAYS<BASIN_FLOWDAYS')
for key, outlet in iteritems(outlets):
outlet.offset = np.zeros(outlet.unit_hydrograph.shape[1],
dtype=np.int16)
dtype=np.int32)
full_time_length = outlet.unit_hydrograph.shape[0]
subset_length = full_time_length
# ---------------------------------------------------------------- #
Expand Down Expand Up @@ -125,6 +125,10 @@ def finish_params(outlets, dom_data, config_dict, directories):
outlet_name = grouped_data['outlet_name']
outlet_upstream_area = grouped_data['outlet_upstream_area']
outlet_upstream_gridcells = grouped_data['outlet_upstream_gridcells']

# Make sure the inds are all greater than zero, ref: Github #79
assert source_decomp_ind.min() >= 0, source_decomp_ind
assert outlet_decomp_ind.min() >= 0, outlet_decomp_ind
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
Expand Down Expand Up @@ -322,7 +326,7 @@ def subset(outlets, subset_length=None):
axis=1)

outlet.offset = np.empty(outlet.unit_hydrograph.shape[1],
dtype=np.int16)
dtype=np.int32)
out_uh = np.zeros((subset_length, outlet.unit_hydrograph.shape[1]),
dtype=np.float64)

Expand Down Expand Up @@ -402,23 +406,23 @@ def group(outlets, subset_length):
gd['frac_sources'] = np.empty(n_sources, dtype=np.float64)
gd['source_lon'] = np.empty(n_sources, dtype=np.float64)
gd['source_lat'] = np.empty(n_sources, dtype=np.float64)
gd['source_x_ind'] = np.empty(n_sources, dtype=np.int16)
gd['source_y_ind'] = np.empty(n_sources, dtype=np.int16)
gd['source_decomp_ind'] = np.empty(n_sources, dtype=np.int16)
gd['source_time_offset'] = np.empty(n_sources, dtype=np.int16)
gd['source2outlet_ind'] = np.empty(n_sources, dtype=np.int16)
gd['source_x_ind'] = np.empty(n_sources, dtype=np.int32)
gd['source_y_ind'] = np.empty(n_sources, dtype=np.int32)
gd['source_decomp_ind'] = np.empty(n_sources, dtype=np.int32)
gd['source_time_offset'] = np.empty(n_sources, dtype=np.int32)
gd['source2outlet_ind'] = np.empty(n_sources, dtype=np.int32)
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
# outlet specific inputs
gd['outlet_lon'] = np.empty(n_outlets, dtype=np.float64)
gd['outlet_lat'] = np.empty(n_outlets, dtype=np.float64)
gd['outlet_x_ind'] = np.empty(n_outlets, dtype=np.int16)
gd['outlet_y_ind'] = np.empty(n_outlets, dtype=np.int16)
gd['outlet_decomp_ind'] = np.empty(n_outlets, dtype=np.int16)
gd['outlet_number'] = np.empty(n_outlets, dtype=np.int16)
gd['outlet_x_ind'] = np.empty(n_outlets, dtype=np.int32)
gd['outlet_y_ind'] = np.empty(n_outlets, dtype=np.int32)
gd['outlet_decomp_ind'] = np.empty(n_outlets, dtype=np.int32)
gd['outlet_number'] = np.empty(n_outlets, dtype=np.int32)
gd['outlet_name'] = np.empty(n_outlets, dtype='S{0}'.format(MAX_NC_CHARS))
gd['outlet_upstream_gridcells'] = np.empty(n_outlets, dtype=np.int16)
gd['outlet_upstream_gridcells'] = np.empty(n_outlets, dtype=np.int32)
gd['outlet_upstream_area'] = np.empty(n_outlets, dtype=np.float64)
# ---------------------------------------------------------------- #

Expand Down
4 changes: 3 additions & 1 deletion rvic/core/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def uhs(data, title, case_id, plot_dir):
plt.xlabel('timesteps')
plt.ylabel('unit-hydrograph')
fig.savefig(pfname)

plt.close()
return pfname
# -------------------------------------------------------------------- #

Expand Down Expand Up @@ -71,6 +71,7 @@ def _fractions_grid(data, dom_x, dom_y, title, case_id, plot_dir):
plt.ylim([0, dom_y.shape[0]])
plt.xlim([0, dom_x.shape[1]])
fig.savefig(pfname)
plt.close()
# ---------------------------------------------------------------- #
return pfname
# -------------------------------------------------------------------- #
Expand Down Expand Up @@ -129,6 +130,7 @@ def _fractions_map(data, dom_x, dom_y, title, case_id, plot_dir):
m.colorbar(cs, location='right', pad='5%')
plt.title(title)
fig.savefig(pfname)
plt.close()
# ---------------------------------------------------------------- #
return pfname
# -------------------------------------------------------------------- #
Expand Down
6 changes: 4 additions & 2 deletions rvic/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ def read_domain(domain_dict, lat0_is_min=False):
# ---------------------------------------------------------------- #
# Create the cell_ids variable
dom_mask = domain_dict['LAND_MASK_VAR']
temp = np.arange(dom_data[dom_mask].size)
dom_data['cell_ids'] = temp.reshape(dom_data[dom_mask].shape)
dom_data['cell_ids'] = np.arange(
dom_data[dom_mask].size).reshape(dom_data[dom_mask].shape)
# Make sure the inds are all greater than zero, ref: Github #79
assert dom_data['cell_ids'].min() >= 0
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
Expand Down
29 changes: 20 additions & 9 deletions rvic/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@

# -------------------------------------------------------------------- #
# Top level driver
def parameters(config_file, numofproc=1):
def parameters(config, numofproc=1):
'''
Top level function for RVIC parameter generation function.
Parameters
----------
config_file : str
Path to RVIC parameters configuration file.
config : str or dict
Path to RVIC parameters configuration file or dictionary of
configuration options.
numofproc : int
Number of processors to use when developing RVIC parameters.
'''

# ---------------------------------------------------------------- #
# Initilize
uh_box, fdr_data, fdr_vatts, dom_data, \
outlets, config_dict, directories = gen_uh_init(config_file)
outlets, config_dict, directories = gen_uh_init(config)
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
Expand Down Expand Up @@ -100,7 +101,7 @@ def parameters(config_file, numofproc=1):
# -------------------------------------------------------------------- #


def gen_uh_init(config_file):
def gen_uh_init(config):
'''Initialize RVIC parameters script.
This function:
Expand All @@ -113,8 +114,9 @@ def gen_uh_init(config_file):
Parameters
----------
config_file : str
Path to RVIC parameters configuration file.
config : str or dict
Path to RVIC parameters configuration file or dictionary of
configuration options.
Returns
----------
Expand All @@ -138,7 +140,10 @@ def gen_uh_init(config_file):

# ---------------------------------------------------------------- #
# Read Configuration files
config_dict = read_config(config_file)
if isinstance(config, dict):
config_dict = config
else:
config_dict = read_config(config)
# ---------------------------------------------------------------- #

# ---------------------------------------------------------------- #
Expand All @@ -158,7 +163,8 @@ def gen_uh_init(config_file):

# ---------------------------------------------------------------- #
# copy inputs to $case_dir/inputs and update configuration
config_dict = copy_inputs(config_file, directories['inputs'])
if not isinstance(config, dict):
config_dict = copy_inputs(config, directories['inputs'])
options = config_dict['OPTIONS']
# ---------------------------------------------------------------- #

Expand Down Expand Up @@ -570,6 +576,11 @@ def gen_uh_run(uh_box, fdr_data, fdr_vatts, dom_data, outlet, config_dict,
outlet.cell_id_source = dom_data['cell_ids'][y, x]
outlet.x_source = x
outlet.y_source = y

# Make sure the inds are all greater than zero, ref: Github #79
assert all(outlet.cell_id_source >= 0)
assert all(outlet.x_source >= 0)
assert all(outlet.y_source >= 0)
# ---------------------------------------------------------------- #
return outlet
# -------------------------------------------------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

MAJOR = 1
MINOR = 1
MICRO = 0
MICRO = 1
ISRELEASED = True
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
QUALIFIER = ''
Expand Down
Loading

0 comments on commit afde384

Please sign in to comment.