Skip to content
Snippets Groups Projects
Commit 10c0262b authored by Simon Grasse's avatar Simon Grasse
Browse files

cleanup imports, refactor metadata functions

parent a2e368b7
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
...@@ -15,8 +15,8 @@ def get_gridded_toar_data( ...@@ -15,8 +15,8 @@ def get_gridded_toar_data(
grid: GridDefinition, grid: GridDefinition,
time: TimeSample, time: TimeSample,
variables: list[str], variables: list[str],
stats: tuple[list[str], list[Metadata]], stats: list[str],
) -> list[xr.Dataset]: ) -> tuple[list[xr.Dataset], list[Metadata]]:
metadatas = [ metadatas = [
Metadata.construct(var, stat, time) for var, stat in product(variables, stats) Metadata.construct(var, stat, time) for var, stat in product(variables, stats)
] ]
......
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum
from dataclasses import dataclass from dataclasses import dataclass
from collections import namedtuple
import json
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import xarray as xr
from toargridding.toarstats_constants import STATISTICS_LIST from toargridding.toarstats_constants import STATISTICS_LIST
from toargridding.static_metadata import global_cf_attributes, TOARVariable from toargridding.static_metadata import global_cf_attributes, TOARVariable
...@@ -62,6 +59,15 @@ class Metadata: ...@@ -62,6 +59,15 @@ class Metadata:
return Metadata(variable, stat, time) return Metadata(variable, stat, time)
def get_id(self):
return f"{self.variable.name}_{self.statistic}_{self.time.daterange_option}_at_{datetime.now().date().isoformat()}"
def get_title(self):
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):
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"
@dataclass @dataclass
class AnalysisRequestResult: class AnalysisRequestResult:
...@@ -70,10 +76,11 @@ class AnalysisRequestResult: ...@@ -70,10 +76,11 @@ class AnalysisRequestResult:
metadata: Metadata metadata: Metadata
def get_global_attributes(metadata): def get_global_attributes(metadata: Metadata):
metadata = { dynamic_cf_attributes = {
"title": get_title(metadata), "id": metadata.get_id(),
"summary": get_summary(metadata), "title": metadata.get_title(),
"summary": metadata.get_summary(),
"date_created": date_created, "date_created": date_created,
"history": f"{date_created}: File created by toargridding package using data from toar-analysis service", "history": f"{date_created}: File created by toargridding package using data from toar-analysis service",
# "geospatial_bounds": 0, # for polygonal desrcription # "geospatial_bounds": 0, # for polygonal desrcription
...@@ -86,16 +93,8 @@ def get_global_attributes(metadata): ...@@ -86,16 +93,8 @@ def get_global_attributes(metadata):
# "time_coverage_duration": 0, # TODO insert durations # "time_coverage_duration": 0, # TODO insert durations
# "time_coverage_resolution": 0, # "time_coverage_resolution": 0,
} }
metadata = metadata | global_cf_attributes cf_attributes = dynamic_cf_attributes | global_cf_attributes
return metadata return cf_attributes
def get_title(metadata: Metadata):
return f"{metadata.time.sampling} {metadata.statistic} statistic for {metadata.variable.standart_name} from {metadata.time.start} to {metadata.time.end} aggregated on global grid"
def get_summary(metadata: Metadata): # TODO make summary different from title
return f"{metadata.time.sampling} {metadata.statistic} statistic for {metadata.variable.standart_name} from {metadata.time.start} to {metadata.time.end} aggregated on global grid"
def get_cf_metadata(variable: Variables, metadata: Metadata | None): def get_cf_metadata(variable: Variables, metadata: Metadata | None):
......
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