Baseο
- class emflow.assets.base.Asset(*, id: ~uuid.UUID = <factory>, name: str | None = None, timeseries: list[~timedatamodel.timeseries.TimeSeries] = <factory>, geometry: ~shapely.geometry.base.BaseGeometry | None = None, extra: dict = <factory>, lat: dataclasses.InitVar[float | None] = None, lon: dataclasses.InitVar[float | None] = None, commissioning_date: ~datetime.date | None = None)[source]ο
Bases:
ElementMarker mixin for physical energy equipment.
Carries fields genuinely shared across every piece of equipment β independent of whether the equipment is shaped like a graph vertex (
WindTurbine) or a graph edge (Line).- commissioning_date: date | None = Noneο
- add_child(obj) Noneο
Attach a child. Override in subclasses that support children.
- property centroid: Point | Noneο
Centroid of
geometry, orNoneif no geometry.
- children() listο
Child elements for tree walking. Override in subclasses with children.
- geometry: BaseGeometry | None = Noneο
- geometry_to_geojson(geometry)ο
- index()ο
Build a
dict[UUID, Element]index of the subtree rooted at self.Use to resolve
Referenceobjects against this tree.
- lat: InitVar[float | None] = Noneο
- property latitude: float | Noneο
Latitude, if
geometryis a shapelyPoint; elseNone.
- lon: InitVar[float | None] = Noneο
- property longitude: float | Noneο
Longitude, if
geometryis a shapelyPoint; elseNone.
- name: str | None = Noneο
- to_dataframe()ο
- to_geojson(exclude_none: bool = True)ο
- to_json(*, exclude_fields: set | None = None) dictο
Serialize to a JSON-compatible dict.
- to_properties() dictο
Domain-specific fields as a dict (excludes infra + children fields).
- to_tree() strο
Return the hierarchy rendered as an indented tree string.
Use
print(element.to_tree())to display it. In a notebook, printing the element directly (element) also renders the tree via__repr__.
- id: UUIDο
- timeseries: list[TimeSeries]ο
- extra: dictο
- class emflow.assets.base.TimeSeries(df: DataFrame | None = None, *, name: str, description: str | None = None, unit: str = 'dimensionless', timezone: str = 'UTC', frequency: Frequency | None = None, data_type: DataType | None = None, timeseries_type: TimeSeriesType = TimeSeriesType.FLAT)[source]ο
Bases:
_TimeSeriesReprMixinPolars-backed container for time series data with rich metadata.
The underlying
dfis optional. Construct withdf=Noneto declare a series structure (name, unit, data type, β¦) before any data exists β useful for registering series in a catalog. Methods that need data (converters,head/tail,convert_unit, β¦) raiseValueErrorwhen no df is attached. Usehas_dfto check.Parametersο
- df:
A
polars.DataFramewhose columns conform to one of the recognisedDataShapepatterns, orNonefor a metadata-only instance. All timestamp columns must usepl.Datetime("us", time_zone="UTC").- name:
Series name (e.g.
"wind_power","electricity.supply").- description:
Human-readable description.
- unit:
Canonical physical unit string (e.g.
"MW","dimensionless").- timezone:
IANA timezone string for display purposes. Internal data is always UTC; this is a metadata hint only.
- frequency:
Pandas offset alias describing the expected data cadence.
- data_type:
Semantic nature of the observations (
DataType).- timeseries_type:
Storage/versioning model (
TimeSeriesType).
- property shape: DataShape | Noneο
Which temporal columns are present (inferred from the DataFrame).
Nonefor metadata-only instances.
- property num_rows: intο
Number of data rows.
0for metadata-only instances.
- property columns: list[str]ο
Column names present in the underlying Polars DataFrame.
Empty list for metadata-only instances.
- property df: DataFrame | Noneο
The underlying
polars.DataFrame(read-only by convention).Nonefor metadata-only instances.
- property has_df: boolο
True when a DataFrame is attached.
- property has_missing: boolο
True if the
valuecolumn contains any null values.Falsefor metadata-only instances.
- classmethod from_polars(df: DataFrame, *, name: str, description: str | None = None, unit: str = 'dimensionless', timezone: str = 'UTC', frequency: Frequency | None = None, data_type: DataType | None = None, timeseries_type: TimeSeriesType = TimeSeriesType.FLAT) TimeSeries[source]ο
Create a
TimeSeriesdirectly from apolars.DataFrame.All timestamp columns must already use
pl.Datetime("us", time_zone="UTC").
- classmethod from_list(data: dict[str, list], *, name: str, description: str | None = None, unit: str = 'dimensionless', timezone: str = 'UTC', frequency: Frequency | None = None, data_type: DataType | None = None, timeseries_type: TimeSeriesType = TimeSeriesType.FLAT) TimeSeries[source]ο
Create a
TimeSeriesfrom a column-oriented dict of lists.Accepts the format returned by
to_list(). Timestamp columns are normalised to UTC automatically.
- classmethod from_numpy(data: dict[str, np.ndarray], *, name: str, description: str | None = None, unit: str = 'dimensionless', timezone: str = 'UTC', frequency: Frequency | None = None, data_type: DataType | None = None, timeseries_type: TimeSeriesType = TimeSeriesType.FLAT) TimeSeries[source]ο
Create a
TimeSeriesfrom a column-oriented dict of NumPy arrays.Accepts the format returned by
to_numpy(). Timestamp columns (numpy.datetime64, always timezone-naive) are localised to UTC.Requires
numpy.
- classmethod from_pyarrow(table: pa.Table, *, name: str, description: str | None = None, unit: str = 'dimensionless', timezone: str = 'UTC', frequency: Frequency | None = None, data_type: DataType | None = None, timeseries_type: TimeSeriesType = TimeSeriesType.FLAT) TimeSeries[source]ο
Create a
TimeSeriesfrom a PyArrow Table.Accepts the format returned by
to_pyarrow(). Arrowtimestamp[us, UTC]columns are converted automatically.Requires
pyarrow.
- classmethod from_pandas(df: DataFrame, *, name: str, description: str | None = None, unit: str = 'dimensionless', timezone: str = 'UTC', frequency: Frequency | None = None, data_type: DataType | None = None, timeseries_type: TimeSeriesType = TimeSeriesType.FLAT) TimeSeries[source]ο
Create a
TimeSeriesfrom apandas.DataFrame.Only
SIMPLEandVERSIONEDshapes can be constructed viafrom_pandas.AUDITandCORRECTEDshapes (which require achange_timecolumn) are read-only results from the database layer.The data shape is inferred from the column names (and MultiIndex levels if the DataFrame uses an index).
Raisesο
- ValueError
If the DataFrame contains a
change_timecolumn.
- validate_for_insert() tuple[DataFrame, DataShape][source]ο
Validate that this TimeSeries can be inserted and return the underlying DataFrame with its shape.
Only
DataShape.SIMPLEandDataShape.VERSIONEDare supported for insert.Returnsο
Tuple[pl.DataFrame, DataShape]
Raisesο
- ValueError
If
shapeisDataShape.AUDITorDataShape.CORRECTED.
- to_pandas() DataFrame[source]ο
Convert to a
pandas.DataFrame.Restores the conventional index:
SIMPLEβvalid_timeas index.VERSIONEDβ(knowledge_time, valid_time)MultiIndex.AUDITβ(knowledge_time, change_time, valid_time)MultiIndex.CORRECTEDβ(valid_time, change_time)MultiIndex.
- to_list() dict[source]ο
Return the series as a column-oriented dict of lists.
Each key is a column name; each value is a Python list of that columnβs values. Timestamps are Python
datetimeobjects; null values areNone.Example:
{"valid_time": [datetime(...), ...], "value": [1.0, None, 3.0, ...]}
- to_numpy() dict[str, np.ndarray][source]ο
Return the series as a dictionary of NumPy arrays.
Each column maps to a 1-D
numpy.ndarray. Timestamp columns becomenumpy.datetime64[us]values; null values becomeNaNorNaT.Requires
numpy. Install with:pip install numpy.
- to_pyarrow() pa.Table[source]ο
Return the series as a
pyarrow.Table.All timestamp columns are Arrow
timestamp[us, UTC].Requires
pyarrow. Install with:pip install pyarrow.
- coverage_bar() CoverageBar[source]ο
Return a
CoverageBarshowing value coverage.True= value present,False= null/missing. In Jupyter the coverage bar renders as an SVG.
- head(n: int = 5) TimeSeries[source]ο
Return the first n rows as a new
TimeSeries.
- tail(n: int = 5) TimeSeries[source]ο
Return the last n rows as a new
TimeSeries.
- convert_unit(target_unit: str) TimeSeries[source]ο
Return a new
TimeSerieswith values converted to target_unit.Uses the pint library for unit conversion. The
unitmetadata field is updated to target_unit.Parametersο
- target_unit:
Target unit string understood by pint (e.g.
"km/h","kW").
Raisesο
- ImportError
If pint is not installed.
- pint.DimensionalityError
If the current unit and target_unit are dimensionally incompatible.
- class emflow.assets.base.Sensor(*, id: ~uuid.UUID = <factory>, name: str | None = None, timeseries: list[~timedatamodel.timeseries.TimeSeries] = <factory>, geometry: ~shapely.geometry.base.BaseGeometry | None = None, extra: dict = <factory>, lat: dataclasses.InitVar[float | None] = None, lon: dataclasses.InitVar[float | None] = None, commissioning_date: ~datetime.date | None = None, members: list[~energydatamodel.element.Element] = <factory>, tz: ~datetime.tzinfo | None = None, height: float | None = None)[source]ο
Bases:
NodeAssetA measurement instrument that observes an environmental variable.
Concrete sensor subclasses (
TemperatureSensor,WindSpeedSensor, β¦) inheritheightfrom here and add no new fields.- height: float | None = Noneο
- property centroid: Point | Noneο
Centroid of
geometry, orNoneif no geometry.
- children() listο
Child elements for tree walking. Override in subclasses with children.
- commissioning_date: date | None = Noneο
- geometry: BaseGeometry | None = Noneο
- geometry_to_geojson(geometry)ο
- index()ο
Build a
dict[UUID, Element]index of the subtree rooted at self.Use to resolve
Referenceobjects against this tree.
- lat: InitVar[float | None] = Noneο
- property latitude: float | Noneο
Latitude, if
geometryis a shapelyPoint; elseNone.
- lon: InitVar[float | None] = Noneο
- property longitude: float | Noneο
Longitude, if
geometryis a shapelyPoint; elseNone.
- name: str | None = Noneο
- to_dataframe()ο
- to_geojson(exclude_none: bool = True)ο
- to_json(*, exclude_fields: set | None = None) dictο
Serialize to a JSON-compatible dict.
- to_properties() dictο
Domain-specific fields as a dict (excludes infra + children fields).
- to_tree() strο
Return the hierarchy rendered as an indented tree string.
Use
print(element.to_tree())to display it. In a notebook, printing the element directly (element) also renders the tree via__repr__.
- tz: datetime.tzinfo | None = Noneο
- members: list[Element]ο
- id: UUIDο
- timeseries: list[TimeSeries]ο
- extra: dictο
- class emflow.assets.base.Collection(*, id: ~uuid.UUID = <factory>, name: str | None = None, timeseries: list[~timedatamodel.timeseries.TimeSeries] = <factory>, geometry: ~shapely.geometry.base.BaseGeometry | None = None, extra: dict = <factory>, lat: dataclasses.InitVar[float | None] = None, lon: dataclasses.InitVar[float | None] = None, members: list[~energydatamodel.element.Element] = <factory>, tz: ~datetime.tzinfo | None = None)[source]ο
Bases:
ElementAn Element whose primary purpose is grouping other Elements.
Not a
Nodeβ collections are organizational groupings, not graph vertices. Carriesmembersandtz(same shape as Node, different semantics).- tz: tzinfo | None = Noneο
- add_child(obj: Element) None[source]ο
Attach a child. Override in subclasses that support children.
- property centroid: Point | Noneο
Centroid of
geometry, orNoneif no geometry.
- geometry: BaseGeometry | None = Noneο
- geometry_to_geojson(geometry)ο
- index()ο
Build a
dict[UUID, Element]index of the subtree rooted at self.Use to resolve
Referenceobjects against this tree.
- lat: InitVar[float | None] = Noneο
- property latitude: float | Noneο
Latitude, if
geometryis a shapelyPoint; elseNone.
- lon: InitVar[float | None] = Noneο
- property longitude: float | Noneο
Longitude, if
geometryis a shapelyPoint; elseNone.
- name: str | None = Noneο
- to_dataframe()ο
- to_geojson(exclude_none: bool = True)ο
- to_json(*, exclude_fields: set | None = None) dictο
Serialize to a JSON-compatible dict.
- to_properties() dictο
Domain-specific fields as a dict (excludes infra + children fields).
- to_tree() strο
Return the hierarchy rendered as an indented tree string.
Use
print(element.to_tree())to display it. In a notebook, printing the element directly (element) also renders the tree via__repr__.
- id: UUIDο
- timeseries: list[TimeSeries]ο
- extra: dictο