Commit b44c5acf authored by Niklas Selke's avatar Niklas Selke
Browse files

Refactored the 'check_statistics' function in 'input_checks.py'.

parent 671ca3ff
......@@ -28,34 +28,32 @@ def check_sampling(sampling_in):
return sampling_out
def check_statistics(input_argument):
def check_statistics(statistics_in):
"""Check the given statistics argument.
:param input_argument: the given argument
:param statistics_in: the given statistics argument
:return: The processed argument or None if there was a problem with
the input
:return: The processed statistics argument or None if there was a
problem while processing the given statistics argument
"""
if not isinstance(input_argument, (list, str)):
if not isinstance(statistics_in, (list, str)):
return None
statistics = []
if isinstance(input_argument, str):
stat = input_argument.strip()
statistics_in_list = (
[statistics_in] if isinstance(statistics_in, str) else statistics_in
)
statistics_out = []
for stat in statistics_in_list:
if not isinstance(stat, str):
continue
stat = stat.strip()
func = getattr(stats, stat, getattr(ozone_metrics, stat, None))
if func is not None:
statistics.append(func)
else:
for stat in input_argument:
if not isinstance(stat, str):
continue
stat = stat.strip()
func = getattr(stats, stat, getattr(ozone_metrics, stat, None))
if func is not None and func not in statistics:
statistics.append(func)
if (not statistics or (stats.diurnal_cycle in statistics
and len(statistics) > 1)):
if func is not None and func not in statistics_out:
statistics_out.append(func)
if not statistics_out:
return None
if stats.diurnal_cycle in statistics_out and len(statistics_out) > 1:
return None
return statistics
return statistics_out
def check_data(input_argument, alt_input_idx, alt_input_vals):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment