You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by fg...@apache.org on 2018/09/22 01:21:58 UTC

[incubator-sdap-nexus] branch master updated: SDAP-152 Error in nexus client (#39)

This is an automated email from the ASF dual-hosted git repository.

fgreg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git


The following commit(s) were added to refs/heads/master by this push:
     new a888889  SDAP-152 Error in nexus client (#39)
a888889 is described below

commit a888889f825c363aba8df43f0a94b3eec9a7dd22
Author: fgreg <fg...@gmail.com>
AuthorDate: Fri Sep 21 18:21:54 2018 -0700

    SDAP-152 Error in nexus client (#39)
    
    * Updated client to parse the new 'iso_time' returned from the time series function.
    
    * handle both cases for backwards compatibility.
---
 client/nexuscli/nexuscli.py           | 39 ++++++++++++++++++++++++-----------
 client/nexuscli/test/nexuscli_test.py |  6 ++++++
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/client/nexuscli/nexuscli.py b/client/nexuscli/nexuscli.py
index 8af07ba..3369a70 100644
--- a/client/nexuscli/nexuscli.py
+++ b/client/nexuscli/nexuscli.py
@@ -53,6 +53,7 @@ __pdoc__['Point.longitude'] = "longitude value"
 __pdoc__['Point.variable'] = "dictionary of variable values"
 
 ISO_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
+PYTHON32_ISO_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
 
 target = 'http://localhost:8083'
 
@@ -155,7 +156,7 @@ def daily_difference_average(dataset, bounding_box, start_datetime, end_datetime
     return time_series_result
 
 
-def time_series(datasets, bounding_box, start_datetime, end_datetime, spark=False):
+def time_series(datasets, bounding_box, start_datetime, end_datetime, spark=True):
     """
     Send a request to NEXUS to calculate a time series.
     
@@ -207,18 +208,32 @@ def time_series(datasets, bounding_box, start_datetime, end_datetime, spark=Fals
         time_series_data = np.array([tuple(each.values()) for each in [entry for entry in data if entry['ds'] == i]])
 
         if len(time_series_data) > 0:
-            time_series_result.append(
-                TimeSeries(
-                    dataset=response['meta'][i]['shortName'],
-                    time=np.array([datetime.utcfromtimestamp(t).replace(tzinfo=UTC) for t in
-                                   time_series_data[:, key_to_index['time']]]),
-                    mean=time_series_data[:, key_to_index['mean']],
-                    standard_deviation=time_series_data[:, key_to_index['std']],
-                    count=time_series_data[:, key_to_index['cnt']],
-                    minimum=time_series_data[:, key_to_index['min']],
-                    maximum=time_series_data[:, key_to_index['max']],
+            if 'iso_time' in key_to_index:
+                time_series_result.append(
+                    TimeSeries(
+                        dataset=response['meta'][i]['shortName'],
+                        time=np.array([datetime.strptime(t, PYTHON32_ISO_FORMAT) for t in
+                                       time_series_data[:, key_to_index['iso_time']]]),
+                        mean=time_series_data[:, key_to_index['mean']],
+                        standard_deviation=time_series_data[:, key_to_index['std']],
+                        count=time_series_data[:, key_to_index['cnt']],
+                        minimum=time_series_data[:, key_to_index['min']],
+                        maximum=time_series_data[:, key_to_index['max']],
+                    )
+                )
+            else:
+                time_series_result.append(
+                    TimeSeries(
+                        dataset=response['meta'][i]['shortName'],
+                        time=np.array([datetime.utcfromtimestamp(int(t)).replace(tzinfo=UTC) for t in
+                                       time_series_data[:, key_to_index['time']]]),
+                        mean=time_series_data[:, key_to_index['mean']],
+                        standard_deviation=time_series_data[:, key_to_index['std']],
+                        count=time_series_data[:, key_to_index['cnt']],
+                        minimum=time_series_data[:, key_to_index['min']],
+                        maximum=time_series_data[:, key_to_index['max']],
+                    )
                 )
-            )
 
     return time_series_result
 
diff --git a/client/nexuscli/test/nexuscli_test.py b/client/nexuscli/test/nexuscli_test.py
index ec5c12e..9dd083d 100644
--- a/client/nexuscli/test/nexuscli_test.py
+++ b/client/nexuscli/test/nexuscli_test.py
@@ -33,6 +33,12 @@ class TestCli(unittest.TestCase):
 
         self.assertEqual(2, len(ts))
 
+    def test_time_series_spark(self):
+        ts = nexuscli.time_series("AVHRR_OI_L4_GHRSST_NCEI", box(-150, 45, -120, 60),
+                                  datetime(2005, 1, 1), datetime(2005, 1, 1), spark=True)
+
+        self.assertEqual(1, len(ts))
+
     def test_list(self):
         ds_list = nexuscli.dataset_list()