Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding glasbey colormaps #25

Merged
merged 38 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
35e7e89
Adding first glasbey assets
jsignell Mar 19, 2019
ca257f8
Finishing adding assets
jsignell Mar 20, 2019
d4b0823
Rewriting init
jsignell Mar 20, 2019
abccb18
Changing the naming scheme
jsignell Mar 20, 2019
2eaa035
Adding a new user guide notebook for glasbey
jsignell Mar 20, 2019
eda599c
Adding some glasbey tests
jsignell Mar 20, 2019
268a1ca
Adding bokeh dependency for examples
jsignell Mar 20, 2019
b890242
Adding reference to glasbey
jsignell Mar 20, 2019
7479653
Apply suggestions from code review
jbednar Mar 26, 2019
2094381
Adding new glasbey colormaps
jsignell Mar 26, 2019
e84b883
Adding new colormaps to python module
jsignell Mar 26, 2019
09fa324
Updating notebook
jsignell Mar 26, 2019
987ad32
Remaking image of all named values
jsignell Mar 26, 2019
1973a49
Adding text to explain bw and list
jsignell Mar 26, 2019
3c2391a
Fixing up tests
jsignell Mar 26, 2019
b0c13a7
Updated glasbey descriptions
jbednar Mar 27, 2019
518c673
Changing the included sets and adding hues
jsignell Mar 28, 2019
e324a13
Adding plotting commands
jsignell Mar 28, 2019
9c58c68
Adding new-style plots and cool/warm
jsignell Mar 28, 2019
7897724
Using new plotting in all notebooks
jsignell Mar 28, 2019
bf4af2c
Fixing up tests
jsignell Mar 28, 2019
43ce5a3
Apply suggestions from code review
jsignell Mar 28, 2019
eaed23a
Linting
jsignell Mar 28, 2019
a5b61e8
Added space to aliases list to improve visual grouping
jbednar Mar 28, 2019
49c1c59
Cleaned up descriptions
jbednar Mar 28, 2019
f4ea72c
Clarified main user guide page
jbednar Mar 29, 2019
899613c
Cleaned up homepage
jbednar Mar 29, 2019
8020969
Adding holoviews colormap and changing colormap plot name
jsignell Mar 29, 2019
6c81adb
Adding base index.ipynb to user_guide
jsignell Mar 29, 2019
4fdd5f2
Fixing reference to assets
jsignell Mar 29, 2019
c737f35
Update assets/CET_to_py.py
jbednar Mar 29, 2019
662597c
Getting rid of in-function hv imports
jsignell Mar 29, 2019
d639e82
Linting
jsignell Mar 29, 2019
e815289
Adding module docstring
jsignell Mar 29, 2019
6108fcc
Adding sine comb function to cc
jsignell Apr 1, 2019
52e915d
Using new sine_comb function
jsignell Apr 1, 2019
6c73f0d
linting
jsignell Apr 1, 2019
4097a78
Update examples/user_guide/index.ipynb
jbednar Apr 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 109 additions & 33 deletions assets/CET_to_py.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""
Generate Python versions for each of the colormaps provided in
http://peterkovesi.com/projects/colourmaps/CETperceptual_csv_0_1.zip

Also adds Glasbey colormaps created using: https://github.com/taketwo/glasbey.git
see https://github.com/pyviz/colorcet/issues/11 for more details
"""

import os, os.path, csv

path = 'CETperceptual_csv_0_1'
paths = ['CETperceptual_csv_0_1', 'Glasbey']
output_file = '../colorcet/__init__.py'
header = '''\
"""
Expand All @@ -32,15 +35,22 @@

<category>_<huesequence>_<lightnessrange>_c<meanchroma>[_s<colorshift>_[r<ifreversed>]]

