Beispiel #1
0
 def test_colorramps(self):
     """make sure our colorramps are happy"""
     c = plot.james()
     self.assertEquals(c.N, 12)
     c = plot.james2()
     self.assertEquals(c.N, 12)
     c = plot.whitebluegreenyellowred()
     self.assertEquals(c.N, 236)
     c = plot.nwssnow()
     self.assertEquals(c.N, 11)
Beispiel #2
0
def test_colorramps():
    """make sure our colorramps are happy"""
    c = plot.james()
    assert c.N == 12
    c = plot.james2()
    assert c.N == 12
    c = plot.whitebluegreenyellowred()
    assert c.N == 236
    c = plot.nwssnow()
    assert c.N == 11
Beispiel #3
0
 def test_colorramps(self):
     """make sure our colorramps are happy"""
     c = plot.james()
     self.assertEquals(c.N, 12)
     c = plot.james2()
     self.assertEquals(c.N, 12)
     c = plot.whitebluegreenyellowred()
     self.assertEquals(c.N, 236)
     c = plot.nwssnow()
     self.assertEquals(c.N, 11)
Beispiel #4
0
def main():
    """Go Main."""
    SQUAW = get_dbconn("squaw")
    cursor = SQUAW.cursor()

    data = np.ma.ones((datetime.date.today().year - 1990 + 1, 53), "f") * -99.0
    data.mask = np.where(data < 0, True, False)
    cursor.execute("""
      SELECT extract(year from valid)::int as yr,
      extract(week from valid)::int as week,
      avg(cfs) from real_flow GROUP by yr, week
    """)

    for row in cursor:
        data[row[0] - 1990, row[1] - 1] = row[2]

    levels = np.percentile(
        np.where(data < 0, 0, data), [10, 20, 30, 40, 50, 60, 70, 80, 90, 99]
    )
    norm = mpcolors.BoundaryNorm(levels, 12)

    cmap = james()
    cmap.set_under("#FFFFFF")
    (fig, ax) = plt.subplots(1, 1)
    res = ax.imshow(
        np.flipud(data),
        interpolation="nearest",
        extent=(1, 54, 1989.5, 2015.5),
        cmap=cmap,
        norm=norm,
        aspect="auto",
    )
    ax.set_xticks(np.arange(1, 56, 7))
    ax.set_xlim(1, 53)
    ax.set_xticklabels(
        ("Jan 1", "Feb 19", "Apr 8", "May 27", "Jul 15", "Sep 2", "Oct 21",
         "Dec 9")
    )
    ax.grid()
    ax.set_title(
      "Squaw Creek @ Lincoln Way in Ames\nWeekly Average Streamflow"
    )
    ax.set_ylabel("Year")
    ax.set_xlabel("Day of Year")
    fig.colorbar(res, extend="both", label="Cubic Feet per Second")
    fig.savefig("test.png")
Beispiel #5
0
--  select model_twp, sum(slope * length) / sum(length) as val from 
-- flowpath_points f, iatwp i where ST_Contains(i.the_geom, f.geom) 
-- GROUP by model_twp
-- )

-- SELECT ST_Transform(the_geom, 4326), data.val * 100.0, data.model_twp from iatwp i JOIN data on (data.model_twp = i.model_twp)

SELECT ST_Transform(the_geom, 4326), model_twp from iatwp i

""")

bins = np.arange(0, 18, 2)
# cmap = cm.get_cmap('BrBG')
# cmap.set_under('orange')
# cmap.set_over('black')
cmap = james()
cmap.set_under("white")
cmap.set_over("black")
norm = mpcolors.BoundaryNorm(bins, cmap.N)
patches = []
for row in cursor:
    geom = loads(row[0].decode("hex"))
    for polygon in geom:
        a = np.asarray(polygon.exterior)
        x, y = m.map(a[:, 0], a[:, 1])
        a = zip(x, y)
        # c = cmap( norm([float(row[1]),]) )[0]
        diff = data.get(row[1], 0) - data1.get(row[1], 0)
        diff = data.get(row[1], 0)
        c = cmap(norm([float(diff)]))[0]
        p = Polygon(a, fc=c, ec="None", zorder=2, lw=0.1)
Beispiel #6
0
aly    0.39560439560439560440
wpc    0.36263736263736263736
afc    0.31868131868131868132
lkn    0.31868131868131868132
akq    0.26373626373626373626
abr    0.26373626373626373626
bro    0.23076923076923076923
zan    0.21978021978021978022
mtr    0.18681318681318681319
unr    0.18681318681318681319
sto    0.17582417582417582418
pih    0.15384615384615384615
eka    0.06593406593406593407
roc    0.03296703296703296703
lms    0.02197802197802197802
zjx    0.02197802197802197802
zma    0.02197802197802197802
rev    0.02197802197802197802"""
d = {}
for line in data.split("\n"):
    tokens = line.split()
    d[tokens[0].upper()] = float(tokens[1])

m = MapPlot(sector='nws', axisbg='white', nologo=True,
            subtitle='Main NWS WFO Rooms Only, NWSBot messages not included', caption='@akrherz',
            title='22 Oct 2015 - 21 Jan 2016 NWSChat Avg Number of Room Messages per Day')
m.fill_cwas(d, lblformat='%.1f', ilabel=True, cmap=james(),
            bins=[0, 0.5, 1, 1.5, 2, 3, 4, 5, 10, 15, 20, 40])
m.postprocess(filename='test.png')

Beispiel #7
0
data = np.ma.ones((26, 53), 'f') * -99.0
data.mask = np.where(data < 0, True, False)
cursor.execute("""
  SELECT extract(year from valid) as yr, extract(week from valid) as week,
  avg(cfs) from real_flow GROUP by yr, week

""")

for row in cursor:
    data[row[0] - 1990, row[1] - 1] = row[2]

levels = np.percentile(np.where(data < 0, 0, data),
                       [10, 20, 30, 40, 50, 60, 70, 80, 90, 99])
norm = mpcolors.BoundaryNorm(levels, 12)

cmap = james()
cmap.set_under("#FFFFFF")
(fig, ax) = plt.subplots(1, 1)
res = ax.imshow(np.flipud(data), interpolation='nearest',
                extent=(1, 54, 1989.5, 2015.5), cmap=cmap,
                norm=norm, aspect='auto')
ax.set_xticks(np.arange(1, 56, 7))
ax.set_xlim(1, 53)
ax.set_xticklabels(('Jan 1', 'Feb 19', 'Apr 8', 'May 27', 'Jul 15',
                    'Sep 2', 'Oct 21', 'Dec 9'))
ax.grid()
ax.set_title("Squaw Creek @ Lincoln Way in Ames\nWeekly Average Streamflow")
ax.set_ylabel("Year")
ax.set_xlabel("Day of Year")
fig.colorbar(res, extend='both', label='Cubic Feet per Second')
fig.savefig('test.png')