Skip to content

Commit

Permalink
add cmyt coloramps too!
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Nov 8, 2024
1 parent 28a17b0 commit 6289a74
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ keywords = yt_idv
packages = find:
install_requires =
Click>=7.0
cmyt
imgui>=1.2.0
matplotlib>=3.0
numpy>=1.18.0
Expand Down
13 changes: 13 additions & 0 deletions yt_idv/_cmyt_utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import cmyt
from matplotlib.colors import Colormap

# we want to display colormap name then cmyt for sorting purposes
cmyt_names = [
f"{cm}.cmyt" for cm in dir(cmyt) if isinstance(getattr(cmyt, cm), Colormap)
]


def validate_cmyt_name(cm):
if cm.endswith(".cmyt"):
return "cmyt." + cm.split(".")[0]
return cm
5 changes: 3 additions & 2 deletions yt_idv/opengl_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# Set up a mapping from numbers to names
from yt.utilities.math_utils import get_scale_matrix, get_translate_matrix

from yt_idv._cmyt_utilities import validate_cmyt_name
from yt_idv.constants import bbox_vertices

const_types = (
Expand Down Expand Up @@ -221,7 +222,7 @@ def __init__(self, *args, **kwargs):
@traitlets.validate("colormap_name")
def _validate_name(self, proposal):
try:
plt.get_cmap(proposal["value"])
plt.get_cmap(validate_cmyt_name(proposal["value"]))
except ValueError:
raise traitlets.TraitError(
"Colormap name needs to be known by" "matplotlib"
Expand All @@ -230,7 +231,7 @@ def _validate_name(self, proposal):

@traitlets.observe("colormap_name")
def _observe_colormap_name(self, change):
cmap = plt.get_cmap(change["new"])
cmap = plt.get_cmap(validate_cmyt_name(change["new"]))
cmap_vals = np.array(cmap(np.linspace(0, 1, 256)), dtype="f4")
self.data = cmap_vals

Expand Down
5 changes: 4 additions & 1 deletion yt_idv/scene_components/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import traitlets
from OpenGL import GL

from yt_idv._cmyt_utilities import cmyt_names
from yt_idv.constants import FULLSCREEN_QUAD
from yt_idv.gui_support import add_popup_help
from yt_idv.opengl_support import (
Expand All @@ -20,7 +21,9 @@

_cmaps = ["arbre", "viridis", "magma", "doom", "cividis", "plasma", "RdBu", "coolwarm"]
_cmaps += [f"{_}_r" for _ in _cmaps]
_cmaps.sort()
# add in all the cmyt colormaps too! this will include the reversed maps too.
_cmaps += cmyt_names
_cmaps.sort(key=lambda v: v.lower())
_buffers = ["frame", "depth"]


Expand Down

0 comments on commit 6289a74

Please sign in to comment.