From 6d08b814978b421d03ae7acd63a9a49ad8cbcb8c Mon Sep 17 00:00:00 2001 From: Niklas Selke <n.selke@fz-juelich.de> Date: Wed, 12 Jul 2023 15:39:05 +0200 Subject: [PATCH] Added a custom sampling option to aggregate over the full time series time span. --- tests/test_metrics/test_interface.py | 2 +- toarstats/metrics/constants.py | 6 ++++-- toarstats/metrics/interface.py | 2 +- toarstats/metrics/stats.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_metrics/test_interface.py b/tests/test_metrics/test_interface.py index ad1dc63..1bf22d7 100644 --- a/tests/test_metrics/test_interface.py +++ b/tests/test_metrics/test_interface.py @@ -74,7 +74,7 @@ def test_calculate_statistics_run_all_statistics_with_all_samplings( elif statistic == "percentiles1": expected_num_columns *= 3 elif statistic == "percentiles2": - if sampling in {"daily", "monthly", "seasonal", "vegseason"}: + if sampling not in {"summer", "xsummer", "annual"}: expected_num_columns *= 7 else: expected_num_columns *= 9 diff --git a/toarstats/metrics/constants.py b/toarstats/metrics/constants.py index af2d0aa..ba01958 100644 --- a/toarstats/metrics/constants.py +++ b/toarstats/metrics/constants.py @@ -16,7 +16,8 @@ ALLOWED_SAMPLING_VALUES = [ "vegseason", "summer", "xsummer", - "annual" + "annual", + "custom" ] STATISTICS_LIST = [ @@ -156,5 +157,6 @@ RSTAGS = { "seasonal": "AS", "summer": "AS", "xsummer": "AS", - "annual": "AS" + "annual": "AS", + "custom": "100AS" } diff --git a/toarstats/metrics/interface.py b/toarstats/metrics/interface.py index bba7fb5..28c88ae 100644 --- a/toarstats/metrics/interface.py +++ b/toarstats/metrics/interface.py @@ -26,7 +26,7 @@ def calculate_statistics( :param sampling: temporal aggregation, one of ``daily``, ``monthly``, ``seasonal``, ``vegseason``, - ``summer``, ``xsummer``, or ``annual``; + ``summer``, ``xsummer``, ``annual``, or ``custom``; ``summer`` will pick the 6-months summer season in the hemisphere where the station is located; ``xsummer`` does the same for a 7-months summer diff --git a/toarstats/metrics/stats.py b/toarstats/metrics/stats.py index b67ba06..e7cea61 100644 --- a/toarstats/metrics/stats.py +++ b/toarstats/metrics/stats.py @@ -484,7 +484,7 @@ def diurnal_cycle(ser, ref, mtype, metadata, seasons, min_data_capture): # data record. nyears = ser.index.year.unique().size vmax = {"daily": 1, "monthly": 29, "seasonal": 91, "summer": 182, - "xsummer": 212, "annual": 365} + "xsummer": 212, "annual": 365, "custom": 365} dcap = int(min_data_capture * vmax[mtype] * nyears) for r in res: grouped = r["ser"].groupby(r["ser"].index.hour) -- GitLab