FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[MRG+1] Fix imshow masked interpolation by tacaswell · Pull Request #8024 · matplotlib/matplotlib · GitHub

Repository navigation

[MRG+1] Fix imshow masked interpolation - #8024

Merged
NelleV merged 1 commit into
matplotlib:v2.0.xfrom
tacaswell:fix_ishow_masked_interpolation
Feb 24, 2017
Merged

NelleV merged 1 commit into
matplotlib:v2.0.xfrom
tacaswell:fix_ishow_masked_interpolation

Conversation

Copy link
Copy Markdown
Member

Closes #8012

The code changes are in the first commit, the image changes are in the second.

This probably needs some more tests and docs. I suspect there is at least one more 🐉 down here...

attn @mdboom

tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Feb 5, 2017
tacaswell added this to the 2.0.1 (next bug fix release) milestone Feb 5, 2017

Copy link
Copy Markdown
Member Author

So, defiantly 🐲 in up-sampling when mixing masking + over/under with in the kernel foot print.

import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.colors as mcolors
import matplotlib.image as mimage
import matplotlib.cm as mcm
import numpy as np
import copy

cm = copy.copy(mcm.get_cmap('viridis'))
cm.set_over('r')
cm.set_under('b')
cm.set_bad('k')

n = mcolors.Normalize(vmin=0, vmax=100)

data = np.arange(100, dtype='float').reshape(10, 10)

data[5, 5] = -1

data[7, 7] = 101

data[3, 3] = np.nan

data[5, 3] = np.inf

mask = np.zeros_like(data).astype('bool')
mask[3, 5] = True

data = np.ma.masked_array(data, mask)


fig, ax_grid = plt.subplots(3, 6)
for interp, ax in zip(mimage._interpd_, ax_grid.ravel()):
    ax.set_title(interp)
    im = ax.imshow(data, norm=n, cmap=cm, interpolation=interp)

Copy link
Copy Markdown
Member Author

Right, forget about the topo failure, that is due to the resample vs not resample change and I have not looked into it yet.

tacaswell force-pushed the fix_ishow_masked_interpolation branch 2 times, most recently from 8786852 to 236b48f Compare February 6, 2017 01:02

Copy link
Copy Markdown
Member Author

On the bright side I have managed to fix this without having to change classic style and only update 1 test image, on the down side, one test is still broken.

Copy link
Copy Markdown
Member Author

and I have fixed the checker-board effect in that png above, that was due to Agg's aggressive clipping.

tacaswell force-pushed the fix_ishow_masked_interpolation branch from 236b48f to 5e83b93 Compare February 6, 2017 02:05
tacaswell closed this Feb 6, 2017
tacaswell reopened this Feb 6, 2017

Copy link
Copy Markdown
Member Author

Of course this passes locally...

tacaswell force-pushed the fix_ishow_masked_interpolation branch 2 times, most recently from a1fbee5 to 73091ac Compare February 6, 2017 13:23
When determining which pixels to mask in the resampled image, if _any_
contribution to final value comes from a masked pixel, mask the
result.

Due to Agg special-casing the meaning of the alpha channel,
the interpolation for the mask channel needs to be done separately.
This is probably a template for doing the over/under separately.

print out exact hash on travis
tacaswell force-pushed the fix_ishow_masked_interpolation branch from 73091ac to 1a7c4ef Compare February 6, 2017 20:22
Comment thread .travis.yml

install:
- ccache -s
- git describe

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not concerned about this, but would like to make sure that you intended to have this here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I did, was a bit worried that gh/travis were having caching / timeout issues and not running the code I thought it was running (turns out the problem is I had accidentally depended on dictionary ordering in 3.6). I think this is a good idea to keep around so that we can verify exactly what code travis runs for testing locally (it should be running on the merge into the target branch, when it re-sets what that merge is is not something I fully understand yet).

QuLogic changed the title Fix ishow masked interpolation Fix imshow masked interpolation Feb 6, 2017

QuLogic commented Feb 6, 2017

Copy link
Copy Markdown
Member

The CI failure appears non-transient.

Copy link
Copy Markdown
Contributor

What happened to Appveyor?

QuLogic commented Feb 6, 2017

Copy link
Copy Markdown
Member

It doesn't run on the v2.0.x branch.

Copy link
Copy Markdown
Contributor

How did I not know that?

dopplershift left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks reasonable to me. Only a minor question.

Comment thread lib/matplotlib/image.py
# 'unshare' the mask array to
# needed to suppress numpy warning
del out_mask
invalid_mask = ~output.mask * ~np.isnan(output.data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would & work here instead of *? Would make more sense given the boolean masks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Are there performance rather than semantic advantages? I think ~(a & b) would also work and have one less temprorary.


fig, ax_grid = plt.subplots(3, 6)
for interp, ax in zip(sorted(mimage._interpd_), ax_grid.ravel()):
ax.set_title(interp)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think there's any point adding a title if remove_text is True in the decorator. Otherwise this patch looks good to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The title is there for human debuggers later (I often copy-past tests into another buffer and just run them)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

👍

for interp, ax in zip(sorted(mimage._interpd_), ax_grid.ravel()):
ax.set_title(interp)
ax.imshow(data, norm=n, cmap=cm, interpolation=interp)
ax.axis('off')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Same as above, prseumably pointless with remove_text == True

dstansby changed the title Fix imshow masked interpolation [MRG+1] Fix imshow masked interpolation Feb 24, 2017
NelleV merged commit 067f9b6 into matplotlib:v2.0.x Feb 24, 2017
tacaswell deleted the fix_ishow_masked_interpolation branch February 24, 2017 22:30

QuLogic commented Feb 24, 2017 •
edited
Loading

Copy link
Copy Markdown
Member

This makes for an ugly change in Cartopy:
v2.0.0:

vs v2.0.x:

and diff:

You might need to view the full resolution image, but it's pretty evident on the lower-most blue one. It used to match the outline, but now there's a very obvious not very straight white bit along the edge.

Copy link
Copy Markdown
Contributor

sigh

QuLogic commented Feb 25, 2017

Copy link
Copy Markdown
Member

The build also failed matplotlib.tests.test_image.test_rotate_image.test on 2.7 and 3.4 when this got merged, though I'm not sure why. This wasn't a troublesome test before.

QuLogic commented Feb 25, 2017

Copy link
Copy Markdown
Member

Even weirder, #8144 is failling on that test on 3.5 but not other versions, even after a rebuild...

Copy link
Copy Markdown
Member Author

The rotate image test did give me trouble when working on this.

Copy link
Copy Markdown
Member Author

I have sorted out the reason (but not the cause) of the rotate_image failures, for some reason the set_bad from the test added here is leaking out to other tests.

QuLogic commented Mar 15, 2017 •
edited
Loading

Copy link
Copy Markdown
Member

Maybe it should use deepcopy instead of copy?

Copy link
Copy Markdown
Member Author

That would fix it, but we should also fix ColorMap so that copy works as expected, see #8299

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL