1616from datetime import datetime
1717from functools import partial
1818
19+ import uuid
1920import numpy as np
2021import shapely .geometry
2122from pytz import timezone
2223
23- from webservice .NexusHandler import nexus_handler
24+ from webservice .NexusHandler import nexus_handler , nexus_restapi_handler
2425from webservice .algorithms_spark .NexusCalcSparkHandler import NexusCalcSparkHandler
2526from webservice .webmodel import NexusResults , NexusProcessingException , NoDataException
2627
2930
3031
3132@nexus_handler
33+ @nexus_restapi_handler
3234class TimeAvgMapNexusSparkHandlerImpl (NexusCalcSparkHandler ):
3335 # __singleton_lock = threading.Lock()
3436 # __singleton_instance = None
@@ -67,19 +69,6 @@ class TimeAvgMapNexusSparkHandlerImpl(NexusCalcSparkHandler):
6769 }
6870 singleton = True
6971
70- # @classmethod
71- # def instance(cls, algorithm_config=None, sc=None):
72- # with cls.__singleton_lock:
73- # if not cls.__singleton_instance:
74- # try:
75- # singleton_instance = cls()
76- # singleton_instance.set_config(algorithm_config)
77- # singleton_instance.set_spark_context(sc)
78- # cls.__singleton_instance = singleton_instance
79- # except AttributeError:
80- # pass
81- # return cls.__singleton_instance
82-
8372 def parse_arguments (self , request ):
8473 # Parse input arguments
8574 self .log .debug ("Parsing arguments" )
@@ -118,7 +107,8 @@ def parse_arguments(self, request):
118107
119108 return ds , bounding_polygon , start_seconds_from_epoch , end_seconds_from_epoch , nparts_requested
120109
121- def calc (self , compute_options , ** args ):
110+ def calc (self , compute_options ,
111+ ** args ):
122112 """
123113
124114 :param compute_options: StatsComputeOptions
@@ -130,6 +120,7 @@ def calc(self, compute_options, **args):
130120 metrics_record = self ._create_metrics_record ()
131121
132122 ds , bbox , start_time , end_time , nparts_requested = self .parse_arguments (compute_options )
123+
133124 self ._setQueryParams (ds ,
134125 (float (bbox .bounds [1 ]),
135126 float (bbox .bounds [3 ]),
@@ -147,13 +138,13 @@ def calc(self, compute_options, **args):
147138 print ('Found {} tiles' .format (len (nexus_tiles )))
148139
149140 daysinrange = self ._get_tile_service ().find_days_in_range_asc (bbox .bounds [1 ],
150- bbox .bounds [3 ],
151- bbox .bounds [0 ],
152- bbox .bounds [2 ],
153- ds ,
154- start_time ,
155- end_time ,
156- metrics_callback = metrics_record .record_metrics )
141+ bbox .bounds [3 ],
142+ bbox .bounds [0 ],
143+ bbox .bounds [2 ],
144+ ds ,
145+ start_time ,
146+ end_time ,
147+ metrics_callback = metrics_record .record_metrics )
157148 ndays = len (daysinrange )
158149 if ndays == 0 :
159150 raise NoDataException (reason = "No data found for selected timeframe" )
@@ -262,6 +253,8 @@ def calc(self, compute_options, **args):
262253 maxLon = bbox .bounds [2 ], ds = ds , startTime = start_time ,
263254 endTime = end_time )
264255
256+
257+
265258 @staticmethod
266259 def _map (tile_service_factory , metrics_callback , tile_in_spark ):
267260 tile_bounds = tile_in_spark [0 ]
0 commit comments