fusion-energy / openmc_regular_mesh_plotter

A Python package for plotting OpenMC regular mesh tally results with underlying geometry from neutronics simulations.
MIT License
9 stars 1 forks source link

LogNorm and vmin cannot be used simultaneously #26

Open RemDelaporteMathurin opened 2 years ago

RemDelaporteMathurin commented 2 years ago
plot = plot_regular_mesh_tally_with_geometry(
    tally=my_tally_xz,
    dagmc_file_or_trimesh_object="dagmc_not_merged.h5m",
    plane_origin=(0, 0, 0),
    plane_normal=[0, 1, 0],
    rotate_geometry=90,
    source_strength=source_strength,
    scale=LogNorm(),
    vmin=1e-3,
    label="Tritium generation (T/m3/s)",
    filename="my_tally_xz.png",
)

produces

  File "convert_results.py", line 24, in <module>
    plot = plot_regular_mesh_tally_with_geometry(
  File "/home/regular_mesh_plotter/regular_mesh_plotter/core.py", line 142, in plot_regular_mesh_tally_with_geometry
    plot = plot_regular_mesh_values(
  File "/home/regular_mesh_plotter/regular_mesh_plotter/core.py", line 48, in plot_regular_mesh_values
    image_map = plt.imshow(values, norm=scale, vmin=vmin, extent=extent, origin='lower')
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/_api/deprecation.py", line 456, in wrapper
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2640, in imshow
    __ret = gca().imshow(
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/_api/deprecation.py", line 456, in wrapper
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/__init__.py", line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5447, in imshow
    im._scale_norm(norm, vmin, vmax)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/cm.py", line 380, in _scale_norm
    raise ValueError(
ValueError: Passing parameters norm and vmin/vmax simultaneously is not supported. Please pass vmin/vmax directly to the norm when creating it.
shimwell commented 2 years ago

ah that is caused by this line, not quite sure how to apply vmin and scale separately.

https://github.com/fusion-energy/regular_mesh_plotter/blob/c5dbff275d56aaef8ec65fd7d85fc43091e6e8ee/regular_mesh_plotter/core.py#L48

RemDelaporteMathurin commented 2 years ago

So vmin and vmax only influence the colorbar. If specifying the norm, you can do :

plot = plot_regular_mesh_tally_with_geometry(
    tally=my_tally_xz,
    dagmc_file_or_trimesh_object="dagmc_not_merged.h5m",
    plane_origin=(0, 0, 0),
    plane_normal=[0, 1, 0],
    rotate_geometry=90,
    source_strength=source_strength,
    scale=LogNorm(vmin=1e-3),
    label="Tritium generation (T/m3/s)",
    filename="my_tally_xz.png",
)
RemDelaporteMathurin commented 2 years ago

But vmin and vmax only change the colorbar, not the actual data, in the sense that it doesn't mask the data below or above this threshold.

It would be a very nice feature: https://stackoverflow.com/questions/32991649/matplotlib-imshow-how-to-apply-a-mask-on-the-matrix

RemDelaporteMathurin commented 2 years ago

I think this will be fixed in #37