Skip to content

Commit

Permalink
Merge pull request dailyerosion#239 from akrherz/240530
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Jun 4, 2024
2 parents 5bedcde + 97e1fc5 commit 271b8c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
13 changes: 13 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version = 1

[[analyzers]]
name = "javascript"

[analyzers.meta]
environment = ["jquery"]

[[analyzers]]
name = "python"

[analyzers.meta]
runtime_version = "3.x.x"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.6"
rev: "v0.4.7"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
39 changes: 20 additions & 19 deletions scripts/tillage/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,35 @@ def iowa():
text(
"""
WITH iahuc12 as (
SELECT huc_12, mlra_id, average_slope_ratio from huc12
where states = 'IA' and scenario = 0
SELECT huc_12, mlra_id, average_slope_ratio,
substr(states, 1, 2) as state from huc12 where scenario = 0
), agg as (
SELECT r.huc_12, i.mlra_id, i.average_slope_ratio,
SELECT r.huc_12, i.mlra_id, i.state, i.average_slope_ratio,
r.scenario, extract(year from valid)::int as yr,
sum(qc_precip) as precip, sum(avg_runoff) as runoff,
sum(avg_delivery) as delivery,
sum(avg_loss) as detachment from results_by_huc12 r JOIN iahuc12 i
on (r.huc_12 = i.huc_12) WHERE r.scenario = ANY(:scenarios)
and r.valid >= '2008-01-01'
and r.valid <= '2024-01-01'
GROUP by r.huc_12, r.scenario, i.mlra_id, i.average_slope_ratio, yr
GROUP by r.huc_12, i.state, r.scenario, i.mlra_id,
i.average_slope_ratio, yr
)
SELECT yr, huc_12, scenario, mlra_id, average_slope_ratio,
SELECT yr, state, huc_12, scenario, mlra_id, average_slope_ratio,
round((avg(precip) / 25.4)::numeric, 2) as precip_in,
round((avg(runoff) / 25.4)::numeric, 2) as runoff_in,
round((avg(delivery) * 4.463)::numeric, 2) as delivery_ta,
round((avg(detachment) * 4.463)::numeric, 2) as detachment_ta
from agg GROUP by yr, huc_12, scenario, mlra_id, average_slope_ratio
from agg GROUP by yr, huc_12, state, scenario, mlra_id,
average_slope_ratio
ORDER by yr, scenario
"""
),
conn,
params={"scenarios": list(SCENARIO2TILLAGE.keys())},
)
df["State"] = "Iowa"
df = df.drop(columns=["mlra_id", "huc_12"])
df = df.rename(
columns={
Expand All @@ -68,10 +69,11 @@ def iowa():
"detachment_ta": "Annual_Det_T/ac",
}
)
"""
l6 = (
df[(df["Year"] >= 2017) & (df["Year"] < 2023)]
.drop(columns=["Year"])
.groupby(["scenario", "State"])
.groupby(["scenario", "HUC12"])
.mean()
.reset_index()
.copy()
Expand All @@ -86,7 +88,7 @@ def iowa():
)
lt = (
df.drop(columns=["Year"])
.groupby(["scenario", "State"])
.groupby(["scenario", "HUC12"])
.mean()
.reset_index()
.copy()
Expand All @@ -99,25 +101,25 @@ def iowa():
}
)
)
df = pd.merge(lt, l6, on=["scenario", "State"])
df = pd.merge(lt, l6, on=["scenario", "HUC12"])
df["Till_Code"] = df["scenario"].map(SCENARIO2TILLAGE)
# df["HUC8"] = df["HUC12"].str.slice(0, 8)
df["HUC8"] = df["HUC12"].str.slice(0, 8)
df.drop(columns=["Slope_x"]).rename(
columns={
# "MLRA_y": "MLRA",
"Slope_y": "Slope",
}
).to_csv("IA_LongTerm.csv", index=False)
).to_csv("HUC12_LongTerm.csv", index=False)
"""
# reorder
df = df.groupby(["State", "Year", "scenario"]).mean().reset_index().copy()
df = df.groupby(["state", "Year", "scenario"]).mean().reset_index().copy()
df["Till_Code"] = df["scenario"].map(SCENARIO2TILLAGE)
#df["HUC8"] = df["HUC12"].str.slice(0, 8)
# df["HUC8"] = df["HUC12"].str.slice(0, 8)
df[
[
"State",
#"MLRA",
#"HUC8",
"state",
# "MLRA",
# "HUC8",
"Till_Code",
"scenario",
"Slope",
Expand All @@ -127,8 +129,7 @@ def iowa():
"Annual_Det_T/ac",
"Annual_Del_T/ac",
]
].to_csv("IA_annual.csv", index=False)
"""
].to_csv("State_annual.csv", index=False)


if __name__ == "__main__":
Expand Down

0 comments on commit 271b8c5

Please sign in to comment.