From e13db5d7130595f0b9fb9d9d7abe72687db09679 Mon Sep 17 00:00:00 2001 From: arbennett Date: Tue, 8 Aug 2017 16:06:57 -0700 Subject: [PATCH 1/5] Adding documentation on longwave calculations --- metsim/disaggregate.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/metsim/disaggregate.py b/metsim/disaggregate.py index c2e9ed4..da7d1e2 100644 --- a/metsim/disaggregate.py +++ b/metsim/disaggregate.py @@ -358,6 +358,14 @@ def longwave(air_temp: pd.Series, vapor_pressure: pd.Series, choosing these parameterizations should be passed in via the `params` argument. + For more information about the options provided in this + function see: + + .. [1] Bohn, T.J., Livneh, B., Oyler, J.W., Running, S.W., Nijssen, B. + and Lettenmaier, D.P., 2013. Global evaluation of MTCLIM and + related algorithms for forcing of ecological and hydrological + models. Agricultural and forest meteorology, 176, pp.38-49. + Parameters ---------- air_temp: @@ -379,18 +387,25 @@ def longwave(air_temp: pd.Series, vapor_pressure: pd.Series, cover fraction. """ emissivity_calc = { - 'DEFAULT': lambda vp: vp, + # TVA 1972 'TVA': lambda vp: 0.74 + 0.0049 * vp, + # Anderson 1954 'ANDERSON': lambda vp: 0.68 + 0.036 * np.power(vp, 0.5), + # Brutsaert 1975 'BRUTSAERT': lambda vp: 1.24 * np.power(vp / air_temp, 0.14285714), + # Satterlund 1979 'SATTERLUND': lambda vp: 1.08 * ( 1 - np.exp(-1 * np.power(vp, (air_temp / 2016)))), + # Idso 1981 'IDSO': lambda vp: 0.7 + 5.95e-5 * vp * np.exp(1500 / air_temp), + # Prata 1996 'PRATA': lambda vp: (1 - (1 + (46.5*vp/air_temp)) * np.exp( -np.sqrt((1.2 + 3. * (46.5*vp / air_temp))))) } cloud_calc = { - 'DEFAULT': lambda emis: (1.0 + (0.17 * tskc ** 2)) * emis, + # TVA 1972 + 'TVA': lambda emis: (1.0 + (0.17 * tskc ** 2)) * emis, + # Deardorff 1978 'CLOUD_DEARDORFF': lambda emis: tskc + (1 - tskc) * emis } # Reindex and fill cloud cover, then convert temps to K From 35cd81ec335c2ff8b25779c97dac0baa434d54f8 Mon Sep 17 00:00:00 2001 From: Bart Nijssen Date: Tue, 8 Aug 2017 17:09:12 -0700 Subject: [PATCH 2/5] Add references for longwave methods --- metsim/disaggregate.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/metsim/disaggregate.py b/metsim/disaggregate.py index da7d1e2..22f9c1c 100644 --- a/metsim/disaggregate.py +++ b/metsim/disaggregate.py @@ -253,7 +253,7 @@ def pressure(temp: pd.Series, elev: float, lr: float): A sub-daily timeseries of temperature elev: Elevation - lr: + lr: Lapse rate Returns @@ -364,7 +364,8 @@ def longwave(air_temp: pd.Series, vapor_pressure: pd.Series, .. [1] Bohn, T.J., Livneh, B., Oyler, J.W., Running, S.W., Nijssen, B. and Lettenmaier, D.P., 2013. Global evaluation of MTCLIM and related algorithms for forcing of ecological and hydrological - models. Agricultural and forest meteorology, 176, pp.38-49. + models. Agricultural and forest meteorology, 176, pp.38-49, + doi:10.1016/j.agrformet.2013.03.003. Parameters ---------- @@ -388,27 +389,50 @@ def longwave(air_temp: pd.Series, vapor_pressure: pd.Series, """ emissivity_calc = { # TVA 1972 + # Tennessee Valley Authority, 1972. Heat and mass transfer between a + # water surface and the atmosphere. Tennessee Valley Authority, Norris, + # TN. Laboratory report no. 14. Water resources research report + # no. 0-6803. 'TVA': lambda vp: 0.74 + 0.0049 * vp, # Anderson 1954 + # Anderson, E.R., 1954. Energy budget studies, water loss + # investigations: lake Hefner studies. U.S. Geol. Surv. Prof. Pap. 269, + # 71–119 [Available from U.S. Geological Survey, 807 National Center, + # Reston, VA 20192.]. 'ANDERSON': lambda vp: 0.68 + 0.036 * np.power(vp, 0.5), # Brutsaert 1975 + # Brutsaert, W., 1975. On a derivable formula for long-wave radiation + # from clear skies. Water Resour. Res. 11 (5), 742–744, + # doi:10.1029/WR011i005p00742. 'BRUTSAERT': lambda vp: 1.24 * np.power(vp / air_temp, 0.14285714), # Satterlund 1979 + # Satterlund, D.R., 1979. An improved equation for estimating long-wave + # radiation from the atmosphere. Water Resour. Res. 15 (6), 1649–1650, + # doi:10.1029/WR015i006p01649. 'SATTERLUND': lambda vp: 1.08 * ( 1 - np.exp(-1 * np.power(vp, (air_temp / 2016)))), # Idso 1981 + # Idso, S.B., 1981. A set of equations for full spectrum and 8- to + # 14-µm and 10.5- to 12.5-µm, thermal radiation from cloudless skies. + # Water Resour. Res. 17 (2), 295–304, doi:10.1029/WR017i002p00295. 'IDSO': lambda vp: 0.7 + 5.95e-5 * vp * np.exp(1500 / air_temp), # Prata 1996 + # Prata, A.J., 1996. A new long-wave formula for estimating downward + # clear-sky radiation at the surface. Q. J. R. Meteor. Soc. 122 (533), + # 1127–1151, doi:10.1002/qj.49712253306. 'PRATA': lambda vp: (1 - (1 + (46.5*vp/air_temp)) * np.exp( -np.sqrt((1.2 + 3. * (46.5*vp / air_temp))))) } cloud_calc = { - # TVA 1972 + # TVA 1972 (see above) 'TVA': lambda emis: (1.0 + (0.17 * tskc ** 2)) * emis, # Deardorff 1978 + # Deardorff, J.W., 1978. Efficient prediction of ground surface + # temperature and moisture, with an inclusion of a layer of vegetation. + # J. Geophys. Res. 83 (N64), 1889–1903, doi:10.1029/JC083iC04p01889. 'CLOUD_DEARDORFF': lambda emis: tskc + (1 - tskc) * emis } - # Reindex and fill cloud cover, then convert temps to K + # Re-index and fill cloud cover, then convert temps to K tskc = tskc.reindex_like(air_temp).fillna(method='ffill') air_temp = air_temp + cnst.KELVIN vapor_pressure = vapor_pressure * 10 From b22d65fce50abcaa6df2cd7404e9e0b62e6074b8 Mon Sep 17 00:00:00 2001 From: arbennett Date: Fri, 8 Sep 2017 12:42:08 -0700 Subject: [PATCH 3/5] Add checks for valid output variables. --- metsim/metsim.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/metsim/metsim.py b/metsim/metsim.py index cf238a5..80f59ba 100644 --- a/metsim/metsim.py +++ b/metsim/metsim.py @@ -470,6 +470,19 @@ def _validate_setup(self): if not len(self.params['out_vars']): errs.append("Output variable list must not be empty") + # Check output variables are valid + daily_out_vars = ['t_min', 't_max', 'prec', 'swe', 'vapor_pressure', + 'shortwave', 'tskc', 'pet', 'wind'] + out_var_check = ['temp', 'prec', 'shortwave', 'vapor_pressure', + 'air_pressure', 'rel_humid', 'spec_humid', + 'longwave', 'tsck', 'wind'] + if int(self.params['time_step']) == 1440: + out_var_check = daily_out_vars + for var in self.params['out_vars']: + if var not in out_var_check: + errs.append('Cannot output variable {} at timestep {}'.format( + var, self.params['time_step'])) + # Check that the parameters specified are available opts = {'mtclim_swe_corr': [True, False], 'out_precision': ['f4', 'f8'], @@ -481,6 +494,7 @@ def _validate_setup(self): if not self.params[k] in v: errs.append("Invalid option given for {}".format(k)) + # If any errors, raise and give a summary if len(errs) > 1: raise Exception("\n ".join(errs)) From 899f722f3e1794a2567bec0996a0847d3ddff99e Mon Sep 17 00:00:00 2001 From: arbennett Date: Fri, 8 Sep 2017 12:46:00 -0700 Subject: [PATCH 4/5] Remove blank line --- metsim/metsim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/metsim/metsim.py b/metsim/metsim.py index 80f59ba..818c70d 100644 --- a/metsim/metsim.py +++ b/metsim/metsim.py @@ -494,7 +494,6 @@ def _validate_setup(self): if not self.params[k] in v: errs.append("Invalid option given for {}".format(k)) - # If any errors, raise and give a summary if len(errs) > 1: raise Exception("\n ".join(errs)) From 0a80a809d864452dd1449a8aea030453cfdf10d7 Mon Sep 17 00:00:00 2001 From: arbennett Date: Fri, 8 Sep 2017 14:36:50 -0700 Subject: [PATCH 5/5] Update whats-new documentation. --- docs/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/whats-new.rst b/docs/whats-new.rst index 88ae3a0..9770350 100644 --- a/docs/whats-new.rst +++ b/docs/whats-new.rst @@ -15,6 +15,8 @@ Enhancements By `Joe Hamman `_. - Added option a flexible time grouper when chunking MetSim runs (:issue:`93`). By `Joe Hamman `_. +- Improved configuration validation by checking for correctness of output variables (:issue:`96`) + By `Andrew Bennett ` Bug fixes ~~~~~~~~~