Skip to content

Commit 1f23666

Browse files
authored
Merge pull request #176 from UW-Hydro/develop
Update master for 2.1.0 release
2 parents 56a34fc + f8fb72e commit 1f23666

13 files changed

+239
-33
lines changed

ci/requirements-3.5.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ channels:
33
- conda-forge
44
dependencies:
55
- python=3.5
6-
- xarray=0.10.9
6+
- xarray>=0.11.0
77
- pandas
88
- netcdf4
99
- numba
1010
- bottleneck
1111
- numpy
1212
- scipy
1313
- pytest
14+
- dask
15+
- distributed
16+
- toolz
1417
- pip:
1518
- coveralls
1619
- pytest-cov

ci/requirements-3.6.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ channels:
33
- conda-forge
44
dependencies:
55
- python=3.6
6-
- xarray=0.10.9
6+
- xarray>=0.11.0
77
- pandas
88
- netcdf4
99
- bottleneck
1010
- numba
1111
- numpy
1212
- scipy
1313
- pytest
14+
- dask
15+
- distributed
16+
- toolz
1417
- pip:
1518
- coveralls
1619
- pytest-cov

docs/configuration.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ the ``forcing`` entry. Can be one of the following: ``ascii``, ``binary``,
3838

3939
**Optional Variables**
4040

41-
``output_prefix :: str``: The output file base name. Defaults to ``forcing``.
41+
``out_prefix :: str``: The output file base name. Defaults to ``forcing``.
4242

4343
``out_precision :: str``: Precision to use when writing output. Defaults to
4444
``f8``. Can be either ``f4`` or ``f8``.
@@ -183,3 +183,27 @@ a mask of valid cells in the domain, and the elevation given in meters. If
183183
``prec_type`` = ``triangle`` or ``mix``, two additonal variables are required
184184
including ``dur`` and ``t_pk`` for disaggregating daily precipitation according
185185
to the "triangle" method.
186+
187+
constant_vars section
188+
-------------------
189+
The ``constant_vars`` section is optional and allows you to set some of the
190+
forcing inputs to a constant value. The specification simply consists of entries
191+
of the form ``metsim_varname = value``, where ``value`` is a number that can be
192+
converted to a double. There can only be one entry per line. If the
193+
``metsim_varname`` corresponds to an entry that is already in the ``forcing_vars``
194+
section, then the constant value will take precedence. In the current
195+
implementation there must be at least one non-constant entry in ``forcings_vars``
196+
(i.e. at least one entry that is not also in ``constant_vars``).
197+
198+
For example:
199+
``wind = 2.0``
200+
will result in a constant wind field in the output file. In this case ``wind``
201+
does not need to be specified in the ``forcing_vars`` section. If it was, it
202+
will still be set to a constant value of 2 m/s.
203+
204+
Similarly:
205+
``t_max = 30
206+
t_min = 10``
207+
will result in output with a diurnal cycle in which the temperature varies at
208+
all locations between 10C and 30C. However, all estimation and disaggregation
209+
routines are still evaluated, with constant ``t_max`` and ``t_min`` as input.

docs/whats-new.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
What's New
44
==========
55

6+
.. _whats-new.2.0.1.develop:
7+
8+
v.2.0.1.develop
9+
-------
10+
Enhancements
11+
~~~~~~~~~~~~
12+
- Allow for specification of constant fields, through addition
13+
of an optional ``constant_vars`` section.
14+
15+
616
.. _whats-new.2.0.0:
717

