API Docs

profiles

This module contains convenience functions to load static profiles from online sources. Static profiles can be defined using the ESDL URIProfile block that points to a file. These can be read by id in the calculation service, and the files in this module can be used to read them.

For reading and validating csv files, Pandera and Polars are used.

libdots.profiles.get_profile_csv_data(uri: str, params: dict[str, str], model: type[T_PANDERA_MODEL], sort_by: str | list[str] | None = None) DataFrame[T_PANDERA_MODEL][source]

Open a csv file from a uri with a profile that matches the pandera model. :param uri: The uri sent to open_uri() :param params: The params sent to open_uri() :param sort_by: A string of list of strings of columns to sort the file by.

from typing import Annotated

import polars as pl

# due to https://github.com/unionai-oss/pandera/issues/1899
from pandera import Field  # pyright: ignore [reportUnknownVariableType]
from pandera.polars import DataFrameModel
from pandera.typing import Series


from libdots.profiles import get_profile_csv_data


class EnergyPriceProfile(DataFrameModel):
    datetime: Series[Annotated[pl.Datetime, "ns", "UTC"]] = Field(coerce=True)
    price: float = Field(coerce=True)


energy_price_profile = get_profile_csv_data("https://example.com/my_file.csv", {}, EnergyPriceProfile)
libdots.profiles.open_gcs_uri(uri: str) IO[bytes][source]

Open Google Cloud Storage uri’s (starting with gs://)

libdots.profiles.open_http_uri(uri: str) IO[bytes][source]

Open HTTP(S) uri’s

libdots.profiles.open_uri(uri: str, params: dict[str, str]) IO[bytes] | None[source]

Open a file from a supported URI. Optionally the uri can contain python string formatting parameters to parametrize the uri.

Parameters:
  • uri – The uri to read.

  • params – A dictionary containing python string formatting values used in uri.

Currently supported are:

  • gs:// Google Cloud Storage files

  • http(s):// Uses httpx to download the file

types

class libdots.types.CalculationServiceDescription[source]

Bases: TypedDict

calc_service_name: str
esdl_type: str
service_image_url: str
class libdots.types.ModelParametersDescription[source]

Bases: TypedDict

calculation_services: list[CalculationServiceDescription]
esdl_base64string: str
esdl_ids: list[str]
nr_of_time_steps: int
simulation_name: str
start_timestamp: float
time_step_seconds: int
class libdots.types.TimeStepDescription[source]

Bases: TypedDict

start_time_stamp: float
time_step_nr: int