Skip to content

Commit

Permalink
standardize color ramps and values as per #60
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Jun 25, 2018
1 parent 54f73ab commit 6f0a61d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docs/meetings.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Claude, Miller, Gelder, Bates, Cruse, Andrea
- Upcoming funded work on evaluating prairie strings within DEP
- Dr Bruno Basso has some sort of digitial corn yield map that would be nice
to use to identify HEL
- [ ] stabilize the ramps used on plots and on the maps
- akrherz/dep#60 stabilize the ramps used on plots and on the maps
- [ ] create state-only images as possible for twitter upload

15 May 2018 - Website HCI + ISU Luggage
Expand Down
46 changes: 12 additions & 34 deletions htdocs/auto/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import memcache
from shapely.wkb import loads
import numpy as np
from jenks import jenks
from pyiem.plot.colormaps import james, james2
from pyiem.util import get_dbconn, ssw
from pyiem.dep import RAMPS

V2NAME = {
'avg_loss': 'Detachment',
Expand All @@ -31,28 +32,6 @@
}


def myjenks(array, label, sz=6):
"""Create classification breaks for the array"""
a = list(set(jenks(array, sz)))
# Some failures happen when number of values > 0 is less than 6
# sys.stderr.write(label + str(a))
a.sort()
if max(a) == 0:
return [0]
if a[1] < 0.01:
newa = [a[0]]
for _ in a[1:]:
if _ > 0.01:
newa.append(_)
a = newa
# sys.stderr.write(label + str(a))
if max(a) == 0 or len(a) < 2:
return [0]
if a[0] == 0 and a[1] > 0.001:
a[0] = 0.001
return [float(_) for _ in a]


def make_map(ts, ts2, scenario, v):
"""Make the map"""
import matplotlib
Expand All @@ -65,16 +44,16 @@ def make_map(ts, ts2, scenario, v):

# suggested for runoff and precip
if v in ['qc_precip', 'avg_runoff']:
c = ['#ffffa6', '#9cf26d', '#76cc94', '#6399ba', '#5558a1']
# c = ['#ffffa6', '#9cf26d', '#76cc94', '#6399ba', '#5558a1']
cmap = james()
# suggested for detachment
elif v in ['avg_loss']:
c = ['#cbe3bb', '#c4ff4d', '#ffff4d', '#ffc44d', '#ff4d4d', '#c34dee']
# c = ['#cbe3bb', '#c4ff4d', '#ffff4d', '#ffc44d', '#ff4d4d', '#c34dee']
cmap = james2()
# suggested for delivery
elif v in ['avg_delivery']:
c = ['#ffffd2', '#ffff4d', '#ffe0a5', '#eeb74d', '#ba7c57', '#96504d']
cmap = mpcolors.ListedColormap(c, 'james')
cmap.set_under('white')
cmap.set_over('black')
# c = ['#ffffd2', '#ffff4d', '#ffe0a5', '#eeb74d', '#ba7c57', '#96504d']
cmap = james2()

pgconn = get_dbconn('idep')
cursor = pgconn.cursor()
Expand Down Expand Up @@ -123,12 +102,11 @@ def make_map(ts, ts2, scenario, v):
patches.append(p)
data.append(row[1])
data = np.array(data) * V2MULTI[v]
if np.max(data) < 0.05:
bins = [0.01, 0.02, 0.03, 0.04, 0.05]
if ts == ts2:
# Daily
bins = RAMPS['english'][0]
else:
bins = myjenks(data, 'bah', len(c))
if len(bins) < 3:
bins = [0.01, 0.02, 0.03, 0.04, 0.05]
bins = RAMPS['english'][1]
norm = mpcolors.BoundaryNorm(bins, cmap.N)
for val, patch in zip(data, patches):
c = cmap(norm([val, ]))[0]
Expand Down
39 changes: 12 additions & 27 deletions htdocs/geojson/huc12.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,10 @@
import datetime

import memcache
from jenks import jenks
from pyiem.dep import RAMPS
from pyiem.util import get_dbconn, ssw


def myjenks(array, _label):
"""Create classification breaks for the array"""
a = list(set(jenks(array, 6)))
# Some failures happen when number of values > 0 is less than 6
# sys.stderr.write(label + str(a))
a.sort()
if max(a) == 0:
return [0]
if a[1] < 0.01:
newa = [a[0]]
for _ in a[1:]:
if _ > 0.01:
newa.append(_)
a = newa
# sys.stderr.write(label + str(a))
if max(a) == 0 or len(a) < 2:
return [0]
if a[0] == 0 and a[1] > 0.001:
a[0] = 0.001
return [float(_) for _ in a]


def do(ts, ts2, domain):
"""Do work"""
pgconn = get_dbconn('idep')
Expand Down Expand Up @@ -85,10 +63,17 @@ def do(ts, ts2, domain):
avg_runoff=row[5]),
geometry=json.loads(row[0])
))
res['jenks'] = dict(avg_loss=myjenks(avg_loss, 'avg_loss'),
qc_precip=myjenks(qc_precip, 'qc_precip'),
avg_delivery=myjenks(avg_delivery, 'avg_delivery'),
avg_runoff=myjenks(avg_runoff, 'avg_runoff'))
myramp = RAMPS['english'][0]
if ts2 is not None:
days = (ts2 - ts).days
myramp = RAMPS['english'][1]
if days > 31:
myramp = RAMPS['english'][2]

res['jenks'] = dict(avg_loss=myramp,
qc_precip=myramp,
avg_delivery=myramp,
avg_runoff=myramp)
return json.dumps(res)


Expand Down
4 changes: 2 additions & 2 deletions htdocs/map/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<div class="row row-offcanvas row-offcanvas-right fill">
<div class="col-xs-12 fill">
<div id="map" style="width: 100%; height: 100%; position:fixed;"></div>
<canvas id="colorbar" width="100" height="100"></canvas>
<canvas id="colorbar" width="100" height="150"></canvas>
</div>
<div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar">
<div class="pull-left" id="buttontabs">
Expand Down Expand Up @@ -304,7 +304,7 @@
};
</script>
<script src="nextgen.js?v=4"></script>
<script src="nextgen.js?v=5"></script>
</html>
EOM;
Expand Down
15 changes: 10 additions & 5 deletions htdocs/map/nextgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ var levels = {
'avg_delivery': [[], []]
};
var colors = {
'qc_precip': ['#ffffa6', '#9cf26d', '#76cc94', '#6399ba', '#5558a1', '#c34dee'],
'avg_runoff': ['#ffffa6', '#9cf26d', '#76cc94', '#6399ba', '#5558a1', '#c34dee'],
'avg_loss': ['#cbe3bb', '#c4ff4d', '#ffff4d', '#ffc44d', '#ff4d4d', '#c34dee'],
'avg_delivery': ['#ffffd2', '#ffff4d', '#ffe0a5', '#eeb74d', '#ba7c57', '#96504d']
'qc_precip': ['#FFFF80', '#CDFA64', '#98F046', '#61E827', '#3BD923', '#3FC453',
'#37AD7A', '#26989E', '#217AA3', '#215394', '#1B3187', '#0C1078'],
'avg_runoff': ['#FFFF80', '#CDFA64', '#98F046', '#61E827', '#3BD923', '#3FC453',
'#37AD7A', '#26989E', '#217AA3', '#215394', '#1B3187', '#0C1078'],
// james2
'avg_loss': ['#FFFF80', '#FFEE70', '#FCDD60', '#FACD52', '#F7BE43', '#F5AF36',
'#E69729', '#CC781F', '#B35915', '#9C400E', '#822507', '#6B0000'],
'avg_delivery': ['#FFFF80', '#FFEE70', '#FCDD60', '#FACD52', '#F7BE43', '#F5AF36',
'#E69729', '#CC781F', '#B35915', '#9C400E', '#822507', '#6B0000']
};

/*
Expand Down Expand Up @@ -468,7 +473,7 @@ function drawColorbar(){
var canvas = document.getElementById('colorbar');
var ctx = canvas.getContext('2d');

canvas.height = colors[appstate.ltype].length * 20 + 50;
canvas.height = colors[appstate.ltype].length * 20 + 10;

// Clear out the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
Expand Down

0 comments on commit 6f0a61d

Please sign in to comment.