Skip to content

Commit

Permalink
rcat rvd workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
jtgilbert authored and MattReimer committed Aug 24, 2023
1 parent 7f7d031 commit 9630d88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
43 changes: 26 additions & 17 deletions packages/rcat/rcat/lib/rcat_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,31 @@ def igo_attributes(database: str, windows: dict):

# departure
log.info('Finding riparian departure')
curs.execute('SELECT IGOAttributes.IGOID, ExistingRiparianMean, HistoricRiparianMean FROM IGOAttributes')
curs.execute('SELECT IGOAttributes.IGOID, ExistingRiparianMean, HistoricRiparianMean, LUI FROM IGOAttributes')

dep = {row[0]: [row[1], row[2]] for row in curs.fetchall()}
dep = {row[0]: [row[1], row[2], row[3]] for row in curs.fetchall()}
for igoid, val in dep.items():
# if val[0] is None:
# val[0] = 0
# if val[1] is None:
if val[1] == 0:
if val[1] == 0 or val[2] is None:
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = 1, RiparianDepartureID = 0 WHERE IGOID = {igoid}')
else:
if 1 > val[0] / val[1] >= 0.9:
depid = 1
elif 0.9 >= val[0] / val[1] > 0.66:
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE IGOID = {igoid}')
elif 0.9 >= val[0] / val[1] > 0.66 and val[2] > 0:
depid = 2
elif 0.66 >= val[0] / val[1] > 0.33:
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE IGOID = {igoid}')
elif 0.66 >= val[0] / val[1] > 0.33 and val[2] > 0:
depid = 3
else:
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE IGOID = {igoid}')
elif val[0] / val[1] <= 0.33 and val[2] > 0:
depid = 4
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE IGOID = {igoid}')
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE IGOID = {igoid}')
else:
depid = 1
curs.execute(f'UPDATE IGOAttributes SET RiparianDeparture = 1, RiparianDepartureID = {depid} WHERE IGOID = {igoid}')

curs.execute('SELECT DGOAttributes.DGOID, ExistingRiparianMean, HistoricRiparianMean FROM DGOAttributes')
dep_dgo = {row[0]: [row[1], row[2]] for row in curs.fetchall()}
Expand Down Expand Up @@ -593,25 +599,28 @@ def reach_attributes(database: str):

# departure
log.info('Finding riparian departure')
curs.execute('SELECT ReachAttributes.ReachID, ExistingRiparianMean, HistoricRiparianMean FROM ReachAttributes')
curs.execute('SELECT ReachAttributes.ReachID, ExistingRiparianMean, HistoricRiparianMean, iPC_LU FROM ReachAttributes')

dep = {row[0]: [row[1], row[2]] for row in curs.fetchall()}
dep = {row[0]: [row[1], row[2], row[3]] for row in curs.fetchall()}
for rid, val in dep.items():
# if val[0] is None:
# val[0] = 0
# if val[1] is None:
if val[1] == 0:
if val[1] == 0 or val[2] is None:
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = 1, RiparianDepartureID = 0 WHERE ReachID = {rid}')
else:
if 1 > val[0] / val[1] >= 0.9:
depid = 1
elif 0.9 >= val[0] / val[1] > 0.66:
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE ReachID = {rid}')
elif 0.9 >= val[0] / val[1] > 0.66 and val[2] > 0:
depid = 2
elif 0.66 >= val[0] / val[1] > 0.33:
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE ReachID = {rid}')
elif 0.66 >= val[0] / val[1] > 0.33 and val[2] > 0:
depid = 3
else:
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE ReachID = {rid}')
elif val[0] / val[1] <= 0.33 and val[2] > 0:
depid = 4
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE ReachID = {rid}')
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = {val[0]/val[1]}, RiparianDepartureID = {depid} WHERE ReachID = {rid}')
else:
depid = 1
curs.execute(f'UPDATE ReachAttributes SET RiparianDeparture = 1, RiparianDepartureID = {depid} WHERE ReachID = {rid}')

# native riparian
# curs.execute('SELECT ReachAttributes.ReachID, ExistingRiparianMean - (ExInv / TotCells), HistoricRiparianMean FROM ReachAttributes'
Expand Down
2 changes: 1 addition & 1 deletion packages/rcat/rcat/rcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def rcat(huc: int, existing_veg: Path, historic_veg: Path, hillshade: Path, pitf
project = RSProject(cfg, output_folder)
project.create(project_name, 'RCAT', [
RSMeta('Model Documentation', 'https://tools.riverscapes.net/rcat', RSMetaTypes.URL, locked=True),
RSMeta(f'HUC', str(huc), RSMetaTypes.HIDDEN, locked=True),
RSMeta('HUC', str(huc), RSMetaTypes.HIDDEN, locked=True),
RSMeta('Hydrologic Unit Code', str(huc), locked=True),
], meta)

Expand Down

0 comments on commit 9630d88

Please sign in to comment.