Commit 63e0a294 authored by Niklas Selke's avatar Niklas Selke
Browse files

Added a function to check which of the metadata, seasons and crops arguments...

Added a function to check which of the metadata, seasons and crops arguments are needed for the given sampling method and statistics.
parent d9bfe2c7
......@@ -4,6 +4,7 @@ This module contains the following functions:
check_sampling - check the given sampling argument
check_statistics - check the given statistics argument
check_data - check the given data argument
mark_required_arguments - mark which extra user inputs are required
check_metadata - check the given metadata argument
check_seasons - check the given seasons argument
check_crops - check the given crops argument
......@@ -126,6 +127,42 @@ def check_data(data_in, datetimes_in, values_in):
return pd.DataFrame({"values": values_out}, index=index_out)
def mark_required_arguments(sampling_method, stats_list, seasons_given):
"""Mark which extra user inputs are required.
:param sampling_method: the given sampling argument
:param stats_list: the given statistics argument
:param seasons_given: boolean denoting whether the seasons argument
is given
:return: A tuple of boolean values denoting which extra user inputs
are required
station_lat_req = False
station_lon_req = False
station_climatic_zone_req = False
seasons_req = False
crops_req = False
if any(stat in ["daylight_aot40", "dark_aot40", "daylight_avg", "dark_avg"]
for stat in stats_list):
station_lat_req = True
station_lon_req = True
if sampling_method in ["summer", "xsummer"]:
station_lat_req = True
if sampling_method in ["seasonal", "vegseason"]:
seasons_req = True
if (not seasons_given
and (sampling_method == "vegseason"
or (sampling_method == "seasonal"
and any("aot40" in stat or "w126" in stat
for stat in stats_list)))):
station_lat_req = True
station_climatic_zone_req = True
crops_req = True
return (station_lat_req, station_lon_req, station_climatic_zone_req,
seasons_req, crops_req)
def check_metadata(metadata_in, station_lat_in, station_lon_in,
"""Check the given metadata argument.
......@@ -6,7 +6,7 @@ calculate_statistics - calculate the requested statistics
from toarstats.input_checks import (
check_crops, check_data, check_data_capture, check_metadata,
check_sampling, check_seasons, check_statistics
check_sampling, check_seasons, check_statistics, mark_required_arguments
......@@ -103,6 +103,9 @@ def calculate_statistics(
raise ValueError("The drmdmax1h statistic cannot be evaluated with"
" monthly sampling")
data_frame = check_data(data, datetimes, values)
(station_lat_req, station_lon_req, station_climatic_zone_req, seasons_req,
crops_req) = mark_required_arguments(sampling_method, stats_list,
seasons is not None)
metadata_tuple = check_metadata(metadata, station_lat, station_lon,
seasons_list = check_seasons(seasons)
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