climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [1/4] climate git commit: CLIMATE-589 - Add units instance attribute to class Dataset and updated functions accordingly
Date Thu, 12 Mar 2015 16:22:30 GMT
Repository: climate
Updated Branches:
  refs/heads/master 8e69e625f -> 2cb39791e


CLIMATE-589 - Add units instance attribute to class Dataset and updated functions accordingly

- As part of adding unit conversion functionality, CLIMATE-587 the following was done:
- Added units attirbute to Dataset to allow for units conversion functionality
- Updated test/test_dataset_processory.py to reflect the new Dataset units attribute


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

Branch: refs/heads/master
Commit: c43235b7d147a4d553d19370a3d17c733b4771b7
Parents: 8e69e62
Author: Kim Whitehall <k_whitehall@yahoo.com>
Authored: Wed Feb 25 17:37:02 2015 -0800
Committer: Michael Joyce <joyce@apache.org>
Committed: Thu Mar 12 09:00:56 2015 -0700

----------------------------------------------------------------------
 ocw/dataset.py                      | 12 +++++++++---
 ocw/tests/test_dataset_processor.py |  9 +++++----
 2 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/c43235b7/ocw/dataset.py
----------------------------------------------------------------------
diff --git a/ocw/dataset.py b/ocw/dataset.py
index 3d2cc48..ce604e3 100644
--- a/ocw/dataset.py
+++ b/ocw/dataset.py
@@ -35,8 +35,8 @@ logger = logging.getLogger(__name__)
 class Dataset:
     '''Container for a dataset's attributes and data.'''
 
-    def __init__(self, lats, lons, times, values, variable=None, name="",
-                 origin=None):
+    def __init__(self, lats, lons, times, values, variable=None, units=None,
+                 origin=None, name=""):
         '''Default Dataset constructor
 
         :param lats: One dimensional numpy array of unique latitude values.
@@ -56,6 +56,9 @@ class Dataset:
         :param variable: Name of the value variable.
         :type variable: :mod:`string`
 
+        :param units: Name of the value units
+        :type units: :mod:`string`
+
         :param name: An optional string name for the Dataset.
         :type name: :mod:`string`
 
@@ -73,6 +76,7 @@ class Dataset:
         self.times = times
         self.values = values
         self.variable = variable
+        self.units = units
         self.name = name
         self.origin = origin
 
@@ -204,6 +208,7 @@ Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (time_count,
             "lon-range: {}, "
             "time_range: {}, "
             "var: {}>"
+            "units: {}>"
         )
 
         return formatted_repr.format(
@@ -211,7 +216,8 @@ Expected shape (%s, %s, %s) but received (%s, %s, %s)""" % (time_count,
             lat_range,
             lon_range,
             time_range,
-            self.variable
+            self.variable,
+            self.units
         )
 
 

http://git-wip-us.apache.org/repos/asf/climate/blob/c43235b7/ocw/tests/test_dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_dataset_processor.py b/ocw/tests/test_dataset_processor.py
index 5e62aa8..88641bc 100644
--- a/ocw/tests/test_dataset_processor.py
+++ b/ocw/tests/test_dataset_processor.py
@@ -236,6 +236,7 @@ class TestSafeSubset(unittest.TestCase):
                                          times,
                                          values,
                                          variable="test variable name",
+                                         units='test variable units',
                                          name='foo')
 
         self.spatial_out_of_bounds = ds.Bounds(
@@ -364,7 +365,7 @@ def ten_year_monthly_dataset():
     # Ten Years of monthly data
     times = np.array([datetime.datetime(year, month, 1) for year in range(2000, 2010) for
month in range(1, 13)])
     values = np.ones([len(times), len(lats), len(lons)])
-    input_dataset = ds.Dataset(lats, lons, times, values, variable="test variable name",
name='foo')
+    input_dataset = ds.Dataset(lats, lons, times, values, variable="test variable name",
units='test variable units', name='foo')
     return input_dataset
 
 def ten_year_monthly_15th_dataset():
@@ -373,7 +374,7 @@ def ten_year_monthly_15th_dataset():
     # Ten Years of monthly data
     times = np.array([datetime.datetime(year, month, 15) for year in range(2000, 2010) for
month in range(1, 13)])
     values = np.ones([len(times), len(lats), len(lons)])
-    input_dataset = ds.Dataset(lats, lons, times, values, variable="test variable name")
+    input_dataset = ds.Dataset(lats, lons, times, values, variable="test variable name",
units='test variable units')
     return input_dataset
 
 def two_year_daily_dataset():
@@ -381,7 +382,7 @@ def two_year_daily_dataset():
     lons = np.array(range(-179, 180, 2))
     times = np.array([datetime.datetime(2001, 1, 1) + datetime.timedelta(days=d) for d in
range(730)])
     values = np.ones([len(times), len(lats), len(lons)])
-    dataset = ds.Dataset(lats, lons, times, values, variable='random data')
+    dataset = ds.Dataset(lats, lons, times, values, variable='random data',units='test variable
units')
     return dataset    
 
 def two_year_daily_2hr_dataset():
@@ -389,7 +390,7 @@ def two_year_daily_2hr_dataset():
     lons = np.array(range(-179, 180, 2))
     times = np.array([datetime.datetime(2001, 1, 1) + datetime.timedelta(days=d, hours=2)
for d in range(730)])
     values = np.ones([len(times), len(lats), len(lons)])
-    dataset = ds.Dataset(lats, lons, times, values, variable='random data')
+    dataset = ds.Dataset(lats, lons, times, values, variable='random data', units='test variable
units')
     return dataset    
 
 def build_ten_cube_dataset(value):


Mime
View raw message