but some have shorter, more convenient aliases, some of which are
inspired by Matplotlib colormaps of the same name and others
based on the qualitative appearance. The colormaps with
but some have shorter, more convenient aliases, some of which are
inspired by Matplotlib colormaps with similar names and others
based on the qualitative appearance. The colormaps with
shorter names tend to be the most useful subset, and for
cases like automatic population of a GUI widget these
colormaps are provided as a separate subset:

palette_n['name'] or palette_n.name
cm_n['name'] or cm_n.name

Also included are some sets of 256 Glasbey colors. These are available via the
same methods described above and are named:

glasbey_<starting_palette>[_<no_gray|dark|light>]

The no_black versions are aliased to their starting palette names.
"""

__version__ = '1.0.0'
Expand All @@ -66,7 +76,7 @@ def register_cmap(name,cmap): pass
LinearSegmentedColormap.from_list=lambda n,c,N: None

def rgb_to_hex(r,g,b):
return '#%02x%02x%02x' % (r,g,b)
return '#%02x%02x%02x' % (r,g,b)

def bokeh_palette(name,colorlist):
palette[name] = [rgb_to_hex(int(r*255),int(g*255),int(b*255)) for r,g,b in colorlist]
Expand All @@ -77,6 +87,65 @@ def mpl_cm(name,colorlist):
register_cmap("cet_"+name, cmap=cm[name])
return cm[name]

def get_aliases(name):
"""Get the aliases for a given colormap name"""
for k, v in aliases.items():
if name == k or name == v:
name = '{0}, {1}'.format(v, k)
return name

def all_original_names(group=None, not_group=None, only_aliased=False):
"""Get all original names - optionally in a particular group - or only those with aliases"""
names = palette.keys()
if group:
names = filter(lambda x: group in x, names)
if not_group:
names = filter(lambda x: not_group not in x, names)
if only_aliased:
names = filter(lambda x: x in aliases.keys(), names)
else:
names = filter(lambda x: x not in aliases.values(), names)
return sorted(list(names))

def colormap(name, cmap=None, bounds=None, array=None,**kwargs):
"""Plot a colormap using matplotlib or bokeh via holoviews"""
import holoviews as hv; from holoviews import opts

title = name if cmap else get_aliases(name)
if bounds is None:
bounds = (0, 0, 256, 1)
if array is None:
import numpy as np
array = np.meshgrid(np.linspace(0, 1, 256), np.linspace(0, 1, 10))[0]

plot = hv.Image(array, bounds=bounds, group=title)
backends = hv.Store.loaded_backends()
if 'bokeh' in backends:
plot.opts(opts.Image(backend='bokeh', width=900, height=100, toolbar='above',
default_tools=['xwheel_zoom', 'xpan', 'save', 'reset'],
cmap=cmap or palette[name]))
if 'matplotlib' in backends:
plot.opts(opts.Image(backend='matplotlib', aspect=15, fig_size=350,
cmap=cmap or cm[name]))
return plot.opts(opts.Image(xaxis=None, yaxis=None), opts.Image(**kwargs))

def colormaps(*args, group=None, not_group=None, only_aliased=False, cols=1, **kwargs):
"""Plot colormaps for given names or names in group"""
import holoviews as hv; from holoviews import opts

args = args or all_original_names(group=group, not_group=not_group,
only_aliased=only_aliased)
plot = hv.Layout([
colormap(arg, **kwargs) if isinstance(arg, str) else
colormap(*arg, **kwargs) for
arg in args]).cols(cols)

backends = hv.Store.loaded_backends()
if 'matplotlib' in backends:
plot.opts(opts.Layout(backend='matplotlib', sublabel_format=None,
fig_size=kwargs.get('fig_size', 350)))
return plot

palette = AttrODict()
cm = AttrODict()
palette_n = AttrODict()
Expand Down Expand Up @@ -106,40 +175,47 @@ def mpl_cm(name,colorlist):
linear_green_5_95_c69 = 'kgy',
linear_grey_0_100_c0 = 'gray', #mpl
linear_grey_10_95_c0 = 'dimgray',
linear_kryw_0_100_c71 = 'fire',
linear_kryw_0_100_c71 = 'fire',
linear_ternary_blue_0_44_c57 = 'kb',
linear_ternary_green_0_46_c42 = 'kg',
linear_ternary_red_0_50_c52 = 'kr',
rainbow_bgyr_35_85_c73 = 'rainbow',
glasbey_bw_minc_20 = 'glasbey',
glasbey_bw_minc_20_minl_30 = 'glasbey_light',
glasbey_bw_minc_20_maxl_70 = 'glasbey_dark',
glasbey_bw_minc_20_hue_330_100 = 'glasbey_warm',
glasbey_bw_minc_20_hue_150_280 = 'glasbey_cool',
)


with open(output_file, "w") as output:
output.write(header)
for filename in os.listdir(path):
if filename.endswith(".csv"):
base = filename[:-4].replace("-","_").replace("_n256","")
output.write("\n\n"+base+" = [\\\n")
with open(os.path.join(path,filename),'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
output.write("["+', '.join(row)+"],\n")
output.write("]\n")
output.write("b_{0} = bokeh_palette('{0}',{0})\n".format(base))
output.write("m_{0} = mpl_cm('{0}',{0})\n".format(base))
output.write("m_{0}_r = mpl_cm('{0}_r',list(reversed({0})))\n".format(base))
if base in aliases:
alias = aliases[base]
output.write("{0} = b_{1}\n".format(alias,base))
output.write("m_{0} = m_{1}\n".format(alias,base))
output.write("m_{0}_r = m_{1}_r\n".format(alias,base))
output.write("palette['{0}'] = b_{1}\n".format(alias,base))
output.write("palette_n['{0}'] = b_{1}\n".format(alias,base))
output.write("cm['{0}'] = m_{1}\n".format(alias,base))
output.write("cm['{0}_r'] = m_{1}_r\n".format(alias,base))
output.write("cm_n['{0}'] = mpl_cm('{0}',{1})\n".format(alias,base))
output.write("cm_n['{0}_r'] = mpl_cm('{0}_r',list(reversed({1})))\n".format(alias,base))
output.write("register_cmap('cet_{0}',m_{1})\n".format(alias,base))
output.write("register_cmap('cet_{0}_r',m_{1}_r)\n".format(alias,base))
output.write("\n\n")
output.write(footer)
output.write("aliases = {}\n".format(aliases))
for path in paths:
for filename in os.listdir(path):
if filename.endswith(".csv"):
base = filename[:-4].replace("-","_").replace("_n256","")
output.write("\n\n"+base+" = [\\\n")
with open(os.path.join(path,filename),'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
output.write("["+', '.join(row)+"],\n")
output.write("]\n")
output.write("b_{0} = bokeh_palette('{0}',{0})\n".format(base))
output.write("m_{0} = mpl_cm('{0}',{0})\n".format(base))
output.write("m_{0}_r = mpl_cm('{0}_r',list(reversed({0})))\n".format(base))
if base in aliases:
alias = aliases[base]
output.write("{0} = b_{1}\n".format(alias,base))
output.write("m_{0} = m_{1}\n".format(alias,base))
output.write("m_{0}_r = m_{1}_r\n".format(alias,base))
output.write("palette['{0}'] = b_{1}\n".format(alias,base))
output.write("palette_n['{0}'] = b_{1}\n".format(alias,base))
output.write("cm['{0}'] = m_{1}\n".format(alias,base))
output.write("cm['{0}_r'] = m_{1}_r\n".format(alias,base))
output.write("cm_n['{0}'] = mpl_cm('{0}',{1})\n".format(alias,base))
output.write("cm_n['{0}_r'] = mpl_cm('{0}_r',list(reversed({1})))\n".format(alias,base))
output.write("register_cmap('cet_{0}',m_{1})\n".format(alias,base))
output.write("register_cmap('cet_{0}_r',m_{1}_r)\n".format(alias,base))
output.write("\n\n")
output.write(footer)
Loading