...
 
Commits (7)
......@@ -39,11 +39,6 @@ iri_vars <- list(
T = 'tref'
)
iri_conversion_factors <- list(
Pr = (1/86400), # mm/day to mm/s
T = 1
)
main <- function(raw_args) {
args <- wsim.io::parse_args(usage, raw_args, types=list(target_month='integer',
lead='integer',
......@@ -62,7 +57,16 @@ main <- function(raw_args) {
lead_months = args$lead,
min_target_year = args$min_year,
max_target_year = args$max_year,
progress = TRUE) * iri_conversion_factors[[args$varname]]
progress = TRUE)
if (args$varname == 'T') {
units <- 'K'
standard_name <- 'surface_temperature'
} else {
dat <- dat / 86400
units <- 'kg/m^2/s'
standard_name <- 'precipitation_flux'
}
wsim.io::infof("Read %d hindcasts for month %d (lead %d) from %s",
dim(dat)[3], args$target_month, args$lead, args$input)
......@@ -80,7 +84,9 @@ main <- function(raw_args) {
list(var = NULL, key = "lead_months", val = args$lead),
list(var = NULL, key = "fit_years", val = sprintf("%d-%d", args$min_year, args$max_year)),
list(var = NULL, key = "distribution", val = args$distribution),
list(var = NULL, key = "variable", val = args$varname)
list(var = NULL, key = "variable", val = args$varname),
list(var = NULL, key = "standard_name", val = standard_name),
list(var = NULL, key = "units", val = units)
)))
wsim.io::infof("Wrote distribution fits to %s.", outfile)
......
This diff is collapsed.
......@@ -293,8 +293,10 @@ class NMMEForecast(paths.ForecastForcing):
if int(member) == 1 and target == dates.add_months(yearmon, 1):
steps += self.download_realtime_anomalies(nmme_yearmon=nmme_yearmon(yearmon))
output = self.forecast_raw(yearmon=yearmon, target=target, member=member).split('::')[0]
steps.append(Step(
targets=self.forecast_raw(yearmon=yearmon, target=target, member=member),
targets=output,
dependencies=[self.forecast_anom(nmme_yearmon=nmme_yearmon(yearmon), varname='T'),
self.forecast_anom(nmme_yearmon=nmme_yearmon(yearmon), varname='Pr'),
self.forecast_clim(nmme_month=nmme_month, varname='T'),
......@@ -307,8 +309,8 @@ class NMMEForecast(paths.ForecastForcing):
'--anom_precip', self.forecast_anom(nmme_yearmon=nmme_yearmon(yearmon), varname='Pr'),
'--anom_temp', self.forecast_anom(nmme_yearmon=nmme_yearmon(yearmon), varname='T'),
'--member', member,
'--lead', str(dates.get_lead_months(yearmon, target)),
'--output', self.forecast_raw(yearmon=yearmon, target=target, member=member)
'--lead', str(dates.get_lead_months(nmme_yearmon(yearmon), target)),
'--output', output
]
]))
......@@ -320,7 +322,7 @@ class NMMEConfig(ConfigBase):
def __init__(self, source, derived):
self._observed = NCEP(source)
self._forecast = {
'CFSv2': CFSForecast(source, derived),
'CFSv2': CFSForecast(source, derived, self._observed),
'CanCM4i': NMMEForecast(source, derived, self._observed, 'CanCM4i', 1982, 2010)
}
self._static = CFSStatic(source)
......
......@@ -269,6 +269,34 @@ class TestCFSConfig(unittest.TestCase):
results_summaries = step_for_target(steps, 'results_summaries')
self.assertEqual(len(results_summaries.dependencies), len(self.config.forecast_targets(yearmon))*(1 + len(self.config.integration_windows())))
def test_hindcast_dates(self):
data = self.config.forecast_data('CFSv2')
hindcasts = [h for h in data.available_hindcasts(target_month=1, lead=1)]
# dates in the asserts below assume we've defined 1983-2009 as our fit years
# this means that we consider all target months in 1983-2009 (some forecasts
# may be generated in 1982)
self.assertEqual(1983, data.min_fit_year)
self.assertEqual(2009, data.max_fit_year)
# first hindcast targets 198301, generated in 198212
first_hindcast_timestamp, first_hindcast_target = hindcasts[0]
self.assertEqual(first_hindcast_timestamp[:6], '198212')
self.assertEqual(first_hindcast_target, '198301')
# last hindcast targets 200901, generated in 200812
last_hindcast_timestamp, last_hindcast_target = hindcasts[-1]
self.assertEqual(last_hindcast_timestamp[:6], '200812')
self.assertEqual(last_hindcast_target, '200901')
def test_missing_hindcasts_skipped(self):
data = self.config.forecast_data('CFSv2')
for timestamp, target in data.available_hindcasts(target_month=3, lead=1):
if timestamp == '1989021500':
self.fail()
@unittest.skip
def test_makefile_readable(self):
import wsim_workflow.output.gnu_make
......
......@@ -30,7 +30,7 @@ class TestWorkspacePaths(unittest.TestCase):
# Forecast data
self.assertEqual(
join(self.root, 'state', 'state_201612_trgt201703_fcstCFSv2_CFS13.nc'),
join(self.root, 'state', 'state_201612_trgt201703_fcstcfsv2_CFS13.nc'),
self.ws.state(yearmon='201612', target='201703', model='CFSv2', member='CFS13')
)
......@@ -54,7 +54,7 @@ class TestWorkspacePaths(unittest.TestCase):
# Forecast data
self.assertEqual(
join(self.root, 'forcing', 'forcing_1mo_201612_trgt201703_fcstCFSv1_13.nc'),
join(self.root, 'forcing', 'forcing_1mo_201612_trgt201703_fcstcfsv1_13.nc'),
self.ws.forcing(yearmon='201612', target='201703', model='CFSv1', member='13', window=1)
)
......@@ -74,12 +74,12 @@ class TestWorkspacePaths(unittest.TestCase):
# Forecast data
self.assertEqual(
join(self.root, 'results', 'results_1mo_201612_trgt201703_fcstCFSv1_13.nc'),
join(self.root, 'results', 'results_1mo_201612_trgt201703_fcstcfsv1_13.nc'),
self.ws.results(yearmon='201612', window=1, target='201703', model='CFSv1', member='13')
)
self.assertEqual(
join(self.root, 'results_integrated', 'results_36mo_201612_trgt201703_fcstCFSv1_13.nc'),
join(self.root, 'results_integrated', 'results_36mo_201612_trgt201703_fcstcfsv1_13.nc'),
self.ws.results(yearmon='201612', target='201703', member='13', model='CFSv1', window=36)
)
......@@ -110,12 +110,12 @@ class TestWorkspacePaths(unittest.TestCase):
# Forecast data
self.assertEqual(
join(self.root, 'rp', 'rp_1mo_201612_trgt201703_fcstCFSv2_13.nc'),
join(self.root, 'rp', 'rp_1mo_201612_trgt201703_fcstcfsv2_13.nc'),
self.ws.return_period(yearmon='201612', target='201703', model='CFSv2', member='13', window=1)
)
self.assertEqual(
join(self.root, 'rp_integrated', 'rp_36mo_201612_trgt201703_fcstCanCM4i_6.nc'),
join(self.root, 'rp_integrated', 'rp_36mo_201612_trgt201703_fcstcancm4i_6.nc'),
self.ws.return_period(yearmon='201612', target='201703', model='CanCM4i', member='6', window=36)
)
......@@ -237,12 +237,12 @@ class TestWorkspacePaths(unittest.TestCase):
def test_standard_anomaly(self):
self.assertEqual(
join(self.root, 'anom', 'anom_1mo_201612_trgt201708_fcstCFSv2_XYZ.nc'),
join(self.root, 'anom', 'anom_1mo_201612_trgt201708_fcstcfsv2_XYZ.nc'),
self.ws.standard_anomaly(yearmon='201612', target='201708', model='CFSv2', member='XYZ', window=1)
)
self.assertEqual(
join(self.root, 'anom_integrated', 'anom_13mo_201612_trgt201708_fcstCFSv2_XYZ.nc'),
join(self.root, 'anom_integrated', 'anom_13mo_201612_trgt201708_fcstcfsv2_XYZ.nc'),
self.ws.standard_anomaly(yearmon='201612', target='201708', model='CFSv2', member='XYZ', window=13)
)
......
......@@ -505,13 +505,7 @@ def correct_forecast(data: ForecastForcing, *, yearmon: str, member: str, target
data.fit_obs(month=target_month, var='T'),
data.fit_obs(month=target_month, var='Pr')
],
forecast=data.forecast_raw(yearmon=yearmon, member=member, target=target) + '',
forecast=data.forecast_raw(yearmon=yearmon, member=member, target=target),
output=data.forecast_corrected(yearmon=yearmon, member=member, target=target),
attrs=[
"Pr:standard_name=precipitation_amount",
"Pr:units=mm",
"T:standard_name=surface_temperature",
"T:units=degree_Celsius"
]
)
]
......@@ -182,7 +182,8 @@ def wsim_fit(*,
inputs: Union[str, Iterable[str]],
output: str,
window: int,
comment: Union[str, None]=None):
attrs: Optional[Mapping[str, str]] = None,
comment: Union[str, None] = None) -> Step:
dependencies = []
targets = []
......@@ -201,6 +202,10 @@ def wsim_fit(*,
if window is not None:
cmd += ['--attr', attributes.integration_window(var=None, months=window)]
if attrs:
for k, v in attrs.items():
cmd += ['--attr', '{}={}'.format(k, v)]
cmd += ['--output', output]
targets.append(output)
......
......@@ -406,7 +406,7 @@ class DefaultWorkspace:
window=window,
time=time,
target=target,
model=model,
model=model.lower() if model else None,
member=member,
basis=basis.value if basis else None)
......
# Copyright (c) 2019 ISciences, LLC.
# All rights reserved.
#
# WSIM is licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Calculate a time stamp on package load so that it's the same for
# each write within a loop. This prevents duplicate history
# entries.
time_loaded <- NULL
.onLoad <- function(libname, pkgname) {
time_loaded <<- Sys.time()
}
......@@ -60,11 +60,7 @@ standard_netcdf_attrs <- function(is_new, is_spatial, existing_history=NULL) {
return(ret)
}
# Calculate a time stamp on package load so that it's the same for
# each write within a loop. This prevents duplicate history
# entries.
time_loaded <- Sys.time()
date_string <- function() {
# time_loaded is defined in init.R
strftime(time_loaded, '%Y-%m-%dT%H:%M:%S%z')
}