CLIMATE-583 - Add Taylor diagram support
Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/f316aefc Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/f316aefc Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/f316aefc Branch: refs/heads/master Commit: f316aefcc4ae731f2e88b1bbd4b007948417f5e0 Parents: 82dd6b6 Author: Michael Joyce <[email protected]> Authored: Fri May 15 08:22:34 2015 -0700 Committer: Michael Joyce <[email protected]> Committed: Thu Jun 4 14:44:13 2015 -0700 ---------------------------------------------------------------------- ocw-config-runner/configuration_parsing.py | 14 +++++--- ocw-config-runner/evaluation_creation.py | 14 ++++++++ .../example/taylor_diagram_example.yaml | 36 ++++++++++++++++++++ ocw-config-runner/plot_generation.py | 31 +++++++++++++---- ocw/evaluation.py | 2 +- 5 files changed, 85 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/f316aefc/ocw-config-runner/configuration_parsing.py ---------------------------------------------------------------------- diff --git a/ocw-config-runner/configuration_parsing.py b/ocw-config-runner/configuration_parsing.py index be8bd00..a0643de 100644 --- a/ocw-config-runner/configuration_parsing.py +++ b/ocw-config-runner/configuration_parsing.py @@ -207,13 +207,17 @@ def _valid_plot_config_data(plot_config_data): if plot_type == 'contour': required_keys = set([ - 'results_indices', - 'lats', - 'lons', - 'output_name' + 'results_indices', + 'lats', + 'lons', + 'output_name' ]) elif plot_type == 'taylor': - logger.warn('Taylor diagrams are currently unsupported. Skipping validation') + required_keys = set([ + 'stddev_results_indices', + 'pattern_corr_results_indices', + 'output_name' + ]) elif plot_type == 'subregion': logger.warn('Subregion plots are currently unsupported. Skipping validation') elif plot_type == 'time_series': http://git-wip-us.apache.org/repos/asf/climate/blob/f316aefc/ocw-config-runner/evaluation_creation.py ---------------------------------------------------------------------- diff --git a/ocw-config-runner/evaluation_creation.py b/ocw-config-runner/evaluation_creation.py index 94967d3..d5bc6d0 100644 --- a/ocw-config-runner/evaluation_creation.py +++ b/ocw-config-runner/evaluation_creation.py @@ -106,6 +106,20 @@ def _prepare_datasets_for_evaluation(reference, targets, config_data): spatial_regrid_lats = config_data['evaluation'].get('spatial_regrid_lats', None) spatial_regrid_lons = config_data['evaluation'].get('spatial_regrid_lons', None) + # If we have a temporal time delta and it's daily (i.e., 1) we will + # normalize the data as daily data (which means we adjust the start times + # for each bucket of data to be consistent). By default we will normalize + # the data as monthly. Note that this will not break yearly data so it's + # safer to do this no matter what. This keeps us from ending up with 1-off + # errors in the resulting dataset shape post-temporal/spatial adjustments + # that break evaluations. + string_time_delta = 'monthly' + if temporal_time_delta and temporal_time_delta == 1: + string_time_delta = 'daily' + + reference = dsp.normalize_dataset_datetimes(reference, string_time_delta) + targets = [dsp.normalize_dataset_datetimes(t, string_time_delta) for t in targets] + if subset: start = dateutil.parser.parse(subset[4]) end = dateutil.parser.parse(subset[5]) http://git-wip-us.apache.org/repos/asf/climate/blob/f316aefc/ocw-config-runner/example/taylor_diagram_example.yaml ---------------------------------------------------------------------- diff --git a/ocw-config-runner/example/taylor_diagram_example.yaml b/ocw-config-runner/example/taylor_diagram_example.yaml new file mode 100644 index 0000000..66eab3b --- /dev/null +++ b/ocw-config-runner/example/taylor_diagram_example.yaml @@ -0,0 +1,36 @@ +evaluation: + temporal_time_delta: 30 + spatial_regrid_lats: !!python/tuple [-45, 42, 1] + spatial_regrid_lons: !!python/tuple [-24, 60, 1] + subset: [-45, 42, -24, 60, "1989-01-01", "1989-12-01"] + +datasets: + reference: + data_source: local + file_count: 1 + path: /tmp/AFRICA_KNMI-RACMO2.2b_CTL_ERAINT_MM_50km_1989-2008_tasmax.nc + variable: tasmax + optional_args: + name: dataset1 + + targets: + - data_source: local + file_count: 1 + path: /tmp/AFRICA_UC-WRF311_CTL_ERAINT_MM_50km-rg_1989-2008_tasmax.nc + variable: tasmax + optional_args: + name: dataset2 +metrics: + - StdDevRatio + - PatternCorrelation + +plots: + - type: taylor + stddev_results_indices: + - !!python/tuple [0, 0] + pattern_corr_results_indices: + - !!python/tuple [0, 1] + output_name: taylor_plot + optional_args: + fmt: png + frameon: False http://git-wip-us.apache.org/repos/asf/climate/blob/f316aefc/ocw-config-runner/plot_generation.py ---------------------------------------------------------------------- diff --git a/ocw-config-runner/plot_generation.py b/ocw-config-runner/plot_generation.py index 2a74878..677188a 100644 --- a/ocw-config-runner/plot_generation.py +++ b/ocw-config-runner/plot_generation.py @@ -38,19 +38,14 @@ def plot_from_config(evaluation, config_data): _draw_contour_plot(evaluation, plot) elif plot['type'] == 'subregion': logger.warn('Subregion plots are currently unsupported. Skipping ...') - continue elif plot['type'] == 'taylor': - logger.warn('Taylor diagrams are currently unsupported. Skipping ...') - continue + _draw_taylor_diagram(evaluation, plot) elif plot['type'] == 'time_series': logger.warn('Time series plots are currently unsupported. Skipping ...') - continue elif plot['type'] == 'portrait': logger.warn('Portrait diagrams are currently unsupported. Skipping ...') - continue else: logger.error('Unrecognized plot type requested: {}'.format(plot['type'])) - continue def _draw_contour_plot(evaluation, plot_config): """""" @@ -70,3 +65,27 @@ def _draw_contour_plot(evaluation, plot_config): np.array(lons), plot_name, **plot_config.get('optional_args', {})) + +def _draw_taylor_diagram(evaluation, plot_config): + """""" + plot_name = plot_config['output_name'] + ref_dataset_name = evaluation.ref_dataset.name + target_dataset_names = [t.name for t in evaluation.target_datasets] + + stddev_results = [ + evaluation.results[row][col] + for (row, col) in plot_config['stddev_results_indices'] + ] + + pattern_corr_results = [ + evaluation.results[row][col] + for (row, col) in plot_config['pattern_corr_results_indices'] + ] + + plot_data = np.array([stddev_results, pattern_corr_results]).transpose() + + plots.draw_taylor_diagram(plot_data, + target_dataset_names, + ref_dataset_name, + fname=plot_name, + **plot_config.get('optional_args', {})) http://git-wip-us.apache.org/repos/asf/climate/blob/f316aefc/ocw/evaluation.py ---------------------------------------------------------------------- diff --git a/ocw/evaluation.py b/ocw/evaluation.py index 9581d96..89e34b4 100644 --- a/ocw/evaluation.py +++ b/ocw/evaluation.py @@ -260,7 +260,7 @@ class Evaluation(object): elif run_unary: return unary_valid else: - return false + return False def _should_run_regular_metrics(self): return len(self.metrics) > 0
