Skip to content
Snippets Groups Projects
Commit 2cbdc557 authored by leufen1's avatar leufen1
Browse files

topography tandemX service uses now the new CommonView class, also min/max...

topography tandemX service uses now the new CommonView class, also min/max valid values are adjusted to range [-500, 9000]
parent 09b213db
Branches
Tags
No related merge requests found
...@@ -46,6 +46,17 @@ class AggSerializer(BaseSerializer): ...@@ -46,6 +46,17 @@ class AggSerializer(BaseSerializer):
except TypeError: except TypeError:
vlength = 1 vlength = 1
if vlength > 1: if vlength > 1:
if obj['direction'] is None:
properties = OrderedDict([
('agg_function', agg_function),
('many', True),
(agg_function, OrderedDict([
(d, v) for d, v in zip(range(vlength), val)
])),
('units', 'm'),
('radius', obj['radius']),
])
else:
properties = OrderedDict([ properties = OrderedDict([
('agg_function', agg_function), ('agg_function', agg_function),
('many', True), ('many', True),
...@@ -55,8 +66,6 @@ class AggSerializer(BaseSerializer): ...@@ -55,8 +66,6 @@ class AggSerializer(BaseSerializer):
('units', 'm'), ('units', 'm'),
('radius', obj['radius']), ('radius', obj['radius']),
]) ])
if obj['direction'] is None:
properties.pop('direction')
else: else:
properties = OrderedDict([ properties = OrderedDict([
('agg_function', agg_function), ('agg_function', agg_function),
......
...@@ -7,7 +7,7 @@ from rest_framework.response import Response ...@@ -7,7 +7,7 @@ from rest_framework.response import Response
from toar_location_services.settings import DEBUG from toar_location_services.settings import DEBUG
from .topography_file_extraction import read_proxydata from .topography_file_extraction import read_proxydata
from .serializers import AggSerializer from .serializers import AggSerializer
from utils.views_commons import get_query_params, get_agg_function from utils.views_commons import CommonViews
from utils.geoutils import Directions from utils.geoutils import Directions
from utils.extraction_tools import extract_value, extract_value_stats from utils.extraction_tools import extract_value, extract_value_stats
...@@ -19,13 +19,17 @@ if DEBUG: ...@@ -19,13 +19,17 @@ if DEBUG:
print("File %s successfully loaded" % (FILENAME), datainfo) print("File %s successfully loaded" % (FILENAME), datainfo)
class TopographyView(APIView): class TopographyView(APIView, CommonViews):
def __init__(self):
CommonViews.__init__(self)
self.remove_agg_allowed('sum')
def _extract(self, lat, lon, radius, agg, direction, by_direction): def _extract(self, lat, lon, radius, agg, direction, by_direction):
"""perform actual extraction of desired quantity""" """perform actual extraction of desired quantity"""
print('**by_direction:', by_direction, '** radius, agg = ', radius, agg) print('**by_direction:', by_direction, '** radius, agg = ', radius, agg)
if agg is not None and radius is not None and radius > 0.: if agg is not None and radius is not None and radius > 0.:
agg_function = get_agg_function(agg) agg_function = self.get_agg_function(agg)
min_angle = None min_angle = None
max_angle = None max_angle = None
if by_direction: if by_direction:
...@@ -36,7 +40,7 @@ class TopographyView(APIView): ...@@ -36,7 +40,7 @@ class TopographyView(APIView):
# ToDo: once we serve the data via rasdaman the calls with directions should use # ToDo: once we serve the data via rasdaman the calls with directions should use
# a polygon query for efficiency reasons. # a polygon query for efficiency reasons.
result[i] = extract_value_stats(lonvec, latvec, data, lon, lat, default_value=-999., result[i] = extract_value_stats(lonvec, latvec, data, lon, lat, default_value=-999.,
out_of_bounds_value=0., min_valid=0., max_valid=2.e6, out_of_bounds_value=0., min_valid=-500., max_valid=9000,
radius=radius, min_angle=min_angle, max_angle=max_angle, radius=radius, min_angle=min_angle, max_angle=max_angle,
agg=agg_function) agg=agg_function)
else: else:
...@@ -45,13 +49,13 @@ class TopographyView(APIView): ...@@ -45,13 +49,13 @@ class TopographyView(APIView):
# ToDo: once we serve the data via rasdaman the calls with directions should use # ToDo: once we serve the data via rasdaman the calls with directions should use
# a polygon query for efficiency reasons. # a polygon query for efficiency reasons.
result = extract_value_stats(lonvec, latvec, data, lon, lat, default_value=-999., result = extract_value_stats(lonvec, latvec, data, lon, lat, default_value=-999.,
out_of_bounds_value=0., min_valid=0., max_valid=2.e6, out_of_bounds_value=-666, min_valid=-500, max_valid=9000,
radius=radius, min_angle=min_angle, max_angle=max_angle, radius=radius, min_angle=min_angle, max_angle=max_angle,
agg=agg_function) agg=agg_function)
else: else:
agg = 'value' agg = 'value'
result = extract_value(lonvec, latvec, data, lon, lat, default_value=-999., result = extract_value(lonvec, latvec, data, lon, lat, default_value=-999.,
out_of_bounds_value=0., min_valid=0., max_valid=2.e6) out_of_bounds_value=0., min_valid=-500, max_valid=9000)
# return data, also return agg and direction as they may have been overwritten # return data, also return agg and direction as they may have been overwritten
return result, agg, direction return result, agg, direction
...@@ -78,7 +82,7 @@ class TopographyView(APIView): ...@@ -78,7 +82,7 @@ class TopographyView(APIView):
by_direction: if True, data are returned as vector with one value aggregated by_direction: if True, data are returned as vector with one value aggregated
over each of 16 wind directions. over each of 16 wind directions.
""" """
lat, lon, radius, agg, direction, by_direction = get_query_params(request.query_params, lat, lon, radius, agg, direction, by_direction = self.get_query_params(request.query_params,
['lat', 'lon', 'radius', 'agg', 'direction', 'by_direction']) ['lat', 'lon', 'radius', 'agg', 'direction', 'by_direction'])
result, agg, direction = self._extract(lat, lon, radius, agg, direction, by_direction) result, agg, direction = self._extract(lat, lon, radius, agg, direction, by_direction)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment