You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2014/02/23 05:45:15 UTC
svn commit: r1570971 - in /incubator/climate/trunk/ocw-ui/backend:
processing.py tests/test_processing.py
Author: joyce
Date: Sun Feb 23 04:45:15 2014
New Revision: 1570971
URL: http://svn.apache.org/r1570971
Log:
CLIMATE-332 - Allow custom naming of loaded datasets
- Update documentation to reflect new optional parameter for passing
dataset names.
- When loading a local file, if no name is passed by the user the
dataset name is defaulted to the file name of the dataset. So
'/some/path/test.nc' will be named 'test.nc'.
- Add tests for default naming and custom naming of local 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=1570971&r1=1570970&r2=1570971&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/processing.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/processing.py Sun Feb 23 04:45:15 2014
@@ -61,12 +61,14 @@ def run_evaluation():
// 'lat_name': The latitude variable name.
// 'lon_name': The longitude variable name.
// 'time_name': The time variable name
+ // 'name': Optional dataset name
// }
//
// if data_source_id == 2 == rcmed:
// {
// 'dataset_id': The dataset id to grab from RCMED.
// 'parameter_id': The variable id value used by RCMED.
+ // 'name': Optional dataset name
// }
'dataset_info': {..}
},
@@ -191,12 +193,14 @@ def _process_dataset_object(dataset_obje
// 'lat_name': The latitude variable name.
// 'lon_name': The longitude variable name.
// 'time_name': The time variable name
+ // 'name': Optional dataset name
// }
//
// if data_source_id == 2 == rcmed:
// {
// 'dataset_id': The dataset id to grab from RCMED.
// 'parameter_id': The variable id value used by RCMED.
+ // 'name': Optional dataset name
// }
'dataset_info': {..}
@@ -248,6 +252,7 @@ def _load_local_dataset_object(dataset_i
'lat_name': The latitude variable name,
'lon_name': The longitude variable name,
'time_name': The time variable name
+ 'name': Optional dataset name
}
:type dataset_info: Dictionary
@@ -261,8 +266,14 @@ def _load_local_dataset_object(dataset_i
lat_name = dataset_info['lat_name']
lon_name = dataset_info['lon_name']
time_name = dataset_info['time_name']
-
- return local.load_file(path, var_name)
+ # If a name is passed for the dataset, use it. Otherwise, use the file name.
+ name = (dataset_info['name']
+ if 'name' in dataset_info.keys()
+ else path.split('/')[-1])
+
+ dataset = local.load_file(path, var_name)
+ dataset.name = name
+ return dataset
def _load_rcmed_dataset_object(dataset_info, eval_bounds):
''' Create an ocw.dataset.Dataset object from supplied data.
@@ -272,6 +283,7 @@ def _load_rcmed_dataset_object(dataset_i
{
'dataset_id': The dataset id to grab from RCMED.
'parameter_id': The variable id value used by RCMED.
+ 'name': Optional dataset name
}
:type dataset_info: Dictionary
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=1570971&r1=1570970&r2=1570971&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:15 2014
@@ -32,8 +32,8 @@ class TestLocalDatasetLoad(unittest.Test
if os.path.exists('test.nc'):
os.remove('test.nc')
- def test_valid_load(self):
- dataset_object = {
+ def setUp(self):
+ self.dataset_object = {
'id': os.path.abspath('test.nc'),
'var_name': 'tasmax',
'lat_name': 'lat',
@@ -41,8 +41,19 @@ class TestLocalDatasetLoad(unittest.Test
'time_name': 'time'
}
- dataset = bp._load_local_dataset_object(dataset_object)
- self.assertEqual(dataset.variable, dataset_object['var_name'])
+ def test_valid_load(self):
+ dataset = bp._load_local_dataset_object(self.dataset_object)
+ self.assertEqual(dataset.variable, self.dataset_object['var_name'])
+
+ def test_default_name_assignment(self):
+ dataset = bp._load_local_dataset_object(self.dataset_object)
+ self.assertEqual(dataset.name, 'test.nc')
+
+ def test_custom_name_assignment(self):
+ self.dataset_object['name'] = 'CustomName'
+ print self.dataset_object
+ dataset = bp._load_local_dataset_object(self.dataset_object)
+ self.assertEqual(dataset.name, self.dataset_object['name'])
class TestDatasetProessingHelper(unittest.TestCase):
def test_invalid_process_dataset_objects(self):