From 6f0a61d90e6c62f79e0bd4530809ecf476c19aca Mon Sep 17 00:00:00 2001 From: akrherz Date: Mon, 25 Jun 2018 14:25:21 -0500 Subject: [PATCH] standardize color ramps and values as per #60 --- docs/meetings.md | 2 +- htdocs/auto/map.py | 46 +++++++++++------------------------------ htdocs/geojson/huc12.py | 39 +++++++++++----------------------- htdocs/map/index.php | 4 ++-- htdocs/map/nextgen.js | 15 +++++++++----- 5 files changed, 37 insertions(+), 69 deletions(-) diff --git a/docs/meetings.md b/docs/meetings.md index c232aa21..7e19063e 100644 --- a/docs/meetings.md +++ b/docs/meetings.md @@ -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 diff --git a/htdocs/auto/map.py b/htdocs/auto/map.py index b288a44b..aa5d727d 100755 --- a/htdocs/auto/map.py +++ b/htdocs/auto/map.py @@ -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', @@ -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 @@ -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() @@ -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] diff --git a/htdocs/geojson/huc12.py b/htdocs/geojson/huc12.py index 49506469..4fd90d6e 100755 --- a/htdocs/geojson/huc12.py +++ b/htdocs/geojson/huc12.py @@ -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') @@ -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) diff --git a/htdocs/map/index.php b/htdocs/map/index.php index 2b5e1e13..79dce4b2 100644 --- a/htdocs/map/index.php +++ b/htdocs/map/index.php @@ -132,7 +132,7 @@
- +