Ejemplo n.º 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]})
Ejemplo n.º 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
                                        })
        header=cubeA.header,
    )

    outpath = 'RatioCube_DendrogramObjects{0}.fits'.format(sm)
    rcube.write(hpath(outpath), overwrite=True)

    max_temcube = tcube.max(axis=0)
    max_temcube.hdu.writeto(hpath(
        'TemperatureCube_DendrogramObjects{0}_Piecewise_max.fits'.format(sm)),
                            clobber=True)
    max_rcube = rcube.max(axis=0)
    max_rcube.hdu.writeto(hpath(
        'RatioCube_DendrogramObjects{0}_Piecewise_max.fits'.format(sm)),
                          clobber=True)

    mean_temcube = tcube.mean(axis=0)
    mean_temcube.hdu.writeto(hpath(
        'TemperatureCube_DendrogramObjects{0}_Piecewise_mean.fits'.format(sm)),
                             clobber=True)
    mean_rcube = rcube.mean(axis=0)
    mean_rcube.hdu.writeto(hpath(
        'RatioCube_DendrogramObjects{0}_Piecewise_mean.fits'.format(sm)),
                           clobber=True)

    hdu_template = mean_rcube.hdu
    tcube = tcube.filled_data[:].value
    weight_cube = cube303sm if 'smooth' in sm else cube303
    weights = weight_cube.filled_data[:].value
    weights[weights < 0] = 0

    mean_temcube = np.nansum(tcube * weights, axis=0) / np.nansum(weights,
    tcube.write(hpath(outpath), overwrite=True)

    rcube = SpectralCube(data=rcubedata, wcs=cubeA.wcs,
                         mask=cubeA.mask, meta={'unit':'K'},
                         header=cubeA.header,
                        )

    outpath = 'RatioCube_DendrogramObjects{0}.fits'.format(sm)
    rcube.write(hpath(outpath), overwrite=True)

    max_temcube = tcube.max(axis=0)
    max_temcube.hdu.writeto(hpath('TemperatureCube_DendrogramObjects{0}_Piecewise_max.fits'.format(sm)), clobber=True)
    max_rcube = rcube.max(axis=0)
    max_rcube.hdu.writeto(hpath('RatioCube_DendrogramObjects{0}_Piecewise_max.fits'.format(sm)), clobber=True)

    mean_temcube = tcube.mean(axis=0)
    mean_temcube.hdu.writeto(hpath('TemperatureCube_DendrogramObjects{0}_Piecewise_mean.fits'.format(sm)), clobber=True)
    mean_rcube = rcube.mean(axis=0)
    mean_rcube.hdu.writeto(hpath('RatioCube_DendrogramObjects{0}_Piecewise_mean.fits'.format(sm)), clobber=True)

    hdu_template = mean_rcube.hdu
    tcube = tcube.filled_data[:].value
    weight_cube = cube303sm if 'smooth' in sm else cube303
    weights = weight_cube.filled_data[:].value
    weights[weights < 0] = 0

    mean_temcube = np.nansum(tcube*weights, axis=0) / np.nansum(weights, axis=0)
    hdu_template.data = mean_temcube
    hdu_template.writeto(hpath('TemperatureCube_DendrogramObjects{0}_Piecewise_weightedmean.fits'.format(sm)), clobber=True)
    mean_rcube = np.nansum(rcube*weights,axis=0) / np.nansum(weights, axis=0)
    hdu_template.data = mean_rcube