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: fix buffer masking in cartesian geometry #3856

Merged
merged 3 commits into from
Mar 31, 2022

Conversation

neutrinoceros
Copy link
Member

PR Summary

Goal: fix #3854
Applying the patch from the issue. Let's see what image tests fail.

@neutrinoceros
Copy link
Member Author

So far I haven't been able to localise the source of differences in the affected PixelizedProjectionValuesTests
I'm trying to reproduce something similar without the testing framework.

@matthewturk, any idea what might be causing this ?

reference
tmponei_20c
this branch
tmpw2pl575s

@matthewturk
Copy link
Member

Can you do a floating point comparison? I'm not entirely sure why the masking would cause these things, except that it's possible that some things that were previously 0.0 are now NaN right at the boundary, or vice versa.

@neutrinoceros
Copy link
Member Author

So I was able to reproduce this locally by running the following on the tip of main

import yt
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

field = ("gas", "temperature")
ds = yt.load("output_00080/info_00080.txt")
obj = ds.sphere("max", (0.1, "unitary"))
axis = 0
weight_field  = ("gas", "density")
proj = ds.proj(field, axis, weight_field=weight_field, data_source=obj)
frb = proj.to_frb((1.0, "unitary"), 256)
np.save(f"main_weightfield_{weight_field}.npy", frb[field].d)

followed by

git checkout cartesian_buffer_masking
pip install -e .

Then repeating the script but saving to a different file

np.save(f"branch_weightfield_{weight_field}.npy", frb[field].d)

and finally running

fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(15, 4))
d1 = np.load(f"main_weightfield_('gas', 'density').npy")
d2 = np.load(f"branch_weightfield_('gas', 'density').npy")

n1 = LogNorm(vmin=np.nanmin(d1), vmax=np.nanmax(d1))
n2 = LogNorm(vmin=np.nanmin(d2), vmax=np.nanmax(d2))
diff = np.nansum((d2, -d1), axis=0)
for data, norm, ax in [
    (d1, n1, axs[0]),
    (d2, n2, axs[1]),
    (diff, LogNorm(), axs[2]),
]:
    im = ax.imshow(data, norm=norm, cmap="cmyt.arbre")
    fig.colorbar(im, ax=ax)
fig.savefig("/tmp/bench.png")

bench

So it seems that your intuition was right Matt, the only place where there are actual differences is at the boundary of the selection, though I still do not understand why that is.
In any case it seems like more pixels get -correctly ?- colorised with this branch. So as far as I understand this looks more like a fix than a regression. I'm just not satisfied with my limited understanding of this difference.
@matthewturk should we move forward with it ? There are other places where buffers get initialised with zero as a filler, I probably should update them too.

@matthewturk
Copy link
Member

I agree with your assertion that this is a fix.

My suspicion is that it involves the anti-aliasing argument, and that if it were turned off we would see less difference. Regardless, this looks like an improvement to me, and I say move forward.

@neutrinoceros neutrinoceros force-pushed the cartesian_buffer_masking branch 3 times, most recently from 385a295 to 30888c2 Compare March 25, 2022 12:47
@neutrinoceros
Copy link
Member Author

So, my attempt to generalise using nan as a fill value to sph-like particle pixelization routines has resulted in multiple test failures that I can't seem to reproduce locally.
As a result, I anticipate that progressing any further in that direction is going to take much more time than I can afford at the moment. @matthewturk, do you think we could get this merged with just the grid/cartesian changes that we already discussed ?

@matthewturk
Copy link
Member

@neutrinoceros Yes, I think that's reasonable.

@neutrinoceros neutrinoceros marked this pull request as ready for review March 28, 2022 14:01
@neutrinoceros neutrinoceros added this to the 4.0.3 milestone Mar 28, 2022
@neutrinoceros
Copy link
Member Author

@matthewturk this is ready

@@ -98,5 +100,4 @@ def test_field_cut_off_axis_octree():
(p3.frb[("gas", "density")] == p4.frb[("gas", "density")]).all(), False
)
p4rho = p4.frb[("gas", "density")]
assert_equal(p4rho.min() == 0.0, True) # Lots of zeros
assert_equal(p4rho[p4rho > 0.0].min() >= 0.5, True)
assert_equal(np.nanmin(p4rho[p4rho > 0.0]) >= 0.5, True)
Copy link
Member

Choose a reason for hiding this comment

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

Why not use the following?

Suggested change
assert_equal(np.nanmin(p4rho[p4rho > 0.0]) >= 0.5, True)
assert np.nanmin(p4rho[p4rho > 0.0]) >= 0.5

Note that I am absolutely happy about the PR as is and don't want to delay it any further, so feel free to push the merge button!

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I’m going to keep it as is to match the local dominant convention, even though this is actually not a unit test-based test, so your suggestion should indeed work.

@neutrinoceros neutrinoceros merged commit 1890365 into yt-project:main Mar 31, 2022
@neutrinoceros neutrinoceros deleted the cartesian_buffer_masking branch March 31, 2022 10:59
meeseeksmachine pushed a commit to meeseeksmachine/yt that referenced this pull request Mar 31, 2022
@cphyc
Copy link
Member

cphyc commented Mar 31, 2022 via email

@matthewturk
Copy link
Member

@cphyc I deleted my comment right after I posted, because I realized

neutrinoceros added a commit that referenced this pull request Mar 31, 2022
…6-on-yt-4.0.x

Backport PR #3856 on branch yt-4.0.x (BUG: fix buffer masking in cartesian geometry)
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.

BUG: inconsistency in cartesian buffer masking
3 participants