Skip to content

Commit

Permalink
Updated to use pyct, pyctdev, nbsite (#19)
Browse files Browse the repository at this point in the history
* Updated packaging, testing, docs to match standard pyviz.
* Allows release on tag, website building, etc.
* Expanded the website, with notebooks, favicon, etc.
* Added license
* Added unit tests
  • Loading branch information
jsignell authored and jbednar committed Feb 13, 2019
1 parent 8532157 commit cf776a0
Show file tree
Hide file tree
Showing 37 changed files with 919 additions and 13,148 deletions.
20 changes: 20 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
environment:
global:
CHANS_DEV: "-c pyviz/label/dev"
matrix:
- PY: "3.6"
PYTHON: "C:\\Python36-x64"
CONDA: "C:\\Miniconda36-x64"

install:
- "SET PATH=%CONDA%;%CONDA%\\Scripts;%PATH%"
- "conda install -y %CHANS_DEV% pyctdev && doit ecosystem_setup"
- "doit env_create --name=colorcet --python=%PY%"
- "activate colorcet"
- "doit develop_install %CHANS_DEV% -o examples"
- "doit env_capture"

build: off

test_script:
- "doit test_all"
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
colorcet/__init__.py export-subst
setup.cfg export-subst
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.py[cod]
#*#
*~
*.egg
*.egg-info
Expand All @@ -14,3 +13,18 @@
!/doc/Reference_Manual/index.rst
.ipynb_checkpoints
.coverage
__pycache__
.doit*
*.egg-info
*/.version
pip-wheel-metadata
**.ipynb_checkpoints

# nbsite
# these files normally shouldn't be checked in as they should be
# dynamically built from notebooks
doc/**/*.rst
doc/**/*.ipynb
doc/**/*.json
# this dir contains the whole website and should not be checked in on master
builtdocs/
105 changes: 105 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
language: generic

env:
global:
- CHANS_DEV="-c pyviz/label/dev"
- CHANS_REL="-c pyviz"
- LABELS_DEV="--label dev"
- LABELS_REL="--label dev --label main"
- PYENV_VERSION=3.6
- PKG_TEST_PYTHON="--test-python=py36 --test-python=py27"

stages:
- test
- name: conda_dev_package
if: tag =~ ^v(\d+|\.)+[a-z]\d+$
- name: pip_dev_package
if: tag =~ ^v(\d+|\.)+[a-z]\d+$
- name: conda_package
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$
- name: pip_package
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$
- name: website_dev
if: tag =~ ^v(\d+|\.)+[a-z]\d+$ OR tag = website_dev
- name: website_release
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$ OR tag = website

jobs:
include:
- &default
stage: test
os: linux
install:
- pip install pyctdev && doit miniconda_install && pip uninstall -y doit pyctdev
- export PATH="$HOME/miniconda/bin:$PATH" && hash -r
- conda config --set always_yes True
- conda install -c pyviz/label/dev pyctdev && doit ecosystem_setup
before_script:
- doit env_create --name=colorcet --python=$PYENV_VERSION
- source activate colorcet
- doit develop_install $CHANS_DEV -o examples
- doit env_capture
script:
- doit test_all


- &website
<<: *default
stage: website_release
script:
# TODO: set chans according to dev/rel
- doit develop_install $CHANS_DEV -o doc -o examples
- doit build_website

deploy:
- provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: ./builtdocs
fqdn: colorcet.pyviz.org
on:
tags: true
all_branches: true

- <<: *website
stage: website_dev
deploy:
- provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: ./builtdocs
repo: pyviz-dev/colorcet
on:
tags: true
all_branches: true

## dev packages

- &pip_pkg
env: PYPI=testpypi PYPIUSER=$TPPU PYPIPASS=$TPPP
stage: pip_dev_package
install: pip install pyctdev && doit ecosystem=pip ecosystem_setup
before_script:
- doit ecosystem=pip package_build $PKG_TEST_PYTHON --test-group=unit --sdist-install-build-deps
script: doit ecosystem=pip package_upload -u $PYPIUSER -p $PYPIPASS --pypi ${PYPI}

- &conda_pkg
<<: *default
stage: conda_dev_package
env: LABELS=$LABELS_DEV CHANS=$CHANS_DEV
before_script:
- travis_wait 60 doit package_build $CHANS $PKG_TEST_PYTHON --package-name colorcet --test-group=unit
script: doit package_upload --token=$ANACONDA_TOKEN $LABELS

## release packages

- <<: *pip_pkg
env: PYPI=pypi PYPIUSER=$PPU PYPIPASS=$PPP
stage: pip_package

- <<: *conda_pkg
stage: conda_package
env: LABELS=$LABELS_REL CHANS=$CHANS_REL

notifications:
email: false
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
include LICENSE.txt
include README.md
include colorcet/.version
graft examples
graft colorcet/examples
global-exclude *.py[co]
global-exclude *~
global-exclude *.ipynb_checkpoints/*
132 changes: 37 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,45 @@
colorcet
--------
<img src="https://github.com/pyviz/colorcet/blob/master/doc/_static/logo.png" width=200><br>

[colorcet](https://github.com/bokeh/colorcet) is a collection of
-----------------

# Colorcet: Collection of perceptually uniform colormaps

| | |
| --- | --- |
| Build Status | [![Linux/MacOS Build Status](https://travis-ci.org/pyviz/colorcet.svg?branch=master)](https://travis-ci.org/pyviz/colorcet) [![Windows Build status](https://img.shields.io/appveyor/ci/pyviz/colorcet/master.svg?logo=appveyor)](https://ci.appveyor.com/project/pyviz/colorcet/branch/master) |
| Latest dev release | [![Github tag](https://img.shields.io/github/tag/pyviz/colorcet.svg?label=tag&colorB=11ccbb)](https://github.com/pyviz/colorcet/tags) |
| Latest release | [![Github release](https://img.shields.io/github/release/pyviz/colorcet.svg?label=tag&colorB=11ccbb)](https://github.com/pyviz/colorcet/releases) [![PyPI version](https://img.shields.io/pypi/v/colorcet.svg?colorB=cc77dd)](https://pypi.python.org/pypi/colorcet) [![colorcet version](https://img.shields.io/conda/v/pyviz/colorcet.svg?colorB=4488ff&style=flat)](https://anaconda.org/pyviz/colorcet) [![conda-forge version](https://img.shields.io/conda/v/conda-forge/colorcet.svg?label=conda%7Cconda-forge&colorB=4488ff)](https://anaconda.org/conda-forge/colorcet) [![defaults version](https://img.shields.io/conda/v/anaconda/colorcet.svg?label=conda%7Cdefaults&style=flat&colorB=4488ff)](https://anaconda.org/anaconda/colorcet) |
| Docs | [![gh-pages](https://img.shields.io/github/last-commit/pyviz/colorcet/gh-pages.svg)](https://github.com/pyviz/colorcet/tree/gh-pages) [![site](https://img.shields.io/website-up-down-green-red/http/colorcet.pyviz.org.svg)](http://colorcet.pyviz.org) |


## What is it?

Colorcet is a collection of
perceptually uniform colormaps for use with Python plotting programs like
[bokeh](http://bokeh.pydata.org),
[matplotlib](http://matplotlib.org),
[holoviews](http://holoviews.org), and
[datashader](https://github.com/bokeh/datashader).

Apart from the four [uniform colormaps now provided with
matplotlib](http://matplotlib.org/users/colormaps.html), most
colormaps shipping with Python plotting Python programs are highly
perceptually nonuniform. That is, small changes in data values
result in large changes in the perceptual appearance of the
corresponding colors, or vice versa. For instance, the popular matplotlib
"hot" and "jet" colormaps have long stretches where the apparent
colors change imperceptibly, such as the yellow region in "hot" and
the cyan/green region in "jet":

![hot/jet](doc/images/hot_jet.png)

When colormaps are used for visualizing scientific datasets, these
perceptual nonlinearities can make interpretation of this data very
difficult, because false boundaries appear in the data, and genuine
boundaries and changes can be obscured.

Matplotlib now offers a [tool to construct uniform
colormaps](https://github.com/matplotlib/viscm), but it doesn't yet
allow construction of colormaps like those above. To address this
need, Peter Kovesi at the Center for Exploration
Targeting created a set of colormaps that are sampled uniformly in a
perceptual color space, using methods he describes in a [paper on
arXiv](https://arxiv.org/abs/1509.03700). For instance, the
perceptually uniform versions of the above colormaps are called "fire"
and "rainbow" in this package:

![fire/rainbow](doc/images/fire_rainbow.png)

You should be able to see the differences right away, revealing more
detail, more faithfully than if you use non-uniform maps. For
instance, here is a population-density dataset (from
[datashader](https://github.com/bokeh/datashader)) rendered with the
original matplotlib "hot" colormap:

![census_hot](doc/images/census_hot.png)

and the same dataset rendered with colorcet's "fire" colormap:

![census_fire](doc/images/census_fire.png)

It should be obvious that the "hot" version completely washes out
detail at the high end, as if the image is overexposed, while "fire"
makes detail visible throughout the data range. Yet the qualitative
effect is still roughly similar, allowing "fire" to be used in nearly
any situation where the original "hot" was useful.

Peter provides [versions of 50 perceptually uniform colormaps for a
variety of different plotting programs](http://peterkovesi.com/projects/colourmaps),
and this package provides those colormaps ready to use from within Python
programs. The colormaps are all illustrated in an
[example notebook](https://colorcet.pyviz.org/) that describes the
different types available and allows you to test how perceptually
uniform they are on your particular display device.

Peter's methods differ from those used in Matplotlib's
uniform colormaps (as implemented in their [viscm
tool](https://github.com/matplotlib/viscm)), which (apart from using a
different color model) are designed to satisfy different constraints.
For instance, mpl's colormaps are always perceptually uniform in their
monochrome representation, not just their original color
representation, and are safe for colorblind viewers, neither of which
are necessarily true of these colormaps. On the other hand, colormaps
like "fire" above, i.e., a usable perceptually equivalent of
matplotlib/matlab's "hot", are not obtainable using viscm in any
straightforward way, limiting the range of useful colormaps that can be created.
In any case, this package focuses on making a set of useful colormaps
readily available from within Python programs, rather than providing
tools for building novel colormaps, for which see the
[viscm tool](https://github.com/matplotlib/viscm) and
[Peter's original site](http://peterkovesi.com/projects/colourmaps).
[datashader](https://github.com/bokeh/datashader) based on the
set of [perceptually uniform colormaps](https://arxiv.org/abs/1509.03700) created
by Peter Kovesi at the Center for Exploration Targeting.


## Installation

colorcet is available on most platforms using the `conda` package manager,
from the `bokeh` channel:
Colorcet supports Python 2.7, 3.5, 3.6 and 3.7 on Linux, Windows, or Mac
and can be installed with conda:

```
conda install -c bokeh colorcet
conda install colorcet
```

or by using pip:
or with pip:

```
pip install colorcet
pip install colorcet
```

Alternatively, you can manually install from the repository if you
wish to be able to modify the code over time:

```
git clone https://github.com/bokeh/colorcet.git
cd colorcet
python setup.py develop
```
For more information take a look at [Getting Started](http://colorcet.pyviz.org/getting_started).

## Learning more

Expand All @@ -114,19 +50,25 @@ background is available in a [1996 paper from
IBM](http://www.research.ibm.com/people/l/lloydt/color/color.HTM).

The matplotlib project also has a number of relevant resources,
including an excellent
including an excellent
[2015 SciPy talk](https://www.youtube.com/watch?v=xAoljeRJ3lU), the
[viscm tool for creating maps like the four in mpl](https://github.com/matplotlib/viscm), the
[cmocean site](http://matplotlib.org/cmocean/) collecting a set of maps created by viscm,
[cmocean site](http://matplotlib.org/cmocean/) collecting a set of maps created by viscm,
and the [discussion of how the mpl maps were created](https://bids.github.io/colormap/).


# Samples
## Samples

All the colorcet colormaps that have short, memorable names (which are probably
the most useful ones) are visible here:

<img src="doc/images/named.png" width="800">
<img src="./examples/assets/images/named.png" width="800">

But the complete set of 50+ is shown in the [User Guide](http://colorcet.pyviz.org/user_guide).


## About PyViz

But the complete set of 50+ is shown in the
[example notebook](https://bokeh.github.io/colorcet).
Colorcet is part of the PyViz initiative for making Python-based visualization tools work well together.
See [pyviz.org](http://pyviz.org) for related packages that you can use with Colorcet and
[status.pyviz.org](http://status.pyviz.org) for the current status of each PyViz project.
9 changes: 5 additions & 4 deletions colorcet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<category>_<huesequence>_<lightnessrange>_c<meanchroma>[_s<colorshift>_[r<ifreversed>]]
but some have shorter, more convenient aliases, some of which are
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
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:
Expand All @@ -33,7 +33,8 @@
cm_n['name'] or cm_n.name
"""

__version__ = '1.0.0'
import param
__version__ = str(param.Version(fpath=__file__,archive_commit="$Format:%h$",reponame="colorcet"))

from collections import OrderedDict

Expand All @@ -56,7 +57,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 Down
20 changes: 20 additions & 0 deletions colorcet/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Matplotlib tests

These tests contain baseline images generated using [pytest-mpl](https://github.com/matplotlib/pytest-mpl).
To run these tests with the fig checking enabled first install pytest-mpl:

```bash
pip install pytest-mpl
```

To regenerate these figures from within this dir run:

```bash
pytest --mpl-generate-path=baseline
```

To run the tests checking that the output is as expected run:

```bash
pytest --mpl
```
Empty file added colorcet/tests/__init__.py
Empty file.
Binary file added colorcet/tests/baseline/test_matplotlib.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions colorcet/tests/test_bokeh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest # noqa
import colorcet as cc

def test_bokeh_palettes_available():
assert len(cc.palette.items()) == 72
assert len(cc.palette_n.items()) == 21

def test_bokeh_palette_is_a_list():
assert isinstance(cc.blues, list)
assert len(cc.blues) == 256
assert cc.blues[0] == '#f0f0f0'
assert cc.blues[-1] == '#3a7bb1'
Loading

0 comments on commit cf776a0

Please sign in to comment.