Commit 376f1b99 authored by Niklas Selke's avatar Niklas Selke
Browse files

Added a function to create a reference data frame.

parent d41eef1b
...@@ -5,6 +5,7 @@ calculate_statistics - calculate the requested statistics ...@@ -5,6 +5,7 @@ calculate_statistics - calculate the requested statistics
""" """
from toarstats.input_checks import check_input_parameters from toarstats.input_checks import check_input_parameters
from toarstats.stats_utils import create_reference_data_frame
def calculate_statistics( def calculate_statistics(
...@@ -104,3 +105,6 @@ def calculate_statistics( ...@@ -104,3 +105,6 @@ def calculate_statistics(
sampling, statistics, data, metadata, seasons, crops, data_capture, sampling, statistics, data, metadata, seasons, crops, data_capture,
datetimes, values, station_lat, station_lon, station_climatic_zone datetimes, values, station_lat, station_lon, station_climatic_zone
) )
reference_data_frame = create_reference_data_frame(
input_parameters.data.index
)
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
This module contains the following functions: This module contains the following functions:
aot40stat - evaluate the sum of values above the given threshold aot40stat - evaluate the sum of values above the given threshold
calc_data_capture - calculate the data capture fraction calc_data_capture - calculate the data capture fraction
create_reference_data_frame - create a reference data frame
dma8_processor - calculate the daily maximum 8-hour running mean dma8_processor - calculate the daily maximum 8-hour running mean
get_elevation_angle - calculate the solar elevation angle get_elevation_angle - calculate the solar elevation angle
get_growing_season - get the correct season name get_growing_season - get the correct season name
...@@ -99,6 +100,23 @@ def calc_data_capture(df, dfref, sampling, how, mincount=0, minfrac=None, ...@@ -99,6 +100,23 @@ def calc_data_capture(df, dfref, sampling, how, mincount=0, minfrac=None,
return dfres return dfres
def create_reference_data_frame(index):
"""Create a reference data frame.
:param index: the given index
:return: A data frame with a date range spanning from the beginning
of the earliest given year to the ending of the latest
given year and filled with zeros
"""
min_date = index.min()
max_date = index.max()
start_date = f"{min_date.year}-01-01 00:{min_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")
return pd.DataFrame(np.zeros(reference_index.size), index=reference_index)
def dma8_processor(df, dfref, mtype, metadata, seasons, data_capture, tshift=0, def dma8_processor(df, dfref, mtype, metadata, seasons, data_capture, tshift=0,
hours=[0, 23], dname="", strict=False, average=False): hours=[0, 23], dname="", strict=False, average=False):
"""Calculate the daily maximum 8-hour running mean. """Calculate the daily maximum 8-hour running mean.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment