You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by hu...@apache.org on 2015/10/06 20:59:45 UTC
[1/2] climate git commit: CLIMATE-685 - Update the examples using
Evaluation Objects
Repository: climate
Updated Branches:
refs/heads/master 260e6b71d -> 9263dc60c
CLIMATE-685 - Update the examples using Evaluation Objects
- most of the examples have been updated and all examples are tested except the esgf_integration_example.py
- CLIMATE-686 should be addressed for running some examples
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/d5a43a35
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/d5a43a35
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/d5a43a35
Branch: refs/heads/master
Commit: d5a43a35252859113517e43b6e88f16d6517a0b5
Parents: b6baf0f
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Mon Oct 5 17:29:52 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Mon Oct 5 17:29:52 2015 -0700
----------------------------------------------------------------------
examples/knmi_to_cru31_full_bias.py | 7 ++-
examples/model_ensemble_to_rcmed.py | 12 ++--
examples/multi_model_evaluation.py | 21 ++-----
examples/multi_model_taylor_diagram.py | 27 ++++-----
.../simple_model_to_model_bias_DJF_and_JJA.py | 64 --------------------
examples/subregions_portrait_diagram.py | 7 ++-
examples/taylor_diagram_example.py | 10 +--
examples/time_series_with_regions.py | 4 ++
8 files changed, 44 insertions(+), 108 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/knmi_to_cru31_full_bias.py
----------------------------------------------------------------------
diff --git a/examples/knmi_to_cru31_full_bias.py b/examples/knmi_to_cru31_full_bias.py
index a241442..beab16f 100644
--- a/examples/knmi_to_cru31_full_bias.py
+++ b/examples/knmi_to_cru31_full_bias.py
@@ -28,6 +28,11 @@ import ocw.dataset_processor as dsp
import ocw.evaluation as evaluation
import ocw.metrics as metrics
import ocw.plotter as plotter
+import ssl
+
+if hasattr(ssl, '_create_unverified_context'):
+ ssl._create_default_https_context = ssl._create_unverified_context
+
# File URL leader
FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
# This way we can easily adjust the time span of the retrievals
@@ -157,7 +162,7 @@ bias_evaluation.run()
# 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]
+results = bias_evaluation.results[0][0,:]
# 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()")
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/model_ensemble_to_rcmed.py
----------------------------------------------------------------------
diff --git a/examples/model_ensemble_to_rcmed.py b/examples/model_ensemble_to_rcmed.py
index 1f653a1..45ab599 100644
--- a/examples/model_ensemble_to_rcmed.py
+++ b/examples/model_ensemble_to_rcmed.py
@@ -29,6 +29,10 @@ import ocw.dataset_processor as dsp
import ocw.evaluation as evaluation
import ocw.metrics as metrics
import ocw.plotter as plotter
+import ssl
+
+if hasattr(ssl, '_create_unverified_context'):
+ ssl._create_default_https_context = ssl._create_unverified_context
# File URL leader
FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
@@ -168,7 +172,7 @@ bias_evaluation.run()
# Accessing the actual results when we have used 3 datasets and 1 metric is
# done this way:
print("Accessing the Results of the Evaluation run")
-results = bias_evaluation.results
+results = bias_evaluation.results[0]
# 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()")
@@ -178,9 +182,9 @@ lons = new_lons
fname = OUTPUT_PLOT
gridshape = (3, 1) # Using a 3 x 1 since we have a 1 year of data for 3 models
plotnames = ["KNMI", "WRF311", "ENSEMBLE"]
-for i, result in enumerate(results):
+for i in np.arange(3):
plot_title = "TASMAX Bias of CRU 3.1 vs. %s (%s - %s)" % (plotnames[i], start_time.strftime("%Y/%d/%m"), end_time.strftime("%Y/%d/%m"))
output_file = "%s_%s" % (fname, plotnames[i].lower())
print "creating %s" % (output_file,)
- plotter.draw_contour_map(result[0], lats, lons, output_file,
- gridshape=gridshape, ptitle=plot_title)
\ No newline at end of file
+ plotter.draw_contour_map(results[i,:], lats, lons, output_file,
+ gridshape=gridshape, ptitle=plot_title)
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/multi_model_evaluation.py
----------------------------------------------------------------------
diff --git a/examples/multi_model_evaluation.py b/examples/multi_model_evaluation.py
index 8136001..a09c526 100644
--- a/examples/multi_model_evaluation.py
+++ b/examples/multi_model_evaluation.py
@@ -16,6 +16,7 @@
# under the License.
import datetime
+import urllib
import numpy as np
from os import path
@@ -37,8 +38,7 @@ if hasattr(ssl, '_create_unverified_context'):
FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
# Three Local Model Files
FILE_1 = "AFRICA_KNMI-RACMO2.2b_CTL_ERAINT_MM_50km_1989-2008_pr.nc"
-FILE_2 = "AFRICA_UC-WRF311_CTL_ERAINT_MM_50km-rg_1989-2008_pr.nc"
-FILE_3 = "AFRICA_UCT-PRECIS_CTL_ERAINT_MM_50km_1989-2008_pr.nc"
+FILE_2 = "AFRICA_UCT-PRECIS_CTL_ERAINT_MM_50km_1989-2008_pr.nc"
# Filename for the output image/plot (without file extension)
OUTPUT_PLOT = "pr_africa_bias_annual"
#variable that we are analyzing
@@ -73,19 +73,14 @@ if path.exists(FILE_2):
else:
urllib.urlretrieve(FILE_LEADER + FILE_2, FILE_2)
-if path.exists(FILE_3):
- pass
-else:
- urllib.urlretrieve(FILE_LEADER + FILE_3, FILE_3)
""" Step 1: Load Local NetCDF File into OCW Dataset Objects and store in list"""
target_datasets.append(local.load_file(FILE_1, varName, name="KNMI"))
-target_datasets.append(local.load_file(FILE_2, varName, name="UC"))
-target_datasets.append(local.load_file(FILE_3, varName, name="UCT"))
+target_datasets.append(local.load_file(FILE_2, varName, name="UCT"))
""" Step 2: Fetch an OCW Dataset Object from the data_source.rcmed module """
-print("Working with the rcmed interface to get CRU3.1 Daily Precipitation")
+print("Working with the rcmed interface to get CRU3.1 Monthly Mean Precipitation")
# the dataset_id and the parameter id were determined from
# https://rcmes.jpl.nasa.gov/content/data-rcmes-database
CRU31 = rcmed.parameter_dataset(10, 37, LAT_MIN, LAT_MAX, LON_MIN, LON_MAX, START, END)
@@ -121,12 +116,9 @@ target_datasets.append(target_datasets_ensemble)
#find the mean value
#way to get the mean. Note the function exists in util.py
_, CRU31.values = utils.calc_climatology_year(CRU31)
-CRU31.values = np.expand_dims(CRU31.values, axis=0)
for member, each_target_dataset in enumerate(target_datasets):
_,target_datasets[member].values = utils.calc_climatology_year(target_datasets[member])
- target_datasets[member].values = np.expand_dims(target_datasets[member].values, axis=0)
-
for target in target_datasets:
allNames.append(target.name)
@@ -144,8 +136,7 @@ RCMs_to_CRU_evaluation.run()
#extract the relevant data from RCMs_to_CRU_evaluation.results
#the results returns a list (num_target_datasets, num_metrics). See docs for further details
-rcm_bias = RCMs_to_CRU_evaluation.results[:][0]
#remove the metric dimension
-new_rcm_bias = np.squeeze(np.array(RCMs_to_CRU_evaluation.results))
+rcm_bias = RCMs_to_CRU_evaluation.results[0]
-plotter.draw_contour_map(new_rcm_bias, new_lats, new_lons, gridshape=(2, 5),fname=OUTPUT_PLOT, subtitles=allNames, cmap='coolwarm_r')
+plotter.draw_contour_map(rcm_bias, new_lats, new_lons, gridshape=(2, 3),fname=OUTPUT_PLOT, subtitles=allNames, cmap='coolwarm_r')
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/multi_model_taylor_diagram.py
----------------------------------------------------------------------
diff --git a/examples/multi_model_taylor_diagram.py b/examples/multi_model_taylor_diagram.py
index f91ab3e..48fc736 100644
--- a/examples/multi_model_taylor_diagram.py
+++ b/examples/multi_model_taylor_diagram.py
@@ -10,8 +10,13 @@ import ocw.utils as utils
import datetime
import numpy as np
+import urllib
from os import path
+import ssl
+if hasattr(ssl, '_create_unverified_context'):
+ ssl._create_default_https_context = ssl._create_unverified_context
+
# File URL leader
FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
@@ -66,7 +71,7 @@ target_datasets.append(local.load_file(FILE_3, varName, name="UCT"))
""" Step 2: Fetch an OCW Dataset Object from the data_source.rcmed module """
-print("Working with the rcmed interface to get CRU3.1 Daily Precipitation")
+print("Working with the rcmed interface to get CRU3.1 Monthly Mean Precipitation")
# the dataset_id and the parameter id were determined from
# https://rcmes.jpl.nasa.gov/content/data-rcmes-database
CRU31 = rcmed.parameter_dataset(10, 37, LAT_MIN, LAT_MAX, LON_MIN, LON_MAX, START, END)
@@ -94,8 +99,7 @@ for member, each_target_dataset in enumerate(target_datasets):
#find the mean values
#way to get the mean. Note the function exists in util.py as def calc_climatology_year(dataset):
-CRU31.values,_ = utils.calc_climatology_year(CRU31)
-CRU31.values = np.expand_dims(CRU31.values, axis=0)
+CRU31.values = utils.calc_temporal_mean(CRU31)
#make the model ensemble
target_datasets_ensemble = dsp.ensemble(target_datasets)
@@ -105,8 +109,7 @@ target_datasets_ensemble.name="ENS"
target_datasets.append(target_datasets_ensemble)
for member, each_target_dataset in enumerate(target_datasets):
- target_datasets[member].values,_ = utils.calc_climatology_year(target_datasets[member])
- target_datasets[member].values = np.expand_dims(target_datasets[member].values, axis=0)
+ target_datasets[member].values = utils.calc_temporal_mean(target_datasets[member])
allNames =[]
@@ -114,8 +117,7 @@ for target in target_datasets:
allNames.append(target.name)
#calculate the metrics
-pattern_correlation = metrics.PatternCorrelation()
-spatial_std_dev = metrics.StdDevRatio()
+taylor_diagram = metrics.SpatialPatternTaylorDiagram()
#create the Evaluation object
@@ -123,17 +125,12 @@ RCMs_to_CRU_evaluation = evaluation.Evaluation(CRU31, # Reference dataset for th
# 1 or more target datasets for the evaluation
target_datasets,
# 1 or more metrics to use in the evaluation
- [spatial_std_dev, pattern_correlation])#, mean_bias,spatial_std_dev_ratio, pattern_correlation])
+ [taylor_diagram])#, mean_bias,spatial_std_dev_ratio, pattern_correlation])
RCMs_to_CRU_evaluation.run()
-rcm_std_dev = [results[0] for results in RCMs_to_CRU_evaluation.results]
-rcm_pat_cor = [results[1] for results in RCMs_to_CRU_evaluation.results]
-
-taylor_data = np.array([rcm_std_dev, rcm_pat_cor]).transpose()
-
-new_taylor_data = np.squeeze(np.array(taylor_data))
+taylor_data = RCMs_to_CRU_evaluation.results[0]
-plotter.draw_taylor_diagram(new_taylor_data,
+plotter.draw_taylor_diagram(taylor_data,
allNames,
"CRU31",
fname=OUTPUT_PLOT,
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/simple_model_to_model_bias_DJF_and_JJA.py
----------------------------------------------------------------------
diff --git a/examples/simple_model_to_model_bias_DJF_and_JJA.py b/examples/simple_model_to_model_bias_DJF_and_JJA.py
deleted file mode 100644
index 364498a..0000000
--- a/examples/simple_model_to_model_bias_DJF_and_JJA.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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.
-
-import datetime
-from os import path
-import urllib
-
-import numpy as np
-
-import ocw.data_source.local as local
-import ocw.dataset_processor as dsp
-import ocw.evaluation as evaluation
-import ocw.metrics as metrics
-import ocw.plotter as plotter
-import ocw.utils as utils
-
-# File URL leader
-FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
-# 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"
-
-FILE_1_PATH = path.join('/tmp', FILE_1)
-FILE_2_PATH = path.join('/tmp', FILE_2)
-
-if not path.exists(FILE_1_PATH):
- urllib.urlretrieve(FILE_LEADER + FILE_1, FILE_1_PATH)
-if not path.exists(FILE_2_PATH):
- urllib.urlretrieve(FILE_LEADER + FILE_2, FILE_2_PATH)
-
-""" Step 1: Load Local NetCDF Files into OCW Dataset Objects """
-print("Loading %s into an OCW Dataset Object" % (FILE_1_PATH,))
-knmi_dataset = local.load_file(FILE_1_PATH, "tasmax")
-print("KNMI_Dataset.values shape: (times, lats, lons) - %s \n" % (knmi_dataset.values.shape,))
-
-print("Loading %s into an OCW Dataset Object" % (FILE_2_PATH,))
-wrf_dataset = local.load_file(FILE_2_PATH, "tasmax")
-print("WRF_Dataset.values shape: (times, lats, lons) - %s \n" % (wrf_dataset.values.shape,))
-
-""" Step 2: Calculate seasonal average """
-print("Calculate seasonal average")
-knmi_DJF_mean = utils.calc_temporal_mean(dsp.temporal_subset(month_start=12, month_end=2, target_dataset=knmi_dataset))
-wrf_DJF_mean = utils.calc_temporal_mean(dsp.temporal_subset(month_start=12, month_end=2, target_dataset=wrf_dataset))
-print("Seasonally averaged KNMI_Dataset.values shape: (times, lats, lons) - %s \n" % (knmi_DJF_mean.shape,))
-print("Seasonally averaged wrf_Dataset.values shape: (times, lats, lons) - %s \n" % (wrf_DJF_mean.shape,))
-knmi_JJA_mean = utils.calc_temporal_mean(dsp.temporal_subset(month_start=6, month_end=8, target_dataset=knmi_dataset))
-wrf_JJA_mean = utils.calc_temporal_mean(dsp.temporal_subset(month_start=6, month_end=8, target_dataset=wrf_dataset))
-
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/subregions_portrait_diagram.py
----------------------------------------------------------------------
diff --git a/examples/subregions_portrait_diagram.py b/examples/subregions_portrait_diagram.py
index 075de2d..d8d982f 100644
--- a/examples/subregions_portrait_diagram.py
+++ b/examples/subregions_portrait_diagram.py
@@ -14,6 +14,9 @@ import numpy.ma as ma
from os import path
import urllib
+import ssl
+if hasattr(ssl, '_create_unverified_context'):
+ ssl._create_default_https_context = ssl._create_unverified_context
# File URL leader
FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
@@ -61,7 +64,7 @@ target_datasets.append(local.load_file(FILE_2, varName, name="REGCM"))
target_datasets.append(local.load_file(FILE_3, varName, name="UCT"))
""" Step 2: Fetch an OCW Dataset Object from the data_source.rcmed module """
-print("Working with the rcmed interface to get CRU3.1 Daily Precipitation")
+print("Working with the rcmed interface to get CRU3.1 Monthly Mean Precipitation")
# the dataset_id and the parameter id were determined from
# https://rcmes.jpl.nasa.gov/content/data-rcmes-database
CRU31 = rcmed.parameter_dataset(10, 37, LAT_MIN, LAT_MAX, LON_MIN, LON_MAX, START, END)
@@ -133,7 +136,7 @@ RCMs_to_CRU_evaluation.run()
new_patcor = np.squeeze(np.array(RCMs_to_CRU_evaluation.results), axis=1)
-plotter.draw_portrait_diagram(new_patcor,allNames, region_list, fname=OUTPUT_PLOT, fmt='png', cmap='coolwarm_r')
+plotter.draw_portrait_diagram(np.transpose(new_patcor),allNames, region_list, fname=OUTPUT_PLOT, fmt='png', cmap='coolwarm_r')
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/taylor_diagram_example.py
----------------------------------------------------------------------
diff --git a/examples/taylor_diagram_example.py b/examples/taylor_diagram_example.py
index b08502e..4ed803e 100644
--- a/examples/taylor_diagram_example.py
+++ b/examples/taylor_diagram_example.py
@@ -85,23 +85,19 @@ wrf_dataset = dsp.spatial_regrid(wrf_dataset, new_lats, new_lons)
# Load the metrics that we want to use for the evaluation.
################################################################################
-sstdr = metrics.StdDevRatio()
-pc = metrics.PatternCorrelation()
+taylor_diagram = metrics.SpatialPatternTaylorDiagram()
# Create our new evaluation object. The knmi dataset is the evaluations
# reference dataset. We then provide a list of 1 or more target datasets
# to use for the evaluation. In this case, we only want to use the wrf dataset.
# Then we pass a list of all the metrics that we want to use in the evaluation.
################################################################################
-test_evaluation = evaluation.Evaluation(knmi_dataset, [wrf_dataset], [sstdr, pc])
+test_evaluation = evaluation.Evaluation(knmi_dataset, [wrf_dataset], [taylor_diagram])
test_evaluation.run()
# Pull our the evaluation results and prepare them for drawing a Taylor diagram.
################################################################################
-spatial_stddev_ratio = test_evaluation.results[0][0]
-spatial_correlation = test_evaluation.results[0][1]
-
-taylor_data = numpy.array([[spatial_stddev_ratio], [spatial_correlation]]).transpose()
+taylor_data = test_evaluation.results[0]
# Draw our taylor diagram!
################################################################################
http://git-wip-us.apache.org/repos/asf/climate/blob/d5a43a35/examples/time_series_with_regions.py
----------------------------------------------------------------------
diff --git a/examples/time_series_with_regions.py b/examples/time_series_with_regions.py
index 1d552a8..ec9516d 100644
--- a/examples/time_series_with_regions.py
+++ b/examples/time_series_with_regions.py
@@ -13,6 +13,10 @@ import numpy as np
import numpy.ma as ma
from os import path
import urllib
+import ssl
+if hasattr(ssl, '_create_unverified_context'):
+ ssl._create_default_https_context = ssl._create_unverified_context
+
# File URL leader
FILE_LEADER = "http://zipper.jpl.nasa.gov/dist/"
[2/2] climate git commit: CLIMATE-685 - Update the examples using
Evaluation Objects - most of the examples have been updated and all examples
are tested except the esgf_integration_example.py
Posted by hu...@apache.org.
CLIMATE-685 - Update the examples using Evaluation Objects
- most of the examples have been updated and all examples are tested except the esgf_integration_example.py
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/9263dc60
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/9263dc60
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/9263dc60
Branch: refs/heads/master
Commit: 9263dc60c776c960165745a646a8989a48f00a65
Parents: 260e6b7 d5a43a3
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Tue Oct 6 11:59:04 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Tue Oct 6 11:59:04 2015 -0700
----------------------------------------------------------------------
examples/knmi_to_cru31_full_bias.py | 7 ++-
examples/model_ensemble_to_rcmed.py | 12 ++--
examples/multi_model_evaluation.py | 21 ++-----
examples/multi_model_taylor_diagram.py | 27 ++++-----
.../simple_model_to_model_bias_DJF_and_JJA.py | 64 --------------------
examples/subregions_portrait_diagram.py | 7 ++-
examples/taylor_diagram_example.py | 10 +--
examples/time_series_with_regions.py | 4 ++
8 files changed, 44 insertions(+), 108 deletions(-)
----------------------------------------------------------------------