From ebe8ef2417c1431b53e1ee291e9dd2144c26adf2 Mon Sep 17 00:00:00 2001
From: Carsten Hinz <c.hinz@fz-juelich.de>
Date: Mon, 29 Apr 2024 15:19:48 +0200
Subject: [PATCH] README.md: - added info to statistics applied during request
 to TOAR-DB

metadata:
- first round of documentation
---
 README.md                |  1 +
 toargridding/metadata.py | 41 ++++++++++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 65230bc..946f6e1 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@ TOAR Gridding Tool
 # About 
 
 The TOARgridding projects data from the TOAD database (https://toar-data.fz-juelich.de/) onto a grid. 
+The request to the database also allows a statistical analysis of the requested value.
 The mean and standard deviation of all stations within a cell are computed. 
 
 The tool handles the request to the database over the REST API and the subsequent processing.
diff --git a/toargridding/metadata.py b/toargridding/metadata.py
index cb45f94..abf9349 100644
--- a/toargridding/metadata.py
+++ b/toargridding/metadata.py
@@ -8,6 +8,8 @@ import pandas as pd
 from toargridding.toarstats_constants import STATISTICS_LIST, ALLOWED_SAMPLING_VALUES
 from toargridding.static_metadata import global_cf_attributes, TOARVariable
 
+from typing import Dict
+
 date_created = datetime.utcnow().strftime("%Y-%m-dT%H:%M:%SZ")
 
 COORDINATE_VARIABLES = ["latitude", "longitude", "time"]
@@ -68,7 +70,7 @@ class TimeSample:
         return TIME_FREQUENCIES[self.sampling]
 
     def as_cf_index(self) -> np.array:
-        """conversion to netCDF Climate and Forecast (CF) Metadata Convertions
+        """conversion to netCDF Climate and Forecast (CF) Metadata Conventions
         
         Calculates the duration in days relative to start time point.
         """
@@ -78,6 +80,15 @@ class TimeSample:
 
 @dataclass
 class Metadata:
+    """MEtadata of a request. 
+
+    variable:
+        support variable of the TOAR data base
+    statistics:
+        statistical processing applied by the TOAR database for this request
+    time:
+        requested time points
+    """
     variable: TOARVariable
     statistic: str
     time: TimeSample
@@ -91,13 +102,23 @@ class Metadata:
 
         return Metadata(variable, stat, time)
 
-    def get_id(self):
+    def get_id(self) -> str:
+        """creation of a request specific ID
+
+        For example, used for saving link to results of a request in the cache.
+        """
         return f"{self.variable.name}_{self.statistic}_{self.time.daterange_option}_at_{datetime.now().date().isoformat()}"
 
-    def get_title(self):
+    def get_title(self) -> str:
+        """creation of a title for metadata of a xarray according to the CF convention
+        """
         return f"{self.time.sampling} {self.statistic} statistic for {self.variable.standart_name} from {self.time.start} to {self.time.end} aggregated on global grid"
 
-    def get_summary(self):
+    def get_summary(self) -> str:
+        """creation of a descriptive string
+         
+        At the moment same as title.
+        """
         return f"{self.time.sampling} {self.statistic} statistic for {self.variable.standart_name} from {self.time.start} to {self.time.end} aggregated on global grid"
 
 
@@ -120,7 +141,9 @@ class AnalysisRequestResult:
     metadata: Metadata
 
 
-def get_global_attributes(metadata: Metadata):
+def get_global_attributes(metadata: Metadata) -> Dict:
+    """combination of global metadata with request specific values.
+    """
     dynamic_cf_attributes = {
         "id": metadata.get_id(),
         "title": metadata.get_title(),
@@ -141,7 +164,13 @@ def get_global_attributes(metadata: Metadata):
     return cf_attributes
 
 
-def get_cf_metadata(variable: Variables, metadata: Metadata | None):
+def get_cf_metadata(variable: Variables, metadata: Metadata | None)-> Dict:
+    """get CF meta data for coordinates and requested parameter
+
+    The resulting meta data follow the CF convention: https://cfconventions.org/cf-conventions/cf-conventions.html. 
+    
+    The resulting dictionary contains the required values for the netCDF files.
+    """
     match variable.name:
         case Variables.latitude.name:
             cf_metadata = {
-- 
GitLab