API documentation¶
The following is API docs for the current functionality of chap-core that is available for use.
Data Fetching¶
Functionality for fetching data
- chap_core.fetch.gee_era5(credentials: GEECredentials | dict[str, str], polygons: FeatureCollectionModel | str, start_period: str, end_period: str, band_names=list[str], reducer: str = 'mean') list[ERA5Entry] ¶
- class chap_core.data.DataSet(data_dict: dict[str, FeaturesT], polygons=None)[source]¶
Class representing severeal time series at different locations.
- classmethod from_pandas(df: DataFrame, dataclass: Type[FeaturesT], fill_missing=False) DataSet[FeaturesT] [source]¶
Create a SpatioTemporalDict from a pandas dataframe. The dataframe needs to have a ‘location’ column, and a ‘time_period’ column. The time_period columnt needs to have strings that can be parsed into a period. All fields in the dataclass needs to be present in the dataframe. If ‘fill_missing’ is True, missing values will be filled with np.nan. Else all the time series needs to be consecutive.
Parameters¶
- dfpd.DataFrame
The dataframe
- dataclassType[FeaturesT]
The dataclass to use for the time series
- fill_missingbool, optional
If missing values should be filled, by default False
Returns¶
- DataSet[FeaturesT]
The SpatioTemporalDict
Examples¶
>>> import pandas as pd >>> from chap_core.spatio_temporal_data.temporal_dataclass import DataSet >>> from chap_core.datatypes import HealthData >>> df = pd.DataFrame( ... { ... "location": ["Oslo", "Oslo", "Bergen", "Bergen"], ... "time_period": ["2020-01", "2020-02", "2020-01", "2020-02"], ... "disease_cases": [10, 20, 30, 40], ... } ... ) >>> DataSet.from_pandas(df, HealthData)
- classmethod from_period_observations(observation_dict: dict[str, list[PeriodObservation]]) DataSet[TimeSeriesData] [source]¶
Create a SpatioTemporalDict from a dictionary of PeriodObservations. The keys are the location names, and the values are lists of PeriodObservations.
Parameters¶
- observation_dictdict[str, list[PeriodObservation]]
The dictionary of observations
Returns¶
- DataSet[TimeSeriesData]
The SpatioTemporalDict
Examples¶
>>> from chap_core.spatio_temporal_data.temporal_dataclass import DataSet >>> from chap_core.api_types import PeriodObservation >>> class HealthObservation(PeriodObservation): ... disease_cases: int >>> observations = { ... "Oslo": [ ... HealthObservation(time_period="2020-01", disease_cases=10), ... HealthObservation(time_period="2020-02", disease_cases=20), ... ] ... } >>> DataSet.from_period_observations(observations) >>> DataSet.to_pandas()
- class chap_core.data.PeriodObservation(*, time_period: str)¶