Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	ControlTable_StreamCat.csv
  • Loading branch information
seliarose committed Sep 9, 2024
2 parents acd5e60 + 945d0f7 commit 265f81b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 52 deletions.
18 changes: 16 additions & 2 deletions ControlTable_StreamCat.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
FullTableName,accum_type,MetricName,AppendMetric,LandscapeLayer,summaryfield,Final_Table_Name,MetricType,Conversion,by_RPU,use_mask,run,notes,Published,Metadata Published,InAPIDatabase,Date Added
AgDrain,Categorical,lookup/AgDrain_lookup.csv,none,AgDrain_stlvl_FINAL.tif,,AgDrain,Percent,1,0,0,0,,Yes,Yes,,7/10/2020
Ag2006HiSlp,Categorical,lookup/Ag2006HiSlp_lookup.csv,none,Ag2006HiSlp.tif,,AgMidHiSlopes,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2006MidSlp,Categorical,lookup/Ag2006MidSlp_lookup.csv,none,Ag2006MidSlp.tif,,AgMidHiSlopes,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2001HiSlp,Categorical,lookup/Ag2001HiSlp_lookup.csv,none,Ag2001HiSlp.tif,,AgMidHiSlopes2001,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2001MidSlp,Categorical,lookup/Ag2001MidSlp_lookup.csv,none,Ag2001MidSlp.tif,,AgMidHiSlopes2001,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2004HiSlp,Categorical,lookup/Ag2006HiSlp_lookup.csv,none,Ag2004HiSlp.tif,,AgMidHiSlopes2004,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2004MidSlp,Categorical,lookup/Ag2006MidSlp_lookup.csv,none,Ag2004MidSlp.tif,,AgMidHiSlopes2004,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2006HiSlp,Categorical,lookup/Ag2006HiSlp_lookup.csv,none,Ag2006HiSlp.tif,,AgMidHiSlopes2006,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2006MidSlp,Categorical,lookup/Ag2006MidSlp_lookup.csv,none,Ag2006MidSlp.tif,,AgMidHiSlopes2006,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2008HiSlp,Categorical,lookup/Ag2008HiSlp_lookup.csv,none,Ag2008HiSlp.tif,,AgMidHiSlopes2008,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2008MidSlp,Categorical,lookup/Ag2008MidSlp_lookup.csv,none,Ag2008MidSlp.tif,,AgMidHiSlopes2008,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2011HiSlp,Categorical,lookup/Ag2011HiSlp_lookup.csv,none,Ag2011HiSlp.tif,,AgMidHiSlopes2011,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2011MidSlp,Categorical,lookup/Ag2011MidSlp_lookup.csv,none,Ag2011MidSlp.tif,,AgMidHiSlopes2011,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2013HiSlp,Categorical,lookup/Ag2013HiSlp_lookup.csv,none,Ag2013HiSlp.tif,,AgMidHiSlopes2013,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2013MidSlp,Categorical,lookup/Ag2013MidSlp_lookup.csv,none,Ag2013MidSlp.tif,,AgMidHiSlopes2013,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2016HiSlp,Categorical,lookup/Ag2016HiSlp_lookup.csv,none,Ag2016HiSlp.tif,,AgMidHiSlopes2016,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2016MidSlp,Categorical,lookup/Ag2016MidSlp_lookup.csv,none,Ag2016MidSlp.tif,,AgMidHiSlopes2016,Percent,1,0,0,0,,Yes,no,,1/21/2021
Ag2019HiSlp,Categorical,lookup/Ag2019HiSlp_lookup.csv,none,Ag2019HiSlp.tif,,AgMidHiSlopes2019,Percent,1,0,0,1,,Yes,no,,1/21/2021
Ag2019MidSlp,Categorical,lookup/Ag2019MidSlp_lookup.csv,none,Ag2019MidSlp.tif,,AgMidHiSlopes2019,Percent,1,0,0,0,,Yes,no,,1/21/2021
CBNF,Continuous,CBNF,none,cbnf.tif,,AgriculturalNitrogen,Mean,1,0,0,0,,Yes,yes,Yes,1/21/2021
Fert,Continuous,Fert,none,fert.tif,,AgriculturalNitrogen,Mean,1,0,0,0,,Yes,yes,Yes,1/21/2021
Manure,Continuous,Manure,none,manure.tif,,AgriculturalNitrogen,Mean,1,0,0,0,,Yes,yes,Yes,1/22/2021
Expand Down
34 changes: 20 additions & 14 deletions PartitionDownscaledResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

# Nutrient file
#nut_dir = 'O:/PRIV/CPHEA/PESD/COR/CORFILES/Geospatial_Library_Projects/StreamCat/NutrientInventory/Inputs/'
nut_dir = 'E:/WorkingData/To_Be_Flow_Accumulated/'
nut = pd.read_csv(nut_dir + 'ClimTerms_2012_10.csv')
# nut_dir = 'E:/WorkingData/To_Be_Flow_Accumulated/'
# nut = pd.read_csv(nut_dir + 'ClimTerms_2012_10.csv')
nut_dir = 'O:/PRIV/CPHEA/PESD/COR/CORFILES/Geospatial_Library_Projects/AmaliaHandler/'
nut = pd.read_csv(nut_dir + 'ToBeFlowAccumulated.csv')

cat_area = pd.read_csv('O:/PRIV/CPHEA/PESD/COR/CORFILES/Geospatial_Library_Projects/StreamCat/NutrientInventory/Inputs/COMID_Scaled_AgVars.csv')
cat_area = cat_area[['COMID','CatAreaSqKm']]
cat_area.head()
Expand All @@ -35,15 +38,18 @@
list(nut)

# select columns - this part we can modify to iterate through columns
final = nut[['COMID', 'SNOW_YrMean', 'CatAreaSqKm', 'VPU']]
final = final.rename(columns={'SNOW_YrMean': 'CatSum'})
final['CatCount'] = final['CatAreaSqKm']
final['CatPctFull'] = 100
final = final.set_axis(['COMID', 'CatSum', 'CatAreaSqKm','VPU', 'CatCount', 'CatPctFull'], axis=1)

for i in VPU:
print(i)
df = final[final['VPU'] == i]
df = df.drop(columns=['VPU'])
df.to_csv(nut_dir + '/Allocation_and_Accumulation/SNOW_YrMean_' + str(i) + '.csv',
index=False)
cols = [i for i in nut.columns if i not in ["COMID", "VPU", "CatAreaSqKm"]]
for col in cols:
final = nut[['COMID', col, 'CatAreaSqKm', 'VPU']]
final = final.rename(columns={'SNOW_YrMean': 'CatSum'})
final['CatCount'] = final['CatAreaSqKm']
final['CatSum'] = final['CatSum'] * final['CatCount']
final['CatPctFull'] = 100
final = final.set_axis(['COMID', 'CatSum', 'CatAreaSqKm','VPU', 'CatCount', 'CatPctFull'], axis=1)

for i in VPU:
print(i)
df = final[final['VPU'] == i]
df = df.drop(columns=['VPU'])
df.to_csv(nut_dir + '/Allocation_and_Accumulation/SNOW_YrMean_' + str(i) + '.csv',
index=False)
72 changes: 36 additions & 36 deletions StreamCat.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,34 @@
end="",
flush=True,
)
# for zone, hydroregion in INPUTS.items():
# if not os.path.exists(f"{OUT_DIR}/{row.FullTableName}_{zone}.csv"):
# print(zone, end=", ", flush=True)
# pre = f"{NHD_DIR}/NHDPlus{hydroregion}/NHDPlus{zone}"
# if not row.accum_type == "Point":
# izd = (
# f"{mask_dir}/{zone}.tif"
# if mask_dir
# else f"{pre}/NHDPlusCatchment/cat"
# )
# cat = createCatStats(
# row.accum_type,
# layer,
# izd,
# OUT_DIR,
# zone,
# row.by_RPU,
# mask_dir,
# NHD_DIR,
# hydroregion,
# apm,
# )
# if row.accum_type == "Point":
# izd = f"{pre}/NHDPlusCatchment/Catchment.shp"
# cat = PointInPoly(
# points, zone, izd, pct_full, mask_dir, apm, summary
# )
# cat.to_csv(f"{OUT_DIR}/{row.FullTableName}_{zone}.csv", index=False)
for zone, hydroregion in INPUTS.items():
if not os.path.exists(f"{OUT_DIR}/{row.FullTableName}_{zone}.csv"):
print(zone, end=", ", flush=True)
pre = f"{NHD_DIR}/NHDPlus{hydroregion}/NHDPlus{zone}"
if not row.accum_type == "Point":
izd = (
f"{mask_dir}/{zone}.tif"
if mask_dir
else f"{pre}/NHDPlusCatchment/cat"
)
cat = createCatStats(
row.accum_type,
layer,
izd,
OUT_DIR,
zone,
row.by_RPU,
mask_dir,
NHD_DIR,
hydroregion,
apm,
)
if row.accum_type == "Point":
izd = f"{pre}/NHDPlusCatchment/Catchment.shp"
cat = PointInPoly(
points, zone, izd, pct_full, mask_dir, apm, summary
)
cat.to_csv(f"{OUT_DIR}/{row.FullTableName}_{zone}.csv", index=False)
print("done!")
print("Accumulating...", end="", flush=True)
for zone in INPUTS:
Expand Down Expand Up @@ -184,11 +184,11 @@
final = pd.merge(cat, upFinal, on="COMID")
final.to_csv(f"{OUT_DIR}/{row.FullTableName}_{zone}.csv", index=False)
print(end="") if processed else print("done!")
if already_processed:
print(
"\n!!!Processing Problem!!!\n\n"
f"{', '.join(already_processed)} already run!\n"
"Be sure to delete the associated files in your `OUTDIR` to rerun:"
f"\n\t> {OUT_DIR}\n\n!!! `$OUT_DIR/DBF_stash/*` "
f"output used in 'Continuous' and 'Categorical' metrics!!!"
)
if already_processed:
print(
"\n!!!Processing Problem!!!\n\n"
f"{', '.join(already_processed)} already run!\n"
"Be sure to delete the associated files in your `OUTDIR` to rerun:"
f"\n\t> {OUT_DIR}\n\n!!! `$OUT_DIR/DBF_stash/*` "
f"output used in 'Continuous' and 'Categorical' metrics!!!"
)

0 comments on commit 265f81b

Please sign in to comment.