Skip to content

Commit

Permalink
Stop before writing empty geodataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
mluck committed Aug 26, 2024
1 parent a1d1648 commit cfe7f10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/derive_level_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ def Derive_level_paths(
feature_attribute=branch_id_attribute, outlet_linestring_index=outlet_linestring_index
)

branch_inlets.to_file(branch_inlets_outfile, index=False, driver="GPKG", engine='fiona')
if not branch_inlets.empty:
branch_inlets.to_file(branch_inlets_outfile, index=False, driver="GPKG", engine='fiona')

return stream_network
if stream_network.empty:
print("Sorry, no streams exist and processing can not continue. This could be an empty file.")
sys.exit(FIM_exit_codes.UNIT_NO_BRANCHES.value) # will send a 60 back
else:
return stream_network


if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 deletions src/stream_branches.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import os
import sys
from collections import deque
from os.path import isfile, splitext
from random import sample
Expand All @@ -19,6 +20,7 @@
from shapely.strtree import STRtree
from tqdm import tqdm

from utils.fim_enums import FIM_exit_codes
from utils.shared_variables import PREP_CRS


Expand Down Expand Up @@ -732,6 +734,12 @@ def select_branches_intersecting_huc(self, wbd, buffer_wbd_streams, out_vector_f
if verbose:
print("Writing selected branches ...")

if self.empty:
print(
"Sorry, no streams exist and processing can not continue. This could be an empty file."
)
sys.exit(FIM_exit_codes.UNIT_NO_BRANCHES.value) # will send a 60 back

self.write(out_vector_files, index=False)

return self
Expand Down

0 comments on commit cfe7f10

Please sign in to comment.