climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omk...@apache.org
Subject [06/16] climate git commit: Updating documentation and adding example to podaac data source
Date Sat, 27 Aug 2016 03:42:28 GMT
Updating documentation and adding example to podaac data source


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/0caf4b71
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/0caf4b71
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/0caf4b71

Branch: refs/heads/master
Commit: 0caf4b71f1f5f1f5d67870fa97936ffb0354bd25
Parents: e12314a
Author: Omkar20895 <omkarreddy2008@gmail.com>
Authored: Sat Aug 13 01:42:27 2016 +0530
Committer: Omkar20895 <omkarreddy2008@gmail.com>
Committed: Sat Aug 13 01:42:27 2016 +0530

----------------------------------------------------------------------
 docs/source/data_source/data_sources.rst |  5 ++
 examples/podaac_integration_example.py   | 75 +++++++++++++++++++++++++++
 ocw/data_source/podaac.py                |  8 +--
 3 files changed, 84 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/0caf4b71/docs/source/data_source/data_sources.rst
----------------------------------------------------------------------
diff --git a/docs/source/data_source/data_sources.rst b/docs/source/data_source/data_sources.rst
index 19f9293..4bb4f16 100644
--- a/docs/source/data_source/data_sources.rst
+++ b/docs/source/data_source/data_sources.rst
@@ -20,3 +20,8 @@ ESGF Module
 ===========
 .. automodule:: esgf
     :members:
+
+PODAAC Module
+===========
+.. automodule:: podaac
+    :members:

http://git-wip-us.apache.org/repos/asf/climate/blob/0caf4b71/examples/podaac_integration_example.py
----------------------------------------------------------------------
diff --git a/examples/podaac_integration_example.py b/examples/podaac_integration_example.py
new file mode 100644
index 0000000..990ee56
--- /dev/null
+++ b/examples/podaac_integration_example.py
@@ -0,0 +1,75 @@
+# 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 ocw.data_source.podaac as podaac
+import ocw.evaluation as evaluation
+import ocw.metrics as metrics
+import ocw.plotter as plotter
+
+datasetId = 'PODAAC-CCF30-01XXX'
+datasetShortName = 'CCMP_MEASURES_ATLAS_L4_OW_L3_0_WIND_VECTORS_FLK'
+variable = 'uwnd'
+name = 'PO.DAAC_test_dataset'
+OUTPUT_PLOT = "cmc_temporal_std"
+""" Step 1: Load Local NetCDF Files into OCW Dataset Objects """
+print("Loading %s dataset into an OCW dataset objects" % datasetShortName)
+cmc_dataset = podaac.load_dataset(
+    variable=variable, datasetId=datasetId, datasetShortName=datasetShortName, name=name)
+print "CMC_Dataset.values shape: (times, lats, lons) - %s \n" % (cmc_dataset.values.shape,)
+
+# Acessing latittudes and longitudes of netCDF file
+lats = cmc_dataset.lats
+lons = cmc_dataset.lons
+
+""" Step 2:  Build a Metric to use for Evaluation - Temporal STD for this example """
+# You can build your own metrics, but OCW also ships with some common metrics
+print "Setting up a Temporal STD metric to use for evaluation"
+std = metrics.TemporalStdDev()
+
+""" Step 3: Create an Evaluation Object using Datasets and our Metric """
+# The Evaluation Class Signature is:
+# 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"
+# Temporal STD Metric gets one target dataset then reference dataset
+# should be None
+std_evaluation = evaluation.Evaluation(None, [cmc_dataset], [std])
+print "Executing the Evaluation using the object's run() method"
+std_evaluation.run()
+
+""" Step 4: 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 = std_evaluation.unary_results[0][0]
+print "The results are of type: %s" % type(results)
+print "Generating a contour map using ocw.plotter.draw_contour_map()"
+
+fname = OUTPUT_PLOT
+gridshape = (4, 5)  # 20 Years worth of plots. 20 rows in 1 column
+plot_title = "CMC Temporal Standard Deviation"
+sub_titles = range(2002, 2010, 1)
+
+plotter.draw_contour_map(results, lats, lons, fname,
+                         gridshape=gridshape, ptitle=plot_title,
+                         subtitles=sub_titles)

http://git-wip-us.apache.org/repos/asf/climate/blob/0caf4b71/ocw/data_source/podaac.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/podaac.py b/ocw/data_source/podaac.py
index 47a5409..7c233b3 100644
--- a/ocw/data_source/podaac.py
+++ b/ocw/data_source/podaac.py
@@ -25,7 +25,7 @@ import urllib
 import xml.etree.ElementTree as ET
 
 
-def _convert_times_to_datetime(time):
+def convert_times_to_datetime(time):
     '''Convert the time object's values to datetime objects
 
     The time values are stored as some unit since an epoch. These need to be
@@ -50,10 +50,10 @@ def load_dataset(variable, datasetId='', datasetShortName='', name=''):
     :param variable: The name of the variable to read from the dataset.
     :type variable: :mod:`string`
 
-        :param datasetId: dataset persistent ID. datasetId or \
+    :param datasetId: dataset persistent ID. datasetId or \
         shortName is required for a granule search. Example: \
         PODAAC-ASOP2-25X01
-    :type datasetId: :mod:`string` 
+    :type datasetId: :mod:`string`
 
     :param shortName: the shorter name for a dataset. \
         Either shortName or datasetId is required for a \
@@ -95,7 +95,7 @@ def load_dataset(variable, datasetId='', datasetShortName='', name=''):
     # these values to datetime objects. Note that we use the main object's
     # time object and not the dataset specific reference to it. We need to
     # grab the 'units' from it and it fails on the dataset specific object.
-        times = np.array(_convert_times_to_datetime(d[time]))
+        times = np.array(convert_times_to_datetime(d[time]))
         lats = np.array(d.variables[lat][:])
         lons = np.array(d.variables[lon][:])
         values = np.array(dataset[:])


Mime
View raw message