4
4
from numpy .testing import assert_allclose
5
5
6
6
from glue .core import Data
7
+ from glue .core .link_helpers import LinkSame
7
8
from glue .tests .helpers import PYSIDE2_INSTALLED # noqa
8
9
from glue .app .qt import GlueApplication
9
10
from glue .utils import nanmean
@@ -23,12 +24,21 @@ def setup_method(self, method):
23
24
self .data .coords = SimpleCoordinates ()
24
25
self .data ['x' ] = np .arange (240 ).reshape ((30 , 4 , 2 )).astype (float )
25
26
27
+ self .data_2d = Data (label = 'd2' )
28
+ self .data_2d ['x' ] = np .arange (8 ).reshape ((4 , 2 )).astype (float )
29
+
26
30
self .app = GlueApplication ()
27
31
self .session = self .app .session
28
32
self .hub = self .session .hub
29
33
30
34
self .data_collection = self .session .data_collection
31
35
self .data_collection .append (self .data )
36
+ self .data_collection .append (self .data_2d )
37
+
38
+ link1 = LinkSame (self .data .pixel_component_ids [1 ], self .data_2d .pixel_component_ids [0 ])
39
+ link2 = LinkSame (self .data .pixel_component_ids [2 ], self .data_2d .pixel_component_ids [1 ])
40
+ self .data_collection .add_link (link1 )
41
+ self .data_collection .add_link (link2 )
32
42
33
43
self .viewer = self .app .new_data_viewer (ProfileViewer )
34
44
self .viewer .state .function = 'mean'
@@ -214,3 +224,48 @@ def test_collapse_reverse(self, capsys):
214
224
out , err = capsys .readouterr ()
215
225
assert out .strip () == ""
216
226
assert err .strip () == ""
227
+
228
+ def test_collapse_with_2d_in_image (self , capsys ):
229
+
230
+ # Regression test for a bug that occurred when collapsing data and when a 2-d
231
+ # dataset was present in the image viewer.
232
+
233
+ self .viewer .add_data (self .data )
234
+ self .viewer .add_data (self .data_2d )
235
+
236
+ image_viewer = self .app .new_data_viewer (ImageViewer )
237
+ image_viewer .add_data (self .data )
238
+ image_viewer .add_data (self .data_2d )
239
+
240
+ self .profile_tools .ui .tabs .setCurrentIndex (2 )
241
+
242
+ # First try in pixel coordinates
243
+
244
+ self .viewer .state .x_att = self .data .pixel_component_ids [0 ]
245
+
246
+ # Force events to be processed to make sure that the callback functions
247
+ # for the computation thread are executed (since they rely on signals)
248
+ self .viewer .layers [0 ].wait ()
249
+ process_events ()
250
+
251
+ x , y = self .viewer .axes .transData .transform ([[0.9 , 4 ]])[0 ]
252
+ self .viewer .axes .figure .canvas .button_press_event (x , y , 1 )
253
+ x , y = self .viewer .axes .transData .transform ([[15.1 , 4 ]])[0 ]
254
+ self .viewer .axes .figure .canvas .motion_notify_event (x , y , 1 )
255
+
256
+ process_events ()
257
+
258
+ self .profile_tools .ui .button_collapse .click ()
259
+
260
+ process_events ()
261
+
262
+ assert isinstance (image_viewer .state .slices [0 ], AggregateSlice )
263
+ assert image_viewer .state .slices [0 ].slice .start == 1
264
+ assert image_viewer .state .slices [0 ].slice .stop == 15
265
+ assert image_viewer .state .slices [0 ].center == 0
266
+ assert image_viewer .state .slices [0 ].function is nanmean
267
+
268
+ out , err = capsys .readouterr ()
269
+
270
+ assert err .strip () == ""
271
+ assert out .strip () == ""
0 commit comments