You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sdap.apache.org by GitBox <gi...@apache.org> on 2018/09/22 01:32:37 UTC

[GitHub] fgreg closed pull request #41: SDAP-152 Error in nexus client

fgreg closed pull request #41: SDAP-152 Error in nexus client
URL: https://github.com/apache/incubator-sdap-nexus/pull/41
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/client/nexuscli/nexuscli.py b/client/nexuscli/nexuscli.py
index 8af07ba..dd24310 100644
--- a/client/nexuscli/nexuscli.py
+++ b/client/nexuscli/nexuscli.py
@@ -53,6 +53,7 @@
 __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[:, float(key_to_index['mean'])],
+                        standard_deviation=time_series_data[:, float(key_to_index['std'])],
+                        count=time_series_data[:, int(key_to_index['cnt'])],
+                        minimum=time_series_data[:, float(key_to_index['min'])],
+                        maximum=time_series_data[:, float(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[:, float(key_to_index['mean'])],
+                        standard_deviation=time_series_data[:, float(key_to_index['std'])],
+                        count=time_series_data[:, int(key_to_index['cnt'])],
+                        minimum=time_series_data[:, float(key_to_index['min'])],
+                        maximum=time_series_data[:, float(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 @@ def test_time_series(self):
 
         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()
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services