From 682c15bb6e4706ba673bd7a97199d617655db03b Mon Sep 17 00:00:00 2001 From: MattLuck-NOAA Date: Fri, 2 Feb 2024 09:24:15 -0800 Subject: [PATCH] v4.4.9.2 Add index to aggregated crosswalk table (#1066) --- docs/CHANGELOG.md | 11 +++++++++++ tools/combine_crosswalk_tables.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d367487a5..1c49ad73a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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.4.9.2 - 2024-02-02 - [PR#1066](https://github.com/NOAA-OWP/inundation-mapping/pull/1066) + +Adds an index to the aggregated `crosswalk_table.csv`. The index is a consecutive integer that starts at 1. Columns have been reordered, renamed, and sorted. + +### Changes + +`tools/combine_crosswalk_tables.py`: Adds index and sorts and renames columns + +

+ ## v4.4.9.1 - 2024-02-02 - [PR#1073](https://github.com/NOAA-OWP/inundation-mapping/pull/1073) Dependabot requested two fixes. One for an upgrade to pillow [#1068](https://github.com/NOAA-OWP/inundation-mapping/pull/1068) and the other for juypterlab #[1067 ](https://github.com/NOAA-OWP/inundation-mapping/pull/1067) diff --git a/tools/combine_crosswalk_tables.py b/tools/combine_crosswalk_tables.py index 9acc2292e..79f0d8d90 100644 --- a/tools/combine_crosswalk_tables.py +++ b/tools/combine_crosswalk_tables.py @@ -22,7 +22,6 @@ def combine_crosswalk_tables(data_directory, output_filename): filename, usecols=['HUC', 'HydroID', 'feature_id', 'LakeID'], dtype={'HUC': str} ) file_df = file_df.drop_duplicates() - file_df = file_df.rename(columns={'HUC': 'huc8'}) file_df['BranchID'] = os.path.split(os.path.dirname(filename))[1] dfs.append(file_df) @@ -32,6 +31,17 @@ def combine_crosswalk_tables(data_directory, output_filename): if len(dfs) > 1: df = pd.concat(dfs) + df = df.rename( + columns={'HUC': 'huc8', 'HydroID': 'hydro_id', 'LakeID': 'lake_id', 'BranchID': 'branch_id'} + ) + + df = df.sort_values(by=['feature_id', 'huc8', 'branch_id', 'hydro_id']) + + df = df.reset_index(drop=True) + df['hand_id'] = df.index + 1 + + df = df[['hand_id', 'feature_id', 'huc8', 'branch_id', 'hydro_id', 'lake_id']] + df.to_csv(output_filename, index=False)