This is an automated email from the ASF dual-hosted git repository. huikyole pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/climate.git
The following commit(s) were added to refs/heads/master by this push: new c8a1001 CLIMATE-965 - Add an option to compare climatologies between climate models and observations new 8ba9330 Merge branch 'CLIMATE-965' c8a1001 is described below commit c8a100194133b21527b007e08461762a4f28e8b0 Author: huikyole <huikyo....@jpl.nasa.gov> AuthorDate: Thu Jun 13 15:54:41 2019 -0700 CLIMATE-965 - Add an option to compare climatologies between climate models and observations --- RCMES/CORDEX/templates/CORDEX.yaml.template | 1 + ....yaml.template => CORDEX_evaluation_run.yaml.template} | 1 + RCMES/run_RCMES.py | 3 +++ ocw/utils.py | 15 +++++++++++++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/RCMES/CORDEX/templates/CORDEX.yaml.template b/RCMES/CORDEX/templates/CORDEX.yaml.template index c0a1994..a7fd492 100644 --- a/RCMES/CORDEX/templates/CORDEX.yaml.template +++ b/RCMES/CORDEX/templates/CORDEX.yaml.template @@ -10,6 +10,7 @@ output_netcdf_filename: {{ basename }}.nc time: maximum_overlap_period: True temporal_resolution: monthly + adjust_model_years_for_climatology_calculation: True {% if season == "winter" %} month_start: 12 month_end: 2 diff --git a/RCMES/CORDEX/templates/CORDEX.yaml.template b/RCMES/CORDEX/templates/CORDEX_evaluation_run.yaml.template similarity index 96% copy from RCMES/CORDEX/templates/CORDEX.yaml.template copy to RCMES/CORDEX/templates/CORDEX_evaluation_run.yaml.template index c0a1994..a823804 100644 --- a/RCMES/CORDEX/templates/CORDEX.yaml.template +++ b/RCMES/CORDEX/templates/CORDEX_evaluation_run.yaml.template @@ -10,6 +10,7 @@ output_netcdf_filename: {{ basename }}.nc time: maximum_overlap_period: True temporal_resolution: monthly + adjust_model_years_for_climatology_calculation: False {% if season == "winter" %} month_start: 12 month_end: 2 diff --git a/RCMES/run_RCMES.py b/RCMES/run_RCMES.py index 3c7291e..8965412 100644 --- a/RCMES/run_RCMES.py +++ b/RCMES/run_RCMES.py @@ -125,6 +125,9 @@ for i, dataset in enumerate(datasets): """ Step 2: Subset the data for temporal and spatial domain """ # Create a Bounds object to use for subsetting +if 'adjust_model_years_for_climatology_calculation' in time_info: + if time_info['adjust_model_years_for_climatology_calculation']: + datasets = utils.adjust_model_years_for_climatology_calculation(datasets) if maximum_overlap_period: start_time, end_time = utils.get_temporal_overlap(datasets) print('Maximum overlap period') diff --git a/ocw/utils.py b/ocw/utils.py index 455c26d..64050fe 100755 --- a/ocw/utils.py +++ b/ocw/utils.py @@ -383,8 +383,6 @@ def get_temporal_overlap(dataset_array): ''' Find the maximum temporal overlap across the observation and model datasets :param dataset_array: an array of OCW datasets - :param idx: start and end indices to denote subset of months used. - :type idx: class:`tuple` ''' start_times = [] end_times = [] @@ -397,6 +395,19 @@ def get_temporal_overlap(dataset_array): return np.max(start_times), np.min(end_times) +def adjust_model_years_for_climatology_calculation(dataset_array): + ''' Using the time length of the first element in the input dataset_array, + adjust years in the rest ofi the dataset_array so that every dataset ends in the same year. + :param dataset_array: an array of OCW datasets + ''' + slc = trim_dataset(dataset_array[0]) + obs_times = dataset_array[0].times[slc] + for idata, dataset in enumerate(dataset_array[1:]): + year_diff = obs_times[-1].year - dataset.times[-1].year + nt = dataset.times.size + for it in np.arange(nt): + dataset.times[it] = dataset.times[it].replace(year = dataset.times[it].year + year_diff) + return dataset_array def trim_dataset(dataset): ''' Trim datasets such that first and last year of data have all 12 months