Commit e59cf788 authored by Leo Pound Singer's avatar Leo Pound Singer
Browse files

Add 'cylon' color map, make default

Original: b15dd4051a66cfe1b230c4a944319455e0e37ab5
parent 29e3b135
......@@ -32,6 +32,7 @@ __author__ = "Leo Singer <leo.singer@ligo.org>"
from optparse import Option, OptionParser
from lalinference.bayestar import command
import lalinference.cmap
from matplotlib import cm
colormap_choices = sorted(cm.cmap_d.keys())
parser = OptionParser(
......@@ -40,7 +41,7 @@ parser = OptionParser(
option_list = [
Option("-o", "--output", metavar="FILE.{pdf,png}",
help="name of output file [default: plot to screen]"),
Option("--colormap", default="jet", choices=colormap_choices,
Option("--colormap", default="cylon", choices=colormap_choices,
metavar='|'.join(colormap_choices),
help="name of matplotlib colormap [default: %default]"),
Option("--figure-width", metavar="INCHES", type=float, default=8.,
......@@ -128,7 +129,7 @@ if opts.geo:
geojson = json.load(geojson_file)
for shape in geojson['geometries']:
verts = np.deg2rad(shape['coordinates'])
plt.plot(verts[:, 0], verts[:, 1], color='black', linewidth=1, alpha=0.25)
plt.plot(verts[:, 0], verts[:, 1], color='0.5', linewidth=0.5)
# Add markers (e.g., for injections or external triggers).
for ra, dec in np.deg2rad(opts.radec):
......
......@@ -16,6 +16,7 @@ pymoduledir = $(pkgpythondir)
pymodule_PYTHON = \
__init__.py \
cmap.py \
fits.py \
plot.py \
git_version.py \
......@@ -24,5 +25,16 @@ pymodule_PYTHON = \
endif
dist_pymodule_DATA = \
cylon.csv \
ne_simplified_coastline.json \
$(END_OF_LIST)
#
# Note: the following script generates a color map RGB data file.
# The output file is distributed to avoid a build dependency on the Python
# `colormath` package (https://pypi.python.org/pypi/colormath).
#
$(srcdir)/cylon.csv: $(srcdir)/cylon.py
$(AM_V_GEN)$(PYTHON) $< > $@
EXTRA_DIST = cylon.py
#
# Copyright (C) 2014 Leo Singer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""Register some extra Matplotlib color maps"""
from matplotlib import cm
from matplotlib import colors
import numpy as np
import os
for name in ['cylon']:
# Read in color map RGB data.
filename = os.path.join(os.path.dirname(__file__), name + '.csv')
data = np.loadtxt(filename, delimiter=',')
# Create color map.
cmap = colors.LinearSegmentedColormap.from_list(name, data)
# Assign in module.
locals().update({name: cmap})
# Register with Matplotlib.
cm.register_cmap(cmap=cmap)
# Generate reversed color map.
name += '_r'
data = data[::-1]
cmap = colors.LinearSegmentedColormap.from_list(name, data)
# Assign in module.
locals().update({name: cmap})
# Register with Matplotlib.
cm.register_cmap(cmap=cmap)
del name, filename, data, cmap, cm, colors, np, os
# RGB data for the "Cylon red" color map.
#
# A print- and screen-friendly color map designed specifically for plotting
# LSC/Virgo sky maps. The color map is constructed in CIE Lab space, following
# a linear ramp in lightness (the `l` coordinate) and a cubic spline in color
# components (the `a` and `b` coordinates).
#
# This particular color map was selected from 20 random realizations of this
# construction.
1.0,0.939165516411,0.880255669068
1.0,0.929015927765,0.85906171669
1.0,0.918926352488,0.838279657804
1.0,0.908897333222,0.817903334328
1.0,0.898929403412,0.797926649829
1.0,0.8890230863,0.778343571272
1.0,0.879178893918,0.759148130872
1.0,0.869397326063,0.740334428065
1.0,0.859678869268,0.721896631596
1.0,0.850023995757,0.703828981736
1.0,0.840433162392,0.686125792633
1.0,0.830906809602,0.66878145481
1.0,0.821445360307,0.651790437813
1.0,0.812049218818,0.635147293023
1.0,0.802718769731,0.618846656636
1.0,0.793454376798,0.60288325283
1.0,0.784256381791,0.58725189712
1.0,0.775125103341,0.571947499915
1.0,0.766060835764,0.556965070297
1.0,0.75706384787,0.542299720017
1.0,0.74813438175,0.527946667729
1.0,0.739272651553,0.513901243482
1.0,0.730478842231,0.50015889346
1.0,0.721753108278,0.486715184999
1.0,0.71309557244,0.473565811884
1.0,0.704506324408,0.460706599936
1.0,0.695985419489,0.44813351289
1.0,0.687532877261,0.435842658583
1.0,0.679148680195,0.423830295435
1.0,0.670832772271,0.412092839236
1.0,0.662585057553,0.400626870224
1.0,0.654405398758,0.389429140439
1.0,0.64629361579,0.378496581338
1.0,0.638249484251,0.367826311632
1.0,0.630272733933,0.357415645309
1.0,0.622363047276,0.347262099779
1.0,0.6145200578,0.337363404068
1.0,0.60674334851,0.327717506978
1.0,0.599032450269,0.318322585074
1.0,0.591386840141,0.309177050375
1.0,0.583805939689,0.30027955756
1.0,0.576289113248,0.291629010484
1.0,0.56883566615,0.283224567748
1.0,0.561444842902,0.275065647042
1.0,0.554115825322,0.267151927907
1.0,0.546847730611,0.259483352538
1.0,0.539639609375,0.25206012419
1.0,0.53249044357,0.244882702704
1.0,0.525399144381,0.237951796626
1.0,0.518364550007,0.231268351356
1.0,0.511385423358,0.224833532763
1.0,0.504460449645,0.218648705667
1.0,0.497588233845,0.212715406648
1.0,0.490767298027,0.207035310685
1.0,0.483996078536,0.201610191234
1.0,0.47727292298,0.196441873491
1.0,0.470596087039,0.191532180804
1.0,0.463963731027,0.186882874444
1.0,0.457373916211,0.182495587241
1.0,0.450824600824,0.17837175196
1.0,0.444313635749,0.174512525682
1.0,0.437838759821,0.170918711811
1.0,0.431397594686,0.167590681763
1.0,0.424987639172,0.164528298669
1.0,0.418606288029,0.161730843468
1.0,0.412251382522,0.159196900424
1.0,0.405921240166,0.156924298066
1.0,0.399614116034,0.154910116044
1.0,0.393328172817,0.153150662708
1.0,0.387061475008,0.1516414668
1.0,0.380811982476,0.150377286204
1.0,0.374577543372,0.149352133776
1.0,0.368355886257,0.148559319487
1.0,0.362144611348,0.147991507374
1.0,0.35594118076,0.147640785152
1.0,0.349742907582,0.147498743865
1.0,0.343546943632,0.14755656463
1.0,0.33735026566,0.147805109425
1.0,0.331149659782,0.148235012929
1.0,0.324941703835,0.148836772639
1.0,0.318722747318,0.149600834887
1.0,0.3124888885,0.15051767475
1.0,0.306235948201,0.151577868383
1.0,0.299959439627,0.152772156757
1.0,0.293654533542,0.154091500254
1.0,0.287316017842,0.155527123962
1.0,0.280938250436,0.15707055387
1.0,0.274515104023,0.158713644413
1.0,0.268039901027,0.16044859803
1.0,0.261505336481,0.16226797751
1.0,0.254903386043,0.164164711995
1.0,0.24822519553,0.166132097503
1.0,0.241460947266,0.16816379285
1.0,0.234599697066,0.170253811781
1.0,0.227629173635,0.172396512076
1.0,0.220535529331,0.174586582314
1.0,0.213303027169,0.176819026901
1.0,0.205913643092,0.179089149883
1.0,0.198346553893,0.181392537999
1.0,0.190577468164,0.183725043341
1.0,0.182577737534,0.18608276594
1.0,0.174313153688,0.188462036504
1.0,0.165742284624,0.190859399534
1.0,0.156814115737,0.193271596942
1.0,0.147464606437,0.195695552294
1.0,0.137611487116,0.198128355758
1.0,0.127146062713,0.200567249812
1.0,0.115919620559,0.203009615731
1.0,0.10371937833,0.205452960882
1.0,0.0902221437142,0.207894906813
1.0,0.0748939478486,0.210333178135
1.0,0.0567314921333,0.212765592173
1.0,0.0336181509815,0.215190049354
1.0,0.00848641096015,0.217604524321
1.0,0.0,0.220007057716
1.0,0.0,0.222395748617
1.0,0.0,0.224768747585
0.998162708594,0.0,0.227124250288
0.993383567055,0.0,0.229460491669
0.988632706227,0.0,0.231775740618
0.983911459424,0.0,0.234068295122
0.979221154901,0.0,0.236336477866
0.974563115999,0.0,0.238578632234
0.969938661267,0.0,0.240793118716
0.965349104561,0.0,0.242978311655
0.96079575514,0.0,0.245132596351
0.956279917723,0.0,0.247254366456
0.951802892545,0.0,0.249342021679
0.947365420608,0.0,0.251393957558
0.94296602736,0.0,0.253408545838
0.938602701024,0.0,0.255384168584
0.93427344957,0.0,0.257319225373
0.929976300917,0.0,0.259212130785
0.925709303108,0.0,0.261061312138
0.921470524463,0.0,0.262865207443
0.917258053703,0.0,0.26462226357
0.91307000005,0.0,0.266330934608
0.908904493299,0.0,0.267989680404
0.904759683868,0.0,0.26959696528
0.900633742822,0.0,0.271151256899
0.896524861867,0.0,0.272651025288
0.892431253325,0.0,0.274094741995
0.888351150083,0.0,0.275480879383
0.884282805512,0.0,0.276807910036
0.880224493372,0.0,0.278074306294
0.876174507683,0.0,0.279278539885
0.872131162579,0.0,0.280419081663
0.868092792134,0.0,0.281494401443
0.864057750171,0.0,0.282502967927
0.860024410042,0.0,0.283443248712
0.855991164392,0.0,0.284313710387
0.851956424894,0.0,0.285112818698
0.84791862197,0.0,0.285839038798
0.843876204488,0.0,0.286490835562
0.839827639433,0.0,0.287066673966
0.835771411569,0.0,0.287565019543
0.831706023071,0.0,0.287984338892
0.827629993142,0.0,0.288323100256
0.823541857608,0.0,0.288579774155
0.819440168502,0.0,0.288752834082
0.815323493617,0.0,0.288840757255
0.811190416053,0.0,0.288842025426
0.807039533736,0.0,0.288755125752
0.80286945893,0.0,0.288578551716
0.798678817725,0.0,0.288310804112
0.794466249508,0.0,0.287950392084
0.790230406423,0.0,0.287495834226
0.785969952809,0.0,0.286945659743
0.78168356463,0.0,0.28629840967
0.777369928882,0.0,0.285552638163
0.773027742987,0.0,0.284706913844
0.76865571418,0.0,0.283759821228
0.764252558871,0.0,0.282709962212
0.759817002002,0.0,0.281555957643
0.755347776385,0.0,0.280296448968
0.750843622031,0.0,0.278930099968
0.746303285466,0.0,0.277455598576
0.741725519033,0.0,0.275871658798
0.737109080188,0.0,0.274177022731
0.732452730777,0.0,0.272370462696
0.727755236314,0.0,0.270450783483
0.723015365237,0.0,0.26841682473
0.718231888171,0.0,0.266267463437
0.713403577165,0.0,0.264001616628
0.708529204941,0.0,0.261618244185
0.703607544122,0.0,0.25911635185
0.698637366468,0.0,0.256494994433
0.693617442098,0.0,0.253753279229
0.688546538718,0.0,0.250890369676
0.68342342085,0.0,0.247905489271
0.678246849055,0.0,0.244797925779
0.673015564049,0.0,0.24156703607
0.667727954487,0.0,0.238212257429
0.662382061267,0.0,0.234733111669
0.656975911728,0.0,0.231129203368
0.651507534328,0.0,0.227400225329
0.645974958186,0.0,0.223545964858
0.640376212657,0.0,0.219566310635
0.634709326941,0.0,0.215461260247
0.628972329738,0.0,0.211230928463
0.623163248943,0.0,0.206875556376
0.617280111407,0.0,0.202395521517
0.611320942748,0.0,0.197791349094
0.605283767238,0.0,0.193063724536
0.599166607773,0.0,0.188213507528
0.59296748593,0.0,0.183241747805
0.58668442213,0.0,0.178149702978
0.58031543593,0.0,0.172938858773
0.573858546445,0.0,0.16761095208
0.567311772936,0.0,0.162167997373
0.560673135583,0.0,0.156612317118
0.553940656473,0.0,0.150946576967
0.547112360838,0.0,0.145173826717
0.540186278578,0.0,0.139297548251
0.533160446125,0.0,0.133321711968
0.526032908698,0.0,0.127250843613
0.518801723011,0.0,0.121090103901
0.511464960525,0.0,0.114845383969
0.504024784564,0.0,0.108458203076
0.496500575391,0.0,0.101574441999
0.488895703728,0.0,0.0940532766187
0.481211091296,0.0,0.0857577699671
0.473447867487,0.0,0.076491692057
0.465607387408,0.0,0.0659561988193
0.457691251942,0.0,0.0536550801568
0.449701330055,0.0,0.0386399977295
0.441639783639,0.0,0.021715201563
0.433509095214,0.0,0.00442913080596
0.425312098834,0.0,0.0
0.417052014605,0.0,0.0
0.408732487256,0.0,0.0
0.400357629268,0.0,0.0
0.391932069098,0.0,0.0
0.383461005106,0.0,0.0
0.374951987641,0.0,0.0
0.366438044303,0.0,0.0
0.357936969319,0.0,0.0
0.349459701788,0.0,0.0
0.341018390947,0.0,0.0
0.332626511185,0.0,0.0
0.324298983273,0.0,0.0
0.316052299929,0.0,0.0
0.307904652819,0.0,0.0
0.299876056727,0.0,0.0
0.291988464941,0.0,0.0
0.284265867782,0.0,0.0
0.276734363703,0.0,0.0
0.269422189547,0.0,0.0
0.26235969354,0.0,0.0
0.255579231674,0.0,0.0
0.249114965843,0.0,0.0
0.243002541041,0.0,0.0
0.23727862007,0.0,0.0
0.231980258498,0.0,0.0
0.227117573678,0.0,0.0
#
# Copyright (C) 2014 Leo Singer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""RGB data for the "Cylon red" color map.
A print- and screen-friendly color map designed specifically for plotting
LSC/Virgo sky maps. The color map is constructed in CIE Lab space, following
a linear ramp in lightness (the `l` coordinate) and a cubic spline in color
components (the `a` and `b` coordinates).
This particular color map was selected from 20 random realizations of this
construction."""
from __future__ import print_function
from colormath.color_conversions import convert_color
from colormath.color_objects import LabColor, sRGBColor
from scipy.interpolate import interp1d
import numpy as np
def lab_to_rgb(*args):
"""Convert Lab color to sRGB, with components clipped to (0, 1)."""
Lab = LabColor(*args)
sRGB = convert_color(Lab, sRGBColor)
return np.clip(sRGB.get_value_tuple(), 0, 1)
L_samples = np.linspace(100, 0, 5)
a_samples = (
33.34664938,
98.09940562,
84.48361516,
76.62970841,
21.43276891)
b_samples = (
62.73345997,
2.09003022,
37.28252236,
76.22507582,
16.24862535)
L = np.linspace(100, 0, 255)
a = interp1d(L_samples, a_samples[::-1], 'cubic')(L)
b = interp1d(L_samples, b_samples[::-1], 'cubic')(L)
for line in __doc__.splitlines():
print('#', line)
for L, a, b in zip(L, a, b):
print(*lab_to_rgb(L, a, b), sep=',')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment