Skip to content

Commit

Permalink
Merge pull request #40 from akrherz/scenario
Browse files Browse the repository at this point in the history
Better HUC12 Scenario Support
  • Loading branch information
akrherz authored Jan 18, 2024
2 parents e192e52 + 4d47167 commit 09a1a29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ jobs:
- name: Setup CI from ci-tooling
run: |
set -e
git clone --depth 1 https://github.com/akrherz/iem-database.git database
git clone --depth 1 https://github.com/akrherz/ci_tooling.git .ci_tooling
. .ci_tooling/postgres.sh
. .ci_tooling/iemwebfarm.sh
cd .ci_tooling
. postgres.sh
. iemwebfarm.sh
cd ..
15 changes: 12 additions & 3 deletions htdocs/auto/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ def make_map(huc, ts, ts2, scenario, v, form):
title = (
f"averaged between {ts:%-d %b} and {ts2:%-d %b} (2008-2023)"
)
# Compute what the huc12 scenario is for this scenario
cursor.execute(
"select huc12_scenario from scenarios where id = %s", (scenario,)
)
huc12_scenario = cursor.fetchone()[0]

# Check that we have data for this date!
cursor.execute(
Expand All @@ -187,6 +192,7 @@ def make_map(huc, ts, ts2, scenario, v, form):
return ram.read(), False
params = {
"scenario": scenario,
"huc12_scenario": huc12_scenario,
"sday1": f"{ts:%m%d}",
"sday2": f"{ts2:%m%d}",
"ts": ts,
Expand All @@ -212,7 +218,7 @@ def make_map(huc, ts, ts2, scenario, v, form):
f"""
SELECT simple_geom as geom,
dominant_tillage as data
from huc12 i WHERE scenario = :scenario {huclimiter}
from huc12 i WHERE scenario = :huc12_scenario {huclimiter}
"""
),
conn,
Expand All @@ -234,7 +240,8 @@ def make_map(huc, ts, ts2, scenario, v, form):
SELECT simple_geom as geom,
coalesce(d.d, 0) * :dbcol as data
from huc12 i LEFT JOIN data d
ON (i.huc_12 = d.huc_12) WHERE i.scenario = :scenario {huclimiter}
ON (i.huc_12 = d.huc_12) WHERE i.scenario = :huc12_scenario
{huclimiter}
"""
),
conn,
Expand All @@ -255,7 +262,8 @@ def make_map(huc, ts, ts2, scenario, v, form):
SELECT simple_geom as geom,
coalesce(d.d, 0) * :dbcol as data
from huc12 i LEFT JOIN data d
ON (i.huc_12 = d.huc_12) WHERE i.scenario = :scenario {huclimiter}
ON (i.huc_12 = d.huc_12) WHERE i.scenario = :huc12_scenario
{huclimiter}
"""
),
conn,
Expand Down Expand Up @@ -361,6 +369,7 @@ def make_map(huc, ts, ts2, scenario, v, form):
plt.savefig(ram, format="png", dpi=100)
plt.close()
ram.seek(0)
pgconn.close()
return ram.read(), True


Expand Down

0 comments on commit 09a1a29

Please sign in to comment.