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

Custom color tables causing crashes/warnings #17

Open
sawellons opened this issue Aug 27, 2021 · 5 comments
Open

Custom color tables causing crashes/warnings #17

sawellons opened this issue Aug 27, 2021 · 5 comments

Comments

@sawellons
Copy link

I am having some issues with the function load_my_custom_color_tables() in firestudio/utils/stellar_utils/colors.py. The first time I tried to make a stellar image the code crashed with the following error:

----> 1 firestudio.utils.stellar_utils.colors.load_my_custom_color_tables()

~/home/python/firestudio/utils/stellar_utils/colors.py in load_my_custom_color_tables()
     98                        (1.0, 0.0, 0.0))}
     99     my_cmap = matplotlib.colors.LinearSegmentedColormap(fna,cdict_tmp,256);
--> 100     matplotlib.cm.register_cmap(name=fna,cmap=my_cmap);
    101 
    102 

/srv/conda/envs/notebook/lib/python3.7/site-packages/matplotlib/cm.py in register_cmap(name, cmap, override_builtin)
    147         if not override_builtin and name in __builtin_cmaps:
    148             msg = f"Trying to re-register the builtin cmap {name!r}."
--> 149             raise ValueError(msg)
    150         else:
    151             msg = f"Trying to register the cmap {name!r} which already exists."

ValueError: Trying to re-register the builtin cmap 'rainbow'.

(Note: this is not the original error, this is a reproduction from me calling the function myself.)

It is upset about trying to create a colormap with the same name as one of the built-in matplotlib maps. I was able to sidestep this by renaming the “rainbow” table to “rainbow_custom”.

A more minor issue is that each subsequent time I make a stellar image, I get a series of warnings about re-registering a name for a map that already exists:
~/home/python/firestudio/utils/stellar_utils/colors.py:28: UserWarning: Trying to register the cmap 'heat_red' which already exists.
(but for every map defined in that function). This does not break anything, but it is somewhat annoying.

@agurvich
Copy link
Owner

Do you know what the original error was? If it failed somewhere in the middle it would fail as you find here because it would be re-registering colormaps it already successfully registered.

@agurvich
Copy link
Owner

Or do you mean the bottom of the stack trace is correct it's the top that is different (because you called it directly?)

@sawellons
Copy link
Author

Yes - the actual error at the bottom of the trace is the same (iirc), I just triggered it directly instead of trying to make an image. Note that it doesn't crash (just warns) if you're just re-registering something you've already made before (that's what the last error is), it's only in the particular case where you're trying to overwrite a built-in matplotlib color map that it halts.

@agurvich
Copy link
Owner

I see. Strange that this has never come up before, I haven't added a call to this particular function anywhere ¯_(ツ)_/¯

@sawellons
Copy link
Author

I agree, strange! If I find myself in a situation where I get a deeper stack trace I'll let you know. Maybe it's from a matplotlib update or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants