Skip to content
Snippets Groups Projects
Commit 51a0a5b8 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

Merge branch 'max_version_0.6.7' into 'master'

fixed statistic output format, updated toarstats to 0.6.7

See merge request !19
parents d833cb2f c6251b77
Branches
Tags v0.6.7
1 merge request!19fixed statistic output format, updated toarstats to 0.6.7
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## v0.6.7 - 2025-02-21 - fixed output format
### general:
* changed statistic output format to cover the whole daterange
## v0.6.6 - 2025-02-10 - fixed osdma8 statistic ## v0.6.6 - 2025-02-10 - fixed osdma8 statistic
### general: ### general:
......
File added
[metadata] [metadata]
name = toarstats name = toarstats
version = 0.6.6 version = 0.6.7
author = Niklas Selke, Martin Schultz, Max Lensing author = Niklas Selke, Martin Schultz, Max Lensing
author_email = n.selke@fz-juelich.de, m.schultz@fz-juelich.de, m.lensing@fz-juelich.de author_email = n.selke@fz-juelich.de, m.schultz@fz-juelich.de, m.lensing@fz-juelich.de
description = Collection of statistics for the TOAR community description = Collection of statistics for the TOAR community
......
...@@ -146,13 +146,8 @@ def calculate_statistics( ...@@ -146,13 +146,8 @@ def calculate_statistics(
) )
) )
if resample_rule == "custom":
custom_index = pd.DatetimeIndex([ref.index.min().strftime("%Y-%m-%d")])
for res in results:
res["ser"].index = custom_index
else:
results = harmonize_time( results = harmonize_time(
results, resample_rule, results, ref, resample_rule,
"H" if "diurnal_cycle" in input_parameters.statistics else None "H" if "diurnal_cycle" in input_parameters.statistics else None
) )
return pd.DataFrame({res["name"]: res["ser"] for res in results}) return pd.DataFrame({res["name"]: res["ser"] for res in results})
...@@ -140,11 +140,11 @@ def create_reference_series(index, sampling, daterange=None): ...@@ -140,11 +140,11 @@ def create_reference_series(index, sampling, daterange=None):
min_date = index.min() min_date = index.min()
max_date = index.max() max_date = index.max()
if daterange is not None: if daterange is not None:
# adjust start and end-date by the minute-offset of the timeseries # adjust start and end-date by the minute/second offset of the timeseries
start_date = pd.to_datetime(daterange.split(",")[0]) start_date = pd.to_datetime(daterange.split(",")[0])
start_date = start_date.replace(minute=min_date.minute) start_date = start_date.replace(minute=min_date.minute, second=min_date.second)
end_date = pd.to_datetime(daterange.split(",")[1]) end_date = pd.to_datetime(daterange.split(",")[1])
end_date = end_date.replace(minute=max_date.minute) end_date = end_date.replace(minute=max_date.minute, second=max_date.second)
if sampling in ["annual", "seasonal", "summer", "xsummer"]: if sampling in ["annual", "seasonal", "summer", "xsummer"]:
start_date = start_date.replace(month=1, day=1, hour=0) start_date = start_date.replace(month=1, day=1, hour=0)
...@@ -290,19 +290,26 @@ def get_seasons(sampling, statistics, metadata, seasons, crops, ...@@ -290,19 +290,26 @@ def get_seasons(sampling, statistics, metadata, seasons, crops,
else DEFAULT_SEASONS for stat in statistics] else DEFAULT_SEASONS for stat in statistics]
def harmonize_time(ser_list, mtype, rsfreq=None): def harmonize_time(ser_list, ref, mtype, rsfreq=None):
"""Harmonize the datetime index of all given series. """Harmonize the datetime index of all given series.
:param ser_list: a list of series :param ser_list: a list of series
:param ref: reference timeseries
:param mtype: aggregation type :param mtype: aggregation type
:param rsfreq: resampling frequency for the datetime index :param rsfreq: resampling frequency for the datetime index
:return: A list of series with harmonized datetime indices :return: A list of series with harmonized datetime indices
""" """
if mtype == "custom":
custom_index = pd.DatetimeIndex([ref.index.min().strftime("%Y-%m-%d")])
for record in ser_list:
record["ser"].index = custom_index
else:
if rsfreq is None: if rsfreq is None:
rsfreq = RSTAGS[mtype] rsfreq = RSTAGS[mtype]
tmin = min(record["ser"].index.min() for record in ser_list) tmin = ref.index.min()
tmax = max(record["ser"].index.max() for record in ser_list) tmax = ref.index.max()
try: try:
newindex = pd.date_range(tmin, tmax, freq=rsfreq) newindex = pd.date_range(tmin, tmax, freq=rsfreq)
except ValueError: except ValueError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment