Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2pt] PR: CatFIM 2.1: Add Alaska, reconcile sites, fix CatFIM V2.0 bugs #1285

Merged
merged 153 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
a2494df
Update to process Alaska and debug AK runs.
May 16, 2024
ca763e6
Adjust flows CatFIM code.
May 20, 2024
ede81d3
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
May 20, 2024
b4d7f2f
Added path checks to beginning and AK processing to stage-based.
May 22, 2024
70b2515
Clean up CatFIM logging.
May 22, 2024
ccc4ad7
Update CatFIM projection handling.
May 23, 2024
c6051b3
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
May 24, 2024
26abbd6
Restore full-scale CatFIM processing.
May 24, 2024
836ae97
Fix syntax error.
May 24, 2024
1412f58
Clean up CatFIM comments.
May 24, 2024
7dbec19
add config as input
May 28, 2024
0fb45e8
Add HUC list as an optional input to CatFIM.
May 28, 2024
ab2a784
Update CatFIM HUC list functionality.
May 29, 2024
db2b964
fix env system
RobHanna-NOAA May 29, 2024
b2314ee
fix env system
RobHanna-NOAA May 29, 2024
a6e54b4
Merge branch 'dev-catfim-alaska' of https://github.com/NOAA-OWP/inund…
RobHanna-NOAA May 29, 2024
db4da8c
added key prints stmts
May 29, 2024
125ab7f
Remove skip_api temp function.
May 30, 2024
e0df33b
Finding stage bug
RobHanna-NOAA May 30, 2024
0c7800c
WIP add partial logging
RobHanna-NOAA May 31, 2024
f25ade2
Partial logging, wrds reuse
RobHanna-NOAA Jun 3, 2024
7c717cd
Basic logger now in place
RobHanna-NOAA Jun 4, 2024
cd4c349
fixing linting
Jun 18, 2024
683b3db
fine tuning flow
RobHanna-NOAA Jul 1, 2024
e01df20
Merge branch 'dev' into dev-catfim-alaska
RobHanna-NOAA Jul 2, 2024
5d3f826
more updates
RobHanna-NOAA Jul 2, 2024
ad2eb62
more updates
RobHanna-NOAA Jul 3, 2024
d6c332c
Temporarily remove AK flows from stage-based processing.
Jul 5, 2024
d422fb4
flow mostly done, starting stage
RobHanna-NOAA Jul 8, 2024
6978b3e
Merge branch 'dev-catfim-alaska' of into dev-catfim-alaska
RobHanna-NOAA Jul 8, 2024
c482f4b
putting msgs system back into stage based
RobHanna-NOAA Jul 8, 2024
f3b9ee5
logging system done
Jul 9, 2024
723507b
Merge branch 'dev' into dev-catfim-alaska
Jul 9, 2024
d792217
Fix CatFIM code so that it runs again.
Jul 19, 2024
3594cfb
Removed debug language.
Jul 19, 2024
346226a
Merge branch 'dev' into dev-catfim-alaska
Jul 19, 2024
eb79194
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
Jul 25, 2024
d893abe
WIP changes
RobHanna-NOAA Aug 12, 2024
68d3007
Revert "WIP changes"
RobHanna-NOAA Aug 12, 2024
1bb75ba
manually overwrite Emily catfim-coords
RobHanna-NOAA Aug 12, 2024
c21b3a3
Merge branch 'dev' into dev-catfim-alaska
RobHanna-NOAA Aug 12, 2024
f532376
updated bug in linting file
RobHanna-NOAA Aug 12, 2024
2928f88
fix some MP logs not being cleaned up
RobHanna-NOAA Aug 12, 2024
ff9b515
Looking into MP issues
RobHanna-NOAA Aug 12, 2024
ddff568
Fix MP and a few other tidbits
RobHanna-NOAA Aug 13, 2024
a162f97
Fix CRS issue and annotate Alaska options.
Aug 13, 2024
7d7b1d7
Merge branch 'dev-catfim-alaska' of https://github.com/NOAA-OWP/inund…
Aug 13, 2024
3b6654b
minor adj
RobHanna-NOAA Aug 13, 2024
63b2a0d
Merge branch 'dev-catfim-alaska' of https://github.com/NOAA-OWP/inund…
RobHanna-NOAA Aug 13, 2024
0893b9b
nws lid site gpkg status fixed
RobHanna-NOAA Aug 14, 2024
a376b2d
fine tuning and adding dissolving
RobHanna-NOAA Aug 14, 2024
83c6e7b
fixing duplication of innundation in some places
RobHanna-NOAA Aug 19, 2024
926b64f
bug fixing, stage and gpkg files
RobHanna-NOAA Aug 28, 2024
a077d02
stage based fixed exc inundation
RobHanna-NOAA Aug 29, 2024
19684aa
Last min stage fixes. all done
RobHanna-NOAA Aug 29, 2024
4ef5b68
Merge remote-tracking branch 'origin/dev' into dev-catfim-alaska
RobHanna-NOAA Aug 29, 2024
93d3467
Linting fixes
RobHanna-NOAA Aug 29, 2024
f00a3e2
re-instate changes to the file which had no changes but git errored
RobHanna-NOAA Aug 30, 2024
54733b1
linting fix
RobHanna-NOAA Aug 30, 2024
845f5ae
Update CHANGELOG.md
RobHanna-NOAA Aug 30, 2024
78160fd
Cleaned up comment for coordinate accuracy update.
EmilyDeardorff Aug 30, 2024
3cd6159
Update CHANGELOG.md for coord accuracy updates.
EmilyDeardorff Aug 30, 2024
7a75890
fix so it works with new docker, fix ahps column name
RobHanna-NOAA Sep 6, 2024
178f6fc
Re-add Alaska code.
Sep 11, 2024
b999676
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
RobHanna-NOAA Sep 16, 2024
1146758
put it back to my lst merge from 2.1
RobHanna-NOAA Sep 16, 2024
c82a27f
Fix CRS issue for flow-based CatFIM.
Sep 18, 2024
3d17cc7
Update AK CatFIM comments.
Sep 18, 2024
f4cbd84
Merge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inundat…
Sep 18, 2024
9efc99a
new ahps site compare tool
RobHanna-NOAA Sep 18, 2024
4919fe5
bug fix nnew ahps site compare tool
RobHanna-NOAA Sep 18, 2024
1ec16ee
Syntax edit.
Sep 19, 2024
d3bf22b
stage based dropped files fixed
RobHanna-NOAA Sep 26, 2024
d554508
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
RobHanna-NOAA Sep 26, 2024
43d3894
Shut off hardcoded huc: Note flow not workign yet
RobHanna-NOAA Sep 26, 2024
f7dd2b2
oops.. did not fully shut off filtered hucs
RobHanna-NOAA Sep 26, 2024
5720776
dang.. did it again... shut off filter hucs
RobHanna-NOAA Sep 26, 2024
ed6d9ba
WIP but status almost done
RobHanna-NOAA Sep 27, 2024
796da89
finished status fixes
RobHanna-NOAA Sep 28, 2024
64b3b33
Debugging box issue - testing code.
Oct 7, 2024
10e9901
Merge in dev-catfim-v2-1-alaska
RobHanna-NOAA Oct 7, 2024
de77b00
linting cleanup and a couple of tweaks from merge
RobHanna-NOAA Oct 8, 2024
0230295
linting fixes
RobHanna-NOAA Oct 8, 2024
f31b07d
more linting fixes
RobHanna-NOAA Oct 8, 2024
5efe962
stages fixed
RobHanna-NOAA Oct 11, 2024
e586449
box fix
RobHanna-NOAA Oct 11, 2024
c940955
linting
Oct 11, 2024
53ae54d
Clean up debug and outdated TODOs.
Oct 15, 2024
714b03b
debugging change
RobHanna-NOAA Oct 15, 2024
b3ee98a
Merge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inundat…
RobHanna-NOAA Oct 15, 2024
638070c
Merge branch 'dev-catfim-v2-1-alaska'
RobHanna-NOAA Oct 15, 2024
da6ce7b
Merge plus move folders
RobHanna-NOAA Oct 15, 2024
e2d5bd6
Add HUC list functionality and decomission LID input.
Oct 18, 2024
be1bea3
Add ahps restricted system
RobHanna-NOAA Oct 25, 2024
b4d687e
add csv file
RobHanna-NOAA Oct 25, 2024
38bb23d
simplify restricted sites system
RobHanna-NOAA Oct 25, 2024
2a7b99d
adj template
RobHanna-NOAA Oct 25, 2024
560a362
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
RobHanna-NOAA Oct 25, 2024
3c21b58
linting fixes
RobHanna-NOAA Oct 25, 2024
27849a9
bug fixed - lid case
RobHanna-NOAA Oct 25, 2024
0235825
linting
RobHanna-NOAA Oct 26, 2024
0f2a7fe
bug fixed for p to ft error
RobHanna-NOAA Oct 28, 2024
72ebebc
Add CatFIM readme.
EmilyDeardorff Oct 30, 2024
8ab65ef
Update formatting of CatFIM README.md
EmilyDeardorff Oct 30, 2024
fcf8311
Add images folder to CatFIM dir.
EmilyDeardorff Oct 30, 2024
783a58e
t pMerge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inun…
EmilyDeardorff Oct 30, 2024
b527e76
Add CatFIM screenshot vis file.
EmilyDeardorff Oct 30, 2024
f20f423
cleanup raster load
RobHanna-NOAA Oct 30, 2024
4c0a7d5
Merge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inundat…
RobHanna-NOAA Oct 30, 2024
18f9dec
Add screenshot to CatFIM README
EmilyDeardorff Oct 30, 2024
a0475dc
Add flow-based CatFIM screenshot
EmilyDeardorff Oct 30, 2024
aa2f2ef
Delete tools/catfim/images/screenshot_flow_based_catfim.JPG
EmilyDeardorff Oct 30, 2024
aa76dc6
Quick merge update
RobHanna-NOAA Oct 31, 2024
66f143d
Merge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inundat…
RobHanna-NOAA Oct 31, 2024
e9d18b4
linting fixes
Oct 31, 2024
2ed8ec0
linting fix
RobHanna-NOAA Oct 31, 2024
79eabcb
trouble with linting the csv
RobHanna-NOAA Oct 31, 2024
365348c
trouble with csv linting
RobHanna-NOAA Oct 31, 2024
158be5d
Linting problems with csv
Oct 31, 2024
074cb2a
linting fixes
Oct 31, 2024
2329e3c
pyproj compatiability issues
Oct 31, 2024
82c8bb4
fine tune linting config
Oct 31, 2024
59d2379
fine tune linting config
Oct 31, 2024
5e14409
fine tune linting changes
Oct 31, 2024
2fa4bc3
fine tune linting changes
Oct 31, 2024
9e6bdfc
fine tune linting config
Oct 31, 2024
98dca11
fine tuning linting
Oct 31, 2024
b70d63d
fine tuning linting
Oct 31, 2024
d67be58
bug fix rasterio to shapes
RobHanna-NOAA Oct 31, 2024
f624890
Update CHANGELOG.md
RobHanna-NOAA Oct 31, 2024
c589232
Fix duplicate LID bug.
Nov 5, 2024
fb034a5
Bug fixes for dup sites , status not corrrect for failed inundation, etc
RobHanna-NOAA Nov 7, 2024
c005216
small edits
Nov 19, 2024
489b662
fine tuning linting
Nov 19, 2024
d7a568f
linting config fixes
Nov 19, 2024
23a0e0a
linting fixes
Nov 19, 2024
cbaf3f9
fixes for status and interals
Dec 3, 2024
085cd98
Merge branch 'dev' into dev-catfim-v2-1
RobHanna-NOAA Dec 3, 2024
64b5c06
WIP
RobHanna-NOAA Dec 3, 2024
d09fe96
Merge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inundat…
RobHanna-NOAA Dec 3, 2024
b1d79ec
linting fixes
Dec 3, 2024
ef2dc6d
Update README.md to include CatFIM site acceptance criteria
EmilyDeardorff Dec 4, 2024
3edee03
status fixes
RobHanna-NOAA Dec 5, 2024
e369d60
Merge branch 'dev-catfim-v2-1' of https://github.com/NOAA-OWP/inundat…
RobHanna-NOAA Dec 5, 2024
b09a10f
fix stages
RobHanna-NOAA Dec 6, 2024
424143b
linting fixes
Dec 6, 2024
5554f40
Last min bugs
RobHanna-NOAA Dec 9, 2024
c86b98c
linting fixes
Dec 9, 2024
38749b7
linting tests
Dec 9, 2024
5006425
prod3 linting tests
RobHanna-NOAA Dec 9, 2024
c603990
dev merged in
Dec 10, 2024
409b7b6
Merge branch 'dev' of https://github.com/NOAA-OWP/inundation-mapping …
Dec 10, 2024
c4b235f
merge in dev
Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ config/*.swp
.vscode/
**/.DS_Store
.private/
!tools/catfim/*.csv
!tools/catfim/catfim.env.template
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# Additional hooks: https://pre-commit.com/hooks.html

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.0.1
hooks:
- id: trailing-whitespace
# Below is python regex to exclude all .md files
exclude: .*md$
- id: end-of-file-fixer
exclude: Pipfile.lock
- id: check-added-large-files
args: ['--maxkb=5000']
- id: check-json
Expand Down
10 changes: 10 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
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.13.0 - 2024-12-10 - [PR#1285](https://github.com/NOAA-OWP/inundation-mapping/pull/1285)

Major upgrades and bug fixes to the CatFIM product, informally called CatFIM 2.1. See the PR for all details

<br/><br/>


## v4.5.12.2 - 2024-12-10 - [PR#1346](https://github.com/NOAA-OWP/inundation-mapping/pull/1346)

This PR updates deny lists to avoid saving unnecessary files.
Expand Down Expand Up @@ -44,6 +52,8 @@ As part of this PR, small modification was applied to bridge_inundation.py.
<br/><br/>




## v4.5.11.3 - 2024-10-25 - [PR#1320](https://github.com/NOAA-OWP/inundation-mapping/pull/1320)

The fix: During the post processing scan for the word "error" or "warning", it was only finding records which had either of those two words as stand alone words and not part of bigger phrases. ie); "error" was found, but not "fielderror". Added wildcards and it is now fixed.
Expand Down
29 changes: 15 additions & 14 deletions pyproject.toml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ maintainers = [
{name = "Hamideh Safa", email = "[email protected]"},
{name = "James Coll", email = "[email protected]"},
{name = "Matt Luck", email = "[email protected]"},
{name = "Nick Chadwick", email = "[email protected]"},
{name = "Riley McDermott", email = "[email protected]"},
{name = "Robert Hanna", email = "[email protected]"},
{name = "Ryan Spies", email = "[email protected]"}
Expand All @@ -39,17 +38,24 @@ Wiki = "https://github.com/NOAA-OWP/inundation-mapping/wiki"
# - Tools -

[tool.black]
line_length = 110
skip-string-normalization = true
skip-magic-trailing-comma = true

line-length = 110
exclude = '''
/(
\.csv$
)/
'''

[tool.isort]
profile = 'black'
line_length = 110
multi_line_output = 3
lines_after_imports = 2
# extend-skip = [".csv"]
skip_glob = ["*.csv"]

# yes, the exclue format is different from black
[tool.flake8]
count = true
doctests = true
Expand All @@ -59,26 +65,21 @@ extend-ignore = """
E203,
E266,
E501,
E712,
W503,
W391
F403,
W391,
F401,
F403,
"""
exclude = ["*.csv"]

per-file-ignores = """
src/subdiv_chan_obank_src.py: E712
src/src_roughness_optimization.py: E712, F841
src/agreedem.py: E712
src/src_roughness_optimization.py: F841
src/build_stream_traversal.py: E722

tools/check_deep_flooding.py: E712
tools/eval_alt_catfim.py: F841
tools/generate_categorical_fim.py: C901, E712
tools/generate_categorical_fim_mapping.py: E712
tools/inundation.py: F821
tools/rating_curve_comparison.py: F821, F841
tools/run_test_case.py: E711
tools/tools_shared_functions.py: F821, F841, E711
tools/vary_mannings_n_composite.py: E712

data/usgs/rating_curve_get_usgs_curves.py: F841
"""
110 changes: 58 additions & 52 deletions src/utils/fim_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import datetime as dt
import os
import random
import traceback
from pathlib import Path


Expand Down Expand Up @@ -147,7 +145,8 @@ def MP_Log_setup(self, parent_log_output_file, file_prefix):
using a defined file path.

As this is an MP file, the parent_log_output_file may have a date in it
The file name is calculated as such {file_prefix}-{random 12 digit key}.log()
The file name is calculated as such
{file_prefix}-{currernt datetime with milli}.log()
ie) catfim_2024_07_09-16_30_02__012345678901.log

The extra file portion is added as in MultiProc, you can have dozens of processes
Expand All @@ -165,8 +164,10 @@ def MP_Log_setup(self, parent_log_output_file, file_prefix):
# -----------------
log_folder = os.path.dirname(parent_log_output_file)

random_id = random.randrange(1000000000, 99999999999)
log_file_name = f"{file_prefix}___{random_id}.log"
# random_id = random.randrange(1000000000, 99999999999)
# this is an epoch time
dt_str = dt.datetime.now().strftime('%H%M%S%f')
log_file_name = f"{file_prefix}___{dt_str}.log"
log_file_path = os.path.join(log_folder, log_file_name)

self.setup(log_file_path)
Expand Down Expand Up @@ -232,63 +233,68 @@ def merge_log_files(self, parent_log_output_file, file_prefix, remove_old_files=
folder_path = os.path.dirname(parent_log_output_file)
os.makedirs(folder_path, exist_ok=True)

log_file_list_paths = list(Path(folder_path).rglob(f"{file_prefix}*"))
log_file_list_paths = list(Path(folder_path).glob(f"*{file_prefix}*"))
log_file_list = [str(x) for x in log_file_list_paths]

if len(log_file_list) > 0:
log_file_list.sort()

# we are merging them in order (reg files, then warnings, then errors)

# open and write to the parent log
# This will write all logs including errors and warning
with open(parent_log_output_file, 'a') as main_log:
# Iterate through list
for temp_log_file in log_file_list:
# Open each file in read mode
with open(temp_log_file) as infile:
main_log.write(infile.read())
if "warning" not in temp_log_file and "error" not in temp_log_file:
if remove_old_files:
os.remove(temp_log_file)

# now the warning files if there are any
log_warning_file_list = list(Path(folder_path).rglob(f"{file_prefix}*_warnings*"))
if len(log_warning_file_list) > 0:
log_warning_file_list.sort()
parent_warning_file = parent_log_output_file.replace(".log", "_warnings.log")
with open(parent_warning_file, 'a') as warning_log:
# It is ok if it fails with a file not found. Sometimes during multi proc
# merging, we get some anomylies. Rare but it happens.
try:
# open and write to the parent log
# This will write all logs including errors and warning
with open(parent_log_output_file, 'a') as main_log:
# Iterate through list
for temp_log_file in log_warning_file_list:
for temp_log_file in log_file_list:
# Open each file in read mode
with open(temp_log_file) as infile:
warning_log.write(infile.read())

if remove_old_files:
os.remove(temp_log_file)

# now the warning files if there are any
log_error_file_list = list(Path(folder_path).rglob(f"{file_prefix}*_errors*"))
if len(log_error_file_list) > 0:
log_error_file_list.sort()
parent_error_file = parent_log_output_file.replace(".log", "_errors.log")
# doesn't yet exist, then create a blank one
with open(parent_error_file, 'a') as error_log:
# Iterate through list
for temp_log_file in log_error_file_list:
# Open each file in read mode
with open(temp_log_file) as infile:
error_log.write(infile.read())

if remove_old_files:
os.remove(temp_log_file)
main_log.write(infile.read())
if "warning" not in temp_log_file and "error" not in temp_log_file:
if remove_old_files:
os.remove(temp_log_file)

# now the warning files if there are any
log_warning_file_list = list(Path(folder_path).rglob(f"{file_prefix}*_warnings*"))
if len(log_warning_file_list) > 0:
log_warning_file_list.sort()
parent_warning_file = parent_log_output_file.replace(".log", "_warnings.log")
with open(parent_warning_file, 'a') as warning_log:
# Iterate through list
for temp_log_file in log_warning_file_list:
# Open each file in read mode
with open(temp_log_file) as infile:
warning_log.write(infile.read())

if remove_old_files:
os.remove(temp_log_file)

# now the warning files if there are any
log_error_file_list = list(Path(folder_path).rglob(f"{file_prefix}*_errors*"))
if len(log_error_file_list) > 0:
log_error_file_list.sort()
parent_error_file = parent_log_output_file.replace(".log", "_errors.log")
# doesn't yet exist, then create a blank one
with open(parent_error_file, 'a') as error_log:
# Iterate through list
for temp_log_file in log_error_file_list:
# Open each file in read mode
with open(temp_log_file) as infile:
error_log.write(infile.read())

if remove_old_files:
os.remove(temp_log_file)
except FileNotFoundError as ex:
print(f"Merge file not found. Details: {ex}. Program continuing")

return

# -------------------------------------------------
def trace(self, msg):
# goes to file only, not console
level = "TRACE " # keeps spacing the same
level = "TRACE".ljust(9) # keeps spacing the same (9 chars wide)
if self.LOG_FILE_PATH == "":
print(self.LOG_SYS_NOT_SETUP_MSG)
return
Expand All @@ -301,7 +307,7 @@ def trace(self, msg):
# -------------------------------------------------
def lprint(self, msg):
# goes to console and log file
level = "LPRINT " # keeps spacing the same
level = "LPRINT".ljust(9) # keeps spacing the same (9 chars wide)
print(f"{msg} ")

if self.LOG_FILE_PATH == "":
Expand All @@ -316,7 +322,7 @@ def lprint(self, msg):
# -------------------------------------------------
def notice(self, msg):
# goes to console and log file
level = "NOTICE " # keeps spacing the same
level = "NOTICE".ljust(9) # keeps spacing the same (9 chars wide)
# print(f"{cl.fore.TURQUOISE_2}{msg}{cl.style.RESET}")
print(f"{level}: {msg}")

Expand All @@ -332,7 +338,7 @@ def notice(self, msg):
# -------------------------------------------------
def success(self, msg):
# goes to console and log file
level = "SUCCESS " # keeps spacing the same
level = "SUCCESS".ljust(9) # keeps spacing the same (9 chars wide)

# c_msg_type = f"{cl.fore.SPRING_GREEN_2B}<{level}>{cl.style.RESET}"
# print(f"{self.__get_clog_dt()} {c_msg_type} : {msg}")
Expand All @@ -350,7 +356,7 @@ def success(self, msg):
# -------------------------------------------------
def warning(self, msg):
# goes to console and log file and warning log file
level = "WARNING " # keeps spacing the same
level = "WARNING".ljust(9) # keeps spacing the same (9 chars wide)

# c_msg_type = f"{cl.fore.LIGHT_YELLOW}<{level}>{cl.style.RESET}"
# print(f"{self.__get_clog_dt()} {c_msg_type} : {msg}")
Expand All @@ -372,7 +378,7 @@ def warning(self, msg):
# -------------------------------------------------
def error(self, msg):
# goes to console and log file and error log file
level = "ERROR " # keeps spacing the same
level = "ERROR".ljust(9) # keeps spacing the same (9 chars wide)

# c_msg_type = f"{cl.fore.RED_1}<{level}>{cl.style.RESET}"
# print(f"{self.__get_clog_dt()} {c_msg_type} : {msg}")
Expand All @@ -393,7 +399,7 @@ def error(self, msg):

# -------------------------------------------------
def critical(self, msg):
level = "CRITICAL".ljust(9)
level = "CRITICAL".ljust(9) # keeps spacing the same (9 chars wide)

# c_msg_type = f"{cl.style.BOLD}{cl.fore.RED_3A}{cl.back.WHITE}{self.__get_dt()}"
# c_msg_type += f" <{level}>"
Expand Down
6 changes: 0 additions & 6 deletions tools/.env.template

This file was deleted.

1 change: 0 additions & 1 deletion tools/.gitignore

This file was deleted.

76 changes: 76 additions & 0 deletions tools/catfim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## About CatFIM
CatFIM is short for Categorical Flood Inundation Mapping. CatFIM is a tool that is run on HAND FIM outputs to inundate a bunch of AHPS sites to specific stages or flow levels. This is useful for quality controlling HAND FIM as well as for preparing for hypothetical flood events. CatFIM models floods at up to 5 different magnitudes: action, minor, moderate, major, and record. The flows or stages for these magnitudes is pulled from the WRDS API.

### Stage-based vs Flow-based
There are two modes for running CatFIM: stage-based and flow-based. Stage-based CatFIM inundates the HAND FIM relative elevation model (REM) based on different magnitudes of stage, which is the height of the water surface. Flow-based CatFIM inundates the REM based on different magnitudes of flow, which is measured as the volume over time of water flowing past a certain point of the river. A rating curve is used to get the water height from the flow volume at a given location.

### How are CatFIM sites selected?

Our goal is to produce good CatFIM for as many APHS sites as possible. In order to meet this goal, a site must meet a variety of acceptance critera and data availability checks for us to produce CatFIM at the site.

If you have a question about why a specific point is being excluded, you can check the "Status" attribute of the CatFIM point to see what issue might be occurring. If there is a question or concern about a specific point, feel free to reach out to GID via Slack or VLAB.


CatFIM sites must:
- have site-specific stage- or flow- thresholds available
- be an NWM forecast point (for sites in CONUS*)
- not be on the stage-based AHPS restricted sites list (for stage-based CatFIM)
- have an accurate vertical datum (for stage-based CatFIM)
- meet the USGS Gages Acceptance Criteria (detailed below)

USGS Gages Acceptance Criteria:
- [Lat/Long Coordinate Method](https://help.waterdata.usgs.gov/code/coord_meth_cd_query?fmt=html) must be one of the following: "C", "D", "W", "X", "Y", "Z", "N", "M", "L", "G", "R", "F", "S"
- [Acceptable Altitute Accuracy Threshold](https://help.waterdata.usgs.gov/codes-and-parameters/codes#SI) must be 1 or lower
- [Altitute Method Type](https://help.waterdata.usgs.gov/code/alt_meth_cd_query?fmt=html) must be one of the following: "A", "D", "F", "I", "J", "L", "N", "R", "W", "X", "Y", "Z"
- [Site Type](https://help.waterdata.usgs.gov/code/site_tp_query?fmt=html) must be: "ST" (stream)

*Note: Previous versions of CatFIM also restricted sites based on [Lat/Long Coordinate Accuracy](https://help.waterdata.usgs.gov/code/coord_acy_cd_query?fmt=html), but that criteria was removed in Fall 2024 to increase availability of CatFIM sites.*

*For sites outside of CONUS: As of 12/4/2024, these criteria are currently being workshopped to account for the unique challenges of producing CatFIM in non-CONUS locations. Check back for updates or reach out to GID via Slack if you have specific questions!


## Running CatFIM
### Who can run CatFIM?
CatFIM can only be run by systems that can access the WRDS API, which is restricted to computers on the NOAA network. If you are outside the NOAA network and would like to run code from inundation-mapping, see the README in NOAA-OWP/inundation-mapping.


### Commands
Stage-based example with step system and pre-downloaded metadata:

`python /foss_fim/tools/generate_categorical_fim.py -f /outputs/Rob_catfim_test_1 -jh 1 -jn 10 -ji 8 -e /data/config/catfim.env -t /data/docker_test_1 -me '/data/nwm_metafile.pkl' -sb -step 2`

Flow-based example with HUC list:

`python /foss_fim/tools/catfim/generate_categorical_fim.py -f /data/previous_fim/fim_4_5_2_11/ -jh 4 -jn 2 -e /data/config/catfim.env -t /data/hand_4_5_11_1_catfim_datavis -o -lh '06010105 17110004 10300101 19020401 19020302'`


### Arguments
- `-f`, `--fim_run_dir`: Path to directory containing HAND outputs, e.g. /data/previous_fim/fim_4_5_2_11
- `-e`, `--env_file`: Docker mount path to the catfim environment file. ie) data/config/catfim.env
- `-jh`, `--job_number_huc`: OPTIONAL: Number of processes to use for HUC scale operations. HUC and inundation job numbers should multiply to no more than one less than the CPU count of the machine. CatFIM sites generally only have 2-3 branches overlapping a site, so this number can be kept low (2-4). Defaults to 1.
- `-jn`, `--job_number_inundate`: OPTIONAL: Number of processes to use for inundating HUC and inundation job numbers should multiply to no more than one less than the CPU count of the machine. Defaults to 1.
- `-ji`, `--job_number_intervals`: OPTIONAL: Number of processes to use for inundating multiple intervals in stage-based inundation and interval job numbers should multiply to no more than one less than the CPU count of the machine. Defaults to 1.
- `-sb`, `--is_stage_based`: Run stage-based CatFIM instead of flow-based? Add this -sb param to make it stage based, leave it off for flow based.
- `-t`, `--output_folder`: OPTIONAL: Target location, Where the output folder will be. Defaults to /data/catfim/
- `-s`, `--search`: OPTIONAL: Upstream and downstream search in miles. How far up and downstream do you want to go? Defaults to 5.
- `-lh`, `--lst_hucs`: OPTIONAL: Space-delimited list of HUCs to produce CatFIM for. Defaults to all HUCs.
- `-mc`, `--past_major_interval_cap`: OPTIONAL: Stage-Based Only. How many feet past major do you want to go for the interval FIMs? of the machine. Defaults to 5.
- `-step`: 'OPTIONAL: By adding a number here, you may be able to skip levels of processing. The number you submit means it will start at that step. e.g. step of 2 means start at step 2 which for flow based is the creating of tifs and gpkgs. Note: This assumes those previous steps have already been processed and the files are present. Defaults to 0 which means all steps processed.
- `-me`, `--nwm_metafile`: OPTIONAL: If you have a pre-existing nwm metadata pickle file, you can path to it here. NOTE: This parameter is for quick debugging only and should not be used in a production mode.
- `-o`, `--overwrite`: OPTIONAL: Overwrite files.

## Visualization Tips & Tricks

### Changing Symbol Drawing Order

- **ArcGIS Pro:** Go to the Symbology pane and navgate to the Symbol layer drawing tab. Make sure the "Enable symbol layer drawing" option is switched "ON", and then adjust the Drawing Order of the magnitudes so they are in this order: action, minor, moderate, major, record.

![screenshot of Symbology pane in ArcGIS Pro](https://github.com/NOAA-OWP/inundation-mapping/blob/b527e762478fef2c1ffc5f0ff4d494f1746663bb/tools/catfim/images/screenshot_vis_settings.JPG)

- **QGIS**: To change the symbol drawing order in QGIS...

## Glossary
- AHPS: Advanced Hydrologic Prediction Services (NOAA)
- WRDS: Water Resources Data System (NOAA)
- REM: relative elevation model
- HAND: height above nearest drainage
Empty file added tools/catfim/__init__.py
Empty file.
Loading
Loading