Skip to content

Commit

Permalink
update dealing with poi_crosswalk to work with NHDNetworks
Browse files Browse the repository at this point in the history
  • Loading branch information
shorvath-noaa committed Sep 11, 2024
1 parent c74f889 commit a6883f6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/troute-network/troute/nhd_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2383,11 +2383,16 @@ def write_flowveldepth(
depth = flowveldepth.iloc[:,2::3].iloc[:,ind]

# Create POI-nexus point crosswalk dataframe (if necessary)
idx = flowveldepth.reset_index()[['featureID','Type']]
poi_crosswalk[['Type', 'featureID']] = poi_crosswalk['id'].str.split('-', expand=True)
poi_crosswalk['Type'] = 'nex' # Types can be 'nex', 'tnx', etc. This just sets them all to generic 'nex'.
poi_crosswalk['featureID'] = poi_crosswalk.featureID.astype(int)
poi_crosswalk = idx.set_index(['featureID','Type']).join(poi_crosswalk[['featureID','Type','poi_id']].set_index(['featureID','Type']))
if not poi_crosswalk.empty:
idx = flowveldepth.reset_index()[['featureID','Type']]
poi_crosswalk_masked = poi_crosswalk.copy()
poi_crosswalk_masked[['Type', 'featureID']] = poi_crosswalk_masked['id'].str.split('-', expand=True)
poi_crosswalk_masked['Type'] = 'nex' # Types can be 'nex', 'tnx', etc. This just sets them all to generic 'nex'.
poi_crosswalk_masked['featureID'] = poi_crosswalk_masked.featureID.astype(int)
poi_crosswalk_masked = idx.set_index(['featureID','Type']).join(poi_crosswalk_masked[['featureID','Type','poi_id']].set_index(['featureID','Type']))
else:
poi_crosswalk_masked = poi_crosswalk.copy()
poi_crosswalk_masked['poi_id'] = [" " for _ in range(len(flowveldepth))]

# Check if the first column of nudge is all zeros
if np.all(nudge[:, 0] == 0):
Expand Down Expand Up @@ -2415,7 +2420,7 @@ def write_flowveldepth(
depth.iloc[:,0:ts_per_file],
nudge_df.iloc[:,0:ts_per_file],
timestamps_sec[0:ts_per_file],t0,
poi_crosswalk)
poi_crosswalk_masked)
if stream_output_type == '.nc':
if cpu_pool > 1 & num_files > 1:
jobs.append(delayed(write_flowveldepth_netcdf)(*args))
Expand Down Expand Up @@ -2443,7 +2448,8 @@ def write_flowveldepth(
depth,
nudge_df,
timestamps_sec,
t0)
t0,
poi_crosswalk_masked)
if stream_output_type == '.nc':
if cpu_pool > 1:
jobs.append(delayed(write_flowveldepth_netcdf)(*args))
Expand Down

0 comments on commit a6883f6

Please sign in to comment.