brails.types.asset_inventory module
This module defines classes associated with asset inventories.
A class representing a Asset Inventory. |
|
|
A data structure for an asset that holds it coordinates and features. |
- class brails.types.asset_inventory.Asset(asset_id: str | int, coordinates: list[list[float]], features: dict[str, Any] | None = None)
Bases:
object
A data structure for an asset that holds it coordinates and features.
- Attributes:
asset_id (str|int):: Unique identifier for the asset. coordinates (list[List[float]]): A list of coordinate pairs
[[lon1, lat1], [lon2, lat2], …, [lonN, latN]].
- features (dict[str, any]): A dictionary of features (attributes) for
the asset.
- Methods:
- add_features(additional_features: dict[str, any],
overwrite: bool = True): Update the existing features in the asset.
print_info(): Print the coordinates and features of the asset.
- add_features(additional_features: dict, overwrite: bool = True)
Update the existing features in the asset.
- Args:
- additional_features (dict[str, any]): New features to merge into
the asset’s features.
- overwrite (bool, optional): Whether to overwrite existing features.
Defaults to True.
- print_info()
Print the coordinates and features of the asset.
- class brails.types.asset_inventory.AssetInventory
Bases:
object
A class representing a Asset Inventory.
- Attributes:
inventory (dict): The inventory stored in a dict accessed by asset_id
- Methods:
print_info(): Print the asset inventory. add_asset(asset_id, Asset): Add an asset to the inventory. add_asset_coordinates(asset_id, coordinates): Add an asset to the
inventory with just a list of coordinates.
- add_asset_features(asset_id, features): Append new features to the
asset.
remove_asset(asset_id): Remove an asset to the inventory. get_asset_features(asset_id): Get coordinates of a particular assset. get_asset_coordinates(asset_id): Get features of a particular assset. get_asset_ids(): Return the asset ids as a list. get_random_sample(size, seed): Get subset of the inventory. get_coordinates(): Return a list of footprints. get_geojson(): Return inventory as a geojson dict. write_to_geojson(): Wtite inventory to file in GeoJSON format. Also return inventory as a geojson dict! read_from_csv(file_path, keep_existing, str_type, id_column): Read
inventory dataset from a csv table
- add_asset_features_from_csv(file_path, id_column): Add asset features
from a csv file.
- add_asset(asset_id: str | int, asset: Asset) bool
Add an Asset to the inventory.
- Args:
asset_id (str|int): The unique identifier for the asset. asset (Asset): The asset to be added.
- Returns:
bool: True if the asset was added successfully, False otherwise.
- add_asset_coordinates(asset_id: str | int, coordinates: list[list[float]]) bool
Add an Asset to the inventory by adding its coordinate information.
- Args:
asset_id (str|int): The unique identifier for the asset. coordinates (list[list[float]]): A two-dimensional list
representing the geometry in [[lon1, lat1], [lon2, lat2], …, [lonN, latN]] format.
- Returns:
bool: True if the asset was added successfully, False otherwise.
- add_asset_features(asset_id: str | int, new_features: dict, overwrite=True) bool
Add new asset features to the Asset with the specified ID.
- Args:
asset_id (str|int): The unique identifier for the asset. new_features (dict): A dictionary of features to add to the asset. overwrite (bool): Whether to overwrite existing features with the
same keys. Defaults to True.
- Returns:
- bool: True if features were successfully added, False if the asset
does not exist or the operation fails.
- add_asset_features_from_csv(file_path, id_column) bool
Read inventory data from a CSV file and add it to the inventory.
- Args:
- file_path (str):
The path to the CSV file
- id_column (str):
The name of column that contains id values. If None, new indicies will be assigned
- Returns:
- bool:
True if assets were addded, False otherwise.
- get_asset_coordinates(asset_id: str | int) tuple[bool, list]
Get the coordinates of a particular asset.
- Args:
asset_id (str | int): The unique identifier for the asset.
- Returns:
- tuple[bool, list]]: A tuple where the first element is a boolean
indicating whether the asset was found, and the second element is a list of coordinate pairs in the format [[lon1, lat1], [lon2, lat2], …, [lonN, latN]] if the asset is present. Returns an empty list if the asset is not found.
- get_asset_features(asset_id: str | int) tuple[bool, dict]
Get features of a particular asset.
- Args:
asset_id (str|int): The unique identifier for the asset.
- Returns:
- tuple[bool, Dict]: A tuple where the first element is a boolean
indicating whether the asset was found, and the second element is a dictionary containing the asset’s features if the asset is present. Returns an empty dictionary if the asset is not found.
- get_asset_ids() list[str | int]
Retrieve the IDs of all assets in the inventory.
- Returns:
- list[str | int]: A list of asset IDs, which may be strings or
integers.
- get_coordinates() tuple[list[list[list[float, float]]], list[str | int]]
Get geometry (coordinates) and keys of all assets in the inventory.
- Returns:
- tuple[list[list[list[float, float]]], list[str | int]]: A tuple
containing: - A list of coordinates for each asset, where each coordinate
is represented as a list of [longitude, latitude] pairs.
A list of asset keys corresponding to each Asset.
- get_dataframe(n_possible_worlds=1, features_possible_worlds=[]) bool
Read inventory data from a CSV file and add it to the inventory.
- Args:
- n_possible_worlds (int):
Number of possible worlds
- features_possible_worlds (list of str):
Indicate the features with multiple possible worlds
- Returns:
- bool:
True if assets were addded, False otherwise.
- get_geojson() dict
Generate a GeoJSON representation of the assets in the inventory.
- Returns:
- dict: A dictionary in GeoJSON format containing all assets, with
each asset represented as a feature. Each feature includes the geometry (Point or Polygon) and associated properties.
- get_random_sample(nsamples: int, seed: int | float | str | bytes | bytearray | None = None)
Generate a smaller AssetInventory with a random selection of assets.
- Args:
- nsamples (int): The number of assets to include in the sampled
inventory.
- seed (int | float | str | bytes | bytearray | None): The seed for
the random generator. If None, the seed is set to the sytem default (i.e., the current system time).
- Returns:
- AssetInventory: A new AssetInventory instance containing a random
subset of assets.
- print_info()
Print the asset inventory.
- read_from_csv(file_path, keep_existing, str_type='building', id_column=None) bool
Read inventory data from a CSV file and add it to the inventory.
- Args:
- file_path (str):
The path to the CSV file
- keep_existing (bool):
If False, the inventory will be initialized
- str_type (str):
“building” or “bridge”
- id_column (str):
The name of column that contains id values. If None, new indicies will be assigned
- Returns:
- bool:
True if assets were addded, False otherwise.
- remove_asset(asset_id: str | int) bool
Remove an Asset from the inventory.
- Args:
asset_id (str|int): The unique identifier for the asset.
- Returns:
bool: True if asset was removed, False otherwise.
- write_to_geojson(output_file: str = '') dict
Generate a GeoJSON representation of the assets in the inventory.
- Returns:
- dict: A dictionary in GeoJSON format containing all assets, with
each asset represented as a feature. Each feature includes the geometry (Point or Polygon) and associated properties.