diff --git a/CHANGELOG.md b/CHANGELOG.md index d92519d7a24b48c9b6d750d26936b77eb699b5dd..1592b8d0db844f11736ba2ccedc7e8d4ccd70f6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog 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 ### general: diff --git a/dist/toarstats-0.6.7-py3-none-any.whl b/dist/toarstats-0.6.7-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..5c72a1c69cbda7390caff50e9858268b61b3126b Binary files /dev/null and b/dist/toarstats-0.6.7-py3-none-any.whl differ diff --git a/setup.cfg b/setup.cfg index 8fe948b755332de3c9da3338b9eabf1b0ff2ac4e..256d56f3d0d17f498ee8f1b5788e57201c5a8322 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = toarstats -version = 0.6.6 +version = 0.6.7 author = Niklas Selke, Martin Schultz, Max Lensing 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 diff --git a/toarstats/metrics/interface.py b/toarstats/metrics/interface.py index a34d97aeecf2db7eadadb7d05e629dd9c572d945..602883bca60681e6c5f1fc566d02a033967dae97 100644 --- a/toarstats/metrics/interface.py +++ b/toarstats/metrics/interface.py @@ -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, resample_rule, - "H" if "diurnal_cycle" in input_parameters.statistics else None - ) + results = harmonize_time( + results, ref, resample_rule, + "H" if "diurnal_cycle" in input_parameters.statistics else None + ) return pd.DataFrame({res["name"]: res["ser"] for res in results}) diff --git a/toarstats/metrics/stats_utils.py b/toarstats/metrics/stats_utils.py index 95b47999e79f89c87ba7899c7ea67f9e2d2d0351..36f4d439999e68e283c7cee7cd766d287efedd97 100644 --- a/toarstats/metrics/stats_utils.py +++ b/toarstats/metrics/stats_utils.py @@ -140,11 +140,11 @@ def create_reference_series(index, sampling, daterange=None): min_date = index.min() max_date = index.max() 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 = 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 = 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"]: start_date = start_date.replace(month=1, day=1, hour=0) @@ -290,25 +290,32 @@ def get_seasons(sampling, statistics, metadata, seasons, crops, 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. :param ser_list: a list of series + :param ref: reference timeseries :param mtype: aggregation type :param rsfreq: resampling frequency for the datetime index :return: A list of series with harmonized datetime indices """ - if rsfreq is None: - rsfreq = RSTAGS[mtype] - tmin = min(record["ser"].index.min() for record in ser_list) - tmax = max(record["ser"].index.max() for record in ser_list) - try: - newindex = pd.date_range(tmin, tmax, freq=rsfreq) - except ValueError: - newindex = pd.DatetimeIndex([]) - for record in ser_list: - record["ser"] = record["ser"].reindex(newindex) + 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: + rsfreq = RSTAGS[mtype] + tmin = ref.index.min() + tmax = ref.index.max() + + try: + newindex = pd.date_range(tmin, tmax, freq=rsfreq) + except ValueError: + newindex = pd.DatetimeIndex([]) + for record in ser_list: + record["ser"] = record["ser"].reindex(newindex) return ser_list