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

Reduce rendered images without considering opacity #4877

Merged
merged 4 commits into from May 15, 2024

Conversation

biboyd
Copy link
Contributor

@biboyd biboyd commented Apr 16, 2024

PR Summary

Issue

This addresses issue #4871, where volume renders of multiple fields with MPI would only produce a portion of the second field in the final image.

I believe I have found where this bug occurs. It mainly has to do with the combining of image arrays in yt/utilities/amr_kdtree/amr_kdtools.py:receive_and_reduce() and how the alpha channel is set in yt/visualization/volume_rendering/render_source.py:VolumeSource.finialize_image()

After the first source is rendered, the last step of finalize_image() sets the alpha channel of the image array to 1's

if not self.transfer_function.grey_opacity:
image[:, :, 3] = 1
return image

This causes issues when the second source is combining the image arrays in recieve_and_reduce() as these two arrays are combined by scaling the back image by ta, 1 minus the front alpha channel. Since the alpha channel was already set by the first source, ta is a zeros array. This eliminates any contribution of back to the final image.

ta = 1.0 - front[:, :, 3]
np.maximum(ta, 0.0, ta)
# This now does the following calculation, but in a memory
# conservative fashion
# image[:,:,i ] = front[:,:,i] + ta*back[:,:,i]
image = back.copy()
for i in range(4):
np.multiply(image[:, :, i], ta, image[:, :, i])
np.add(image, front, image)
return image

Solution

My proposed solution is to add a pathway to combine image arrays without the consideration of opacity. This would be used when transfer_function.grey_opacity=False. In this case, front and back don't have any relevance and we can simply add the two image arrays.

PR Checklist

  • New features are documented, with docstrings and narrative docs
  • Adds a test for any bugs fixed. Adds tests for new features.

Copy link

welcome bot commented Apr 16, 2024

Hi! Welcome, and thanks for opening this pull request. We have some guidelines for new pull requests, and soon you'll hear back about the results of our tests and continuous integration checks. Thank you for your contribution!

@chrishavlin
Copy link
Contributor

thanks for the pull request! I'll review in detail soon, but you're getting a lot of real test failures that you could fix by making your new use_opacity argument a keyword argument instead (and ideally the default value would be such that it does not change current behavior if you do not set the keyword argument).

@biboyd
Copy link
Contributor Author

biboyd commented Apr 17, 2024

Thanks! Made the change to a keyword and now reduce_tree_images should default to the original behavior

Copy link
Member

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

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

This seems sound, but we should probably add a test too. In the mean time here are a couple suggestions

yt/utilities/amr_kdtree/amr_kdtools.py Outdated Show resolved Hide resolved
yt/utilities/amr_kdtree/amr_kdtools.py Outdated Show resolved Hide resolved
yt/utilities/amr_kdtree/amr_kdtree.py Outdated Show resolved Hide resolved
yt/utilities/amr_kdtree/amr_kdtree.py Outdated Show resolved Hide resolved
biboyd and others added 2 commits April 17, 2024 14:53
Co-authored-by: Clément Robert <cr52@protonmail.com>
@chrishavlin chrishavlin self-requested a review April 24, 2024 18:16
@cphyc
Copy link
Member

cphyc commented May 6, 2024

@yt-fido test this please

1 similar comment
@chrishavlin
Copy link
Contributor

@yt-fido test this please

Copy link
Contributor

@chrishavlin chrishavlin left a comment

Choose a reason for hiding this comment

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

This looks good to me. Apologies for the very delayed review here, @biboyd

@neutrinoceros I'm not certain what could be added for a test since the changes here only have an effect when running with MPI. any ideas?

@chrishavlin chrishavlin linked an issue May 13, 2024 that may be closed by this pull request
@neutrinoceros
Copy link
Member

Do you mean we don't have any form of continuous testing with MPI yet ? if so, I'd agree to leave it out of this PR, but we should probably open issue for it.

@chrishavlin
Copy link
Contributor

Do you mean we don't have any form of continuous testing with MPI yet ? if so, I'd agree to leave it out of this PR, but we should probably open issue for it.

Ya, that's what I meant (but wasn't positive about it).

So IMO this PR is OK as it is.

@neutrinoceros
Copy link
Member

Thanks for clarifying. Feel free to merge then.

@chrishavlin chrishavlin merged commit bdef0b6 into yt-project:main May 15, 2024
13 checks passed
Copy link

welcome bot commented May 15, 2024

Hooray! Congratulations on your first merged pull request! We hope we keep seeing you around! 🎆

@neutrinoceros neutrinoceros added this to the 4.4.0 milestone May 15, 2024
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 this pull request may close these issues.

Volume Rendering Multiple Fields with MPI
4 participants