Skip to content

DataAccessor

Bases: BaseModel

Access data from a versioned data source.

This class provides a standardized interface to locate and load technology datasets from predefined data sources. It can either load a specific version or automatically determine and load the latest available version.

Attributes:

  • data_source (str) –

    The name of the data source to access, as defined in the DataSourceName enumeration.

  • version ((str, optional)) –

    The specific version string of the data to load (e.g., "v1.0.0"). If not provided, the latest version will be automatically determined and used. Default is None.

Methods:

  • get_latest_version_string

    Find the latest version string for the data source.

  • load

    Load the default 'technologies.json' from the package data.

  • parse

    Run the parser for the specified data source and version.

data_source instance-attribute

data_source: Annotated[str, Field(description='The name of the data source.')]

version class-attribute instance-attribute

version: Annotated[str | None, Field(description='The version of the data source.')] = None

get_latest_version_string staticmethod

get_latest_version_string(data_source_path_list: list[Path]) -> str

Find the latest version string for the data source.

Returns:

  • str

    The string of the latest version (e.g., 'v10', 'v1.0.0').

Raises:

  • FileNotFoundError

    If the data source directory or valid version directories are not found.

load

load() -> DataPackage

Load the default 'technologies.json' from the package data.

Returns:

  • DataPackage

    An instance of DataPackage initialized with the requested data.

Raises:

  • FileNotFoundError

    If the data source directory or the specified version directory is not found.

  • ValueError

    If the specified version is not found. The user is notified of the latest available version.

parse

parse(input_file_name: str, num_digits: int = 4, archive_source: bool = False, filter_params: bool = False, export_schema: bool = False) -> None

Run the parser for the specified data source and version.

This method locates the appropriate parser for the given data source and version, and executes it to generate the technology data package.

Parameters:

  • input_file_name (str) –

    The name of the input file in the 'raw' directory.

  • num_digits (int, default: 4 ) –

    Number of significant digits to round the values. Default is 4.

  • archive_source (bool, default: False ) –

    Store the source object on the Wayback Machine. Default is False.

  • filter_params (bool, default: False ) –

    Filter the parameters stored to technologies.json. Default is False.

  • export_schema (bool, default: False ) –

    Export the Source/TechnologyCollection schemas. Default is False.

Raises:

  • ValueError

    If the specified data source or version is not supported.

  • FileNotFoundError

    If the required input data file is not found.