BuildingInventory#
cheersafe.inventory.BuildingInventory loads a building-geometry JSON file and
creates one Building object per building-type column.
Purpose And When To Use#
Use BuildingInventory for normal CHEERSafe workflows. Damage probability,
damage ratio, and loss workflows expect an inventory object whose buildings
attribute is a list of Building instances.
Inputs#
| Input | Default | Unit, indexing, or file dependency |
|---|---|---|
buildings_file_name |
"BuildingGeometry_Old.json" |
File name under Config.INPUTS_PATH. The JSON must be a 2D list with shape [28, n_buildings]; rows follow the Building constructor order and columns are 1-based archetype IDs in the input data. |
The default runtime path is Inputs/BuildingGeometry_Old.json.
BuildingGeometry.json is the newer table with the same shape and schema, but
the default loader still uses the old file unless you pass
buildings_file_name="BuildingGeometry.json".
Outputs And Returns#
When the inventory is loaded, buildings is a list of Building objects. The
bundled geometry files create 8 buildings.
instantiate_buildings_from_json() reads the JSON file, assigns
self.buildings, and currently returns None.
AUTO_LOAD_DATASETS Behavior#
With AUTO_LOAD_DATASETS = True, BuildingInventory(...) immediately calls
instantiate_buildings_from_json().
With AUTO_LOAD_DATASETS = False, initialization does not create buildings.
Call instantiate_buildings_from_json() manually when you are ready to load the
file.
AUTO_EXECUTE_METHODS Behavior#
BuildingInventory itself does not calculate geometry outputs. The flag is
passed through indirectly because loading the inventory constructs Building
objects. If AUTO_EXECUTE_METHODS = True, each loaded building has panel and RWC
outputs. If it is False, the buildings are loaded but their calculation
outputs must be requested manually from each building.
Minimal Automatic Example#
PYTHONPATH=src python3 - <<'PY'
from cheersafe.config import Config
from cheersafe.inventory import BuildingInventory
Config.reset_flags()
Config.INPUTS_PATH = "Inputs"
inventory = BuildingInventory()
first = inventory.buildings[0]
print(len(inventory.buildings))
print(first.BldgType, first.PanelCoordinate.shape)
Config.reset_flags()
PY
Minimal Manual-Control Example#
PYTHONPATH=src python3 - <<'PY'
from cheersafe.config import Config
from cheersafe.inventory import BuildingInventory
Config.reset_flags()
Config.AUTO_LOAD_DATASETS = False
Config.AUTO_EXECUTE_METHODS = False
inventory = BuildingInventory(buildings_file_name="BuildingGeometry_Old.json")
print(hasattr(inventory, "buildings"))
inventory.instantiate_buildings_from_json()
building = inventory.buildings[0]
panel_coordinate, num_panel = building.fn_panel_coordinate()
print(len(inventory.buildings))
print(panel_coordinate.shape, num_panel.tolist())
Config.reset_flags()
PY
Related Links#
- API reference: Inventory
- Input file manual: Building Geometry
- Planned notebook: Inventory building geometry