|
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
|
@@ -363,12 +368,64 @@ def __init__(self, *args, image_width=500, image_height=500):
|
363 | 368 | viewer_aspect_ratio=viewer_aspect)
|
364 | 369 | self._interval = None
|
365 | 370 | self._stretch = None
|
366 |
| - self._colormap = 'Grays' |
| 371 | + self.set_colormap('Greys_r') |
367 | 372 | self._marker_table = MarkerTableManager()
|
368 | 373 | self._data = None
|
369 | 374 | self._wcs = None
|
370 | 375 | self._is_marking = False
|
| 376 | + |
371 | 377 | self.marker = {'color': 'red', 'radius': 20, 'type': 'square'}
|
| 378 | + self.cuts = apviz.AsymmetricPercentileInterval(1, 99) |
| 379 | + |
| 380 | + self._cursor = ipw.HTML('Coordinates show up here') |
| 381 | + self._init_mouse_callbacks() |
| 382 | + self.children = [self._astro_im, self._cursor] |
| 383 | + |
| 384 | + def _init_mouse_callbacks(self): |
| 385 | + |
| 386 | + def on_mouse_message(interaction, event_data, buffers): |
| 387 | + """ |
| 388 | + This function simply detects the event type then dispatches |
| 389 | + to the method that handles that event. |
| 390 | +
|
| 391 | + The ``event_data`` contains all of the information we need. |
| 392 | + """ |
| 393 | + if event_data['event'] == 'mousemove': |
| 394 | + self._mouse_move(event_data) |
| 395 | + |
| 396 | + self._astro_im.interaction.on_msg(on_mouse_message) |
| 397 | + |
| 398 | + def _mouse_move(self, event_data): |
| 399 | + if self._data is None: |
| 400 | + # Nothing to display, so exit |
| 401 | + return |
| 402 | + |
| 403 | + xc = event_data['domain']['x'] |
| 404 | + yc = event_data['domain']['y'] |
| 405 | + |
| 406 | + # get the array indices into the data so that we can get data values |
| 407 | + x_index = int(np.trunc(xc + 0.5)) |
| 408 | + y_index = int(np.trunc(yc + 0.5)) |
| 409 | + |
| 410 | + # Check that the index is in the array. |
| 411 | + in_image = (self._data.shape[1] > x_index >= 0) and (self._data.shape[0] > y_index >= 0) |
| 412 | + if in_image: |
| 413 | + val = self._data[y_index, x_index] |
| 414 | + else: |
| 415 | + val = None |
| 416 | + |
| 417 | + if val is not None: |
| 418 | + value = f'value: {val:8.3f}' |
| 419 | + else: |
| 420 | + value = 'value: N/A' |
| 421 | + |
| 422 | + pixel_location = f'X: {xc:.2f} Y: {yc:.2f}' |
| 423 | + if self._wcs is not None: |
| 424 | + sky = self._wcs.pixel_to_world(xc, yc) |
| 425 | + ra_dec = f'RA: {sky.icrs.ra:3.7f} Dec: {sky.icrs.dec:3.7f}' |
| 426 | + else: |
| 427 | + ra_dec = '' |
| 428 | + self._cursor.value = ', '.join([pixel_location, ra_dec, value]) |
372 | 429 |
|
373 | 430 | def _interval_and_stretch(self):
|
374 | 431 | """
|
|
0 commit comments