<commit_before>from pyiem.plot import MapPlot
import mx.DateTime
import numpy as np
import psycopg2
from pyiem.network import Table as NetworkTable
st = NetworkTable('IACLIMATE')
COOP = psycopg2.connect(database='coop', host='iemdb', user='nobody')
ccursor = COOP.cursor()

ts = mx.DateTime.now() - mx.DateTime.RelativeDateTime(days=1)

nrain = []
lats = []
lons = []

# Get normals!
ccursor.execute("""SELECT station, sum(precip) as acc from climate51
    WHERE valid <= '2000-%s' and station NOT IN ('IA7842','IA4381')
    and substr(station,0,3) = 'IA'
    GROUP by station ORDER by acc ASC""" % (ts.strftime("%m-%d"), ))
for row in ccursor:
    station = row[0]
    if station not in st.sts:
        continue
    nrain.append(row[1])
    lats.append(st.sts[station]['lat'])
    lons.append(st.sts[station]['lon'])

m = MapPlot(axisbg='white',
            title=("Iowa %s Normal Precipitation Accumulation"
                   ) % (ts.strftime("%Y"), ),
            subtitle="1 Jan - %s" % (ts.strftime("%d %b %Y"), ))
m.contourf(lons, lats, nrain, np.arange(int(min(nrain))-1, int(max(nrain))+1),
           units='inch')
pqstr = "plot c 000000000000 summary/year/normals.png bogus png"
m.postprocess(view=False, pqstr=pqstr)
m.close()

# ----------------------------------
# - Compute departures
nrain = []
lats = []
lons = []
ccursor.execute("""select climate.station, norm, obs from
    (select c.station, sum(c.precip) as norm from climate51 c
     where c.valid < '2000-%s' and substr(station,0,3) = 'IA'
     GROUP by c.station) as climate,
    (select a.station, sum(a.precip) as obs from alldata a
     WHERE a.year = %s and substr(a.station,0,3) = 'IA'
     GROUP by station) as obs
  WHERE obs.station = climate.station""" % (ts.strftime("%m-%d"), ts.year))
for row in ccursor:
    station = row[0]
    if station not in st.sts:
        continue
    nrain.append(row[2] - row[1])
    lats.append(st.sts[station]['lat'])
    lons.append(st.sts[station]['lon'])

m = MapPlot(axisbg='white',
            title=("Iowa %s Precipitation Depature"
                   ) % (ts.strftime("%Y"), ),
            subtitle="1 Jan - %s" % (ts.strftime("%d %b %Y"), ))
m.contourf(lons, lats, nrain, np.arange(int(min(nrain))-1, int(max(nrain))+1),
           units='inch')
pqstr = "plot c 000000000000 summary/year/diff.png bogus png"
m.postprocess(view=False, pqstr=pqstr)
m.close()<commit_msg>correct issue with yearly precip plot for early in year<commit_after>from pyiem.plot import MapPlot
import datetime
import numpy as np
import psycopg2
from pyiem.network import Table as NetworkTable
st = NetworkTable('IACLIMATE')
COOP = psycopg2.connect(database='coop', host='iemdb', user='nobody')
ccursor = COOP.cursor()

ts = datetime.datetime.now() - datetime.timedelta(days=1)

nrain = []
lats = []
lons = []

# Get normals!
ccursor.execute("""SELECT station, sum(precip) as acc from climate51
    WHERE valid <= '2000-%s' and station NOT IN ('IA7842','IA4381')
    and substr(station,0,3) = 'IA'
    GROUP by station ORDER by acc ASC""" % (ts.strftime("%m-%d"), ))
for row in ccursor:
    station = row[0]
    if station not in st.sts:
        continue
    nrain.append(row[1])
    lats.append(st.sts[station]['lat'])
    lons.append(st.sts[station]['lon'])

m = MapPlot(axisbg='white',
            title=("Iowa %s Normal Precipitation Accumulation"
                   ) % (ts.strftime("%Y"), ),
            subtitle="1 Jan - %s" % (ts.strftime("%d %b %Y"), ))
rng = np.arange(int(min(nrain))-1, int(max(nrain))+1)
if max(nrain) < 10:
    rng = np.arange(0, 10)
m.contourf(lons, lats, nrain, rng, units='inch')
pqstr = "plot c 000000000000 summary/year/normals.png bogus png"
m.postprocess(view=False, pqstr=pqstr)
m.close()

# ----------------------------------
# - Compute departures
nrain = []
lats = []
lons = []
ccursor.execute("""select climate.station, norm, obs from
    (select c.station, sum(c.precip) as norm from climate51 c
     where c.valid < '2000-%s' and substr(station,0,3) = 'IA'
     GROUP by c.station) as climate,
    (select a.station, sum(a.precip) as obs from alldata a
     WHERE a.year = %s and substr(a.station,0,3) = 'IA'
     GROUP by station) as obs
  WHERE obs.station = climate.station""" % (ts.strftime("%m-%d"), ts.year))
for row in ccursor:
    station = row[0]
    if station not in st.sts:
        continue
    nrain.append(row[2] - row[1])
    lats.append(st.sts[station]['lat'])
    lons.append(st.sts[station]['lon'])

m = MapPlot(axisbg='white',
            title=("Iowa %s Precipitation Depature"
                   ) % (ts.strftime("%Y"), ),
            subtitle="1 Jan - %s" % (ts.strftime("%d %b %Y"), ))
rng = np.arange(int(min(nrain))-1, int(max(nrain))+1)
if max(nrain) < 10:
    rng = np.arange(0, 10)
m.contourf(lons, lats, nrain, rng, units='inch')
pqstr = "plot c 000000000000 summary/year/diff.png bogus png"
m.postprocess(view=False, pqstr=pqstr)
m.close()
{'fraction_non_alphanumeric': 0.18089223874516194, 'fraction_numerical': 0.028111631696883275, 'mean_word_length': 3.2770034843205575, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1422515', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1755, 'n_words': 430}