Beispiel #1
0
    def _spectrum_from_component(self, layer, component, wcs, mask=None):
        data = SpectralCube(component.data, wcs)

        if mask is not None:
            data = data.with_mask(mask)

        if self._data_operation.currentIndex() == 1:
            spec_data = data.mean((1, 2))
        elif self._data_operation.currentIndex() == 2:
            spec_data = data.median((1, 2))
        else:
            spec_data = data.sum((1, 2))

        spec_data = Spectrum1DRef(spec_data.data,
                                  unit=spec_data.unit,
                                  dispersion=data.spectral_axis.data,
                                  dispersion_unit=data.spectral_axis.unit,
                                  wcs=data.wcs,
                                  name=layer.label)

        # Store the relation between the component and the specviz data. If
        # the data exists, first remove the component from specviz and then
        # re-add it.
        if layer in self._specviz_data_cache:
            old_spec_data = self._specviz_data_cache[layer]
            dispatch.on_remove_data.emit(old_spec_data)

        self._specviz_data_cache[layer] = spec_data

        dispatch.on_add_to_window.emit(data=spec_data,
                                       style={'color': layer.style.rgba[:3]})
Beispiel #2
0
    def _spectrum_from_component(self,
                                 layer,
                                 component,
                                 wcs,
                                 mask=None,
                                 cid=None):
        data = SpectralCube(component.data, wcs)

        if mask is not None:
            data = data.with_mask(mask)

        # Update the associated data attribute in the plugin
        self._spec_ops.spectral_data = data
        self._spec_ops.component_id = cid

        if self._data_operation.currentIndex() == 1:
            spec_data = data.mean((1, 2))
        elif self._data_operation.currentIndex() == 2:
            spec_data = data.median((1, 2))
        else:
            spec_data = data.sum((1, 2))

        spec_data = Spectrum1DRef(spec_data.data,
                                  unit=spec_data.unit,
                                  dispersion=data.spectral_axis.data,
                                  dispersion_unit=data.spectral_axis.unit,
                                  wcs=data.wcs,
                                  name=layer.label)

        spec_layer = Spectrum1DRefLayer.from_parent(spec_data)

        # Store the relation between the component and the specviz data. If
        # the data exists, first remove the component from specviz and then
        # re-add it.
        old_spec_layer = self._specviz_data_cache.get(layer)

        self._specviz_data_cache[layer] = spec_layer

        if old_spec_layer is None:
            dispatch.on_add_to_window.emit(layer=spec_layer,
                                           style={
                                               'color': layer.style.rgba[:3],
                                               'line_width': 3
                                           },
                                           vertical_line=True)
        else:
            dispatch.replace_layer.emit(old_layer=old_spec_layer,
                                        new_layer=spec_layer,
                                        style={
                                            'color': layer.style.rgba[:3],
                                            'line_width': 3
                                        })