

Show HN: Spectra – Python color scales made easy - jsvine
https://github.com/jsvine/spectra

======
hellomrjack
Looks like a very useful little library. Although, have you looked at
OpenColourIO and its Python bindings? It is the VFX industry standard for
working with colour spaces, most companies will use OCIO for colour management
throughout the process.

~~~
jsvine
I hadn't heard of OpenColourIO; it looks fascinating and quite powerful.
Thanks for the tip!

------
japhyr
This looks really useful. I've played around with colormaps in a few
visualization projects, but I've never made the time to learn about the
various color packages.

What does this add to colormath and grapefruit?

~~~
jsvine
Thanks! Colormath does an amazing job handling the mathematical conversions
between color spaces, but has (at least to me) a somewhat verbose API. Spectra
wraps that API in something simpler, and adds scales, ranges, blending,
brightening/darkening, and saturation/desaturation.

Spectra uses grapefruit for parsing HTML names and hexcodes.

~~~
japhyr
I'm most excited about the color scales. It looks like a helpful tool for
situations where the standard colormaps in matplotlib/pyplot don't work well.
Is that an appropriate use case?

I also like seeing nbviewer used for documentation, I haven't seen that very
often.

~~~
jsvine
> It looks like a helpful tool for situations where the standard colormaps in
> matplotlib/pyplot don't work well. Is that an appropriate use case?

Yes, that's definitely the type of use-case I had in mind. Another big one:
Choropleth maps.

> I also like seeing nbviewer used for documentation, I haven't seen that very
> often.

Glad to hear it! It's my first attempt at writing documentation in an IPython
notebook. Seemed like a good fit for something so visual.

------
ekimekim
Unrelated to the library itself: I dislike when python projects have an
external website containing the docs, and have no docstrings in the code
itself. Not only is the code harder to read, but it makes the inbuilt help()
useless.

~~~
jsvine
Fair criticism. I should add those docstrings. Issue opened:
[https://github.com/jsvine/spectra/issues/1](https://github.com/jsvine/spectra/issues/1)

~~~
jsvine
Added docstrings in v0.0.6:
[https://github.com/jsvine/spectra/issues/1](https://github.com/jsvine/spectra/issues/1)

------
mark-r
Doesn't seem terribly well specified. Is the rgb space actually sRGB? And what
is the parameter to brighten/darken/saturate/desaturate?

~~~
jsvine
Yes, the library definitely does need some stronger specs. Thanks for
flagging. Addressing these two specific issues:

> Is the rgb space actually sRGB?

Yes. Added:
[https://github.com/jsvine/spectra/commit/7f1ac6f5287340ed356...](https://github.com/jsvine/spectra/commit/7f1ac6f5287340ed356df389cdd61ba3c980c2b1)

> And what is the parameter to brighten/darken/saturate/desaturate?

The parameter for brighten/darken is a positive/negative linear adjustment to
the L(ightness) value of the color's Lab representation. (Spectra converts the
color to Lab, makes the change, and then converts back to the original color
space.)

Likewise, the parameter for saturate/desaturate is a positive/negative linear
adjustment to the c(hroma) value of the color's Lch representation.

Added a note here:
[https://github.com/jsvine/spectra/commit/fd3cbde9338ce388849...](https://github.com/jsvine/spectra/commit/fd3cbde9338ce3888491472724d4d18d36930535)

The goal is to, ultimately, have all these details in the docstrings:
[https://github.com/jsvine/spectra/issues/1](https://github.com/jsvine/spectra/issues/1)

~~~
mark-r
What happens when the adjusted color goes out of gamut?

~~~
jsvine
Another thanks for flagging, mark-r. I've updated spectra to address this
issue more explicitly. Per colormath[0], colors are allowed to go out of
gamut. Colors now have `mycolor.rgb` and `mycolor.rgb_clamped` properties;
`mycolor.hexcode` uses the clamped values. Are there other ways you'd like to
see the out-of-gamut issue addressed? Open to suggestions.

[0]: [http://python-
colormath.readthedocs.org/en/latest/conversion...](http://python-
colormath.readthedocs.org/en/latest/conversions.html?highlight=clamp#rgb-
conversions-and-out-of-gamut-coordinates)

