Skip to content
Snippets Groups Projects
Commit 9513b475 authored by Carsten Hinz's avatar Carsten Hinz
Browse files

fixed time difference for monthly and annual sampling

added documentation
parent 4da83bc5
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
...@@ -67,7 +67,7 @@ class TimeSample: ...@@ -67,7 +67,7 @@ class TimeSample:
def daterange_option(self) -> str: def daterange_option(self) -> str:
"""Conversion of range to a string """Conversion of range to a string
Range is given as start<=incuded days < end Range is given as [start, end)
""" """
end_with_padding = self.end + timedelta(1) end_with_padding = self.end + timedelta(1)
return f"{self.start.isoformat()},{end_with_padding.isoformat()}" return f"{self.start.isoformat()},{end_with_padding.isoformat()}"
...@@ -84,9 +84,8 @@ class TimeSample: ...@@ -84,9 +84,8 @@ class TimeSample:
Calculates the duration in days relative to start time point. Calculates the duration in days relative to start time point.
""" """
#TODO: could this be an issue for monthly sampling? tp = self.as_datetime_index()
n_days = (self.end - self.start).days return np.array([ (t - tp[0]).days for t in tp])
return np.arange(n_days + 1)
@dataclass @dataclass
...@@ -121,8 +120,6 @@ class Metadata: ...@@ -121,8 +120,6 @@ class Metadata:
""" """
variable = TOARVariable.get(standart_name) variable = TOARVariable.get(standart_name)
return Metadata(variable, time, stat) return Metadata(variable, time, stat)
@property @property
...@@ -209,6 +206,7 @@ def get_cf_metadata(variable: Variables, metadata: Metadata | None)-> Dict: ...@@ -209,6 +206,7 @@ def get_cf_metadata(variable: Variables, metadata: Metadata | None)-> Dict:
The resulting dictionary contains the required values for the netCDF files. The resulting dictionary contains the required values for the netCDF files.
""" """
match variable.name: match variable.name:
case Variables.latitude.name: case Variables.latitude.name:
cf_metadata = { cf_metadata = {
......
...@@ -49,8 +49,14 @@ class TOARVariable: ...@@ -49,8 +49,14 @@ class TOARVariable:
@classmethod @classmethod
def get(cls, standart_name: str) -> "TOARVariable": def get(cls, standart_name: str) -> "TOARVariable":
"""searches the known variables for the requested variable """searches the known variables for the requested variable
Parameters:
----------
standart_name:
name of the variable following the CF convention.
return: provides direct access to the meta data of the selected variable return:
provides direct access to the meta data of the selected variable
""" """
for var in cls.vars: for var in cls.vars:
if var.standart_name == standart_name: if var.standart_name == standart_name:
......
...@@ -380,7 +380,16 @@ class AnalysisServiceDownload(AnalysisService): ...@@ -380,7 +380,16 @@ class AnalysisServiceDownload(AnalysisService):
self.sample_dir = sample_dir self.sample_dir = sample_dir
self.use_downloaded = use_downloaded self.use_downloaded = use_downloaded
def get_timeseries_and_metadata(self, metadata: Metadata): def get_timeseries_and_metadata(self, metadata: Metadata) -> tuple[pd.DataFrame, pd.DataFrame]:
"""loading of cached data or requesting of data from the TOARDB
Parameters:
----------
metadata:
information on requested data
return:
tuple[timeseries, station coordinates]
"""
filename = self.sample_dir / self.get_sample_file_name(metadata) filename = self.sample_dir / self.get_sample_file_name(metadata)
query_options = QueryOptions.from_metadata(metadata) query_options = QueryOptions.from_metadata(metadata)
needs_fresh_download = (not self.use_downloaded) or (not filename.is_file()) needs_fresh_download = (not self.use_downloaded) or (not filename.is_file())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment