API Reference
DataPoint
TimeSeries
TimeSeriesTable
- class timedatamodel.TimeSeriesTable(frequency, *, timezone='UTC', timestamps=None, values, names=None, units=None, descriptions=None, data_types=None, locations=None, timeseries_types=None, attributes=None, labels=None, index_names=None)[source]
Bases:
_TimeSeriesBase,_TimeSeriesTableReprMixin,_DataFrameMixin,_TimeSeriesTableOpsMixin,_TimeSeriesTableIOMixin,_TimeSeriesTableConverterMixin- Parameters:
- locations: list[GeoLocation | GeoArea | None]
- timeseries_types: list[TimeSeriesType]
- convert_unit(target_unit, column=None)[source]
Return a new table with values converted to target_unit.
- Parameters:
- Return type:
- filter_columns_by_location(center, radius_km)[source]
Keep only columns within radius_km of center.
- Return type:
- Parameters:
center (GeoLocation)
radius_km (float)
- filter_columns_by_area(area)[source]
Keep only columns inside area.
- Return type:
- Parameters:
area (GeoArea)
- nearest_columns(target, n=1)[source]
Keep the n nearest columns to target.
- Return type:
- Parameters:
target (GeoLocation)
n (int)
- to_univariate_list()[source]
Convert to a list of univariate TimeSeriesList, one per column.
- Return type:
list[‘TimeSeriesList’]
- head(n=5)[source]
Return a new TimeSeriesTable with the first n points.
- Return type:
- Parameters:
n (int)
- tail(n=5)[source]
Return a new TimeSeriesTable with the last n points.
- Return type:
- Parameters:
n (int)
TimeSeriesArray
- class timedatamodel.TimeSeriesArray(frequency, *, timezone='UTC', name=None, unit=None, description=None, data_type=None, attributes=None, dimensions=None, values)[source]
Bases:
_TimeSeriesArrayReprMixin- Parameters:
- to_xarray()[source]
Convert to an xarray DataArray.
Each
Dimensionbecomes a named coordinate. Masked values are exported asNaN. Metadata is stored inDataArray.attrsso thatfrom_xarraycan round-trip it.- Return type:
xr.DataArray
- classmethod from_xarray(da, frequency=None, *, timezone=None, name=None, unit=None, description=None, data_type=None, attributes=None)[source]
Construct a
TimeSeriesArrayfrom anxr.DataArray.Metadata is read from
da.attrsbut explicit keyword arguments take precedence.
- apply_xarray(func)[source]
Apply an xarray transformation, reading metadata from result.attrs with self as fallback.
- Return type:
- apply_pandas(func)[source]
Apply a pandas transformation to the array as a DataFrame.
Gated to arrays with at most 2 non-time dimensions.
- Return type:
- apply_polars(func)[source]
Apply a polars transformation to the array as a DataFrame.
Gated to arrays with at most 2 non-time dimensions.
- Return type:
- classmethod from_numpy(dimensions, values, frequency, *, timezone='UTC', name=None, unit=None, description=None, data_type=None, attributes=None)[source]
Dimension
TimeSeriesCollection
- class timedatamodel.TimeSeriesCollection(series=None, *, name=None, description=None)[source]
Container for TimeSeriesList and/or TimeSeriesTable objects that don’t share an index.
Items are stored internally as an ordered
dict[str, TimeSeriesList | TimeSeriesTable].- Parameters:
series (list[TimeSeriesList | TimeSeriesTable] | dict[str, TimeSeriesList | TimeSeriesTable] | None)
name (str | None)
description (str | None)
- add(item, name=None)[source]
- Return type:
- Parameters:
item (TimeSeriesList | TimeSeriesTable)
name (str | None)
- filter_by_location(center, radius_km)[source]
Keep series within radius_km of center.
- Return type:
- Parameters:
center (GeoLocation)
radius_km (float)
- nearest(target, n=1)[source]
Keep the n nearest series to target.
- Return type:
- Parameters:
target (GeoLocation)
n (int)
- to_pandas_dataframe()[source]
Outer-join all series into a single pandas DataFrame.
Each series becomes a column named by its key. The index is the union of all timestamps (outer join), with
NaNfor missing values.- Return type:
pd.DataFrame
Frequency
DataType
- class timedatamodel.DataType(*values)[source]
- ACTUAL = 'ACTUAL'
- OBSERVATION = 'OBSERVATION'
- DERIVED = 'DERIVED'
- CALCULATED = 'CALCULATED'
- ESTIMATION = 'ESTIMATION'
- FORECAST = 'FORECAST'
- PREDICTION = 'PREDICTION'
- SCENARIO = 'SCENARIO'
- SIMULATION = 'SIMULATION'
- RECONSTRUCTION = 'RECONSTRUCTION'
- REFERENCE = 'REFERENCE'
- BASELINE = 'BASELINE'
- BENCHMARK = 'BENCHMARK'
- IDEAL = 'IDEAL'
TimeSeriesType
GeoLocation
- class timedatamodel.GeoLocation(latitude, longitude)[source]
-
- distance_to(other, unit='km')[source]
Haversine great-circle distance to other.
- Return type:
- Parameters:
other (GeoLocation)
unit (str)
- bearing_to(other)[source]
Initial bearing in degrees [0, 360) from self to other.
- Return type:
- Parameters:
other (GeoLocation)
- midpoint(other)[source]
Geographic midpoint on the great circle.
- Return type:
- Parameters:
other (GeoLocation)
GeoArea
- class timedatamodel.GeoArea(polygon, name=None)[source]
- Parameters:
polygon (Polygon)
name (str | None)
- polygon: Polygon
- property centroid: GeoLocation
- classmethod from_coordinates(coords, name=None)[source]
Create a GeoArea from a list of (lat, lon) coordinate pairs.
- contains_point(location)[source]
True if location is inside this area.
- Return type:
- Parameters:
location (GeoLocation)
- distance_to(other)[source]
Approximate distance in km (centroid-based Haversine).
Returns 0.0 if the point is contained or the areas overlap.
- Return type:
- Parameters:
other (GeoLocation | GeoArea)
AggregationMethod
HierarchyNode
- class timedatamodel.HierarchyNode(key, level, children=<factory>, timeseries=None, location=None, _parent=None)[source]
- Parameters:
key (str)
level (str)
children (list[HierarchyNode])
timeseries (TimeSeriesList | None)
location (GeoLocation | GeoArea | None)
_parent (HierarchyNode | None)
- children: list[HierarchyNode]
- location: GeoLocation | GeoArea | None
- property parent: HierarchyNode | None
- property siblings: list[HierarchyNode]
HierarchyTree
- class timedatamodel.HierarchyTree(root)[source]
Displayable tree visualization for a HierarchicalTimeSeries.
- Parameters:
root (HierarchyNode)
HierarchicalTimeSeries
- class timedatamodel.HierarchicalTimeSeries(root, *, name=None, description=None, aggregation=AggregationMethod.SUM, levels=None)[source]
Bases:
_HierarchicalTimeSeriesReprMixinA tree of time series organised into named hierarchy levels.
- Parameters:
root (HierarchyNode)
name (str | None)
description (str | None)
aggregation (AggregationMethod)
- classmethod from_dict(tree, series_map, *, levels=None, name=None, description=None, aggregation=AggregationMethod.SUM)[source]
Build from a nested dict and a flat series mapping.
Example:
tree = {"Norway": {"Bergen": "bergen_ts", "Oslo": "oslo_ts"}} series_map = {"bergen_ts": ts_bergen, "oslo_ts": ts_oslo}
- Return type:
- Parameters:
- classmethod from_dataframe(df, level_columns, value_column, timestamp_column=None, *, name=None, description=None, aggregation=AggregationMethod.SUM, frequency=None, timezone='UTC')[source]
Build from a long-format pandas DataFrame with hierarchy columns.
- Return type:
- Parameters:
- property root: HierarchyNode
- walk(order='pre')[source]
Yield nodes in pre-order or post-order.
- Return type:
- Parameters:
order (str)
- subtree(*path)[source]
Extract sub-hierarchy rooted at the given path.
- Return type:
- Parameters:
path (str)
- aggregate(node=None, method=None, auto_align=False)[source]
Recursive bottom-up aggregation.
- Return type:
TimeSeriesList- Parameters:
node (HierarchyNode | None)
method (AggregationMethod | None)
auto_align (bool)