Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobHanna-NOAA committed Aug 29, 2024
1 parent 4ef5b68 commit 93d3467
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
7 changes: 3 additions & 4 deletions tools/generate_categorical_fim.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ def iterate_through_huc_stage_based(

def __adjust_datum_ft(flows, metadata, lid, huc_lid_id):


# TODO: Aug 2024: This whole parts needs revisiting. Lots of lid data has changed and this
# is all likely very old.

Expand Down Expand Up @@ -960,8 +959,8 @@ def __create_acceptable_usgs_elev_df(usgs_elev_df, huc_lid_id):

# # TEMP DEBUG Record row difference and write it to a CSV or something
# label = 'Old code' ## TEMP DEBUG
# num_potential_rows = usgs_elev_df.shape[0]
# num_acceptable_rows = acceptable_usgs_elev_df.shape[0]
# num_potential_rows = usgs_elev_df.shape[0]
# num_acceptable_rows = acceptable_usgs_elev_df.shape[0]
# out_message = f'{label}: kept {num_acceptable_rows} rows out of {num_potential_rows} available rows.'

except Exception:
Expand Down Expand Up @@ -1188,7 +1187,7 @@ def generate_stage_based_categorical_fim(
# Join messages to populate status field to candidate sites. Assign
# status for null fields.
viz_out_gdf = viz_out_gdf.merge(status_df, how='left', on='nws_lid')

# viz_out_gdf.reset_index(inplace=True)

viz_out_gdf['status'] = viz_out_gdf['status'].fillna('undetermined')
Expand Down
6 changes: 3 additions & 3 deletions tools/generate_categorical_fim_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def generate_flows(
nwm_metafile,
log_output_file,
):

# TODO; Most docstrings like this are now very outdated and need updating
'''
This will create static flow files for all nws_lids and save to the
Expand Down Expand Up @@ -310,7 +310,7 @@ def generate_flows(
# FLOG.trace("args coming into generate flows")
# FLOG.trace(locals()) # see all args coming in to the function

attributes_dir = os.path.join(output_catfim_dir, 'attributes')
attributes_dir = os.path.join(output_catfim_dir, 'attributes')
mapping_dir = os.path.join(output_catfim_dir, "mapping") # create var but don't make folder yet

all_start = datetime.now(timezone.utc)
Expand Down Expand Up @@ -385,7 +385,7 @@ def generate_flows(

# only flow based needs the "flow" dir
output_flows_dir = os.path.join(output_catfim_dir, "flows")
if os.path.exists(output_flows_dir) == False:
if not os.path.exists(output_flows_dir):
os.mkdir(output_flows_dir)

start_dt = datetime.now(timezone.utc)
Expand Down
30 changes: 17 additions & 13 deletions tools/generate_categorical_fim_mapping.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3

import argparse

# import glob
import os

# import shutil
import sys
import time
Expand Down Expand Up @@ -83,7 +85,7 @@ def produce_stage_based_catfim_tifs(
# Produce extent tif hand_stage. Multiprocess across branches.
# branches = os.listdir(branch_dir)
MP_LOG.lprint(f"{huc_lid_cat_id} branch_dir is {branch_dir}")

branches = [x for x in os.listdir(branch_dir) if os.path.isdir(os.path.join(branch_dir, x))]
branches.sort()

Expand Down Expand Up @@ -509,8 +511,8 @@ def run_inundation(
# The intermediatary are all inundated branch tifs.

# The ones we want to keep stop at _extent.tif
#branch_tifs = glob.glob(os.path.join(output_huc_site_mapping_dir, '*_extent_*.tif'))
#for tif_file in branch_tifs:
# branch_tifs = glob.glob(os.path.join(output_huc_site_mapping_dir, '*_extent_*.tif'))
# for tif_file in branch_tifs:
# os.remove(tif_file)

return
Expand Down Expand Up @@ -731,14 +733,16 @@ def post_process_cat_fim_for_viz(
gpkg_files.sort()

merged_layers_gdf = None
ctr=0
for layer in tqdm(gpkg_files,
total=len(gpkg_files),
desc="Merging gpkg layers",
bar_format="{desc}:({n_fmt}/{total_fmt})|{bar}| {percentage:.1f}% ",
ncols=80):

# for ctr, layer in enumerate(gpkg_files):
ctr = 0
for layer in tqdm(
gpkg_files,
total=len(gpkg_files),
desc="Merging gpkg layers",
bar_format="{desc}:({n_fmt}/{total_fmt})|{bar}| {percentage:.1f}% ",
ncols=80,
):

# for ctr, layer in enumerate(gpkg_files):
# FLOG.lprint(f"Merging gpkg ({ctr+1} of {len(gpkg_files)} - {}")
FLOG.trace(f"Merging gpkg ({ctr+1} of {len(gpkg_files)} : {layer}")

Expand Down Expand Up @@ -769,13 +773,13 @@ def post_process_cat_fim_for_viz(
if catfim_method == "flow_based":
FLOG.lprint("Dissolving flow based catfim_libary by ahps and magnitudes")
merged_layers_gdf = merged_layers_gdf.dissolve(by=['ahps_lid', 'magnitude'], as_index=False)

merged_layers_gdf.reset_index(inplace=True)

output_file_name = f"{catfim_method}_catfim_library"

# TODO: Aug 2024: gpkg are not opening in qgis now? project, wkt, non defined geometry columns?
# gkpg_file_path = os.path.join(output_mapping_dir, f'{output_file_name}.gpkg')
# gkpg_file_path = os.path.join(output_mapping_dir, f'{output_file_name}.gpkg')
# FLOG.lprint(f"Saving catfim library gpkg version to {gkpg_file_path}")
# merged_layers_gdf.to_file(gkpg_file_path, driver='GPKG', index=True, engine="fiona", crs=PREP_PROJECTION)

Expand Down

0 comments on commit 93d3467

Please sign in to comment.