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

[bug] errors in using log normalization with large data ranges #3170

Closed
chrishavlin opened this issue Apr 7, 2021 · 5 comments · Fixed by #3754
Closed

[bug] errors in using log normalization with large data ranges #3170

chrishavlin opened this issue Apr 7, 2021 · 5 comments · Fixed by #3754
Labels

Comments

@chrishavlin
Copy link
Contributor

Bug report

This is an overview of an upstream matplotlib bug and the temporary fix going into yt to address it so that we do not forget to update yt down the line.

In the recent versions of matplotlib (not sure exactly when this appeared in the 3.3, 3.4 series) if you use a log color scaling with imshow and if your data range is very large you can get some unexpected behavior including crashes. This arises from some internal re-scaling that imshow does, resulting in rounding error when your max/min data range span many orders of magnitude. If your data also includes zeros, this can lead to the the color scale min being set to 0, which errors for log scaling, which is the source of the error in yt's issue #2890.

The current yt fix introduced by PR #3161 is to switch to symlog scaling if you have 0s and a data range greater than 15 orders of magnitude. As the fix in #3161 is not ideal, it should be eventually removed as the fixes get merged upstream. Note that the upstream fix introduces a new boolean keyword argument, interp_postrgba, that yt would need to pass to its calls to imshow, likely with an initial matplotlib version check for some period of time (I believe these changes would be implemented in yt.visualization.base_plot_types.ImagePlotMPL._init_image).

matplotlib links for tracking:

@chrishavlin chrishavlin added the bug label Apr 7, 2021
@munkm
Copy link
Member

munkm commented Apr 8, 2021

@chrishavlin does the fix in #3161 actually fix #2890?

@chrishavlin
Copy link
Contributor Author

The following now runs without error on main:

import yt
fn = 'FIRE_M12i_ref11/snapshot_600.hdf5'
ds = yt.load(fn)
p = yt.ProjectionPlot(ds, 'x', ('gas', 'density'))
p.save('projection.png')

are there more errors?

@munkm
Copy link
Member

munkm commented Apr 8, 2021

Nope! I just want to close #2890!!!

@neutrinoceros
Copy link
Member

It seems like the PR addressing this upstream was merged some time ago and is currently only included in Matplotlib 3.5.0rc1, so it should land with Matplotlib 3.5.0.

@neutrinoceros
Copy link
Member

Indeed matplotlib/matplotlib#18782 was released in MPL 3.5
It'd be sufficient to make the temporary hack from #3161 version-aware (only use it with MPL < 3.5) to close the present PR, I think.

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

Successfully merging a pull request may close this issue.

3 participants