Skip to content

Commit

Permalink
icoscp_stilt - return basic dobj metadata together with observation r…
Browse files Browse the repository at this point in the history
…esults
  • Loading branch information
mirzov committed Aug 21, 2024
1 parent b209e2c commit 26887f0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions icoscp_stilt/src/icoscp_stilt/stilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def has_observation_data(self) -> bool:
"""
return self.icosId is not None

@dataclass(frozen=True)
class ObservationResult:
dobj: DataObjectLite
columns: ArraysDict

@dataclass(frozen=True)
class ObservationDfResult:
dobj: DataObjectLite
df: pd.DataFrame

def list_stations() -> list[StiltStation]:
"""
Expand Down Expand Up @@ -244,7 +253,7 @@ def fetch_observations_pandas(
spec: URL,
stations: list[StiltStation],
columns: list[str] | None = None
) -> dict[str, pd.DataFrame]:
) -> dict[str, ObservationDfResult]:
"""
Batch-fetch observational datasets for a number of STILT stations
Expand All @@ -257,19 +266,19 @@ def fetch_observations_pandas(
within the observational datasets; if omitted, all columns are included
in the result
:return (dict[str, DataFrame]): a dictionary with STILT station IDs as
keys and pandas DataFrames with observational datasets as values
:return (dict[str, ObservationDfResult]): a dictionary with STILT station IDs as
keys and instances of ObservationDfResult as values
"""
return {
st_id: pd.DataFrame(arrs)
for st_id, arrs in fetch_observations(spec, stations, columns).items()
st_id: ObservationDfResult(obs_res.dobj, pd.DataFrame(obs_res.columns))
for st_id, obs_res in fetch_observations(spec, stations, columns).items()
}

def fetch_observations(
spec: URL,
stations: list[StiltStation],
columns: list[str] | None = None
) -> dict[str, ArraysDict]:
) -> dict[str, ObservationResult]:
"""
Batch-fetch observational datasets for a number of STILT stations. Is a
lower-level and better-performing version of `fetch_observations_pandas`.
Expand All @@ -287,8 +296,8 @@ def fetch_observations(
within the observational datasets; if omitted, all columns are included
in the result
:return (dict[str, dict[str, ndarray]]): a dictionary with STILT station IDs as
keys and as values, dictionaries of column names vs numpy arrays
:return (dict[str, ObservationResult]): a dictionary with STILT station IDs as
keys and ObservationResult instances as values
"""

icos2ss: dict[tuple[URL, float], StiltStation] = {
Expand All @@ -312,8 +321,8 @@ def lookup_ss(dobj: DataObjectLite) -> list[StiltStation]:
if lookup_ss(dobj)
]
return {
ss.id: arrs
for dobj, arrs in data.batch_get_columns_as_arrays(dobjs_to_fetch, columns)
ss.id: ObservationResult(dobj, cols)
for dobj, cols in data.batch_get_columns_as_arrays(dobjs_to_fetch, columns)
for ss in lookup_ss(dobj)
}

Expand Down

0 comments on commit 26887f0

Please sign in to comment.