Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cmocean/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def _register_cmap(cmap, *, name):
if MPL_VERSION >= Version("3.5"):
mpl.colormaps.register(cmap, name=name)
else:
# deprecated API
mpl.cm.register_cmap(name=name, cmap=cmap)
# deprecated API. `matplotlib.cm` is imported here because importing
# `matplotlib` alone does not make the submodule available, so this
# branch used to raise an AttributeError.
import matplotlib.cm
matplotlib.cm.register_cmap(name=name, cmap=cmap)

# add colormaps and reversed to dictionary
for cmapname in cmapnames:
Expand All @@ -53,11 +56,11 @@ def _register_cmap(cmap, *, name):
rgb_with_alpha = np.zeros((rgb.shape[0],4))
rgb_with_alpha[:,:3] = rgb
rgb_with_alpha[:,3] = 1. #set alpha channel to 1
reg_map = colors.ListedColormap(rgb_with_alpha, N=rgb.shape[0])
reg_map = colors.ListedColormap(rgb_with_alpha)
_register_cmap(reg_map, name=f'cmo.{cmapname}')

# Register the reversed map
reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:], N=rgb.shape[0])
reg_map_r = colors.ListedColormap(rgb_with_alpha[::-1,:])
_register_cmap(reg_map_r, name=f'cmo.{cmapname}_r')

# Load inverted cmaps
Expand All @@ -71,9 +74,9 @@ def _register_cmap(cmap, *, name):
rgb_with_alpha[:,3] = 1. #set alpha channel to 1

# Register inverted cmaps
reg_map_i = colors.ListedColormap(rgb_with_alpha, N=rgb_i.shape[0])
reg_map_i = colors.ListedColormap(rgb_with_alpha)
_register_cmap(reg_map_i, name=f'cmo.{cmapname}_i')
reg_map_r_i = colors.ListedColormap(rgb_with_alpha[::-1,:], N=rgb_i.shape[0])
reg_map_r_i = colors.ListedColormap(rgb_with_alpha[::-1,:])
_register_cmap(reg_map_r_i, name=f'cmo.{cmapname}_r_i')

# order shouldn't matter
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"
15 changes: 1 addition & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@
setup.py for cmocean

"""
import sys
from setuptools import setup # to support "develop" mode
from setuptools.command.test import test as TestCommand

class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.verbose = True

def run_tests(self):
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)

extras_require={
'plots': ["colorspacious", "viscm"],
'test': ["pytest"],
}
# # in case I add more later
# extras_require['complete'] = sorted(set(sum(extras_require.values(), [])))
Expand All @@ -44,9 +33,7 @@ def run_tests(self):
ext_package='cmocean',
scripts = [],
keywords = ['colormaps', 'oceanography', 'plotting', 'visualization'],
setup_requires=['setuptools'],
install_requires=['matplotlib', 'numpy', 'packaging'],
tests_require=['pytest'],
python_requires=">=3.8",
extras_require=extras_require
)