You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by ja...@apache.org on 2016/06/14 06:40:57 UTC
[1/3] climate git commit: Remove redundant code
Repository: climate
Updated Branches:
refs/heads/master d94bbdc05 -> 54986818e
Remove redundant code
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/a4777fb6
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/a4777fb6
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/a4777fb6
Branch: refs/heads/master
Commit: a4777fb604264cafacd19168709e143c61a8e1c0
Parents: aaa3bc5
Author: Ibrahim <ja...@gmail.com>
Authored: Mon Jun 13 13:14:46 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 01:15:55 2016 +0530
----------------------------------------------------------------------
ocw/data_source/local.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/a4777fb6/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index f4844f9..0fa81b1 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -228,12 +228,13 @@ def load_file(file_path,
try:
netcdf = netCDF4.Dataset(file_path, mode='r')
- except RuntimeError:
+ except IOError:
err = "Dataset filepath is invalid. Please ensure it is correct."
raise ValueError(err)
except:
err = (
- "The given file cannot be loaded. Please ensure that it is a valid "
+ "The given file cannot be loaded. Either the path is invalid or the given file is invalid. "
+ "Please ensure that it is a valid "
"NetCDF file. If problems persist, report them to the project's "
"mailing list."
)
[2/3] climate git commit: Add tests for local module
Posted by ja...@apache.org.
Add tests for local module
- Add new tests for local module
- Add .coveragerc file to remove redundant code from test coverage
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/80664b66
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/80664b66
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/80664b66
Branch: refs/heads/master
Commit: 80664b66ba5d40610e670fdba7fe74536e82a4bb
Parents: a4777fb
Author: Ibrahim <ja...@gmail.com>
Authored: Mon Jun 13 13:15:15 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 01:17:11 2016 +0530
----------------------------------------------------------------------
.coveragerc | 5 +++
ocw/tests/test_local.py | 104 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/80664b66/.coveragerc
----------------------------------------------------------------------
diff --git a/.coveragerc b/.coveragerc
index 4e4a627..fa45ba4 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -18,3 +18,8 @@
[report]
exclude_lines =
if __name__ == .__main__.:
+ # These lines will never be executed under any circumstances
+ if level_index == 0:
+ elif level_index == 1:
+ elif level_index == 2:
+ else:
http://git-wip-us.apache.org/repos/asf/climate/blob/80664b66/ocw/tests/test_local.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_local.py b/ocw/tests/test_local.py
index 6137563..1c747f9 100644
--- a/ocw/tests/test_local.py
+++ b/ocw/tests/test_local.py
@@ -40,6 +40,12 @@ class test_load_file(unittest.TestCase):
def tearDown(self):
os.remove(self.file_path)
+ def test_load_invalid_file_path(self):
+ self.invalid_netcdf_path = '/invalid/path'
+ with self.assertRaises(ValueError):
+ local.load_file(file_path=self.invalid_netcdf_path,
+ variable_name='test variable')
+
def test_function_load_file_lats(self):
"""To test load_file function for latitudes"""
self.assertItemsEqual(local.load_file(
@@ -76,6 +82,104 @@ class test_load_file(unittest.TestCase):
self.assertEqual(ds.origin['source'], 'local')
+class TestLoadMultipleFiles(unittest.TestCase):
+ def setUp(self):
+ # Read netCDF file
+ self.file_path = create_netcdf_object()
+ self.netCDF_file = netCDF4.Dataset(self.file_path, 'r')
+ self.latitudes = self.netCDF_file.variables['latitude'][:]
+ self.longitudes = self.netCDF_file.variables['longitude'][:]
+ self.values = self.netCDF_file.variables['value'][:]
+ self.variable_name_list = ['latitude',
+ 'longitude', 'time', 'level', 'value']
+ self.possible_value_name = ['latitude', 'longitude', 'time', 'level']
+
+ def tearDown(self):
+ os.remove(self.file_path)
+
+ def test_function_load_multiple_files_data_name(self):
+ dataset, data_name = local.load_multiple_files(self.file_path, "value")
+ self.assertEqual(data_name, ['model'])
+
+ def test_function_load_multiple_files_lons(self):
+ """To test load_multiple_file function for longitudes"""
+ dataset, data_name = local.load_multiple_files(self.file_path, "value")
+ self.assertItemsEqual(dataset[0].lons, self.longitudes)
+
+ def test_function_load_multiple_files_times(self):
+ """To test load_multiple_files function for times"""
+ dataset, data_name = local.load_multiple_files(self.file_path, "value")
+
+ newTimes = datetime.datetime(2001, 01, 01), datetime.datetime(
+ 2001, 02, 01), datetime.datetime(2001, 03, 01)
+ self.assertItemsEqual(dataset[0].times, newTimes)
+
+ def test_function_load_multiple_files_values(self):
+ """To test load_multiple_files function for values"""
+ new_values = self.values[:, 0, :, :]
+ dataset, data_name = local.load_multiple_files(
+ self.file_path, "value")
+ self.assertTrue(numpy.allclose(dataset[0].values, new_values))
+
+ def test_load_multiple_files_custom_dataset_name(self):
+ """Test adding a custom name to a dataset"""
+ dataset, data_name = local.load_multiple_files(self.file_path,
+ "value",
+ dataset_name='foo')
+ self.assertEqual(dataset[0].name, 'foo')
+
+ def test_dataset_origin(self):
+ dataset, data_name = local.load_multiple_files(self.file_path, 'value')
+ expected_keys = set(['source', 'path', 'lat_name', 'lon_name',
+ 'time_name'])
+ self.assertEqual(set(dataset[0].origin.keys()), expected_keys)
+ self.assertEqual(dataset[0].origin['source'], 'local')
+
+
+class TestLoadDatasetFromMultipleNetcdfFiles(unittest.TestCase):
+ def setUp(self):
+ self.file_path = create_netcdf_object()
+ self.netCDF_file = netCDF4.Dataset(self.file_path, 'r+')
+ self.latitudes = self.netCDF_file.variables['latitude'][:]
+ self.longitudes = self.netCDF_file.variables['longitude'][:]
+ self.values = self.netCDF_file.variables['value'][:]
+ self.variable_name_list = ['latitude',
+ 'longitude', 'time', 'level', 'value']
+ self.possible_value_name = ['latitude', 'longitude', 'time', 'level']
+ self.dataset = local.load_dataset_from_multiple_netcdf_files(
+ variable_name='value',
+ file_path='',
+ filename_pattern=[
+ self.file_path])
+
+ def tearDown(self):
+ os.remove(self.file_path)
+
+ def test_variable_name(self):
+ self.assertEqual(self.dataset.variable, 'value')
+
+ def test_function_load_dataset_from_multiple_netcdf_files_lats(self):
+ """To test load_multiple_files function for times"""
+ _, self.latitudes = numpy.meshgrid(self.longitudes, self.latitudes)
+ numpy.testing.assert_array_equal(self.dataset.lats, self.latitudes)
+
+ def test_function_load_dataset_from_multiple_netcdf_files_lons(self):
+ """To test load_multiple_files function for times"""
+ self.longitudes, _ = numpy.meshgrid(self.longitudes, self.latitudes)
+ numpy.testing.assert_array_equal(self.dataset.lons, self.longitudes)
+
+ def test_function_load_dataset_from_multiple_netcdf_files_times(self):
+ """To test load_multiple_files function for times"""
+ newTimes = datetime.datetime(2001, 01, 01), datetime.datetime(
+ 2001, 02, 01), datetime.datetime(2001, 03, 01)
+ self.assertItemsEqual(self.dataset.times, newTimes)
+
+ def test_function_load_dataset_from_multiple_netcdf_files_values(self):
+ """To test load_multiple_files function for values"""
+ new_values = self.values[:, 0, :, :]
+ self.assertTrue(numpy.allclose(self.dataset.values, new_values))
+
+
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"
[3/3] climate git commit: Merge branch 'CLIMATE-806'
Posted by ja...@apache.org.
Merge branch 'CLIMATE-806'
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/54986818
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/54986818
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/54986818
Branch: refs/heads/master
Commit: 54986818e4e8afcbb550696e056f807bec5d85a7
Parents: d94bbdc 80664b6
Author: Ibrahim <ja...@gmail.com>
Authored: Tue Jun 14 12:09:28 2016 +0530
Committer: Ibrahim <ja...@gmail.com>
Committed: Tue Jun 14 12:09:28 2016 +0530
----------------------------------------------------------------------
.coveragerc | 5 ++
ocw/data_source/local.py | 5 +-
ocw/tests/test_local.py | 104 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 112 insertions(+), 2 deletions(-)
----------------------------------------------------------------------