Skip to content

Commit

Permalink
v4.5.14.4 fixed bug in aggregate_by_huc.py (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZahraGhahremani authored Jan 31, 2025
1 parent 5be6514 commit 662bdb5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
All notable changes to this project will be documented in this file.
We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.

## v4.5.14.4 - 2025-01-31 - [PR#1404]https://github.com/NOAA-OWP/inundation-mapping/pull/1404

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.

### Changes

- `src/aggregate_by_huc.py`: Apply specific data types after reading the file and set a CRS for osm_bridge_points.gpkg.

<br/><br/>


## v4.5.14.3 - 2025-01-31 - [PR#1413](https://github.com/NOAA-OWP/inundation-mapping/pull/1413)

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.
Expand Down
19 changes: 18 additions & 1 deletion src/aggregate_by_huc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@

import geopandas as gpd
import pandas as pd
from dotenv import load_dotenv

from heal_bridges_osm import flows_from_hydrotable
from utils.shared_functions import progress_bar_handler


load_dotenv('/foss_fim/src/bash_variables.env')
DEFAULT_FIM_PROJECTION_CRS = os.getenv('DEFAULT_FIM_PROJECTION_CRS')
ALASKA_CRS = os.getenv('ALASKA_CRS')


class HucDirectory(object):
def __init__(self, fim_directory, huc_id, limit_branches=[]):
self.fim_directory = fim_directory
Expand Down Expand Up @@ -205,7 +211,9 @@ def aggregate_bridge_pnts(self, branch_path, branch_id):
if not os.path.isfile(bridge_filename):
return

bridge_pnts = gpd.read_file(bridge_filename, dtype=self.bridge_dtypes)
bridge_pnts = gpd.read_file(bridge_filename)
for col, dtype in self.bridge_dtypes.items():
bridge_pnts[col] = bridge_pnts[col].astype(dtype)
if bridge_pnts.empty:
return
hydrotable_filename = join(branch_path, f'hydroTable_{branch_id}.csv')
Expand Down Expand Up @@ -289,6 +297,15 @@ def agg_function(
] = 1
# Write file
bridge_pnts = bridge_pnts.astype(self.bridge_dtypes, errors='ignore')

# Set the CRS if it is not already set
huc2Identifier = huc_id[:2]
if bridge_pnts.crs is None:
# Alaska
if huc2Identifier == '19':
bridge_pnts.set_crs(ALASKA_CRS, inplace=True)
else:
bridge_pnts.set_crs(DEFAULT_FIM_PROJECTION_CRS, inplace=True)
bridge_pnts.to_file(bridge_pnts_file, index=False, engine='fiona')

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

0 comments on commit 662bdb5

Please sign in to comment.