def run_js(self, js): if not js: return if self._wwt_ready: logger.debug('Running javascript: %s' % js) self.page.runJavaScript(js) else: logger.debug('Caching javascript: %s' % js) self._js_queue += js + '\n'
def _update_presentation(self, force=False, **kwargs): changed = set() if force else self.pop_changed_properties() logger.debug("updating WWT for 2D image %s" % self.layer.label) if self.visible is False: self.clear() return if force or 'mode' in changed or self.wwt_layer is None: self.clear() force = True if force or any(x in changed for x in RESET_IMAGE_PROPERTIES): self.clear() if not isinstance(self.layer.coords, WCS): raise ValueError('oh no not wcs') wcs = self.layer.coords try: data = self.layer[self.state.img_data_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.img_data_att) return self.wwt_layer = self.wwt_client.layers.add_image_layer( (data, wcs)) default_lims = np.percentile(data, [5., 95.]) self.state.vmin = default_lims[0] self.state.vmax = default_lims[1] force = True if force or 'alpha' in changed: if self.state.alpha is not None: self.wwt_layer.opacity = float(self.state.alpha) if force or 'stretch' in changed: if self.state.stretch is not None: self.wwt_layer.stretch = self.state.stretch if force or 'vmin' in changed: if self.state.vmin is not None: self.wwt_layer.vmin = self.state.vmin if force or 'vmax' in changed: if self.state.vmax is not None: self.wwt_layer.vmax = self.state.vmax self.enable()
def catalog(self, layer): logger.debug("adding %s" % layer.label) x = layer[self.option_panel.ra] y = layer[self.option_panel.dec] circles = [] for i in range(x.size): label = "%s_%i" % (layer.label.replace(' ', '_').replace('.', '_'), i) circles.append(circle(x[i], y[i], label, layer.style.color)) circles.append("wwt.addAnnotation(%s);" % label) js = "\n".join(circles) xcen = x.mean() ycen = y.mean() fov = y.max() - y.min() self._run_js(js) self.move(xcen, ycen, fov) return True
def catalog(self, layer): logger.debug("adding %s" % layer.label) x = layer[self.option_panel.ra] y = layer[self.option_panel.dec] circles = [] for i in range(x.size): label = "%s_%i" % (layer.label.replace(' ', '_').replace('.', '_'), i) circles.append(circle(x[i], y[i], label, layer.style.color)) circles.append("wwt.addAnnotation(%s);" % label) js = "\n".join(circles) xcen = x.mean() ycen = y.mean() fov = y.max() - y.min() self._run_js(js) self.move(xcen, ycen, fov) return True
def update(self, force=False, **kwargs): logger.debug("updating WWT for %s" % self.layer.label) coords = {} if force or 'ra_att' in kwargs or 'dec_att' in kwargs: try: ra = self.layer[self.state.ra_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.ra_att) return try: dec = self.layer[self.state.dec_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.dec_att) return if len(ra) > 0: try: coord = SkyCoord(ra, dec, unit=(u.deg, u.deg)) except ValueError as exc: # self.disable(str(exc)) return coord_icrs = coord.icrs ra = coord_icrs.ra.degree dec = coord_icrs.dec.degree coords = {'coords': (ra, dec)} self.enable() self.markers.set(self.layer_id, color=self.state.color, alpha=self.state.alpha, visible=self.visible, zorder=self.zorder, size=self.state.size, **coords)
def compute(self, data, view=None): """ For a given data set, compute the component comp_to given the data associated with each comp_from and the ``using`` function This raises an :class:`glue.core.exceptions.IncompatibleAttribute` if the data set doesn't have all the ComponentIDs needed for the transformation Parameters ---------- data : `~glue.core.data.Data` The data set to use view : `None` or `slice` or `tuple` Optional view (e.g. slice) through the data to use Returns ------- result The data associated with comp_to component """ # First we get the values of all the 'from' components. args = [data[join_component_view(f, view)] for f in self._from] # We keep track of the original shape of the arguments original_shape = args[0].shape logger.debug("shape of first argument: %s", original_shape) # We now unbroadcast the arrays to only compute the link with the # smallest number of values we can. This can help for cases where # the link depends only on e.g. pixel components or world coordinates # that themselves only depend on a subset of pixel components. # Unbroadcasting is the act of returning the smallest array that # contains all the information needed to be broadcasted back to its # full value args = [unbroadcast(arg) for arg in args] # We now broadcast these to the smallest common shape in case the # linking functions don't know how to broadcast arrays with different # shapes. args = np.broadcast_arrays(*args) # We call the actual linking function result = self._using(*args) # We call asarray since link functions may return Python scalars in some cases result = np.asarray(result) # In some cases, linking functions return ravelled arrays, so we # fix this here. logger.debug("shape of result: %s", result.shape) if result.shape != args[0].shape: logger.debug("ComponentLink function %s changed shape. Fixing", self._using.__name__) result.shape = args[0].shape # Finally we broadcast the final result to desired shape result = broadcast_to(result, original_shape) return result
def compute(self, data, view=None): """ For a given data set, compute the component comp_to given the data associated with each comp_from and the ``using`` function This raises an :class:`glue.core.exceptions.IncompatibleAttribute` if the data set doesn't have all the ComponentIDs needed for the transformation Parameters ---------- data : `~glue.core.data.Data` The data set to use view : `None` or `slice` or `tuple` Optional view (e.g. slice) through the data to use Returns ------- result The data associated with comp_to component """ # First we get the values of all the 'from' components. args = [data[join_component_view(f, view)] for f in self._from] # We keep track of the original shape of the arguments original_shape = args[0].shape logger.debug("shape of first argument: %s", original_shape) # We now unbroadcast the arrays to only compute the link with the # smallest number of values we can. This can help for cases where # the link depends only on e.g. pixel components or world coordinates # that themselves only depend on a subset of pixel components. # Unbroadcasting is the act of returning the smallest array that # contains all the information needed to be broadcasted back to its # full value args = [unbroadcast(arg) for arg in args] # We now broadcast these to the smallest common shape in case the # linking functions don't know how to broadcast arrays with different # shapes. args = np.broadcast_arrays(*args) # We call the actual linking function result = self._using(*args) # We call asarray since link functions may return Python scalars in some cases result = np.asarray(result) # In some cases, linking functions return ravelled arrays, so we # fix this here. logger.debug("shape of result: %s", result.shape) if result.shape != args[0].shape: logger.debug("ComponentLink function %s changed shape. Fixing", self._using.__name__) result.shape = args[0].shape # Finally we broadcast the final result to desired shape result = broadcast_to(result, original_shape) return result
def update(self, view=None): logger.debug("updating WWT for %s" % self.layer.label) self.clear() layer = self.layer if not self.visible: return try: ra = self.layer[self.xatt] dec = self.layer[self.yatt] except IncompatibleAttribute: print("Cannot fetch attributes %s and %s" % (self.xatt, self.yatt)) return for i in range(ra.size): label = "marker_%s_%i" % (layer.label.replace(' ', '_').replace('.', '_'), i) cmd = circle(ra[i], dec[i], label, layer.style.color) self.markers[label] = cmd js = '\n'.join(self.markers.values()) js += '\n'.join(["wwt.addAnnotation(%s);" % l for l in self.markers]) self._driver.run_js(js)
def update(self, view=None): logger.debug("updating WWT for %s" % self.layer.label) self.clear() layer = self.layer if not self.visible: return try: ra = self.layer[self.xatt] dec = self.layer[self.yatt] except IncompatibleAttribute: print("Cannot fetch attributes %s and %s" % (self.xatt, self.yatt)) return for i in range(ra.size): label = "marker_%s_%i" % (layer.label.replace(' ', '_').replace( '.', '_'), i) cmd = circle(ra[i], dec[i], label, layer.style.color) self.markers[label] = cmd js = '\n'.join(self.markers.values()) js += '\n'.join(["wwt.addAnnotation(%s);" % l for l in self.markers]) self._driver.run_js(js)
def _update_image(self, force=False, **kwargs): changed = set() if force else self.pop_changed_properties() logger.debug("updating WWT for 2D image %s" % self.layer.label) if self.visible is False: if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None return if force or 'mode' in changed or self.wwt_layer is None: self.clear() force = True if force or any(x in changed for x in RESET_TABLE_PROPERTIES): self.clear() if not isinstance(self.layer.coords, WCSCoordinates): raise ValueError('oh no not wcs') wcs = self.layer.coords.wcs try: data = self.layer[self.state.img_data_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.img_data_att) return self.wwt_layer = self.wwt_client.layers.add_image_layer( (data, wcs)) force = True # if force or 'cmap_vmax' in changed: # self.wwt_layer.cmap_vmax = self.state.cmap_vmax self.enable()
def _update_presentation(self, force=False, **kwargs): if self._removed: return changed = set() if force else self.pop_changed_properties() if self._viewer_state.lon_att is None or self._viewer_state.lat_att is None: if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None return logger.debug("updating WWT for table %s" % self.layer.label) if self.visible is False: if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None return if force or 'mode' in changed or self.wwt_layer is None: self.clear() force = True # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 # for now we set unit to pc and scale values accordingly, so if the # unit changes we need to refresh the data just in case if force or any(x in changed for x in RESET_TABLE_PROPERTIES): try: lon = self.layer[self._viewer_state.lon_att] except IncompatibleAttribute: self.disable_invalid_attributes(self._viewer_state.lon_att) return try: lat = self.layer[self._viewer_state.lat_att] except IncompatibleAttribute: self.disable_invalid_attributes(self._viewer_state.dec_att) return if self._viewer_state.alt_att is not None: try: alt = self.layer[self._viewer_state.alt_att] except IncompatibleAttribute: self.disable_invalid_attributes(self._viewer_state.alt_att) return if self.state.size_mode == 'Linear' and self.state.size_att is not None: try: size_values = self.layer[self.state.size_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.size_att) return else: size_values = None if self.state.color_mode == 'Linear' and self.state.cmap_att is not None: try: cmap_values = self.layer[self.state.cmap_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.cmap_att) return else: cmap_values = None self.clear() if not len(lon): return if self._viewer_state.mode in MODES_3D: ref_frame = 'Sky' else: ref_frame = self._viewer_state.mode if ref_frame == 'Sky': try: coord = SkyCoord( lon, lat, unit=u.deg, frame=self._viewer_state.frame.lower()).icrs except Exception as exc: self.disable(str(exc)) return lon = coord.spherical.lon.degree lat = coord.spherical.lat.degree # For some reason in 3D mode, when the frame is Sky, we need to # shift the longitudes by 180 degrees. However we also make sure # we send the original version since this might be needed e.g. when # exporting tours. if self._viewer_state.mode in MODES_3D: lon_orig = lon.copy() lon = lon + 180 lon[lon > 360] -= 360 else: lon_orig = None # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 # for now we set unit to pc and scale values accordingly if self._viewer_state.alt_att is not None and self._viewer_state.alt_unit == 'kpc': alt = alt * 1000 data_kwargs = {} tab = Table() tab['lon'] = lon * u.degree tab['lat'] = lat * u.degree if self._viewer_state.alt_att is not None: # FIXME: allow arbitrary units tab['alt'] = alt data_kwargs['alt_att'] = 'alt' if size_values is not None: tab['size'] = size_values data_kwargs['size_att'] = 'size' if cmap_values is not None: tab['cmap'] = cmap_values data_kwargs['cmap_att'] = 'cmap' if lon_orig is not None: tab['lon_orig'] = lon_orig * u.degree self.wwt_layer = self.wwt_client.layers.add_table_layer( tab, frame=ref_frame, lon_att='lon', lat_att='lat', **data_kwargs) self.wwt_layer.far_side_visible = self._viewer_state.mode in MODES_3D self._coords = lon, lat force = True if force or 'alt_unit' in changed: # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 # for now we set unit to pc and scale values accordingly if self._viewer_state.alt_unit == 'kpc': self.wwt_layer.alt_unit = u.pc else: self.wwt_layer.alt_unit = self._viewer_state.alt_unit if force or 'alt_type' in changed: self.wwt_layer.alt_type = self._viewer_state.alt_type.lower() if force or 'size' in changed or 'size_mode' in changed or 'size_scaling' in changed: if self.state.size_mode == 'Linear': self.wwt_layer.size_scale = self.state.size_scaling else: self.wwt_layer.size_scale = self.state.size * 5 * self.state.size_scaling if force or 'color' in changed: self.wwt_layer.color = self.state.color if force or 'alpha' in changed: self.wwt_layer.opacity = self.state.alpha if force or 'size_vmin' in changed: self.wwt_layer.size_vmin = self.state.size_vmin if force or 'size_vmax' in changed: self.wwt_layer.size_vmax = self.state.size_vmax if force or 'cmap_vmin' in changed: self.wwt_layer.cmap_vmin = self.state.cmap_vmin if force or 'cmap_vmax' in changed: self.wwt_layer.cmap_vmax = self.state.cmap_vmax if force or 'cmap' in changed: self.wwt_layer.cmap = self.state.cmap self.enable()
def notify_subtract(mode): log.debug("Subtracting in '{0}' mode in pyspeckit".format(mode))
def notify_fit(mode): log.debug("Fitting in '{0}' mode in pyspeckit".format(mode))
def notify(mode): log.debug("Setting mode to '{0}' in pyspeckit control panel".format(mode))
def _update_markers(self, force=False, **kwargs): if self._viewer_state.lon_att is None or self._viewer_state.lat_att is None: if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None return logger.debug("updating WWT for %s" % self.layer.label) if self.visible is False: if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None return if force or 'mode' in kwargs or self.wwt_layer is None: if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None self._coords = [], [] force = True # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 # for now we set unit to pc and scale values accordingly, so if the # unit changes we need to refresh the data just in case if force or any(x in kwargs for x in RESET_DATA_PROPERTIES): try: lon = self.layer[self._viewer_state.lon_att] except IncompatibleAttribute: self.disable_invalid_attributes(self._viewer_state.lon_att) return try: lat = self.layer[self._viewer_state.lat_att] except IncompatibleAttribute: self.disable_invalid_attributes(self._viewer_state.dec_att) return if self._viewer_state.alt_att is not None: try: alt = self.layer[self._viewer_state.alt_att] except IncompatibleAttribute: self.disable_invalid_attributes(self._viewer_state.alt_att) return if self.state.size_mode == 'Linear' and self.state.size_att is not None: try: size_values = self.layer[self.state.size_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.size_att) return else: size_values = None if self.state.color_mode == 'Linear' and self.state.cmap_att is not None: try: cmap_values = self.layer[self.state.cmap_att] except IncompatibleAttribute: self.disable_invalid_attributes(self.state.cmap_att) return else: cmap_values = None if self.wwt_layer is not None: self.wwt_layer.remove() self.wwt_layer = None self._coords = [], [] if len(lon) > 0: if self._viewer_state.mode in MODES_3D: ref_frame = 'Sky' else: ref_frame = self._viewer_state.mode if ref_frame == 'Sky': try: coord = SkyCoord(lon, lat, unit=u.deg, frame=self._viewer_state.frame.lower()).icrs except Exception as exc: self.disable(str(exc)) return lon = coord.spherical.lon.degree lat = coord.spherical.lat.degree # For some reason in 3D mode, when the frame is Sky, we need to # shift the longitudes by 180 degrees. if self._viewer_state.mode in MODES_3D: lon = lon + 180 lon[lon > 360] -= 360 # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 # for now we set unit to pc and scale values accordingly if self._viewer_state.alt_att is not None and self._viewer_state.alt_unit == 'kpc': alt = alt * 1000 data_kwargs = {} tab = Table() tab['lon'] = lon * u.degree tab['lat'] = lat * u.degree if self._viewer_state.alt_att is not None: # FIXME: allow arbitrary units tab['alt'] = alt data_kwargs['alt_att'] = 'alt' if size_values is not None: tab['size'] = size_values data_kwargs['size_att'] = 'size' if cmap_values is not None: tab['cmap'] = cmap_values data_kwargs['cmap_att'] = 'cmap' self.wwt_layer = self.wwt_client.layers.add_data_layer(tab, frame=ref_frame, lon_att='lon', lat_att='lat', **data_kwargs) self.wwt_layer.far_side_visible = self._viewer_state.mode in MODES_3D self._coords = lon, lat force = True else: return if force or 'alt_unit' in kwargs: # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 # for now we set unit to pc and scale values accordingly if self._viewer_state.alt_unit == 'kpc': self.wwt_layer.alt_unit = u.pc else: self.wwt_layer.alt_unit = self._viewer_state.alt_unit if force or 'alt_type' in kwargs: self.wwt_layer.alt_type = self._viewer_state.alt_type.lower() if force or 'size' in kwargs or 'size_mode' in kwargs or 'size_scaling' in kwargs: if self.state.size_mode == 'Linear': self.wwt_layer.size_scale = self.state.size_scaling else: self.wwt_layer.size_scale = self.state.size * 5 * self.state.size_scaling if force or 'color' in kwargs: self.wwt_layer.color = self.state.color if force or 'alpha' in kwargs: self.wwt_layer.opacity = self.state.alpha if force or 'size_vmin' in kwargs: self.wwt_layer.size_vmin = self.state.size_vmin if force or 'size_vmax' in kwargs: self.wwt_layer.size_vmax = self.state.size_vmax if force or 'cmap_vmin' in kwargs: self.wwt_layer.cmap_vmin = self.state.cmap_vmin if force or 'cmap_vmax' in kwargs: self.wwt_layer.cmap_vmax = self.state.cmap_vmax if force or 'cmap' in kwargs: self.wwt_layer.cmap = self.state.cmap self.enable()