Giter VIP home page Giter VIP logo

cmap's Introduction

I'm a neurobiologist and microscopist by training, and I enjoy maintaining libraries in the general ecosystem of python image visualization and analysis.

  • I was a core developer of napari.
  • Many of the reusable patterns I developed there have been extracted into reusable libraries in the pyapp-kit organization which I continue to maintain.
  • I also maintain the pymmcore-plus organization, a set of packages for microscopy aquisition in pure-python/C++ environments.

In this github org, notable libraries include:

  • FPbase: source code for fpbase.org, the fluorescent protein database.
  • nd2: modern nd2 (Nikon NIS-elements) file reader with broad support
  • ome-types: Python classes for working with the OME datamodel (i.e. OME-XML metadata)
  • pycudadecon: Python wrapper for CUDA-accelerated 3D deconvolution for microscopy
  • pycudasirecon: CUDA-accelerated reconstruction for 3D-structured-illumination
  • cmap: Comprehensive colormap library, with only numpy dependency
  • PSFmodels: Scalar and vectorial models of the 3D microscope point spread function.
  • mrc: deltavision (.mrc/.dv) image file format reader/writer.

cmap's People

Contributors

andy-sweet avatar dependabot[bot] avatar jhsmit avatar pre-commit-ci[bot] avatar tlambert03 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cmap's Issues

Todo: cleanup catalog structure

The catalog structure has already gotten a little hard to reason about (particularly with regards to aliases). It needs to be documented better, commented, and cleaned up

[Task] Todo

  • work on namespacing and colormap string name parsing
  • #19
  • consider plugin system... or interface for registration
  • refine catalog mechanism
  • continue to improve attributions and references

Feature: improve ergonomics for cyclic qualitative/categorical colormaps

  • cmap version: 0.2.0
  • Python version: 3.9.18
  • Operating System: macOS 14.4.1

Description

I am using cmap to generate a qualitative colormap for integer valued images in a napari plugin. The integer values can be greater than the number of colors in the qualitative/categorical colormap, so I want to cycle through those colors.

I might be missing something in the API, but I found this to be a little awkward right now. I think I need to do something like the following:

from cmap import Colormap
index: int = 0 # but could take any non-negative integer value
colormap = Colormap("colorbrewer:set1_8")
color = colormap(index % len(colormap.color_stops))

The main reason I found this awkward is because it is was hard to find Colormap.color_stops. Alternatively, I also found len(tuple(Colormap.iter_colors())), but this felt wasteful and even more verbose.

For more context, see the equivalent lines at a commit in a recent PR.

Ideas

I'm not sure what to suggest here since I only just started using cmap and I don't want to pollute what is a very concise API.

Adding something like Colormap.num_colors is probably enough to make me happy here (where num_colors is equal to len(colormap.color_stops)).

I also thought of something like Colormap.cycle(values) as an alternative to Colormap.__call__ that would do this automatically, but not sure if I like that either.

Summary

This is a super nit-picky feature request, so you should feel free to close and move on. The only way I could justify putting more thought in here is if the cyclic mapping is one that is likely to used frequently.

If there is interest, I'm happy to think a bit more and have a go at an implementation.

Otherwise, I am loving cmap and its docsite - the catalog and perceptual plots are beautiful!

hue plots should not show discontinuity when jumping from 0 to 100 or from 100 to 0

  • cmap version: 0.0.2
  • Python version: any
  • Operating System: any

Description

The hue plots, e.g. at https://cmap-docs.readthedocs.io/en/latest/catalog/cyclic/cmocean%3Aphase/#hue-saturation, show a discontinuity when the hue jumps from 0 to 100 or the other way round, but that's an artefact as hues are defined modulo 100 (in the scale here). It would be nice if the vertical line connecting 0 to 100 was not drawn...

What I Did

N/A

Question compatibility with colorbar of Matplotlib

  • cmap version: 0.2.1
  • Python version: 3.11.3
  • Operating System: MacOS

Description

Hi!
I am trying to use cmap to plot a colorbar with Matplotlib. To do so, I need to create it manually using plt.cm.ScalarMappableas in the following MWE. It seems not possible to use plt.cm.ScalarMappable from matplotlib to scale directly the colorbars from cmap. Is there a work-around to this?

What I Did

Here the code crash at sm = plt.cm.ScalarMappable(cmap=colormap, norm=norm). If I replace colormap = Colormap('crameri:roma') by colormap = plt.get_cmap('cividis') (see commented line nb 12) it works as expected.

import numpy as np
import matplotlib.pyplot as plt
from cmap import Colormap

# Create a range of x values
x = np.linspace(0, 2 * np.pi, 100)

# Create a range of y values as sine and cosine curves
y = np.array([np.sin(x + phi) for phi in np.linspace(0, np.pi, 10)])

# Create a colormap
# colormap = plt.get_cmap('cividis')
colormap = Colormap('crameri:roma')

