in analysis/webservice/algorithms/Tomogram.py [0:0]
def parse_args(self, compute_options):
ds, parameter = super().parse_args(compute_options)
def get_required_float(name):
val = compute_options.get_float_arg(name, None)
if val is None:
raise NexusProcessingException(reason=f'Missing required parameter: {name}', code=400)
return val
def get_required_int(name):
val = compute_options.get_int_arg(name, None)
if val is None:
raise NexusProcessingException(reason=f'Missing required parameter: {name}', code=400)
return val
latitude = compute_options.get_argument('latitude', None)
output = compute_options.get_content_type().lower()
if latitude is None:
raise NexusProcessingException(reason='Missing required parameter: latitude', code=400)
if re.match(FLOAT_PATTERN, latitude):
latitude = float(latitude)
if latitude < -180 or latitude > 180:
raise NexusProcessingException(reason='Invalid latitude: out of range', code=400)
latitude = [latitude]
elif ',' in latitude:
if output == 'png':
raise NexusProcessingException(reason='Cannot use PNG output with multi-latitude slicing', code=400)
try:
latitude = list(sorted([float(l) for l in latitude.split(',')]))
except ValueError:
raise NexusProcessingException(reason='Invalid latitude: invalid format', code=400)
if any([l < -180 or l > 180] for l in latitude):
raise NexusProcessingException(reason='Invalid latitude: out of range', code=400)
elif ':' in latitude:
if output == 'png':
raise NexusProcessingException(reason='Cannot use PNG output with multi-longitude slicing', code=400)
try:
latitude = slice(*(float(p) if p else None for p in latitude.split(':')))
except:
raise NexusProcessingException(reason='Invalid latitude: invalid format', code=400)
if latitude.start is not None and latitude.stop is not None and latitude.start >= latitude.stop:
raise NexusProcessingException(reason='Invalid latitude: out of order', code=400)
# Some helpers for a < b / a > b where a could be None and return false in that case
def lt(a, b):
return a is not None and a < b
def gt(a, b):
return a is not None and a > b
if (lt(latitude.start, -180) or gt(latitude.start, 180) or
lt(latitude.stop, -180) or gt(latitude.stop, 180)):
raise NexusProcessingException(reason='Invalid latitude: out of range', code=400)
elif latitude == '*':
if output == 'png':
raise NexusProcessingException(reason='Cannot use PNG output with multi-latitude slicing', code=400)
latitude = slice(None, None, None)
else:
raise NexusProcessingException(reason='Invalid latitude argument', code=400)
min_lon = get_required_float('minLon')
max_lon = get_required_float('maxLon')
min_elevation = get_required_int('minElevation')
max_elevation = get_required_int('maxElevation')
horizontal_margin = compute_options.get_float_arg('horizontalMargin', 0.001)
ch_ds = compute_options.get_argument('canopy_ds', None)
g_ds = compute_options.get_argument('ground_ds', None)
if ch_ds is not None:
ch_ds = [v.strip() for v in ch_ds.split(',')]
else:
ch_ds = []
if len(ch_ds) > 2:
raise NexusProcessingException(
reason='Too many datasets provided for canopy_ds', code=400
)
if g_ds is not None:
g_ds = [v.strip() for v in g_ds.split(',')]
else:
g_ds = []
if len(g_ds) > 2:
raise NexusProcessingException(
reason='Too many datasets provided for ground_ds', code=400
)
percentiles = compute_options.get_boolean_arg('elevPercentiles')
if percentiles and (ch_ds is None or g_ds is None):
raise NexusProcessingException(
code=400,
reason='\'elevPercentiles\' argument requires \'canopy_ds\' and \'ground_ds\' be set'
)
peaks = compute_options.get_boolean_arg('peaks') and not percentiles
cmap = mpl.colormaps.get(
compute_options.get_argument('cmap', 'viridis'),
mpl.colormaps['viridis']
)
return (ds, parameter, latitude, min_lon, max_lon, min_elevation, max_elevation,horizontal_margin, peaks, ch_ds,
g_ds, percentiles, cmap)