-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:BenWibking/Amrvis into update-homeb…
…rew-paths
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import importlib | ||
|
||
import matplotlib as mpl | ||
import numpy as np | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Generate Amrvis palette files from matplotlib colormaps." | ||
) | ||
parser.add_argument("cmap", nargs="+", help="the name of a matplotlib colormap") | ||
parser.add_argument( | ||
"--import", | ||
action="append", | ||
dest="extra_imports", | ||
metavar="MODULE", | ||
default=[], | ||
help="module to import for additional colormaps", | ||
) | ||
args = parser.parse_args() | ||
print(args) | ||
|
||
for name in args.extra_imports: | ||
importlib.import_module(name) | ||
|
||
for cm_name in args.cmap: | ||
cmap = mpl.colormaps.get_cmap(cm_name) | ||
colors = cmap.resampled(256)(np.linspace(0, 1, 256)) | ||
data = np.round(colors * (255, 255, 255, 100)).astype(np.uint8).T.reshape(-1) | ||
filename = f"{cmap.name}.pal" | ||
data.tofile(filename) | ||
print(f"wrote palette to {filename}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters