glue
glue copied to clipboard
GWCS crashes Glue linking (grism)
I am not allowed to share the image but I can show you the GWCS like this (spoiler: it is grism):
>>> dm.meta.wcs
<WCS(output_frame=world, input_frame=grism_detector, forward_transform=Model: CompoundModel
Inputs: ('x', 'y', 'x0', 'y0', 'order')
Outputs: ('lon', 'lat', 'x0', 'x1')
Model set size: 1
Expression: [0] | ([1] & [2] | [3] | [4] & [5] | [6] | [7] | [8] & [9] | [10] | [11] & [12]) & [13] | [14] & [15] | ([16] & [17] | [18] | [19] | [20]) & [21]
Components:
[0]: <NIRISSForwardRowGrismDispersion(name='niriss_forward_row_grism_dispersion')>
[1]: <Shift(offset=-1023.5)>
[2]: <Shift(offset=-1023.5)>
[3]: <Mapping((0, 1, 0, 1))>
[4]: <Polynomial2D(4, c0_0=-0., c1_0=0.06539229, c2_0=0.00000002, c3_0=-0., c4_0=-0., c0_1=-0., c0_2=0., c0_3=-0., c0_4=0., c1_1=-0.00000001, c1_2=-0., c1_3=0., c2_1=-0., c2_2=-0., c3_1=0.)>
[5]: <Polynomial2D(4, c0_0=0., c1_0=-0.00029856, c2_0=-0.00000005, c3_0=-0., c4_0=0., c0_1=0.06588855, c0_2=-0., c0_3=-0., c0_4=0., c1_1=0.00000003, c1_2=-0., c1_3=0., c2_1=-0., c2_2=0., c3_1=-0.)>
[6]: <Identity(2)>
[7]: <Mapping((0, 1, 0, 1))>
[8]: <Polynomial2D(1, c0_0=0., c1_0=-0.99995054, c0_1=0.00994595)>
[9]: <Polynomial2D(1, c0_0=0., c1_0=0.00994595, c0_1=0.99995054)>
[10]: <Identity(2)>
[11]: <Shift(offset=-291.219)>
[12]: <Shift(offset=-698.181)>
[13]: <Identity(2)>
[14]: <Identity(2)>
[15]: <Identity(2)>
[16]: <Scale(factor=0.00027778)>
[17]: <Scale(factor=0.00027778)>
[18]: <SphericalToCartesian()>
[19]: <RotationSequence3D(angles=[ -0.08089417, 0.19393917, 0.22537397, -70.08363513, -81.08180572])>
[20]: <CartesianToSpherical()>
[21]: <Identity(2)>
Parameters:
offset_1 offset_2 c0_0_4 c1_0_4 c2_0_4 c3_0_4 ... c0_1_9 offset_11 offset_12 factor_16 factor_17 angles_19 [5]
-------- -------- ------ ------------------- ---------------------- ----------------------- ... ----------------- --------- --------- --------------------- --------------------- -----------------------------------------
-1023.5 -1023.5 -0.0 0.06539229315982802 2.3048392287757872e-08 -2.3007847857064428e-12 ... 0.999950537846242 -291.219 -698.181 0.0002777777777777778 0.0002777777777777778 -0.08089416666666667 .. -81.0818057202483)>
The code goes something like this:
from glue.core.data import Component, Data
from jwst import datamodels
dm = datamodels.open(fileobj)
imdata = dm.data # 2048 x 2048
c = Component.autotyped(imdata, units=dm.meta.bunit_data) # DN/s
data = Data(label='foo')
data.coords = dm.meta.wcs
data.add_component(component=c, label='comp') # crashes
.../glue/core/data.py in add_component(self, component, label)
976 if len(self._components) == 0:
977 # TODO: make sure the following doesn't raise a componentsraised message
--> 978 self._create_pixel_and_world_components(ndim=component.ndim)
979
980 # In some cases, such as when loading a session, we actually disable the
.../glue/core/data.py in _create_pixel_and_world_components(self, ndim)
1110 def _create_pixel_and_world_components(self, ndim):
1111 self._update_pixel_components(ndim)
-> 1112 self._update_world_components(ndim)
1113
1114 def _update_pixel_components(self, ndim):
.../glue/core/data.py in _update_world_components(self, ndim)
1139 cid = self.add_component(comp, label)
1140 self._world_component_ids.append(cid)
-> 1141 self._set_up_coordinate_component_links(ndim)
1142
1143 def _set_up_coordinate_component_links(self, ndim):
.../glue/core/data.py in _set_up_coordinate_component_links(self, ndim)
1148 result = []
1149 for i in range(ndim):
-> 1150 link = CoordinateComponentLink(self._pixel_component_ids,
1151 self._world_component_ids[i],
1152 self.coords, i)
.../glue/core/component_link.py in __init__(self, comp_from, comp_to, coords, index, pixel2world)
366 self._from_all = comp_from
367
--> 368 comp_from = [comp_from[i] for i in self.from_needed]
369 super(CoordinateComponentLink, self).__init__(
370 comp_from, comp_to, self.using)
.../glue/core/component_link.py in <listcomp>(.0)
366 self._from_all = comp_from
367
--> 368 comp_from = [comp_from[i] for i in self.from_needed]
369 super(CoordinateComponentLink, self).__init__(
370 comp_from, comp_to, self.using)
IndexError: list index out of range
xref spacetelescope/jdaviz#778
What does glue.core.coordinate_helpers.dependent_axes(data.coords, i) return for i in range(ndim)?
Does this help?
>>> for i in range(imdata.ndim):
... print(i, glue.core.coordinate_helpers.dependent_axes(data.coords, i))
0 (0, 1, 2, 3, 4)
1 (0, 1, 2, 3, 4)
I think glue doesn't yet work well with WCSes that have a different number of pixel and world dimensions - see https://github.com/glue-viz/glue/issues/2162
Feel free to close this as duplicate if it is. Thanks!