Skip to content
Snippets Groups Projects
Commit af3295e1 authored by Max Lensing's avatar Max Lensing
Browse files

bugfix create_reference_series, updated toarstats to 0.6.4

parent 28b69523
No related branches found
No related tags found
1 merge request!16bugfix create_reference_series, updated toarstats to 0.6.4
# 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.4 - 2024-09-16 - bugfix reference-series
### general:
* daterange in create_reference_series is now optional, therefore the series is created by dataframe indices
## v0.6.3 - 2024-07-30 - fixed custom-sampling ## v0.6.3 - 2024-07-30 - fixed custom-sampling
### general: ### general:
......
File added
[metadata] [metadata]
name = toarstats name = toarstats
version = 0.6.3 version = 0.6.4
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
......
...@@ -121,8 +121,9 @@ def calc_data_capture(ser, ref, sampling, how, mincount=0, minfrac=None, ...@@ -121,8 +121,9 @@ def calc_data_capture(ser, ref, sampling, how, mincount=0, minfrac=None,
return fcov.reindex(ser_tmp.index) return fcov.reindex(ser_tmp.index)
def create_reference_series(index, sampling, daterange): def create_reference_series(index, sampling, daterange=None):
"""Create a reference series by the daterange. Additional extends to the intervals specified by the sampling. """Create a reference series by the daterange. Additional extends to the intervals specified by the sampling.
If no daterange is given, the series is based on the indices of the dataframe.
:param index: the given index :param index: the given index
...@@ -133,11 +134,12 @@ def create_reference_series(index, sampling, daterange): ...@@ -133,11 +134,12 @@ def create_reference_series(index, sampling, daterange):
if set, the reference series creates a series from start to end-date if set, the reference series creates a series from start to end-date
:return: A series with a date range based on the specified date range. The date range is extended based on the :return: A series with a date range based on the specified date range or indices. The date range is extended based on the
specified sampling. specified sampling.
""" """
min_date = index.min() min_date = index.min()
max_date = index.max() 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-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)
...@@ -154,8 +156,9 @@ def create_reference_series(index, sampling, daterange): ...@@ -154,8 +156,9 @@ def create_reference_series(index, sampling, daterange):
elif sampling == "daily": elif sampling == "daily":
start_date = start_date.replace(hour=0) start_date = start_date.replace(hour=0)
end_date = end_date.replace(hour=23) end_date = end_date.replace(hour=23)
reference_index = pd.date_range(start=start_date, end=end_date, freq="h") reference_index = pd.date_range(start=start_date, end=end_date, freq="h")
else:
reference_index = pd.date_range(start=min_date, end=max_date, freq="h")
return pd.Series(0, reference_index) return pd.Series(0, reference_index)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment