-
Notifications
You must be signed in to change notification settings - Fork 280
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
Off-axis (non-SPH) particle projections #4440
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks alright! Minor comments.
While I'm thinking of it, I do also think we should consider a mode of rotation for particle-based datasets. Specifically, it seems like we could interpose anywhere the IO happens to have the particles rotated. I don't think this would work with a context manager (necessarily) but maybe could. |
This is a good thought--I've recently had occasion to make copies of particle datasets where I have rotated and shifted the coordinates and velocities. |
I am completely baffled by the Jenkins failures. |
@yt-fido test this please |
@Xarthisius any idea what happened with the seemingly unrelated Jenkins failures? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to make time for a thorough review soon, for now here are a couple comments
Co-authored-by: Clément Robert <cr52@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great. I got a couple nits and questions, but more importantly, a comment on how to change the name of the argument (axis
-> normal
) without immediately breaking backward compat.
Co-authored-by: Clément Robert <cr52@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finishing with details of the deprecation cycle, I'll try to circle back for an other full review tonight
Co-authored-by: Clément Robert <cr52@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I wasn't able to review as early as I wanted. I have some important concerns with the current design of the ParticleProjectionPlot
class, and I'd like it be made closer to ProjectionPlot
while we have the chance.
data_source, bounds, (nx, ny), periodic=all(ds.periodicity) | ||
) | ||
elif isinstance(data_source, ParticleDummyDataSource): | ||
if hasattr(data_source, "normal_vector"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_source.normal_vector
is not actually used in the following so it is a bit obscure why the branching is done depending on wether or not this attribute exists. If we're going to treat OffAxis...DummyDataSource
classes as a protocol, I'd rather we do it more explicitly (yes it's uglier, but also much easier to understand and refactor if we ever manage to)
if hasattr(data_source, "normal_vector"): | |
if re.fullmatch(r"OffAxis\w+DummyDataSource", type(data_source).__name__): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer we find a less ugly way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's frankly better to add a comment here why we check this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to be extremely careful that this doesn't creep out of scope. I would prefer this be a minimally invasive change for new functionality, and the branching -- while perhaps a bit unexpected -- is pragmatic and certainly consistent with other branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's way to implement this check using isinstance
instead of hasattr
that
- can be checked continuously
- doesn't require a (possibly outdated) comment
- doesn't require inheritance
Namely: typing.Protocol
(which we do have access to since we don't support Python < 3.8 any more)
For illustration, here's a minimal implementation
from typing import Protocol, runtime_checkable
import numpy as np
@runtime_checkable
class OffAxisDummyDataSource:
normal_vector: np.ndarray
class Dumdumdatasource:
normal_vector = np.zeros(3)
assert isinstance(Dumdumdatasource(), OffAxisDummyDataSource)
I understand that this goes beyond the scope of this PR, which is why I instead suggested an (ugly) one-line refactor to make the code more expressive, but long term I'd like to start using such protocol classes to replace calls to hasattr
; IMO they would fit nicely in the yt._typing
namespace. Is this something we can all get behind ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like an answer to this before I hit approve. I'm happy to put in the work for yt 4.3.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm obviously happy to discuss anything, and it does look like a better long-term solution, but needless to say we'll have to hash that out in a different forum.
That ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, I just didn't want to leave unresolved threads before merging this important PR.
I attempted to implement the new functionality in a way that mimicks what we do for No idea why the doc build is failing, looks like a separate issue. |
@yt-fido test this please |
this is ready to go |
PR Summary
This PR adds support for off-axis projections of particles which are not SPH particles, by adding this capability to the
ParticleProjectionPlot
class for plots, and adding a new classFITSParticleOffAxisProjection
for FITS files.Example:
Still need to add tests, will do that soon.
PR Checklist