You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by go...@apache.org on 2013/09/02 17:04:29 UTC

svn commit: r1519459 - /incubator/climate/trunk/examples/simple_model_to_model_bias.py

Author: goodale
Date: Mon Sep  2 15:04:28 2013
New Revision: 1519459

URL: http://svn.apache.org/r1519459
Log:
CLIMATE-263: Model to Model End to End Testing - Completed

* Added in more Print statements to show the user what is happening in the code
* Added in the Plotter function to create a set of contour plots from the 20 years
of data.

Modified:
    incubator/climate/trunk/examples/simple_model_to_model_bias.py

Modified: incubator/climate/trunk/examples/simple_model_to_model_bias.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/examples/simple_model_to_model_bias.py?rev=1519459&r1=1519458&r2=1519459&view=diff
==============================================================================
--- incubator/climate/trunk/examples/simple_model_to_model_bias.py (original)
+++ incubator/climate/trunk/examples/simple_model_to_model_bias.py Mon Sep  2 15:04:28 2013
@@ -6,10 +6,13 @@ import ocw.data_source.local as local
 import ocw.dataset_processor as dsp
 import ocw.evaluation as eval
 import ocw.metrics as metrics
+import ocw.plotter as plotter
 
 # Two Local Model Files 
 FILE_1 = "AFRICA_KNMI-RACMO2.2b_CTL_ERAINT_MM_50km_1989-2008_tasmax.nc"
 FILE_2 = "AFRICA_UC-WRF311_CTL_ERAINT_MM_50km-rg_1989-2008_tasmax.nc"
+# Filename for the output image/plot (without file extension)
+OUTPUT_PLOT = "wrf_bias_compared_to_knmi"
 
 """ Step 1: Load Local NetCDF Files into OCW Dataset Objects """
 print("Loading %s into an OCW Dataset Object" % (FILE_1,))
@@ -20,8 +23,6 @@ print("Loading %s into an OCW Dataset Ob
 wrf_dataset = local.load_file(FILE_2, "tasmax")
 print("WRF_Dataset.values shape: (times, lats, lons) - %s \n" % (wrf_dataset.values.shape,))
 
-
-
 """ Step 2: Temporally Rebin the Data into an Annual Timestep """
 print("Temporally Rebinning the Datasets to an Annual Timestep")
 knmi_dataset = dsp.temporal_rebin(knmi_dataset, datetime.timedelta(days=365))
@@ -29,8 +30,6 @@ wrf_dataset = dsp.temporal_rebin(wrf_dat
 print("KNMI_Dataset.values shape: %s" % (knmi_dataset.values.shape,))
 print("WRF_Dataset.values shape: %s \n\n" % (wrf_dataset.values.shape,))
 
-
-
 """ Step 3: Spatially Regrid the Dataset Objects to a 1 degree grid """
 #  The spatial_boundaries() function returns the spatial extent of the dataset
 print("The KNMI_Dataset spatial bounds (min_lat, max_lat, min_lon, max_lon) are: \n"
@@ -56,6 +55,7 @@ print("Final shape of the WRF_Dataset: \
 
 """ Step 4:  Build a Metric to use for Evaluation - Bias for this example """
 # You can build your own metrics, but OCW also ships with some common metrics
+print("Setting up a Bias metric to use for evaluation")
 bias = metrics.Bias()
 
 """ Step 5: Create an Evaluation Object using Datasets and our Metric """
@@ -63,9 +63,33 @@ bias = metrics.Bias()
 # Evaluation(reference, targets, metrics, subregions=None)
 # Evaluation can take in multiple targets and metrics, so we need to convert
 # our examples into Python lists.  Evaluation will iterate over the lists
+print("Making the Evaluation definition")
 bias_evaluation = eval.Evaluation(knmi_dataset, [wrf_dataset], [bias])
+print("Executing the Evaluation using the object's run() method")
 bias_evaluation.run()
 
-
-
-
+""" Step 6: Make a Plot from the Evaluation.results """
+# The Evaluation.results are a set of nested lists to support many different
+# possible Evaluation scenarios.
+#
+# The Evaluation results docs say:
+# The shape of results is (num_metrics, num_target_datasets) if no subregion
+# Accessing the actual results when we have used 1 metric and 1 dataset is
+# done this way:
+print("Accessing the Results of the Evaluation run")
+results = bias_evaluation.results[0][0]
+print("The results are of type: %s" % type(results))
+
+# From the bias output I want to make a Contour Map of the region
+print("Generating a contour map using ocw.plotter.draw_contour_map()")
+
+lats = new_lats
+lons = new_lons
+fname = OUTPUT_PLOT
+gridshape = (4, 5) # 20 Years worth of plots. 20 rows in 1 column
+plot_title = "TASMAX Bias of WRF Compared to KNMI (1989 - 2008)"
+sub_titles = range(1989, 2009, 1)
+
+plotter.draw_contour_map(results, lats, lons, fname, 
+                         gridshape=gridshape, ptitle=plot_title, 
+                         subtitles=sub_titles)
\ No newline at end of file