|
35 | 35 | # Barbaros Cetiner |
36 | 36 | # |
37 | 37 | # Last updated: |
38 | | -# 02-27-2025 |
| 38 | +# 06-06-2025 |
39 | 39 |
|
40 | 40 | """ |
41 | 41 | This module defines the class object for downloading ASCE Hazard data. |
|
45 | 45 | ASCE_HAZARD_DATA_SCRAPER |
46 | 46 | """ |
47 | 47 |
|
48 | | -import concurrent.futures |
49 | | -import logging |
50 | | -from tqdm import tqdm |
| 48 | +from typing import Dict, Any, TYPE_CHECKING |
51 | 49 | from shapely.geometry import box |
| 50 | +from brails.utils.api import ArcgisAPIServiceHelper |
| 51 | +from brails.utils.inventory_validator import InventoryValidator |
52 | 52 |
|
53 | | -from brails.types.asset_inventory import AssetInventory |
54 | | -from brails.utils import GeoTools |
55 | | -from brails.utils import ArcgisAPIServiceHelper |
| 53 | +if TYPE_CHECKING: |
| 54 | + from brails.types.asset_inventory import AssetInventory |
56 | 55 |
|
57 | | -# Configure logging: |
58 | | -logging.basicConfig(level=logging.INFO) |
59 | | -logger = logging.getLogger(__name__) |
60 | 56 |
|
61 | 57 | API_ENDPOINT = ('https://gis.asce.org/arcgis/rest/services/ASCE722/' |
62 | 58 | 'w2022_Tile_RC_I/MapServer/2/query') |
63 | 59 |
|
64 | 60 |
|
65 | | -class ASCE_HAZARD_DATA_SCRAPER(): |
| 61 | +class ASCE_HAZARD_DATA_SCRAPER: |
66 | 62 | """ |
67 | | - A class to generate footprint data using FEMA USA Structures building data. |
68 | | -
|
69 | | - This class interacts with the FEMA USA Structures API to download |
70 | | - building footprints, attributes (such as height), and additional metadata |
71 | | - for a given geographic region. The class is built on top of the |
72 | | - `FootprintScraper` class. |
| 63 | + A class to retrieve wind speed hazard data. |
73 | 64 |
|
74 | 65 | Attributes: |
75 | 66 | length_unit (str): |
76 | | - Unit of length for building heights (default is 'ft'). |
| 67 | + Unit of length for building attributes (default is 'ft'). |
77 | 68 |
|
78 | 69 | Methods: |
79 | | - get_footprints(region: RegionBoundary): |
80 | | - Obtains building footprints and creates an inventory for the |
81 | | - specified region. |
| 70 | + get_windspeeds(inventory): |
| 71 | + Retrieves wind speed data and attaches it to the asset inventory. |
82 | 72 | """ |
83 | 73 |
|
84 | | - def __init__(self, input_dict: dict): |
| 74 | + def __init__(self, input_dict: Dict[str, Any]): |
85 | 75 | """ |
86 | | - Initialize the class object. |
| 76 | + Initialize the ASCE_HAZARD_DATA_SCRAPER instance. |
87 | 77 |
|
88 | | - Args |
89 | | - input_dict: |
90 | | - A dictionary specifying length units; if "length" is not |
91 | | - provided, "ft" is used as the default. |
| 78 | + Args: |
| 79 | + input_dict (dict): |
| 80 | + A dictionary specifying configuration parameters. If the key |
| 81 | + 'length' is present, it defines the unit of length (e.g., 'ft', |
| 82 | + 'm'). Defaults to 'ft'. |
92 | 83 | """ |
93 | 84 | self.length_unit = input_dict.get('length', 'ft') |
94 | 85 |
|
95 | | - def get_windspeeds(self, inventory: AssetInventory()) -> AssetInventory: |
| 86 | + def get_windspeeds(self, inventory: "AssetInventory") -> "AssetInventory": |
96 | 87 | """ |
97 | | - Retrieve building footprints and attributes for a specified region. |
| 88 | + Retrieve wind speed data for each asset in the inventory and attach it. |
98 | 89 |
|
99 | | - This method divides the provided region into smaller cells, if |
100 | | - necessary, and then downloads building footprint data for each cell |
101 | | - using the FEMA USA Structures API. The footprints and attributes are |
102 | | - returned as an AssetInventory for buildings within the region. |
| 90 | + This method downloads wind speed data using the ArcGIS API for a |
| 91 | + bounding polygon (currently hardcoded) and is intended to associate |
| 92 | + hazard attributes with assets. |
103 | 93 |
|
104 | 94 | Args: |
105 | | - region (RegionBoundary): |
106 | | - The geographic region for which building footprints and |
107 | | - attributes are to be obtained. |
| 95 | + inventory (AssetInventory): |
| 96 | + The asset inventory containing building locations. |
108 | 97 |
|
109 | 98 | Returns: |
110 | 99 | AssetInventory: |
111 | | - An inventory of buildings in the region, including their |
112 | | - footprints and associated attributes (e.g., height). |
| 100 | + Updated inventory with appended wind speed attributes. |
113 | 101 |
|
114 | 102 | Raises: |
115 | 103 | TypeError: |
116 | | - If the 'region' argument is not an instance of the BRAILS++ |
117 | | - 'RegionBoundary' class. |
118 | | -
|
119 | | - Notes: |
120 | | - - The region is split into smaller cells if the bounding area |
121 | | - contains more than the maximum allowed number of elements per |
122 | | - cell. |
123 | | - - If the `plot_cells` flag is set to `True`, the cell boundaries |
124 | | - are plotted and saved as an image. |
125 | | - - The method creates a polygon mesh for the region, splits it if |
126 | | - needed, and downloads building data for each cell in the region. |
| 104 | + If the 'inventory' argument is not an instance of |
| 105 | + AssetInventory. |
127 | 106 | """ |
128 | | - if not isinstance(inventory, AssetInventory()): |
129 | | - raise TypeError("The 'inventory' argument must be an " |
130 | | - "'AssetInventory'") |
| 107 | + if not InventoryValidator.is_inventory(inventory): |
| 108 | + raise TypeError( |
| 109 | + "The 'inventory' argument must be an instance of " |
| 110 | + "'AssetInventory'.") |
131 | 111 |
|
132 | | - # Define a random bounding polygon. This specific API returns the same |
133 | | - # output irrespective of the input geometry, yet does not allow |
134 | | - # omitting the geometry argument: |
| 112 | + # Define a hardcoded bounding polygon |
135 | 113 | bpoly = box(-118.5534678, 33.9666583, 34.0505825, -118.4435336) |
136 | 114 |
|
137 | | - # Get the number of elements allowed per cell by the API: |
| 115 | + # Get the number of elements allowed per cell by the API |
138 | 116 | api_tools = ArcgisAPIServiceHelper(API_ENDPOINT) |
139 | 117 |
|
140 | 118 | datalist = api_tools.download_attr_from_api(bpoly, 'all') |
| 119 | + |
| 120 | + # TO-DO: Implement data post-processing to match to inventory |
| 121 | + |
| 122 | + return datalist |
0 commit comments