yt-project / yt

Main yt repository
http://yt-project.org
Other
467 stars 276 forks source link

yt Failed to load: Trying to re-register the builtin cmap 'cubehelix'. #4317

Closed Sifyrena closed 1 year ago

Sifyrena commented 1 year ago

Bug report

Bug summary

Hi there, I just now upgraded yt 3 to yt 4.0.5 on my system, and it fails to initially load on my system, with the following error

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

Code for reproduction


import matplotlib
matplotlib.__version__ # 3.5.1
import yt

Actual outcome

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [4], in <cell line: 3>()
      1 import numpy as np
      2 import matplotlib.pyplot as plt
----> 3 import yt
      4 get_ipython().run_line_magic('matplotlib', 'notebook')

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/__init__.py:63, in <module>
     46 from yt.units.unit_object import define_unit
     47 from yt.units.yt_array import \
     48     YTArray, \
     49     YTQuantity, \
   (...)
     60     savetxt, \
     61     display_ytarray
---> 63 from yt.fields.api import \
     64     field_plugins, \
     65     DerivedField, \
     66     FieldDetector, \
     67     FieldInfoContainer, \
     68     ValidateParameter, \
     69     ValidateDataField, \
     70     ValidateProperty, \
     71     ValidateSpatial, \
     72     ValidateGridType, \
     73     add_field, \
     74     derived_field, \
     75     add_xray_emissivity_field
     77 from yt.data_objects.api import \
     78     DatasetSeries, ImageArray, \
     79     particle_filter, add_particle_filter, \
     80     create_profile, Profile1D, Profile2D, Profile3D, \
     81     ParticleProfile
     83 # For backwards compatibility

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/fields/api.py:19, in <module>
      7 #-----------------------------------------------------------------------------
      8 # Copyright (c) 2013, yt Development Team.
      9 #
   (...)
     12 # The full license is in the file COPYING.txt, distributed with this software.
     13 #-----------------------------------------------------------------------------
     15 from .field_plugin_registry import \
     16     register_field_plugin, \
     17     field_plugins
---> 19 from . import angular_momentum
     20 from . import astro_fields
     21 from . import cosmology_fields

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/fields/angular_momentum.py:26, in <module>
     20 from .derived_field import \
     21     ValidateParameter
     23 from .field_plugin_registry import \
     24     register_field_plugin
---> 26 from .vector_operations import \
     27     create_magnitude_field
     29 from yt.utilities.lib.misc_utilities import \
     30     obtain_position_vector, \
     31     obtain_relative_velocity_vector
     33 @register_field_plugin
     34 def setup_angular_momentum(registry, ftype = "gas", slice_info = None):
     35     # Angular momentum defined here needs to be consistent with
     36     # _particle_specific_angular_momentum in particle_fields.py

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/fields/vector_operations.py:32, in <module>
     20 from yt.utilities.math_utils import \
     21     get_sph_r_component, \
     22     get_sph_theta_component, \
   (...)
     25     get_cyl_z_component, \
     26     get_cyl_theta_component
     28 from yt.funcs import \
     29     just_one, \
     30     handle_mks_cgs
---> 32 from yt.geometry.geometry_handler import \
     33     is_curvilinear
     35 from yt.utilities.lib.misc_utilities import obtain_relative_velocity_vector
     37 def get_bulk(data, basename, unit):

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/geometry/geometry_handler.py:29, in <module>
     27 from yt.utilities.io_handler import io_registry
     28 from yt.utilities.logger import ytLogger as mylog
---> 29 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     30     ParallelAnalysisInterface, parallel_root_only
     31 from yt.utilities.exceptions import YTFieldNotFound
     33 class Index(ParallelAnalysisInterface):

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/utilities/parallel_tools/parallel_analysis_interface.py:30, in <module>
     26 from yt.funcs import \
     27     ensure_list, iterable
     29 from yt.config import ytcfg
---> 30 from yt.data_objects.image_array import ImageArray
     31 import yt.utilities.logger
     32 from yt.utilities.lib.quad_tree import \
     33     QuadTree, merge_quadtrees

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/data_objects/image_array.py:18, in <module>
     15 import numpy as np
     16 from yt.config import \
     17     ytcfg
---> 18 from yt.visualization.image_writer import write_bitmap, write_image
     19 from yt.units.yt_array import YTArray
     22 class ImageArray(YTArray):

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/visualization/image_writer.py:26, in <module>
     24 from yt.units.yt_array import YTQuantity
     25 from yt.utilities.exceptions import YTNotInsideNotebook
---> 26 from .color_maps import mcm
     27 from . import _colormap_data as cmd
     28 import yt.utilities.lib.image_utilities as au

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/visualization/color_maps.py:164, in <module>
    156 _h_cubehelix = 1.0
    158 _cubehelix_data = {
    159         'red': lambda x: x**_gamma_cubehelix + (_h_cubehelix * x**_gamma_cubehelix * (1 - x**_gamma_cubehelix) / 2) * (-0.14861 * np.cos(2 * np.pi * (_s_cubehelix / 3 + _r_cubehelix * x)) + 1.78277 * np.sin(2 * np.pi * (_s_cubehelix / 3 + _r_cubehelix * x))),
    160         'green': lambda x: x**_gamma_cubehelix + (_h_cubehelix * x**_gamma_cubehelix * (1 - x**_gamma_cubehelix) / 2) * (-0.29227 * np.cos(2 * np.pi * (_s_cubehelix / 3 + _r_cubehelix * x)) - 0.90649 * np.sin(2 * np.pi * (_s_cubehelix / 3 + _r_cubehelix * x))),
    161         'blue': lambda x: x**_gamma_cubehelix + (_h_cubehelix * x**_gamma_cubehelix * (1 - x**_gamma_cubehelix) / 2) * (1.97294 * np.cos(2 * np.pi * (_s_cubehelix / 3 + _r_cubehelix * x))),
    162 }
--> 164 add_colormap("cubehelix", _cubehelix_data)
    166 # The turbo colormap, by Anton Mikhailov.
    167 # from: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
    169 _turbo_colormap_data = np.array(
    170     [[0.18995,0.07176,0.23217],[0.19483,0.08339,0.26149],
    171      [0.19956,0.09498,0.29024],[0.20415,0.10652,0.31844],
   (...)
    296      [0.51989,0.02756,0.00780],[0.50664,0.02354,0.00863],
    297      [0.49321,0.01963,0.00955],[0.47960,0.01583,0.01055]])

File ~/opt/anaconda3/lib/python3.9/site-packages/yt/visualization/color_maps.py:52, in add_colormap(name, cdict)
     50 mcm.__dict__[name] = cdict
     51 try: # API compatibility
---> 52     mcm.register_cmap(name, yt_colormaps[name])
     53 except AttributeError:
     54     pass

File ~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/cm.py:245, in register_cmap(name, cmap, override_builtin)
    243 if not override_builtin and name in __builtin_cmaps:
    244     msg = f"Trying to re-register the builtin cmap {name!r}."
--> 245     raise ValueError(msg)
    246 else:
    247     msg = f"Trying to register the cmap {name!r} which already exists."

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

Version Information

welcome[bot] commented 1 year ago

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

Sifyrena commented 1 year ago

duplicate installs on my system. Not a bug. Sorry about this.

neutrinoceros commented 1 year ago

For posterity, this is a known incompatibility between matplotlib>=3.4 and yt<4.0, which was resolved in #3149