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

reference_series creation allows daterange argument, updated toarstats to 0.6.1

parent 4bd14add
No related branches found
No related tags found
1 merge request!13reference_series creation allows daterange argument, updated toarstats to 0.6.1
# 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.1 - 2024-07-15 - bugfixes
### general:
* updated sampling daterange to exact dates
### technical:
* bugfix for reference_series creation by adding optional daterange argument
* updated deprecated constants
## v0.6.0 - 2023-07-13 - adding custom sampling ## v0.6.0 - 2023-07-13 - adding custom sampling
### general: ### general:
......
...@@ -17,6 +17,11 @@ authors: ...@@ -17,6 +17,11 @@ authors:
family-names: Schultz family-names: Schultz
given-names: Martin given-names: Martin
affiliation: Forschungszentrum Jülich affiliation: Forschungszentrum Jülich
- email: m.lensing@fz-juelich.de
orcid: https://orcid.org/0009-0004-2443-8792
family-names: Lensing
given-names: Max
affiliation: Forschungszentrum Jülich
contact: contact:
- email: m.schultz@fz-juelich.de - email: m.schultz@fz-juelich.de
orcid: https://orcid.org/0000-0003-3455-774X orcid: https://orcid.org/0000-0003-3455-774X
......
File added
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
project = 'toarstats' project = 'toarstats'
copyright = '2021, Forschungszentrum Jülich GmbH' copyright = '2021, Forschungszentrum Jülich GmbH'
author = 'Niklas Selke' author = 'Niklas Selke, Martin Schultz, Max Lensing'
release = '0.6.0' release = '0.6.1'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
......
[metadata] [metadata]
name = toarstats name = toarstats
version = 0.6.0 version = 0.6.1
author = Niklas Selke author = Niklas Selke, Martin Schultz, Max Lensing
author_email = n.selke@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
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown
......
...@@ -154,9 +154,9 @@ ALLOWED_CROPS_VALUES = [ ...@@ -154,9 +154,9 @@ ALLOWED_CROPS_VALUES = [
RSTAGS = { RSTAGS = {
"daily": "D", "daily": "D",
"monthly": "MS", "monthly": "MS",
"seasonal": "AS", "seasonal": "YS",
"summer": "AS", "summer": "YS",
"xsummer": "AS", "xsummer": "YS",
"annual": "AS", "annual": "YS",
"custom": "100AS" "custom": "100YS"
} }
...@@ -16,7 +16,8 @@ from toarstats.metrics.stats_utils import ( ...@@ -16,7 +16,8 @@ from toarstats.metrics.stats_utils import (
def calculate_statistics( def calculate_statistics(
sampling=None, statistics=None, data=None, metadata=None, seasons=None, sampling=None, statistics=None, data=None, metadata=None, seasons=None,
crops=None, min_data_capture=None, datetimes=None, values=None, crops=None, min_data_capture=None, datetimes=None, values=None,
station_lat=None, station_lon=None, station_climatic_zone=None station_lat=None, station_lon=None, station_climatic_zone=None,
daterange=None
): ):
"""Calculate the requested statistics. """Calculate the requested statistics.
...@@ -126,7 +127,7 @@ def calculate_statistics( ...@@ -126,7 +127,7 @@ def calculate_statistics(
else DEFAULT_CROPS, input_parameters.required.seasons, else DEFAULT_CROPS, input_parameters.required.seasons,
input_parameters.required.crops input_parameters.required.crops
) )
ref = create_reference_series(input_parameters.data.index) ref = create_reference_series(input_parameters.data.index, daterange)
resample_rule = ("seasonal" if input_parameters.sampling == "vegseason" resample_rule = ("seasonal" if input_parameters.sampling == "vegseason"
else input_parameters.sampling) else input_parameters.sampling)
min_data_capture_value = (input_parameters.min_data_capture min_data_capture_value = (input_parameters.min_data_capture
......
...@@ -118,20 +118,28 @@ def calc_data_capture(ser, ref, sampling, how, mincount=0, minfrac=None, ...@@ -118,20 +118,28 @@ 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): def create_reference_series(index, daterange=None):
"""Create a reference series. """Create a reference series.
:param index: the given index :param index: the given index
:param daterange: start- and end-date separated by comma
if set, the reference series creates a series from start to end-date
:return: A series with a date range spanning from the beginning of :return: A series with a date range spanning from the beginning of
the earliest given year to the ending of the latest given the earliest given year to the ending of the latest given
year and filled with zeros year and filled with zeros
""" """
if daterange:
start_date = daterange.split(",")[0]
end_date = daterange.split(",")[1]
else:
min_date = index.min() min_date = index.min()
max_date = index.max() max_date = index.max()
start_date = f"{min_date.year}-01-01 00:{min_date.minute}" start_date = f"{min_date.year}-01-01 00:{min_date.minute}"
end_date = f"{max_date.year}-12-31 23:{max_date.minute}" end_date = f"{max_date.year}-12-31 23:{max_date.minute}"
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")
return pd.Series(0, reference_index) return pd.Series(0, reference_index)
...@@ -494,6 +502,8 @@ def stat_processor_1(label, ser, ref, mtype, seasons, func=resample, ...@@ -494,6 +502,8 @@ def stat_processor_1(label, ser, ref, mtype, seasons, func=resample,
:return: A list of dictionaries containing the processed data :return: A list of dictionaries containing the processed data
""" """
res = prepare_data(ser, ref, mtype, seasons, label) res = prepare_data(ser, ref, mtype, seasons, label)
if minfrac == 0:
minfrac = None
for r in res: for r in res:
r["ser"] = func(r["ser"], r["ref"], RSTAGS[mtype], how, r["ser"] = func(r["ser"], r["ref"], RSTAGS[mtype], how,
mincount=mincount, minfrac=minfrac, mincount=mincount, minfrac=minfrac,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment