예제 #1
0
파일: data.py 프로젝트: robintw/glue
    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)
예제 #2
0
    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()
예제 #3
0
파일: subset.py 프로젝트: sarahb55/glue
 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()
예제 #4
0
 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()
예제 #5
0
    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)
예제 #6
0
파일: subset.py 프로젝트: sarahb55/glue
 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]
예제 #7
0
파일: data.py 프로젝트: harshalkokate/glue
    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
예제 #8
0
 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()
예제 #9
0
 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()
예제 #10
0
    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()
예제 #11
0
    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()