Skip to content

Commit

Permalink
Merge pull request dailyerosion#237 from akrherz/240524
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored May 30, 2024
2 parents f6bbd59 + dec7440 commit 5bedcde
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
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.5"
rev: "v0.4.6"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
17 changes: 11 additions & 6 deletions scripts/dynamic_tillage/nass_comparison.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Plot our planting progress vs that of NASS."""

import os
from datetime import date, timedelta

import click
import geopandas as gpd
import numpy as np
Expand Down Expand Up @@ -28,9 +31,10 @@ def compute_limits(huc12s, year):
rows = []
# June 10th is mud-it-in and we have no estimates then
for dt in pd.date_range(f"{year}-04-11", f"{year}-06-09"):
status = pd.read_feather(
f"/mnt/idep2/data/huc12status/{year}/{dt:%Y%m%d}.feather"
)
pfn = f"/mnt/idep2/data/huc12status/{year}/{dt:%Y%m%d}.feather"
if not os.path.isfile(pfn):
continue
status = pd.read_feather(pfn)
status = status.loc[huc12s]
sz = len(huc12s)
rows.append(
Expand Down Expand Up @@ -173,9 +177,10 @@ def main(year, district, state, crop):
# accumulate acres planted by date
accum = fields[["plant", "acres"]].groupby("plant").sum().cumsum()
accum["percent"] = accum["acres"] / fields["acres"].sum() * 100.0
accum = accum.reindex(
pd.date_range(f"{year}-04-11", f"{year}-05-08")
).ffill()
ldate = f"{year}-06-09"
if ldate >= f"{date.today():%Y-%m-%d}":
ldate = f"{(date.today() - timedelta(days=1)):%Y-%m-%d}"
accum = accum.reindex(pd.date_range(f"{year}-04-11", ldate)).ffill()

if state is not None:
title = f"state of {state_names[state]}"
Expand Down
3 changes: 2 additions & 1 deletion scripts/import/flowpath2prj.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def do_flowpath(pgconn, scenario, zone, metadata):
f"/i/{scenario}/prj/{res['huc8']}/{res['huc12'][-4:]}/"
f"{res['huc12']}_{metadata['fpath']}.prj"
)
res["length"] = df.iloc[0]["real_length"] # all rows are equal
# Add up the OFEs to get the total length
res["length"] = df.groupby("ofe").first()["real_length"].sum()

# Slope data
# Here be dragons: dailyerosion/dep#79 dailyerosion/dep#158
Expand Down
43 changes: 34 additions & 9 deletions scripts/tillage/residue_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,8 @@ def curate():
fields.to_feather("residue.feather")


def main():
"""Go Main."""
if not os.path.isfile("residue.feather"):
curate()
fields = pd.read_feather("residue.feather")
fields = fields[
(fields["prevlanduse"].isin(["C"]))
& (fields["landuse"].isin(["C", "B"]) & (fields["residue"] >= 0))
]
def plot_assignment(fields):
""""""
fig, ax = figure_axes(
title="DEP Tillage Code Assignment after Corn with Residue",
logo="dep",
Expand All @@ -122,5 +115,37 @@ def main():
fig.savefig("test.png")


def main():
"""Go Main."""
if not os.path.isfile("residue.feather"):
curate()
fields = pd.read_feather("residue.feather")
fields = fields[
(fields["prevlanduse"].isin(["C", "B"]))
& (fields["landuse"].isin(["C", "B"]) & (fields["residue"] >= 0))
]
fig, ax = figure_axes(
title=(
"2017-2022 Distribution of Residue "
"Cover Estimate after Given Crop"
),
logo="dep",
figsize=(8, 6),
)

sns.despine(fig)

sns.histplot(
fields,
x="residue",
hue="prevlanduse",
element="step",
bins=100,
)
ax.grid(True)

fig.savefig("test.png")


if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion scripts/util/rot2verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ def main(huc12):
if lastline != "":
outfh.write(f"{lastline}\n")
lastline = ""
outfh.write(f"{now:%Y %03j} 0\n")
else:
outfh.write(f"{now:%Y %03j} 0\n")
now = now + timedelta(days=1)
# Need to accumulate the data per Grace needs
if dt == lastdt:
outfh.write(
f"{lastline} {tokens[5]:>20s} {tokens[6]}\n"
)
lastline = ""
now = now + timedelta(days=1)
elif lastline != "":
outfh.write(f"{lastline}\n")
lastline = ""
now = now + timedelta(days=1)
else:
lastline = (
f"{dt:%Y %03j} 1 {tokens[5]:>20s} {tokens[6]}"
Expand Down

0 comments on commit 5bedcde

Please sign in to comment.