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

Add masking for phase plots. #2504

Merged
merged 3 commits into from
Mar 22, 2022

Conversation

matthewturk
Copy link
Member

This PR does not yet work, because I need some help figuring out the right way to navigate a collision between unyt arrays and masked arrays.

Here is an example script:

import yt
ds = yt.load_sample("IsolatedGalaxy")
dd = ds.all_data()
p = dd.profile(["density", "temperature"], "velocity_x", logs = {('gas', 'velocity_x'): False}, weight_field="mass").plot()
p.set_log("velocity_x", False)
p.save("hi.png")

And before and after images:

phase_plot_before
phase_plot_after

I made these with a slight modification to this PR, which was to change the creation of masked_data to:

masked_data = np.ma.masked_array(data.v, ~self.profile.used)

(adding the .v on data)

I'm not sure that's the right way to go. If I don't strip the unyt status, at some point in the copying process the unyt machinery tries to coerce the boolean mask into units, or something, which breaks stuff.

@matthewturk
Copy link
Member Author

I think with this change it should work fine.

@munkm munkm changed the base branch from yt-4.0 to master June 22, 2020 15:26
@matthewturk
Copy link
Member Author

matthewturk commented Jun 22, 2020

There have been enough wonky answer-store submodule changes that I've merged and pushed that merged version of this to get a new set of tests.

@matthewturk
Copy link
Member Author

I think that this is now going to be easier with the changes in unyt to support masked arrays. I will try again.

Base automatically changed from master to main January 20, 2021 15:27
@munkm
Copy link
Member

munkm commented Apr 8, 2021

Hi @matthewturk did you get a chance to look at unyt's updates to see if it is more compatible for these changes now? This seems like a cool feature!

@matthewturk
Copy link
Member Author

Just updated -- let's see how it does.

@Xarthisius
Copy link
Member

@yt-fido test this please

1 similar comment
@matthewturk
Copy link
Member Author

@yt-fido test this please

@matthewturk
Copy link
Member Author

Aiming to figure this out in time for 4.0.

@neutrinoceros
Copy link
Member

closing + reopening to reactualize CI

@neutrinoceros
Copy link
Member

This patch seems to be viable still, but I note that the reference images have changed since, namely, the lower value in the colorbar is now negative. I do not know what is the intended behaviour, is this a regression or a fix ?
hi

hi

@matthewturk
Copy link
Member Author

@neutrinoceros The two images you show have the same colorbounds, I think?

@neutrinoceros
Copy link
Member

They did, and still do, I'm just wondering wether negative values are expected to be displayed there.
I'm sure there are some in the dataset, but I don't know if the phase plot is supposed to show absolute values or actual velocities. In any case, the behaviour changed since you opened this, but that's not caused by your patch !

@neutrinoceros
Copy link
Member

Anyway it looks to me that they used to be clipped to 0 (which is incorrect in any case), so I think the current behaviour is ok !

@matthewturk
Copy link
Member Author

I think the root cause is related to what we are masking; previously, we were masking using the value zero. So, lots of the colors were very close to the color assigned to zero. (I suspect that using a symlog colorbar would draw this out more.) Now, we can actually see them. (And, coincidentally, the real values that were close to or equal to zero would show up, whereas before we couldn't pick them out.)

@neutrinoceros
Copy link
Member

There's been many changes in the answer store since this was last synced. I think we could simply merge this if we can get this green first, which you should be able to do by merging from the main branch again :)

@neutrinoceros
Copy link
Member

The one failure on Jenkins is expected, since the difference is intended.

@neutrinoceros neutrinoceros added the backport-yt-4.0.x on-merge: backport to yt-4.0.x label Dec 6, 2021
@neutrinoceros
Copy link
Member

Force-pushed with a rebase.

@neutrinoceros
Copy link
Member

I am not 100% convinced these differences are expected actually.
Screenshot 2021-12-06 at 17 02 48
@matthewturk, does this make any sense to you ?

@matthewturk
Copy link
Member Author

One possibility is that now we are no longer using zeros anywhere, which may slightly change the colorbar calculation in vmin; if it gets a NaN it might do a different calculation than if not, in the norm.

@neutrinoceros
Copy link
Member

I'm not convinced either way. I cannot reproduce a similar change in pure matplotlib at the moment. AFAICT, masking with 0s or NaNs seems to produce visually identical results when using a LogNorm + "nearest" shading

I'm however confident the patch is correct so I'm tempted to approve anyway, but this diff is intriguing.

@neutrinoceros neutrinoceros removed the backport-yt-4.0.x on-merge: backport to yt-4.0.x label Jan 21, 2022
@neutrinoceros
Copy link
Member

It seems plausible that #3793 may have resolved this problem. Let's run the test suite again: close+reopen

@neutrinoceros
Copy link
Member

This bugfix is crucial to a refactor I'm working on, so I'll be optimistic and use auto-merge and set it up for backport. 🤞🏻

@neutrinoceros neutrinoceros added this to the 4.0.3 milestone Mar 12, 2022
@neutrinoceros
Copy link
Member

@matthewturk I'd really like to move forward with this and I confirm that I think the new results are correct. Do you need a hand to update gold standards ?

@matthewturk
Copy link
Member Author

@neutrinoceros yes please

@neutrinoceros
Copy link
Member

Here's the supporting answer store PR yt-project/answer-store#30

and the patch needed to for Jenkins-hosted tested, in this PR

diff --git a/tests/tests.yaml b/tests/tests.yaml
index e042e5670..f7836ea15 100644
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -95,7 +95,7 @@ answer_tests:
     - yt/frontends/owls/tests/test_outputs.py:test_snapshot_033
     - yt/frontends/owls/tests/test_outputs.py:test_OWLS_particlefilter

-  local_pw_041:  # PR 3670
+  local_pw_042:  # PR 2504
     - yt/visualization/tests/test_plotwindow.py:test_attributes
     - yt/visualization/tests/test_particle_plot.py:test_particle_projection_answers
     - yt/visualization/tests/test_particle_plot.py:test_particle_projection_filter

@neutrinoceros neutrinoceros merged commit c150d95 into yt-project:main Mar 22, 2022
meeseeksmachine pushed a commit to meeseeksmachine/yt that referenced this pull request Mar 22, 2022
neutrinoceros added a commit that referenced this pull request Mar 22, 2022
…4-on-yt-4.0.x

Backport PR #2504 on branch yt-4.0.x (Add masking for phase plots.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants