Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Raise warning and downsample if data given to _image.resample is too large #19368

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

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Jan 26, 2021

Fixes #19276. This still needs:

  • Documentation
  • Tests

@dstansby dstansby marked this pull request as draft January 26, 2021 16:53
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can accurately downsample so I don't think we should error here. An aliased downsampled image is still zoomable, at which point the aliasing will go away. If the image is above 2**23 we should just subsample by a factor of 2 and warn.

@dstansby
Copy link
Member Author

dstansby commented Jan 26, 2021

We can accurately downsample so I don't think we should error here. An aliased downsampled image is still zoomable, at which point the aliasing will go away. If the image is above 2**23 we should just subsample by a factor of 2 and warn.

👍 - for subsampling, would you recommend just doing arr[::2]?

@jklymak
Copy link
Member

jklymak commented Jan 26, 2021

I think we want arr[::int(np.ceil(Ny/2**23)), :][:,::int(np.ceil(Nx/2**23))]?

@dstansby
Copy link
Member Author

Yep, my comment was modulo finding the right stride, but just wanted to double check that striding was the correct approach.

@jklymak
Copy link
Member

jklymak commented Jan 26, 2021

The right approach is open to debate, in that you could anti-alias the data before hitting it with a stride. But for such a massive subsample, I think a simple stride is better than an unspecified overflow/wrap!

@dstansby dstansby changed the title Raise errors if data given to _image.resample is too large Raise warning and downsample if data given to _image.resample is too large Apr 3, 2021
@dstansby dstansby force-pushed the resample-error branch 3 times, most recently from 5f1773c to 1fd6269 Compare April 4, 2021 09:39
@dstansby dstansby force-pushed the resample-error branch 2 times, most recently from 40b5664 to a81575c Compare September 7, 2021 19:01
@timhoffm
Copy link
Member

timhoffm commented Sep 8, 2021

Why do we bother to downsample at all? We cannot display more than N pixels and should refuse to accept more (In the face of ambiguity refuse the temptation to guess). If a user has more data, it's their responsibility and competence to reduce them.

@dstansby
Copy link
Member Author

dstansby commented Sep 8, 2021

I'm happy to go either way - perhaps worth discussing on a dev call and coming back with a decision?

@jklymak
Copy link
Member

jklymak commented Sep 8, 2021

We almost always resample so I don't see the problem with reducing the data before trying the final resample step. This will be aliased, but a max-sized image will also be aliased by the final downsample, so I doubt it would be detectable.

@tacaswell
Copy link
Member

I am 👍🏻 in favor of this.

@jklymak
Copy link
Member

jklymak commented Sep 10, 2021

As discussed on the call, we should go ahead and subsample and warn, which I think is what this PR does.

@dstansby
Copy link
Member Author

👍 - I still need to add a test for resampling the columns that's similar to the existing one for rows

@dstansby dstansby force-pushed the resample-error branch 2 times, most recently from 60a3373 to cecd991 Compare December 28, 2021 10:44
@dstansby dstansby marked this pull request as ready for review December 28, 2021 11:30
@dstansby
Copy link
Member Author

This should be good for review now. Tests and an API note added.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to let this languish. I think this looks good.

@jklymak jklymak added this to the v3.6.0 milestone Jan 5, 2022
Comment on lines 176 to 185
if data.shape[1] > 2**23:
warnings.warn(msg.format(n='2**23 rows'))
step = int(np.ceil(data.shape[1] / 2**23))
data = data[:, ::step]
transform = Affine2D().scale(step, 1) + transform
if data.shape[0] > 2**24:
warnings.warn(msg.format(n='2**24 columns'))
step = int(np.ceil(data.shape[0] / 2**24))
data = data[::step, :]
transform = Affine2D().scale(1, step) + transform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is the rows, 1 is the columns; you have the message swapped. I don't know if the limits should be swapped as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - I checked the limits and they are correct, just the message that needed changing.

@QuLogic
Copy link
Member

QuLogic commented Jan 11, 2022

Needs rebase for docs to work.

@tacaswell
Copy link
Member

power-cycled to pick up the CI config from main.

@QuLogic QuLogic merged commit d100c42 into matplotlib:main Jan 27, 2022
@dstansby dstansby deleted the resample-error branch February 7, 2022 10:49
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

Successfully merging this pull request may close these issues.

imshow with very large arrays not working as expected
5 participants