-
Notifications
You must be signed in to change notification settings - Fork 279
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
[Feature] Wiring frb buffers with plot_window #1877
Conversation
There is a lot of room for improvement in this PR and I don't really like the way it is wired now, because the frb should in principle be independent of the plot window. One way to improve that would be to expose the frb-bound filters at the plot window level, and invalidate the data and call the subsequent frb filter from the plot window instead of relying on the filter to invalidate the data. |
# We need to invalidate the data to force the plot window to | ||
# take the filter into account. | ||
if frb.plot_window: | ||
frb.plot_window._data_valid = False |
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.
What if FixedResolutionBuffer instances had a _data_valid
attribute. We would need to refactor PlotWindow to store that state on the frb
attribute but I think it would be a straightforward refactor.
yt/visualization/fixed_resolution.py
Outdated
self.data = {} | ||
FixedResolutionBuffer.__init__(self, data_source, bounds, buff_size, | ||
antialias, periodic) | ||
super(ParticleImageBuffer, self).__init__(*args, **kwargs) |
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.
Can you explicitly pass the arguments?
yt/visualization/fixed_resolution.py
Outdated
@@ -555,11 +554,9 @@ class ParticleImageBuffer(FixedResolutionBuffer): | |||
buffer. | |||
|
|||
""" | |||
def __init__(self, data_source, bounds, buff_size, antialias=True, | |||
periodic=False): | |||
def __init__(self, *args, **kwargs): |
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.
Can we explicitly list the arguments?
yt/visualization/plot_window.py
Outdated
@@ -240,6 +240,7 @@ def fget(self): | |||
def fset(self, value): | |||
self._frb = value | |||
self._data_valid = True | |||
self._plot_valid = False |
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 don't think this is used anywhere
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 is at line 751 of the same file.
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.
Ah I see, this is a good cleanup then. Sorry for not looking at the whole file, just the diff.
yt/visualization/plot_window.py
Outdated
@@ -665,6 +667,9 @@ def __init__(self, *args, **kwargs): | |||
self._splat_color = kwargs.pop("splat_color", None) | |||
PlotWindow.__init__(self, *args, **kwargs) | |||
|
|||
def data_is_valid(self): | |||
return self._data_valid and self._frb and self._frb._data_valid |
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.
Now that you've refactored everything into this function, do you think we need both _data_valid
and frb._data_valid
? Can't we just use frb._data_valid
and get rid of the attribute on the plot itself?
I also like to make helpers like this properties so you don't need to append the ()
every time you use them.
Awesome, the latest version is much cleaner! |
doc/source/visualizing/callbacks.rst
Outdated
@@ -777,3 +777,21 @@ Overplot the Path of a Ray | |||
p.annotate_ray(oray) | |||
p.annotate_ray(ray) | |||
p.save() | |||
|
|||
|
|||
Operating on the final image |
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 would call this "applying filters"
yt/visualization/plot_window.py
Outdated
@@ -659,6 +667,10 @@ def __init__(self, *args, **kwargs): | |||
self._splat_color = kwargs.pop("splat_color", None) | |||
PlotWindow.__init__(self, *args, **kwargs) | |||
|
|||
@property | |||
def data_is_valid(self): | |||
return self._data_valid and self._frb and self._frb._data_valid |
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 commented on this before and I don't think you responded - can you explain why we need both plot._data_valid
and _frb._data_valid
? I'd prefer to only store this state in one place if possible.
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've updated the code removing plot._data_valid
, let's see if the test pass.
The logic behind |
OK, fair enough. I guess back out that last change? I will try to take a look at this this week sometime and see if there's a way to clean this up. Would you be ok with me pushing directly to this branch? |
@ngoldbaum it would indeed be enough to revert c3ef894 and 4cead9d and I'm fine with you pushing directly on the branch. |
@cphyc Other than the merge conflict, is this ready to go? I realize it's been a long time. |
@cphyc Hey, what do you think about this? |
I think this is ready to go. I remember having to think thoroughly to make sense of the logic behind the validation process (which would likely require need to be refactored). Let me trigger the tests to check that. |
@yt-fido test this please. |
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 left some minor comments, obviously this has already been refined a lot and overall it looks great, I would love if we could get this merged for the 4.0 release.
The only change I wish to request is about the gaussian filter refactor and deprecation.
6b5cb7f
to
275ba01
Compare
When adding a filter to a fixed resolution buffer, we want the plot_window to be invalidated so that the plot is redrawn using the filter.
…ects without a data_is_valid attribute
for more information, see https://pre-commit.ci
15c0ff5
to
166afce
Compare
ENH: expose FRB filtering API (remake #1877)
PR Summary
This wires the FixedResolutionBuffer objects to their parent
plot_window
(if any) so that the addition of a filter results in the invalidation of the plot window.The PR also modified the
apply_gauss_beam
filter to use https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.ndimage.filters.gaussian_filter.html.PR Checklist
Example script