Skip to content

Commit 6307def

Browse files
authored
Merge pull request #103 from bacetiner/master
Updates for Python 3.7+ compatibility
2 parents c7d15f5 + f824dd4 commit 6307def

21 files changed

Lines changed: 1449 additions & 1093 deletions

CITATION.cff

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ authors:
1010
orcid: 'https://orcid.org/0000-0002-9726-8120'
1111
- given-names: Frank
1212
family-names: McKenna
13+
- given-names: Sang-ri
14+
family-names: Yi
15+
orcid: 'https://orcid.org/0000-0001-7196-127X'
16+
- given-names: Brian
17+
family-names: Wang
1318
- given-names: Ioannis Vouvakis
1419
family-names: Manousakis
1520
orcid: 'https://orcid.org/0009-0009-6143-6741'
@@ -25,5 +30,5 @@ keywords:
2530
- computer vision
2631
- natural hazards engineering
2732
license: BSD-3-Clause
28-
version: 4.0.0
29-
date-released: '2024-09-30'
33+
version: 4.1.0
34+
date-released: '2025-06-06'

brails/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# Package metadata:
4747
name = 'brails'
48-
__version__ = '4.0'
48+
__version__ = '4.1.0'
4949
__copyright__ = 'Copyright (c) 2024' \
5050
'The Regents of the University of California'
5151
__license__ = 'BSD 3-Clause License'

brails/scrapers/asce_hazard_data_scraper/asce_hazard_data_scraper.py

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# Barbaros Cetiner
3636
#
3737
# Last updated:
38-
# 02-27-2025
38+
# 06-06-2025
3939

4040
"""
4141
This module defines the class object for downloading ASCE Hazard data.
@@ -45,96 +45,78 @@
4545
ASCE_HAZARD_DATA_SCRAPER
4646
"""
4747

48-
import concurrent.futures
49-
import logging
50-
from tqdm import tqdm
48+
from typing import Dict, Any, TYPE_CHECKING
5149
from shapely.geometry import box
50+
from brails.utils.api import ArcgisAPIServiceHelper
51+
from brails.utils.inventory_validator import InventoryValidator
5252

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
5655

57-
# Configure logging:
58-
logging.basicConfig(level=logging.INFO)
59-
logger = logging.getLogger(__name__)
6056

6157
API_ENDPOINT = ('https://gis.asce.org/arcgis/rest/services/ASCE722/'
6258
'w2022_Tile_RC_I/MapServer/2/query')
6359

6460

65-
class ASCE_HAZARD_DATA_SCRAPER():
61+
class ASCE_HAZARD_DATA_SCRAPER:
6662
"""
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.
7364
7465
Attributes:
7566
length_unit (str):
76-
Unit of length for building heights (default is 'ft').
67+
Unit of length for building attributes (default is 'ft').
7768
7869
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.
8272
"""
8373

84-
def __init__(self, input_dict: dict):
74+
def __init__(self, input_dict: Dict[str, Any]):
8575
"""
86-
Initialize the class object.
76+
Initialize the ASCE_HAZARD_DATA_SCRAPER instance.
8777
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'.
9283
"""
9384
self.length_unit = input_dict.get('length', 'ft')
9485

95-
def get_windspeeds(self, inventory: AssetInventory()) -> AssetInventory:
86+
def get_windspeeds(self, inventory: "AssetInventory") -> "AssetInventory":
9687
"""
97-
Retrieve building footprints and attributes for a specified region.
88+
Retrieve wind speed data for each asset in the inventory and attach it.
9889
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.
10393
10494
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.
10897
10998
Returns:
11099
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.
113101
114102
Raises:
115103
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.
127106
"""
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'.")
131111

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
135113
bpoly = box(-118.5534678, 33.9666583, 34.0505825, -118.4435336)
136114

137-
# Get the number of elements allowed per cell by the API:
115+
# Get the number of elements allowed per cell by the API
138116
api_tools = ArcgisAPIServiceHelper(API_ENDPOINT)
139117

140118
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

brails/scrapers/boundary/__init__.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

brails/scrapers/boundary/boundary_location.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)