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

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

Added a check for the 'seasons' argument in 'interface.py'. The check function is included in 'input_checks.py'.
parent f15793a2
......@@ -5,6 +5,7 @@ check_sampling - check the given sampling argument
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
"""
from collections import namedtuple
......@@ -14,7 +15,7 @@ import pandas as pd
from toarstats import ozone_metrics
from toarstats import stats
from toarstats.stats_utils import CLIMATIC_ZONE, RSTAGS
from toarstats.stats_utils import CLIMATIC_ZONE, RSTAGS, SEASON_DICT
def check_sampling(sampling_in):
......@@ -147,3 +148,28 @@ def check_metadata(metadata_in, station_lat_in, station_lon_in,
else:
metadata_dict["station_climatic_zone"] = None
return namedtuple("Metadata", metadata_dict)(**metadata_dict)
def check_seasons(seasons_in):
"""Check the given seasons argument.
:param seasons_in: the given seasons argument
:return: The processed seasons argument or None if there was a
problem while processing the given seasons argument
"""
if not isinstance(seasons_in, (list, str)):
return None
seasons_in_list = (
[seasons_in] if isinstance(seasons_in, str) else seasons_in
)
seasons_out = []
for season in seasons_in_list:
if not isinstance(season, str):
continue
season = season.strip()
if season in SEASON_DICT and season not in seasons_out:
seasons_out.append(season)
if not seasons_out:
return None
return seasons_out
......@@ -5,7 +5,7 @@ calculate_statistics - calculate the requested statistics
"""
from toarstats.input_checks import (check_data, check_metadata, check_sampling,
check_statistics)
check_seasons, check_statistics)
def calculate_statistics(sampling, statistics, data=None, metadata=None,
......@@ -96,3 +96,4 @@ def calculate_statistics(sampling, statistics, data=None, metadata=None,
data_frame = check_data(data, datetimes, values)
metadata_tuple = check_metadata(metadata, station_lat, station_lon,
station_climatic_zone)
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