def get_component(self, component_id): """Fetch the component corresponding to component_id. :param component_id: the component_id to retrieve """ if component_id is None: raise IncompatibleAttribute() if isinstance(component_id, six.string_types): component_id = self.id[component_id] try: return self._components[component_id] except KeyError: raise IncompatibleAttribute(component_id)
def _to_linked_pixel_coords(self, data): # Determine which pixel dimensions are being sliced over dimensions = [idim for idim, slc in enumerate(self.slices) if slc.start is not None] # Determine pixel to pixel correlation matrix matrix = pixel_cid_to_pixel_cid_matrix(self.reference_data, data) # Find pixel dimensions in 'data' that are correlated correlated_dims = np.nonzero(np.any(matrix[dimensions], axis=0))[0] # Check that if we do the operation backwards we just get the # original dimensions back check_dimensions = np.nonzero(np.any(matrix[:, correlated_dims], axis=1))[0] if np.array_equal(dimensions, check_dimensions): pix_coord_in = tuple([slice(0, 1) if slc.start is None else slc for slc in self.slices]) pix_coord_out = [] for idim, pix_cid in enumerate(data.pixel_component_ids): if idim in correlated_dims: coord = int(np.round(self.reference_data[pix_cid, pix_coord_in].ravel()[0])) else: coord = None pix_coord_out.append(coord) return pix_coord_out raise IncompatibleAttribute()
def to_mask(self, data, view=None): if data.uuid == self._data_uuid or self._data_uuid is None: # XXX this is inefficient for views result = np.zeros(data.shape, dtype=bool) if self._indices is not None: try: result.flat[self._indices] = True except IndexError: if self._data_uuid is None: raise IncompatibleAttribute() else: raise if view is not None: result = result[view] return result else: raise IncompatibleAttribute()
def to_mask(self, data, view=None): if data in self._data: return super(PatchedElementSubsetState, self).to_mask(data, view=view) else: # TODO: should really be IncompatibleDataException but many other # viewers don't recognize this. raise IncompatibleAttribute()
def get_component(self, component_id): """Fetch the component corresponding to component_id. :param component_id: the component_id to retrieve """ if component_id is None: raise IncompatibleAttribute() if isinstance(component_id, six.string_types): component_id = self.id[component_id] if component_id in self._components: return self._components[component_id] elif component_id in self._externally_derivable_components: return self._externally_derivable_components[component_id] else: raise IncompatibleAttribute(component_id)
def to_array(self, data, att): if data is self.reference_data: slices = self.slices else: order = data.pixel_aligned_data.get(self.reference_data, None) if order is None: raise IncompatibleAttribute() slices = [self.slices[idx] for idx in order] return data[att, slices]
def __getitem__(self, key): """ Shortcut syntax to access the numerical data in a component. Equivalent to: ``component = data.get_component(component_id).data`` :param key: The component to fetch data from :type key: :class:`~glue.core.component_id.ComponentID` :returns: :class:`~numpy.ndarray` """ key, view = split_component_view(key) if isinstance(key, six.string_types): _k = key key = self.find_component_id(key) if key is None: raise IncompatibleAttribute(_k) if isinstance(key, ComponentLink): return key.compute(self, view) if key in self._components: comp = self._components[key] elif key in self._externally_derivable_components: comp = self._externally_derivable_components[key] else: raise IncompatibleAttribute(key) shp = view_shape(self.shape, view) if view is not None: result = comp[view] else: if comp.categorical: result = comp.codes else: result = comp.data assert result.shape == shp, \ "Component view returned bad shape: %s %s" % (result.shape, shp) return result
def to_mask(self, data, view=None): if data.uuid in self._indices_dict: indices = self._indices_dict[data.uuid] result = np.zeros(data.shape, dtype=bool) result.flat[indices] = True if view is not None: result = result[view] return result else: raise IncompatibleAttribute()
def to_mask(self, data, view=None): if data.uuid in self._mask_dict: mask = self._mask_dict[data.uuid] if mask.dtype.kind != 'b': # backward-compatibility with indices_dict indices = mask mask = np.zeros(data.shape, dtype=bool) mask.flat[indices] = True if view is not None: mask = mask[view] return mask else: raise IncompatibleAttribute()
def to_array(self, data, att): try: return super(PixelSubsetState, self).to_array(data, att) except IncompatibleAttribute: if data is not self.reference_data: pix_coord_out = self._to_linked_pixel_coords(data) pix_coord_out = tuple([slice(None) if p is None else slice(p, p + 1) for p in pix_coord_out]) return data[att, pix_coord_out] raise IncompatibleAttribute()
def set_attribute(self, attribute): if not self.display_data or \ attribute not in self.display_data.component_ids(): raise IncompatibleAttribute( "Attribute not in data's attributes: %s" % attribute) if self.display_attribute is not None: self._norm_cache[self.display_attribute] = self.get_norm() self.display_attribute = attribute if attribute in self._norm_cache: self.set_norm(norm=self._norm_cache[attribute]) else: self.clear_norm() self._update_data_plot() self._redraw()