Commit cc8c1e86 authored by Cynthia Crowley's avatar Cynthia Crowley

Include forcing variables T and Pr in lsm results file

parent 4fb548c5
......@@ -424,10 +424,12 @@ class CFSConfig(ConfigBase):
self._forecast.global_prep_steps()
def historical_years(self):
return range(1948, 2018) # 1948-2017
return range (1948, 1951)
#return range(1948, 2018) # 1948-2017
def result_fit_years(self):
return range(1950, 2010) # 1950-2009
return range (1948, 1951)
#return range(1950, 2010) # 1950-2009
def forecast_ensemble_members(self, yearmon, *, lag_hours: Optional[int] = None):
# Build an ensemble of 28 forecasts by taking the four
......
......@@ -98,6 +98,10 @@ class GLDAS20_NoahConfig(ConfigBase):
@classmethod
def forcing_rp_vars(cls, basis=None):
return []
@classmethod
def forcing_integrated_vars(cls, basis=None):
return []
@classmethod
def lsm_rp_vars(cls, basis=None):
......
......@@ -365,8 +365,9 @@ def fit_var(config: ConfigBase,
else:
param_to_read = param
if param in config.forcing_rp_vars():
assert window == 1
# Don't look for Pr_sum and T_ave in forcing directory.
if param in config.forcing_rp_vars() and stat is None:
assert window == 1
assert basis is None
infile = config.workspace().forcing(yearmon=input_range)
......
......@@ -154,12 +154,9 @@ class ConfigBase(metaclass=abc.ABCMeta):
'PETmE',
'PET',
'P_net',
'Pr',
'RO_mm',
'Sa',
'Sm',
'Sw',
'T',
'Ws'
]
......@@ -184,10 +181,8 @@ class ConfigBase(metaclass=abc.ABCMeta):
'E': ['sum'],
'PETmE': ['sum'],
'P_net': ['sum'],
'Pr' : ['sum'],
'RO_mm': ['sum'],
#'Sa' : ['sum'],
'T' : ['ave'],
'Sa' : ['sum'],
'Ws': ['ave'],
}
......@@ -221,4 +216,43 @@ class ConfigBase(metaclass=abc.ABCMeta):
"""
return [var + '_' + stat for var, stats in cls.lsm_integrated_vars(basis=basis).items() for stat in stats]
@classmethod
def forcing_integrated_vars(cls, basis: Optional[Basis]=None) -> Dict[str, List[str]]:
"""
Provides a dictionary whose keys are forcing variables to be time-integrated, and whose
values are lists of stats to apply to each of those variables (min, max, ave, etc.)
"""
if not basis:
return {
'Pr' : ['sum'],
'T' : ['ave'],
}
assert False
@classmethod
def forcing_integrated_var_names(cls, basis: Optional[Basis]=None) -> List[str]:
"""
Provides a flat list of time-integrated variable names
"""
return [var + '_' + stat for var, stats in cls.forcing_integrated_vars(basis=basis).items() for stat in stats]
@classmethod
def all_integrated_stats(cls, basis: Optional[Basis]=None) -> Dict[str, List[str]]:
"""
Provides a dictionary whose keys are stat names and whose values are a list of variables
two which that stat should be applied. This combines the inverse of forcing_integrated_vars()
and lsm_integrated_vars().
"""
integrated_stats = cls.lsm_integrated_stats(basis=basis)
for var, varstats in cls.forcing_integrated_vars(basis=basis).items():
for stat in varstats:
if stat not in integrated_stats:
integrated_stats[stat] = []
integrated_stats[stat].append(var)
return integrated_stats
......@@ -69,8 +69,8 @@ def spinup(config, meta_steps):
steps += all_fits.require(fit_var(config, param=param, month=month))
# Compute fits for time-integrated parameters
for param in config.lsm_integrated_vars().keys():
for stat in config.lsm_integrated_vars()[param]:
for param in {**config.lsm_integrated_vars(), **config.forcing_integrated_vars()}.keys():
for stat in {**config.lsm_integrated_vars(), **config.forcing_integrated_vars()}[param]:
for window in config.integration_windows():
assert window > 1
for month in all_months:
......@@ -248,7 +248,6 @@ def run_lsm_from_mean_spinup_state(config: Config) -> List[Step]:
first_month = int(first_timestep[4:])
postprocess_steps = list(itertools.chain(*[config.result_postprocess_steps(yearmon=yearmon)
for yearmon in config.historical_yearmons()]))
make_initial_state = Step(
comment="Create initial state file",
targets=config.workspace().state(yearmon=first_timestep),
......@@ -291,16 +290,17 @@ def run_lsm_from_mean_spinup_state(config: Config) -> List[Step]:
def time_integrate_results(config: Config, window: int, *, basis: Optional[Basis]=None) -> List[Step]:
"""
Integrate all LSM results and any specified forcing variables with the given time window
Integrate specified LSM results (and any included forcing variables) over the given time window
"""
yearmons_in = config.historical_yearmons()
yearmons_out = yearmons_in[window-1:]
integrate = wsim_integrate(
inputs=read_vars(config.workspace().results(window=1, yearmon=date_range(yearmons_in), basis=basis),
*config.lsm_integrated_vars(basis=basis).keys()),
inputs=[read_vars(config.workspace().results(window=1, yearmon=date_range(yearmons_in), basis=basis),
*{**config.lsm_integrated_vars(basis=basis), **config.forcing_integrated_vars(basis=basis)}.keys())
],
window=window,
stats=[stat + '::' + ','.join(varname) for stat, varname in config.lsm_integrated_stats(basis=basis).items()],
stats=[stat + '::' + ','.join(varname) for stat, varname in config.all_integrated_stats(basis=basis).items()],
attrs=[attrs.integration_window(var='*', months=window)],
output=config.workspace().results(yearmon=date_range(yearmons_out),
window=window,
......
......@@ -41,12 +41,14 @@ make_results <- function(
PET,
PETmE,
P_net,
Pr,
RO_m3,
RO_mm,
Runoff_m3,
Runoff_mm,
Sa,
Sm,
T,
Ws,
dWdt,
extent
......@@ -60,12 +62,14 @@ make_results <- function(
PET= PET,
PETmE= PETmE,
P_net= P_net,
Pr=Pr,
RO_m3= RO_m3,
RO_mm= RO_mm,
Runoff_m3= Runoff_m3,
Runoff_mm= Runoff_mm,
Sa= Sa,
Sm= Sm,
T= T,
Ws= Ws,
dWdt= dWdt
)
......
......@@ -96,14 +96,14 @@ run <- function(static, state, forcing) {
P_net= P,
PET= E0,
PETmE= E0 - E,
#Pr= forcing$Pr,
Pr= forcing$Pr,
RO_mm= revised_runoff,
RO_m3= revised_runoff*area_m2/1000,
Runoff_mm= R,
Runoff_m3= R*area_m2/1000,
Sa= Sa,
Sm= ifelse(is.na(Sa), NA, Sm),
#T= forcing$T,
T= forcing$T,
Ws= Ws_ave
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment