-
Notifications
You must be signed in to change notification settings - Fork 0
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
show sky coordinates in subset plugin when wcs linked #19
Conversation
1bd45a7
to
bc3be34
Compare
0f0ecc2
to
26568a5
Compare
Displaying the RA/Dec of the subsets seems to work fine, however I'm not sure if updating the values in the plugin and then clicking update is doing the correct thing. I would have expected that if I updated one value (max RA in the video below) then at least one of the corners of the subset would remain in the same place as it started. However, it seems like the subset completely changes both shape and the location of all four corners when I update the max RA: Screen.Recording.2023-11-15.at.2.35.44.PM.movAm I right that this is unexpected? |
@rosteen thanks for testing. to clarify, are you only seeing this issue for rectangle? |
Yes, the other shapes seem to behave in the way I would expect when updating their center or radius values. |
ok let me try to debug this. Theres a lot of room for error with that subset since i need to do many conversions between pixel and sky, and also between rectangles defined with xmin/xmax (for ROI) and height/width (for regions). |
Is |
I'm not seeing the issue with composite subsets, I've been testing it out and it seems to work as intended, but I will keep looking into it |
I tested out the rectangle issue at theta=0 to take the angle out of it (rotation is done last), and I'm convinced that this is working as intended. Its unintuitive but this PR doesn't introduce that. I also tested 'recenter' and that continues to work with these changes (the UI is updated in sky coordinates when WCS linked as the subset moves) |
if self.config == 'cubeviz': | ||
parent_data = subset_state.attributes[0].parent | ||
wcs = parent_data.meta.get("_orig_spatial_wcs", None) | ||
else: | ||
wcs = subset_state.xatt.parent.coords |
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 know this isn't new code, but maybe we need a tech debt ticket to try to clean this up?
# convert previous entered sky coords to pixel | ||
orig_xy = [x['orig'] for x in sub if 'Center' in x['name']] | ||
orig_rad = [x['orig'] for x in sub if 'Radius' in x['name']][0] | ||
orig_pixregion = CircleSkyRegion(center=SkyCoord(*orig_xy*u.deg), radius=orig_rad*u.deg).to_pixel(wcs) | ||
new_orig_xy = (orig_pixregion.center.x, orig_pixregion.center.y) | ||
new_orig_rad = orig_pixregion.radius |
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.
did you try getting rid of these and just always updating the internal state? Does that cause problems? I just worry that the code-duplication and extra computations will have more cost than just pushing an extra update (with no changes).
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 haven't tried that yet, maybe this could be a follow up ticket since this already existed in the code before this PR? i'm fairly certain that removing this (and the check for if new matches old to avoid update) will just cause it to update every time, and is less costly than checking every time, but im worried about unintended consequences.
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.
hmm, ok, then is it possible to do the comparison in sky (store the orig sky in the dictionary instead of orig pixel and do the "change comparison" based on that)? It would just be nice to avoid duplicated code and minimize the number of conversions
existing issue about composite subsets made with 'remove' mode. spacetelescope#2570. |
8f4abc2
to
1d62999
Compare
jdaviz/configs/default/plugins/subset_plugin/tests/test_subset_plugin.py
Outdated
Show resolved
Hide resolved
Still 3 failures. |
mins_maxs = {'xmin': sky_region.center.ra.deg - ((sky_region.width).to(u.deg).value / 2.), | ||
'xmax': sky_region.center.ra.deg + ((sky_region.width).to(u.deg).value / 2.), | ||
'ymin': sky_region.center.dec.deg - ((sky_region.height).to(u.deg).value / 2.), | ||
'ymax': sky_region.center.dec.deg + ((sky_region.height).to(u.deg).value / 2.)} |
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.
mins_maxs = {'xmin': sky_region.center.ra.deg - ((sky_region.width).to(u.deg).value / 2.), | |
'xmax': sky_region.center.ra.deg + ((sky_region.width).to(u.deg).value / 2.), | |
'ymin': sky_region.center.dec.deg - ((sky_region.height).to(u.deg).value / 2.), | |
'ymax': sky_region.center.dec.deg + ((sky_region.height).to(u.deg).value / 2.)} | |
d_ra = sky_region.width.to_value(u.deg) * 0.5 | |
d_dec = sky_region.height.to_value(u.deg) * 0.5 | |
mins_maxs = {'xmin': sky_region.center.ra.deg - d_ra, | |
'xmax': sky_region.center.ra.deg + d_ra, | |
'ymin': sky_region.center.dec.deg - d_dec, | |
'ymax': sky_region.center.dec.deg + d_dec} |
Somehow this patch is loading an existing DS9 annulus region file incorrectly. You can try to run the code manually and debug outside the test session.
|
|
Similar problem as #19 (comment) . When linked by pixel, these two images have the bright pixel aligned on the same pixel, so both should return same value, but not
|
@pllim i 'fixed' the test - the bug with loading regions is now the same as it is on main. the fix here was to not try to get a sky region when 'get_subsets' is run on init, but it should be safe to do this once the underlying issue is fixed. ill link the follow up issue here. |
BTW, I am fixing that test on Looks like you will need another approval from Brett to run the CI. |
@cshanahan1 Still looks like one test related to this PR is failing: https://github.com/bmorris3/jdaviz/actions/runs/7107838227/job/19375803669?pr=19#step:5:695 |
Tsk tsk... cannot run the CI without spacetelescope#2595 |
Remaining failures will be solved by rebasing spacetelescope#2179 against main. Thanks @cshanahan1! |
This PR changes the behavior of the subset plugin to reflect link type (pixel or wcs). If wcs linked, subset attributes (e.g center, radius) will be displayed in the plugin in sky coordinates. If pixel linked, they will be displayed in pixels.
I added a subset_plugin.utils module to handle the translation between what is referred to in the plugin as 'subset_definition', a list of dictionaries each containing information about each subset attribute and regions/ROI/etc. This keeps most of the translations out of the actual plugin, and accessible by tests. I can think of some ways this could be improved in the future (defining a 'SubsetDefinition' class in the plugin, so that the structure of the dictionary doesn't have to be repeated so much), but in another PR.
Additionally, as referenced in the discussion below, we may want to remove the check if old==new upon update because this adds in another unnecessary pixel <> sky. I tried doing that by simply removing the check, and allowing it to change upon clicking 'update' even if the values didn't change, and I noticed that it wandered a bit while I did this presumably due to rounding and pixel>sky conversion internally. I do think this could be done smarter, but I'm not sure I want to change that here (I tried the comparison before conversion, and other errors came up, so I need to dig into this more).
Finally, the comment about rectangle corners not staying fixed upon changing one boundary is unfortunately how it's supposed to work. The rectangular subset xmin/xmax/ymin/ymax are the bounds before rotation, so the center can change. It is unintuitive but re defining it in terms of center/width/height will have to happen down the line.