CLIMATE-594 - Update local data load with origin info
Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/25b7267f Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/25b7267f Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/25b7267f Branch: refs/heads/master Commit: 25b7267faaa6dfd49afefa34b79ffdd0f6c68085 Parents: e716ad9 Author: Michael Joyce <[email protected]> Authored: Fri Feb 27 12:18:37 2015 -0800 Committer: Michael Joyce <[email protected]> Committed: Fri Feb 27 12:18:37 2015 -0800 ---------------------------------------------------------------------- ocw/data_source/local.py | 11 ++++++++++- ocw/tests/test_local.py | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/25b7267f/ocw/data_source/local.py ---------------------------------------------------------------------- diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py index c6405a9..2b56d69 100644 --- a/ocw/data_source/local.py +++ b/ocw/data_source/local.py @@ -206,4 +206,13 @@ def load_file(file_path, else: values = values [:,:,:,elevation_index] - return Dataset(lats, lons, times, values, variable_name, name=name) + origin = { + 'path': file_path, + 'lat_name': lat_name, + 'lon_name': lon_name, + 'time_name': time_name + } + if elevation_index != 0: origin['elevation_index'] = elevation_index + + return Dataset(lats, lons, times, values, variable_name, + name=name, origin=origin) http://git-wip-us.apache.org/repos/asf/climate/blob/25b7267f/ocw/tests/test_local.py ---------------------------------------------------------------------- diff --git a/ocw/tests/test_local.py b/ocw/tests/test_local.py index 27f4245..6d67896 100644 --- a/ocw/tests/test_local.py +++ b/ocw/tests/test_local.py @@ -69,6 +69,13 @@ class test_load_file(unittest.TestCase): ds = local.load_file(self.file_path, 'value', name='foo') self.assertEqual(ds.name, 'foo') + def test_dataset_origin(self): + ds = local.load_file(self.file_path, 'value', elevation_index=1) + expected_keys = set(['path', 'lat_name', 'lon_name', + 'time_name', 'elevation_index' ]) + self.assertEqual(set(ds.origin.keys()), expected_keys) + + class test_get_netcdf_variable_names(unittest.TestCase): file_path = "http://zipper.jpl.nasa.gov/dist/" test_model = "AFRICA_KNMI-RACMO2.2b_CTL_ERAINT_MM_50km_1989-2008_tasmax.nc"
