Commit 270e114f authored by Niklas Selke's avatar Niklas Selke
Browse files

Added a check for the 'crops' argument in 'interface.py'. The check function...

Added a check for the 'crops' argument in 'interface.py'. The check function is included in 'input_checks.py'.
parent 177ab437
...@@ -6,6 +6,7 @@ check_statistics - check the given statistics argument ...@@ -6,6 +6,7 @@ check_statistics - check the given statistics argument
check_data - check the given data argument check_data - check the given data argument
check_metadata - check the given metadata argument check_metadata - check the given metadata argument
check_seasons - check the given seasons argument check_seasons - check the given seasons argument
check_crops - check the given crops argument
""" """
from collections import namedtuple from collections import namedtuple
...@@ -173,3 +174,26 @@ def check_seasons(seasons_in): ...@@ -173,3 +174,26 @@ def check_seasons(seasons_in):
if not seasons_out: if not seasons_out:
return None return None
return seasons_out return seasons_out
def check_crops(crops_in):
"""Check the given crops argument.
:param crops_in: the given crops argument
:return: The processed crops argument or None if there was a problem
while processing the given crops argument
"""
if not isinstance(crops_in, (list, str)):
return None
crops_in_list = [crops_in] if isinstance(crops_in, str) else crops_in
crops_out = []
for crop in crops_in_list:
if not isinstance(crop, str):
continue
crop = crop.strip()
if crop in {"wheat", "rice"} and crop not in crops_out:
crops_out.append(crop)
if not crops_out:
return None
return crops_out
...@@ -4,8 +4,9 @@ This module contains the following function: ...@@ -4,8 +4,9 @@ This module contains the following function:
calculate_statistics - calculate the requested statistics calculate_statistics - calculate the requested statistics
""" """
from toarstats.input_checks import (check_data, check_metadata, check_sampling, from toarstats.input_checks import (check_crops, check_data, check_metadata,
check_seasons, check_statistics) check_sampling, check_seasons,
check_statistics)
def calculate_statistics(sampling, statistics, data=None, metadata=None, def calculate_statistics(sampling, statistics, data=None, metadata=None,
...@@ -97,3 +98,4 @@ def calculate_statistics(sampling, statistics, data=None, metadata=None, ...@@ -97,3 +98,4 @@ def calculate_statistics(sampling, statistics, data=None, metadata=None,
metadata_tuple = check_metadata(metadata, station_lat, station_lon, metadata_tuple = check_metadata(metadata, station_lat, station_lon,
station_climatic_zone) station_climatic_zone)
seasons_list = check_seasons(seasons) seasons_list = check_seasons(seasons)
crops_list = check_crops(crops)
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