Skip to content

Modules

buildstock_fetch.main.fetch_bldg_ids(state)

Fetch a list of Building ID's

Provided a state, returns a list of building ID's for that state.

Parameters:

Name Type Description Default
state str

The state to fetch building ID's for.

required

Returns:

Type Description
list[BuildingID]

A list of building ID's for the given state.

Source code in buildstock_fetch/main.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def fetch_bldg_ids(state: str) -> list[BuildingID]:
    """Fetch a list of Building ID's

    Provided a state, returns a list of building ID's for that state.

    Args:
        state: The state to fetch building ID's for.

    Returns:
        A list of building ID's for the given state.
    """
    if state == "MA":
        return [
            BuildingID(bldg_id=7),
            BuildingID(bldg_id=8),
            BuildingID(bldg_id=9),
        ]

    else:
        raise NotImplementedError(f"State {state} not supported")

buildstock_fetch.main.fetch_bldg_data(bldg_ids)

Download building data for a given list of building ids

Downloads the data for the given building ids and returns list of paths to the downloaded files.

Parameters:

Name Type Description Default
bldg_ids list[BuildingID]

A list of BuildingID objects to download data for.

required

Returns:

Type Description
list[Path]

A list of paths to the downloaded files.

Source code in buildstock_fetch/main.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def fetch_bldg_data(bldg_ids: list[BuildingID]) -> list[Path]:
    """Download building data for a given list of building ids

    Downloads the data for the given building ids and returns list of paths to the downloaded files.

    Args:
        bldg_ids: A list of BuildingID objects to download data for.

    Returns:
        A list of paths to the downloaded files.
    """
    data_dir = Path(__file__).parent.parent / "data"
    downloaded_paths = []
    os.makedirs(data_dir, exist_ok=True)

    for bldg_id in bldg_ids:
        response = requests.get(bldg_id.get_download_url(), timeout=30)
        response.raise_for_status()

        output_path = data_dir / f"{bldg_id.bldg_id:07}_upgrade{bldg_id.upgrade_id}.zip"
        with open(output_path, "wb") as file:
            file.write(response.content)

        downloaded_paths.append(output_path)
    return downloaded_paths