glue-viz / glue-astronomy

Plugin to add astronomy-specific functionality to glue
https://glue-astronomy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
11 stars 13 forks source link

Subset on dithered data linked by WCS ignores the dither #52

Open pllim opened 2 years ago

pllim commented 2 years ago

I saw this at Imviz (from jdaviz) but I think the bug is within the regions translator, but I am not familiar enough with this package to fix it.

>>> from astropy.utils.data import download_file
>>> from glue.core.subset import Subset
>>> from jdaviz import Imviz
>>> imviz = Imviz(verbosity='warning')  # Hide info messages
>>> acs_47tuc_1 = download_file('https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HST/product/jbqf03gjq_flc.fits', cache=True)
>>> acs_47tuc_2 = download_file('https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HST/product/jbqf03h1q_flc.fits', cache=True)
>>> imviz.load_data(acs_47tuc_1, data_label='acs_47tuc_1')
>>> imviz.load_data(acs_47tuc_2, data_label='acs_47tuc_2')
>>> imviz.link_data(link_type='wcs')
>>> my_cen = (1090, 1157)
>>> my_radius = 10
>>> imviz._apply_interactive_region(
...     'bqplot:circle', (my_cen[0] - my_radius, my_cen[1] - my_radius),
...                      (my_cen[0] + my_radius, my_cen[1] + my_radius))
>>> regions = {}
>>> for lyr in imviz.default_viewer.layers:
...     if isinstance(lyr.layer, Subset):
...         regions[f'{lyr.layer.label}[{lyr.layer.data.label}]'] = lyr.layer.data.get_selection_definition(subset_id=lyr.layer.label, format='astropy-regions')
>>> regions
{'Subset 1[acs_47tuc_1[SCI,1]]': <CirclePixelRegion(center=PixCoord(x=1090.0, y=1157.0), radius=10.0)>,
 'Subset 1[acs_47tuc_2[SCI,1]]': <CirclePixelRegion(center=PixCoord(x=1090.0, y=1157.0), radius=10.0)>}

I expected the center for subset region derived from acs_47tuc_1[SCI,1] to be a little different from acs_47tuc_2[SCI,1] but they are exactly the same. One of them is wrong.

On the Imviz display, I see the Subset properly displayed at the correct sky location when I blink them.

🐱

pllim commented 2 years ago

@astrofrog said to fix this properly, the fix should be here:

https://github.com/glue-viz/glue-astronomy/blob/7f3229d01bdc2bff64fdb1a83738447cf696c59d/glue_astronomy/translators/regions.py#L49

Maybe translating ROI of the Subset, if not w.r.t. reference data, to polygon ROI. He needs to think about it.

Currently, it always returns the Subset w.r.t. reference data even if you pass in a Subset w.r.t. non-reference data.

pllim commented 2 years ago

Note to self: If this remains unfixed and we get desperate, we ferret out the masks at the Glue level and use that for photometry. But in doing that, we lose the ability to have sub-pixel sampling.

imviz.app.data_collection[i].subset[j].to_mask()
imviz.app.data_collection[i+1].subset[j].to_mask()
pllim commented 2 years ago

I ended up just working around this for that one plugin. See https://github.com/spacetelescope/jdaviz/pull/1524