|
6 | 6 | from astropy.table import Table, vstack |
7 | 7 | from astropy import units as u |
8 | 8 | import astropy.visualization as apviz |
| 9 | +from astropy.wcs import WCS |
9 | 10 |
|
10 | 11 | from bqplot import Figure, LinearScale, Axis, ColorScale, PanZoom, ScatterGL |
11 | 12 | from bqplot_image_gl import ImageGL |
@@ -177,6 +178,10 @@ def center(self, value): |
177 | 178 | self._scales['y'].max = y_c + width_y / 2 |
178 | 179 | self._scales['y'].min = y_c - width_y / 2 |
179 | 180 |
|
| 181 | + @property |
| 182 | + def interaction(self): |
| 183 | + return self._figure.interaction |
| 184 | + |
180 | 185 | def set_color(self, colors): |
181 | 186 | # colors here means a list of hex colors |
182 | 187 | self._image.scales['image'].colors = colors |
@@ -364,12 +369,64 @@ def __init__(self, *args, image_width=500, image_height=500): |
364 | 369 | viewer_aspect_ratio=viewer_aspect) |
365 | 370 | self._interval = None |
366 | 371 | self._stretch = None |
367 | | - self._colormap = 'Grays' |
| 372 | + self.set_colormap('Greys_r') |
368 | 373 | self._marker_table = MarkerTableManager() |
369 | 374 | self._data = None |
370 | 375 | self._wcs = None |
371 | 376 | self._is_marking = False |
| 377 | + |
372 | 378 | self.marker = {'color': 'red', 'radius': 20, 'type': 'square'} |
| 379 | + self.cuts = apviz.AsymmetricPercentileInterval(1, 99) |
| 380 | + |
| 381 | + self._cursor = ipw.HTML('Coordinates show up here') |
| 382 | + self._init_mouse_callbacks() |
| 383 | + self.children = [self._astro_im, self._cursor] |
| 384 | + |
| 385 | + def _init_mouse_callbacks(self): |
| 386 | + |
| 387 | + def on_mouse_message(interaction, event_data, buffers): |
| 388 | + """ |
| 389 | + This function simply detects the event type then dispatches |
| 390 | + to the method that handles that event. |
| 391 | +
|
| 392 | + The ``event_data`` contains all of the information we need. |
| 393 | + """ |
| 394 | + if event_data['event'] == 'mousemove': |
| 395 | + self._mouse_move(event_data) |
| 396 | + |
| 397 | + self._astro_im.interaction.on_msg(on_mouse_message) |
| 398 | + |
| 399 | + def _mouse_move(self, event_data): |
| 400 | + if self._data is None: |
| 401 | + # Nothing to display, so exit |
| 402 | + return |
| 403 | + |
| 404 | + xc = event_data['domain']['x'] |
| 405 | + yc = event_data['domain']['y'] |
| 406 | + |
| 407 | + # get the array indices into the data so that we can get data values |
| 408 | + x_index = int(np.trunc(xc + 0.5)) |
| 409 | + y_index = int(np.trunc(yc + 0.5)) |
| 410 | + |
| 411 | + # Check that the index is in the array. |
| 412 | + in_image = (self._data.shape[1] > x_index >= 0) and (self._data.shape[0] > y_index >= 0) |
| 413 | + if in_image: |
| 414 | + val = self._data[y_index, x_index] |
| 415 | + else: |
| 416 | + val = None |
| 417 | + |
| 418 | + if val is not None: |
| 419 | + value = f'value: {val:8.3f}' |
| 420 | + else: |
| 421 | + value = 'value: N/A' |
| 422 | + |
| 423 | + pixel_location = f'X: {xc:.2f} Y: {yc:.2f}' |
| 424 | + if self._wcs is not None: |
| 425 | + sky = self._wcs.pixel_to_world(xc, yc) |
| 426 | + ra_dec = f'RA: {sky.icrs.ra:3.7f} Dec: {sky.icrs.dec:3.7f}' |
| 427 | + else: |
| 428 | + ra_dec = '' |
| 429 | + self._cursor.value = ', '.join([pixel_location, ra_dec, value]) |
373 | 430 |
|
374 | 431 | def _interval_and_stretch(self): |
375 | 432 | """ |
|
0 commit comments