Skip to content

Commit 662bdb5

Browse files
v4.5.14.4 fixed bug in aggregate_by_huc.py (#1404)
1 parent 5be6514 commit 662bdb5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
All notable changes to this project will be documented in this file.
22
We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.
33

4+
## v4.5.14.4 - 2025-01-31 - [PR#1404]https://github.com/NOAA-OWP/inundation-mapping/pull/1404
5+
6+
This PR resolves warnings when running aggregate_by_huc.py with the bridge_flag option. The warnings happened because the GeoPandas read_file method does not support a dtype argument when reading GeoPackages. This PR also, modifies aggregate_by_huc.py to set the CRS for osm_bridge_points.gpkg. It will only set the CRS if the file does not already have a CRS defined.
7+
8+
### Changes
9+
10+
- `src/aggregate_by_huc.py`: Apply specific data types after reading the file and set a CRS for osm_bridge_points.gpkg.
11+
12+
<br/><br/>
13+
14+
415
## v4.5.14.3 - 2025-01-31 - [PR#1413](https://github.com/NOAA-OWP/inundation-mapping/pull/1413)
516

617
Implements a denylist for flow-based CatFIM (that uses the same conventions as the existing denylist functionality used in stage-based CatFIM. Adds CMUG1 to the denylist for flow-based CatFIM.

src/aggregate_by_huc.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111

1212
import geopandas as gpd
1313
import pandas as pd
14+
from dotenv import load_dotenv
1415

1516
from heal_bridges_osm import flows_from_hydrotable
1617
from utils.shared_functions import progress_bar_handler
1718

1819

20+
load_dotenv('/foss_fim/src/bash_variables.env')
21+
DEFAULT_FIM_PROJECTION_CRS = os.getenv('DEFAULT_FIM_PROJECTION_CRS')
22+
ALASKA_CRS = os.getenv('ALASKA_CRS')
23+
24+
1925
class HucDirectory(object):
2026
def __init__(self, fim_directory, huc_id, limit_branches=[]):
2127
self.fim_directory = fim_directory
@@ -205,7 +211,9 @@ def aggregate_bridge_pnts(self, branch_path, branch_id):
205211
if not os.path.isfile(bridge_filename):
206212
return
207213

208-
bridge_pnts = gpd.read_file(bridge_filename, dtype=self.bridge_dtypes)
214+
bridge_pnts = gpd.read_file(bridge_filename)
215+
for col, dtype in self.bridge_dtypes.items():
216+
bridge_pnts[col] = bridge_pnts[col].astype(dtype)
209217
if bridge_pnts.empty:
210218
return
211219
hydrotable_filename = join(branch_path, f'hydroTable_{branch_id}.csv')
@@ -289,6 +297,15 @@ def agg_function(
289297
] = 1
290298
# Write file
291299
bridge_pnts = bridge_pnts.astype(self.bridge_dtypes, errors='ignore')
300+
301+
# Set the CRS if it is not already set
302+
huc2Identifier = huc_id[:2]
303+
if bridge_pnts.crs is None:
304+
# Alaska
305+
if huc2Identifier == '19':
306+
bridge_pnts.set_crs(ALASKA_CRS, inplace=True)
307+
else:
308+
bridge_pnts.set_crs(DEFAULT_FIM_PROJECTION_CRS, inplace=True)
292309
bridge_pnts.to_file(bridge_pnts_file, index=False, engine='fiona')
293310

294311
# print(f"agg_by_huc for huc id {huc_id} is done")

0 commit comments

Comments
 (0)