# Normalize the y values for the colormap
y_min = np.min(y)
y_max = np.max(y)
normalize_y = (y - y_min) / (y_max - y_min)

fig, ax = plt.subplots(1, 1)

# Plot each curve with a color from the colormap
for i in range(len(y)):
    ax.plot(x, y[i], color=colormap(normalize_y[i][0]))

# Add a colorbar to the plot
norm = plt.Normalize(vmin=y_min, vmax=y_max)
sm = plt.cm.ScalarMappable(cmap=colormap, norm=norm)

cbar = fig.colorbar(sm, ax=ax, shrink=0.95)
fig.show()

Include semantically meaningful colorcet colormap names

  • cmap version: 0.0.2
  • Python version: any
  • Operating System: any

Description

The colorcet names colorcet:CET_<letter><number> are not particularly memorable. There are some aliases available, which are listed both on the colorcet python package (e.g. "bgy", "bgyw", etc.), and also, if you want a more "official" source for the names, in Peter Kovesi's colorcet.m (http://www.peterkovesi.com/matlabfns/Colourmaps/colorcet.m : "Some colour maps have alternate names for convenience and readability." -- also note that the matlab code effectively makes the colormap names case-insensitive, but I guess lowercase reads nicer). It would be nice to have these aliases available. Thanks!

What I Did

N/A

Expose glasbey variants exposed by the (python) colorcet package

  • cmap version: 0.0.3
  • Python version: any
  • Operating System: any

Description

colorcet (the Python package) exposes a few variants on the glasbey color series (not really colormaps, but rather lists of maximally different colors), per holoviz/colorcet#11 (comment).

Admittedly these are constructs from the colorcet maintainers and not so much from the original glasbey paper, but it would be nice to include them, as I don't think there's any other color lists (designed for that use case) in cmap.

(Also, as a side point, glasbey should probably be categorized as "qualitative", not as "misc.")

What I Did

N/A

Addition of Paul Tol's colormaps

Hi, thanks for developing this very nice library!
I keep installing matplotlib/colorcet etc etc dependencies to have the full selection of colormaps I like to use :)

One set of color maps I like a lot is from Paul Tol: https://personal.sron.nl/~pault/
Are you willing to add / accept a PR for adding these colormaps?

There is python code provided here: https://personal.sron.nl/~pault/data/tol_colors.py
The code is licensed under BSD but I think the color data themselves should be no problem to add if we include the license?

Is there a preferred format for the colormaps or can be anything accepted by cmap.Colormap constructor?

`_repr_png_` does not respect `interpolation=False`

import cmap as cm
cm_cmap = cm.Colormap(['#364B9A', '#4A7BB7', '#6EA6CD', '#98CAE1', '#C2E4EF',
                '#EAECCC', '#FEDA8B', '#FDB366', '#F67E4B', '#DD3D2D',
                '#A50026'], interpolation=False)

image

matplotlib result (expected):

cm_cmap.to_matplotlib()

image

However,

cmap = cm.Colormap('colorbrewer:Accent_5')
cmap

does produce a discrete colors png

Provide API for shifting (cyclic) colormaps

  • cmap version: 0.0.3
  • Python version: any
  • Operating System: any

Description

For cyclic colormaps, a useful operation can be to shift the position of the zero. For example, CET_C3 maps 0 to white, 0.5 to black, and 1 to white again; one could want to do the opposite (0 and 1 mapped to black, 0.5 mapped to white).
An API such as cmap.shifted(0.5) could be useful there (it's up to you how you want to handle the name kwarg, but note that unlike reverse()ing, there can be multiple meaningful shifts).

What I Did

N/A

Bug: docs catalog pages for `chrisluts` return 404

  • cmap version: N/A
  • Python version: N/A
  • Operating System: N/A

Description

Clicking any of the chrisluts on the catalog page:
https://cmap-docs.readthedocs.io/en/latest/catalog/
returns 404 error (stable and latest Build #20340125).

However, using the burger menu does allow access, so the files are there, e.g.:
https://cmap-docs.readthedocs.io/en/latest/catalog/sequential/chrisluts%3AI_Blue/

It appears that the links in the catalog page use lower case letters, while the actual file names have caps, so I suspect this could affect other cmaps—if not now, then in the future.

Also, for chrisluts:I_Red the link from the catalog uses chrisluts:ied

Edit: Here's two of the problematic div (the nav ones are fine):
image

Ah, so the I_Red issue is this matching gone awry:

return f'/catalog/{self.category}/{self.name.replace("_r", "")}/'

self.name is lowercase (consistent with the 404 issue), so then the _r replacement gets the internal _r from _Red.

Edit2:
the cmap-name constructed here is correct:

cmap/docs/_hooks.py

Lines 15 to 20 in e1de598

CMAP_DIV = """
<div class="cmap {class_list}" id="cmap-{name}">
<div class="cmap-name">{name}</div>
{img}
</div>
"""

but this doesn't use self.name

What I Did

Was clicking the different color maps to see the cool visuals.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.