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

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

Added a check for the 'crops' argument in ''. The check function is included in ''.
parent 177ab437
......@@ -6,6 +6,7 @@ check_statistics - check the given statistics argument
check_data - check the given data argument
check_metadata - check the given metadata argument
check_seasons - check the given seasons argument
check_crops - check the given crops argument
from collections import namedtuple
......@@ -173,3 +174,26 @@ def check_seasons(seasons_in):
if not seasons_out:
return None
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):
crop = crop.strip()
if crop in {"wheat", "rice"} and crop not in crops_out:
if not crops_out:
return None
return crops_out
......@@ -4,8 +4,9 @@ This module contains the following function:
calculate_statistics - calculate the requested statistics
from toarstats.input_checks import (check_data, check_metadata, check_sampling,
check_seasons, check_statistics)
from toarstats.input_checks import (check_crops, check_data, check_metadata,
check_sampling, check_seasons,
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,
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