818
v.2.0.0

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
dependencies:
55
- python>=3.5
6-
- xarray=0.10.9
6+
- xarray>=0.11.0
77
- pandas
88
- netcdf4>=1.2.5
99
- numba
@@ -12,3 +12,4 @@ dependencies:
1212
- dask
1313
- distributed
1414
- toolz
15+
- pytest
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This is an example of an input file for MetSim
2+
[MetSim]
3+
out_vars = ['temp', 'prec', 'shortwave', 'longwave', 'vapor_pressure', 'rel_humid', 'air_pressure', 'wind']
4+
5+
# Time step in minutes
6+
time_step = 60
7+
8+
# Forcings begin here (year/month/day:hour) (hour optional)
9+
start = 1949/1/1
10+
11+
# Forcings end at this date (year/month/day)
12+
stop = 1949/1/31
13+
14+
# Input and output directories
15+
forcing = ./metsim/data/ascii
16+
domain = ./metsim/data/stehekin.nc
17+
state = ./metsim/data/state_vic.nc
18+
forcing_fmt = ascii
19+
out_dir = ./results
20+
out_prefix = forcing_constant_vars
21+
22+
# How to disaggregate
23+
method = mtclim
24+
25+
[chunks]
26+
lat = 10
27+
lon = 10
28+
29+
# Variables given
30+
[forcing_vars]
31+
prec = prec
32+
t_max = t_max
33+
t_min = t_min
34+
wind = wind
35+
36+
[state_vars]
37+
prec = prec
38+
t_max = t_max
39+
t_min = t_min
40+
41+
[domain_vars]
42+
lat = lat
43+
lon = lon
44+
mask = mask
45+
elev = elev
46+
47+
[constant_vars]
48+
wind = 2.0
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This is an example of an input file for MetSim
2+
[MetSim]
3+
out_vars = ['temp', 'prec', 'shortwave', 'longwave', 'vapor_pressure', 'rel_humid', 'air_pressure', 'wind']
4+
5+
# Time step in minutes
6+
time_step = 30
7+
# Forcings begin here (year/month/day:hour) (hour optional)
8+
start = 1949/1/1
9+
10+
# Forcings end at this date (year/month/day)
11+
stop = 1953/12/31
12+
13+
# Input and output directories
14+
forcing = ./metsim/data/binary
15+
domain = ./metsim/data/stehekin.nc
16+
state = ./metsim/data/state_vic.nc
17+
forcing_fmt = binary
18+
out_dir = ./results
19+
out_prefix = forcing_constant_vars
20+
21+
[chunks]
22+
lat = 10
23+
lon = 10
24+
25+
# Variables given
26+
[forcing_vars]
27+
prec = 40.0 unsigned
28+
t_max = 100.0 signed
29+
t_min = 100.0 signed
30+
wind = 100.0 signed
31+
32+
[state_vars]
33+
prec = prec
34+
t_max = t_max
35+
t_min = t_min
36+
37+
[domain_vars]
38+
lat = lat
39+
lon = lon
40+
mask = mask
41+
elev = elev
42+
43+
[constant_vars]
44+
wind = 2.0
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This is an example of an input file for MetSim
2+
[MetSim]
3+
out_vars = ['temp', 'prec', 'shortwave', 'longwave', 'vapor_pressure', 'rel_humid', 'air_pressure', 'wind']
4+
5+
# Time step in minutes
6+
time_step = 30
7+
8+
# Forcings begin here (year/month/day:hour) (hour optional)
9+
start = 1950/1/1
10+
11+
# Forcings end at this date (year/month/day)
12+
stop = 1950/1/31
13+
14+
# Input and output directories
15+
forcing = ./metsim/data/test.nc
16+
domain = ./metsim/data/domain.nc
17+
state = ./metsim/data/state_nc.nc
18+
19+
forcing_fmt = netcdf
20+
in_format = netcdf
21+
22+
out_dir = ./results
23+
out_prefix = forcing_constant_vars
24+
25+
prec_type = triangle
26+
utc_offset = True
27+
28+
[chunks]
29+
lat = 3
30+
lon = 3
31+
32+
[forcing_vars]
33+
prec = Prec
34+
t_max = Tmax
35+
t_min = Tmin
36+
wind = wind
37+
38+
[state_vars]
39+
prec = prec
40+
t_max = t_max
41+
t_min = t_min
42+
43+
[domain_vars]
44+
lat = lat
45+
lon = lon
46+
mask = mask
47+
elev = elev
48+
t_pk = t_pk
49+
dur = dur
50+
51+
[constant_vars]
52+
wind = 2.0

metsim/cli/ms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import os
2626
import sys
2727
from collections import OrderedDict
28-
from configparser import SafeConfigParser
28+
from configparser import ConfigParser
2929

3030

3131
def _is_valid_file(parser, arg):
@@ -52,13 +52,13 @@ def parse(args):
5252

5353
def init(opts):
5454
"""Initialize some information based on the options & config"""
55-
config = SafeConfigParser()
55+
config = ConfigParser()
5656
config.optionxform = str
5757
config.read(opts.config)
5858
conf = OrderedDict(config['MetSim'])
5959

6060
def invert_dict(d):
61-
return OrderedDict({v: k for k, v in d.items()})
61+
return OrderedDict([reversed(item) for item in d.items()])
6262

6363
def to_list(s):
6464
return json.loads(s.replace("'", '"').split('#')[0])
@@ -69,6 +69,8 @@ def to_list(s):
6969
conf['domain_vars'] = invert_dict(OrderedDict(config['domain_vars']))
7070
conf['state_vars'] = invert_dict(OrderedDict(config['state_vars']))
7171
conf['chunks'] = OrderedDict(config['chunks'])
72+
if 'constant_vars' in config:
73+
conf['constant_vars'] = OrderedDict(config['constant_vars'])
7274

7375
# If the forcing variable is a directory, scan it for files
7476
if os.path.isdir(conf['forcing']):

metsim/io.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def read_ascii(data_handle, domain=None,
120120
dates = date_range(start, stop, calendar=calendar)
121121
names = var_dict.keys()
122122
ds = pd.read_csv(data_handle, header=None, delim_whitespace=True,
123-
sep='\t', names=names).head(len(dates))
123+
names=names).head(len(dates))
124124
ds.index = dates
125125
return ds
126126

@@ -146,7 +146,7 @@ def read_netcdf(data_handle, domain=None,
146146
if var_dict is not None:
147147
var_list = list(var_dict.keys())
148148
ds = ds[var_list]
149-
ds.rename(var_dict, inplace=True)
149+
ds = ds.rename(var_dict)
150150

151151
if start is not None or stop is not None:
152152
ds = ds.sel(time=slice(start, stop))
@@ -162,7 +162,7 @@ def read_data(data_handle, domain=None,
162162
"""Read data directly from an xarray dataset"""
163163
varlist = list(data_handle.keys())
164164
if var_dict is not None:
165-
data_handle.rename(var_dict, inplace=True)
165+
data_handle = data_handle.rename(var_dict)
166166
varlist = list(var_dict.values())
167167
data_handle = data_handle[varlist]
168168

0 commit comments

Comments
 (0)