Skip to content

Asset

Assets are a subset of Nodes. They correspond to physical plants and equipment like different types of power stations and steelworks.

To access data for assets, you can use this Jupyter Notebook on Github.

Bases: NodeBase

Source code in tz/client/asset.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Asset(schemas.NodeBase):
    _source_objects: List[ForwardRef("Source")] | None = None  # type: ignore[valid-type] # noqa

    @classmethod
    def from_id(cls, id: str):
        """Initialise Asset from `id` as a positional argument"""
        node = api.assets.get(ids=id)[0]
        return cls(**node.model_dump())

    @classmethod
    def search(
        cls,
        alias: str,
        threshold: float = 0.5,
        node_type: str | None = None,
        sector: str | None = None,
        limit: int = 10,
        page: int = 0,
    ) -> list["schemas.Node"]:
        """
        Search for nodes using an alias.

        Args:
            alias (str): The target alias to search.
            threshold (float): The desired confidence in the search result.
            node_type (str): filter search to a specific node type.
            sector (str): the industrial sector to filter assets for
            limit (int): The maximum number of search results to return per page.
            page (int): The page number of search results to return.

        Returns:
            list[schemas.Node]: A list of Node objects.
        """

        search_results = api.aliases.get(
            alias=alias,
            threshold=threshold,
            node_type=node_type,
            sector=sector,
            includes="power_unit",
            limit=limit,
            page=page,
        )

        return [
            cls(**alias.node.model_dump())  # type: ignore[union-attr, misc]
            for alias in search_results.aliases
        ]

    @property
    def sources(self):
        if self._source_objects is None:
            asset = api.assets.get(ids=self.id, includes="sources")[0]
            self._source_objects = [Source(**source.model_dump()) for source in asset.base_sources]
        return self._source_objects

    def __str__(self) -> str:
        return f"Asset: {self.name_primary_en} (id={self.id})"

from_id(id) classmethod

Initialise Asset from id as a positional argument

Source code in tz/client/asset.py
13
14
15
16
17
@classmethod
def from_id(cls, id: str):
    """Initialise Asset from `id` as a positional argument"""
    node = api.assets.get(ids=id)[0]
    return cls(**node.model_dump())

search(alias, threshold=0.5, node_type=None, sector=None, limit=10, page=0) classmethod

Search for nodes using an alias.

Parameters:

Name Type Description Default
alias str

The target alias to search.

required
threshold float

The desired confidence in the search result.

0.5
node_type str

filter search to a specific node type.

None
sector str

the industrial sector to filter assets for

None
limit int

The maximum number of search results to return per page.

10
page int

The page number of search results to return.

0

Returns:

Type Description
list[Node]

list[schemas.Node]: A list of Node objects.

Source code in tz/client/asset.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@classmethod
def search(
    cls,
    alias: str,
    threshold: float = 0.5,
    node_type: str | None = None,
    sector: str | None = None,
    limit: int = 10,
    page: int = 0,
) -> list["schemas.Node"]:
    """
    Search for nodes using an alias.

    Args:
        alias (str): The target alias to search.
        threshold (float): The desired confidence in the search result.
        node_type (str): filter search to a specific node type.
        sector (str): the industrial sector to filter assets for
        limit (int): The maximum number of search results to return per page.
        page (int): The page number of search results to return.

    Returns:
        list[schemas.Node]: A list of Node objects.
    """

    search_results = api.aliases.get(
        alias=alias,
        threshold=threshold,
        node_type=node_type,
        sector=sector,
        includes="power_unit",
        limit=limit,
        page=page,
    )

    return [
        cls(**alias.node.model_dump())  # type: ignore[union-attr, misc]
        for alias in search_results.aliases
    ]