climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jarifibra...@apache.org
Subject climate git commit: CLIMATE-786 - Update rcmed.py and test_rcmed.py
Date Tue, 24 May 2016 14:27:42 GMT
Repository: climate
Updated Branches:
  refs/heads/master cc95db85f -> b4819fa5d


CLIMATE-786 - Update rcmed.py and test_rcmed.py

- Update rcmed.py file
- Fix test_rcmed.py file

Fixes https://issues.apache.org/jira/browse/CLIMATE-786


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

Branch: refs/heads/master
Commit: b4819fa5dd4530e74a909c36d47bca3de17c62ce
Parents: cc95db8
Author: Ibrahim <jarifibrahim@gmail.com>
Authored: Sat Apr 30 11:57:53 2016 +0530
Committer: Ibrahim <jarifibrahim@gmail.com>
Committed: Tue May 24 19:43:40 2016 +0530

----------------------------------------------------------------------
 ocw/data_source/rcmed.py | 11 +++--------
 ocw/tests/test_rcmed.py  | 18 +++++++++++++++---
 2 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/b4819fa5/ocw/data_source/rcmed.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/rcmed.py b/ocw/data_source/rcmed.py
index 142a612..8892032 100644
--- a/ocw/data_source/rcmed.py
+++ b/ocw/data_source/rcmed.py
@@ -76,12 +76,7 @@ def _make_mask_array(values, parameter_id, parameters_metadata):
         if each['parameter_id'].encode() == str(parameter_id):
             missing_values = each['missingdataflag'].encode()
             break
-    # Need to encode the string to proper dtype so the mask is applied
-    if 'float' in str(values.dtype):
-        missing_values = float(missing_values)
-    if 'int' in str(values.dtype):
-        missing_values = int(missing_values)
-
+    missing_values = float(missing_values)
     values = ma.masked_array(values, mask=(values == missing_values))
 
     return values
@@ -225,10 +220,10 @@ def _end_of_date(time, time_step):
     '''
 
     last_day_of_month = calendar.monthrange(time.year, time.month)[1]
-    if time.day != last_day_of_month:
+    if time_step.lower() == 'monthly':
         time = datetime(time.year, time.month, last_day_of_month)
     elif time_step.lower() == 'daily':
-        time = datetime(time.year, time.month, end_time.day, 23, 59, 59)
+        time = datetime(time.year, time.month, time.day, 23, 59, 59)
 
     return time
 

http://git-wip-us.apache.org/repos/asf/climate/blob/b4819fa5/ocw/tests/test_rcmed.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_rcmed.py b/ocw/tests/test_rcmed.py
index 58c38bc..d098489 100644
--- a/ocw/tests/test_rcmed.py
+++ b/ocw/tests/test_rcmed.py
@@ -44,7 +44,7 @@ class test_rcmed(unittest.TestCase, CustomAssertions):
         self.end_time = datetime.datetime(2002, 10, 1)
         #start and end time for URL to query database is the beginning and end of start_time
and end_time
         self.start_time_for_url = "20020801T0000Z"
-        self.end_time_for_url = "20021031T0000Z"
+        self.end_time_for_url = "20021001T2359Z"
         self.url = "http://rcmes.jpl.nasa.gov/query-api/query.php?"
         self.lats=numpy.arange(50.5, 70, 1)
         self.lons=numpy.arange(1.5, 15, 1)
@@ -69,8 +69,11 @@ class test_rcmed(unittest.TestCase, CustomAssertions):
 
 
     def return_text(self, url):
-        if url == self.url + "datasetId={0}&parameterId={1}&latMin={2}&latMax={3}&lonMin={4}&lonMax={5}&timeStart=20020801T0000Z&timeEnd=20021031T0000Z"\
-                .format(self.dataset_id, self.parameter_id, self.min_lat, self.max_lat, self.min_lon,
self.max_lon, self.start_time_for_url, self.end_time_for_url):
+        if url == self.url + ("datasetId={0}&parameterId={1}&latMin={2}&latMax={3}"
+                              "&lonMin={4}&lonMax={5}&timeStart={6}&timeEnd={7}").format(
+                               self.dataset_id, self.parameter_id, self.min_lat,
+                               self.max_lat, self.min_lon, self.max_lon,
+                               self.start_time_for_url, self.end_time_for_url):
             return open(os.path.join(self.file_path, "parameter_dataset_text.txt"))
         elif url == self.url + "&param_info=yes":
             return open(os.path.join(self.file_path, "parameters_metadata_text.txt"))
@@ -83,6 +86,14 @@ class test_rcmed(unittest.TestCase, CustomAssertions):
         self.assertEqual(rcmed.get_parameters_metadata(), self.param_metadata_output)
 
 
+    def test_function_parameter_dataset_lats_monthly(self):
+        self.dataset_id = 6
+        self.parameter_id = 32
+        self.end_time_for_url = "20021031T0000Z"
+        rcmed.urllib2.urlopen = self.return_text
+        self.assert1DArraysEqual(rcmed.parameter_dataset(self.dataset_id, self.parameter_id,
self.min_lat, self.max_lat, self.min_lon, self.max_lon, self.start_time, self.end_time).lats,
self.lats)
+
+
     def test_function_parameter_dataset_lats(self):
         rcmed.urllib2.urlopen = self.return_text
         self.assert1DArraysEqual(rcmed.parameter_dataset(self.dataset_id, self.parameter_id,
self.min_lat, self.max_lat, self.min_lon, self.max_lon, self.start_time, self.end_time).lats,
self.lats)
@@ -108,6 +119,7 @@ class test_rcmed(unittest.TestCase, CustomAssertions):
         ds = rcmed.parameter_dataset(self.dataset_id, self.parameter_id, self.min_lat, self.max_lat,
self.min_lon, self.max_lon, self.start_time, self.end_time, name='foo')
         self.assertEquals(ds.name, 'foo')
 
+
     def test_dataset_origin(self):
         rcmed.urllib2.urlopen = self.return_text
         ds = rcmed.parameter_dataset(self.dataset_id,


Mime
View raw message