climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1570972 - in /incubator/climate/trunk/ocw-ui/backend: processing.py tests/test_processing.py
Date Sun, 23 Feb 2014 04:45:21 GMT
Author: joyce
Date: Sun Feb 23 04:45:21 2014
New Revision: 1570972

URL: http://svn.apache.org/r1570972
Log:
CLIMATE-332 - Add custom naming for RCMED loaded datasets

- When loading a dataset from RCMED, if the user does not pass a name
  for the dataset the backend will attempt to grab the `longname` for
  the selected dataset. If it is unable to find that, it will default to
  'RCMED dataset'.
- Add tests for default naming and custom naming of RCMED datasets.

Modified:
    incubator/climate/trunk/ocw-ui/backend/processing.py
    incubator/climate/trunk/ocw-ui/backend/tests/test_processing.py

Modified: incubator/climate/trunk/ocw-ui/backend/processing.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/processing.py?rev=1570972&r1=1570971&r2=1570972&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/processing.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/processing.py Sun Feb 23 04:45:21 2014
@@ -304,14 +304,30 @@ def _load_rcmed_dataset_object(dataset_i
     :raises KeyError: If the required keys aren't present in the dataset_info or
         eval_bounds objects.
     '''
-    return rcmed.parameter_dataset(dataset_info['dataset_id'],
-								   dataset_info['parameter_id'],
-								   eval_bounds['lat_min'],
-								   eval_bounds['lat_max'],
-								   eval_bounds['lon_min'],
-								   eval_bounds['lon_max'],
-								   eval_bounds['start_time'],
-								   eval_bounds['end_time'])
+    dataset = rcmed.parameter_dataset(dataset_info['dataset_id'],
+								      dataset_info['parameter_id'],
+								      eval_bounds['lat_min'],
+								      eval_bounds['lat_max'],
+								      eval_bounds['lon_min'],
+								      eval_bounds['lon_max'],
+								      eval_bounds['start_time'],
+								      eval_bounds['end_time'])
+
+    # If a name is passed for the dataset, use it. Otherwise, use the file name.
+    if 'name'in dataset_info.keys():
+        name = dataset_info['name']
+    else:
+        for m in rcmed.get_parameters_metadata():
+            if m['parameter_id'] == str(dataset_info['parameter_id']):
+                name = m['longname']
+                break
+        else:
+            # If we can't find a name for the dataset, default to something...
+            name = "RCMED dataset"
+
+    dataset.name = name
+
+    return dataset
 
 def _calculate_new_latlon_bins(eval_bounds, lat_grid_step, lon_grid_step):
     ''' Calculate the new lat/lon ranges for spatial re-binning.

Modified: incubator/climate/trunk/ocw-ui/backend/tests/test_processing.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/tests/test_processing.py?rev=1570972&r1=1570971&r2=1570972&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/tests/test_processing.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/tests/test_processing.py Sun Feb 23 04:45:21 2014
@@ -64,17 +64,17 @@ class TestDatasetProessingHelper(unittes
                 invalid_dataset_object, 'fake parameter')
 
 class TestRCMEDDatasetLoad(unittest.TestCase):
-    def test_valid_load(self):
+    def setUp(self):
         metadata = rcmed.get_parameters_metadata()
         # Load TRMM from RCMED
         dataset_dat = [m for m in metadata if m['parameter_id'] == '36'][0]
 
-        dataset_info = {
+        self.dataset_info = {
             'dataset_id': int(dataset_dat['dataset_id']),
             'parameter_id': int(dataset_dat['parameter_id'])
         }
 
-        eval_bounds = {
+        self.eval_bounds = {
             'start_time': dt.datetime(1998, 02, 01),
             'end_time': dt.datetime(1998, 03, 01),
             'lat_min': -10,
@@ -83,16 +83,27 @@ class TestRCMEDDatasetLoad(unittest.Test
             'lon_max': 15
         }
 
-        dataset = bp._load_rcmed_dataset_object(dataset_info, eval_bounds)
+    def test_valid_load(self):
+        dataset = bp._load_rcmed_dataset_object(self.dataset_info, self.eval_bounds)
         lat_min, lat_max, lon_min, lon_max = dataset.spatial_boundaries()
         start_time, end_time = dataset.time_range()
 
-        self.assertTrue(eval_bounds['lat_min'] <= lat_min)
-        self.assertTrue(eval_bounds['lat_max'] >= lat_max)
-        self.assertTrue(eval_bounds['lon_min'] <= lon_min)
-        self.assertTrue(eval_bounds['lon_max'] >= lon_max)
-        self.assertTrue(eval_bounds['start_time'] <= start_time)
-        self.assertTrue(eval_bounds['end_time'] >= end_time)
+        self.assertTrue(self.eval_bounds['lat_min'] <= lat_min)
+        self.assertTrue(self.eval_bounds['lat_max'] >= lat_max)
+        self.assertTrue(self.eval_bounds['lon_min'] <= lon_min)
+        self.assertTrue(self.eval_bounds['lon_max'] >= lon_max)
+        self.assertTrue(self.eval_bounds['start_time'] <= start_time)
+        self.assertTrue(self.eval_bounds['end_time'] >= end_time)
+
+    def test_default_name_assignment(self):
+        dataset = bp._load_rcmed_dataset_object(self.dataset_info, self.eval_bounds)
+        self.assertEquals(dataset.name, 'TRMM v.7 Monthly Precipitation')
+
+    def test_custom_name_assignment(self):
+        self.dataset_info['name'] = 'CustomName'
+        dataset = bp._load_rcmed_dataset_object(self.dataset_info, self.eval_bounds)
+        self.assertEquals(dataset.name, self.dataset_info['name'])
+
 
 class TestMetricLoad(unittest.TestCase):
     def test_get_valid_metric_options(self):



Mime
View raw message