Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: load colormaps from binaries instead of text files #102

Merged
merged 1 commit into from
Dec 18, 2023
Merged
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
Binary file added cmasher/colormaps/cm_amber.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_amethyst.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_apple.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_arctic.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_bubblegum.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_chroma.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_copper.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_cosmic.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_dusk.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_eclipse.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_ember.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_emerald.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_emergency.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_fall.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_flamingo.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_freeze.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_fusion.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_gem.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_ghostlight.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_gothic.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_guppy.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_holly.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_horizon.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_iceburn.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_infinity.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_jungle.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_lavender.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_lilac.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_neon.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_neutral.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_nuclear.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_ocean.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_pepper.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_pride.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_prinsenvlag.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_rainforest.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_redshift.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_sapphire.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_savanna.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_seasons.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_seaweed.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_sepia.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_sunburst.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_swamp.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_torch.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_toxic.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_tree.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_tropical.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_viola.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_voltage.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_waterlily.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_watermelon.npy
Binary file not shown.
Binary file added cmasher/colormaps/cm_wildfire.npy
Binary file not shown.
18 changes: 18 additions & 0 deletions cmasher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,13 +1115,31 @@ def import_cmaps(cmap_path: str, *, _skip_registration: bool = False) -> None:
cm_files = list(map(path.basename, glob("%s/cm_*" % (cmap_dir))))
cm_files.sort()

def sort_key(name):
# prioritize binary files over text files because binary loads faster
_, ext = path.splitext(name)
if ext == ".npy":
return 0
if ext == ".txt":
return 1
return 10

cm_files.sort(key=sort_key)
del sort_key

if any(file.endswith(".jscm") for file in cm_files) and not _HAS_VISCM:
raise ValueError("The 'viscm' package is required to read '.jscm' files!")

# Read in all the defined colormaps, transform and register them
seen: set[str] = set()
for cm_file in cm_files:
# Split basename and extension
base_str, ext_str = path.splitext(cm_file)
if base_str in seen:
continue
else:
seen.add(base_str)

cm_name = base_str[3:]

# Obtain absolute path to colormap data file
Expand Down
Loading