-
Notifications
You must be signed in to change notification settings - Fork 153
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
Make stretches be customizable on a layer by layer basis #2453
Make stretches be customizable on a layer by layer basis #2453
Conversation
…tretch_parameters callback properties on a state class and define stretch_object, keeping everything in sync
for key, value in self.stretch_parameters.items(): | ||
if hasattr(self._stretch_object, key): | ||
setattr(self._stretch_object, key, value) | ||
else: | ||
raise ValueError( | ||
f"Stretch object {self._stretch_object.__class__.__name__} has no attribute {key}" | ||
) |
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.
If a stretch accepts multiple attributes but needs to validate them wrt each other (for example: x/y coordinates of knot locations for a spline), what would be the best way to handle that?
As this stands, those will need to be passed as a single entry (stretch_parameters['knots'] = ([x1, x2], [y1, y2])
) so that validation can occur in a single setter on the stretch object.
Alternative ideas:
- support some sort of context manager (similar to
hold_sync
) that validates the attributes after setting all of them at the end of this for-loop? This of course needs to be compatible with the astropy stretch objects that are used by default as we probably can't modify those upstream just to account for this. - instead of looping and checking for
hasattr
on the individual keys, could we instead require aupdate_parameters
method (ifstretch_parameters
is not empty) on the stretch object which handles this logic internally by getting the entire dictionary in one pass?
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.
Just to put another idea out there, could you perhaps not validate when the attributes are set but when the stretch is called?
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.
That's an option, but probably causes unnecessary cost when calling the stretch repeatedly. In our case, we can probably just validate externally since we manage the stretch object, but then if a user modifies the values, they will need to make sure they make sense.
Is this patch not backward compatible? |
I did try and make it backward compatible but may have missed something. I will investigate the jdaviz failures tomorrow. |
I think it is ok. I ended up doing a version check and it seems to work. See spacetelescope/jdaviz#2591 |
For the image and scatter viewers, this adds a new dictionary property
stretch_parameters
which can be used to set stretch parameters specific to the layer. These parameters are then set as attribute on state instances. So the requirement for new stretch classes is that parameters can be set as attributes on existing instances (e.g.LogStretch.exp
). Example:Glue deals with keeping
stretch_parameters
in sync with the stretch instance/object, and will deal with refreshing the plot.