def main():
    #  Initialize the 'GaussPyDecompose' class and read in the parameter settings from 'gausspy+.ini'.
    decompose = GaussPyDecompose(config_file='gausspy+.ini')

    #  The following lines will override the corresponding parameter settings defined in 'gausspy+.ini'.

    #  Filepath to pickled dictionary of the prepared data.
    decompose.path_to_pickle_file = os.path.join('decomposition_grs',
                                                 'gpy_prepared',
                                                 'grs-test_field.pickle')
    #  First smoothing parameter
    decompose.alpha1 = 2.58
    #  Second smoothing parameter
    decompose.alpha2 = 5.14
    #  Suffix for the filename of the pickled dictionary with the decomposition results.
    decompose.suffix = '_g+'
    #  Start the decomposition.
    decompose.decompose()

    #  (Optional) Produce a FITS image showing the number of fitted components
    decompose.produce_component_map()
    #  (Optional) Produce a FITS image showing the reduced chi-square values
    decompose.produce_rchi2_map()

    #  (Optional) Plot some of the spectra and the decomposition results

    #  Filepath to pickled dictionary of the prepared data.
    path_to_pickled_file = decompose.path_to_pickle_file
    #  Filepath to pickled dictionary with the decomposition results
    path_to_decomp_pickle = os.path.join('decomposition_grs', 'gpy_decomposed',
                                         'grs-test_field_g+_fit_fin.pickle')
    #  Directory in which the plots are saved.
    path_to_plots = os.path.join('decomposition_grs', 'gpy_plots')
    #  Here we select a subregion of the data cube, whose spectra we want to plot.
    pixel_range = {'x': [30, 34], 'y': [25, 29]}
    plot_spectra(path_to_pickled_file,
                 path_to_plots=path_to_plots,
                 path_to_decomp_pickle=path_to_decomp_pickle,
                 signal_ranges=True,
                 pixel_range=pixel_range)
示例#2
0
            'decomposition/gpy_prepared/smc_HI_cube_askap_sub_16.pickle') and (
                filename !=
                'decomposition/gpy_prepared/smc_HI_cube_askap_sub_24.pickle'
            ) and (
                filename !=
                'decomposition/gpy_prepared/smc_HI_cube_askap_sub_32.pickle'):
        filestr = filename.split(".pickle")[0]
        filestr = filestr.split("sub_")[1]
        #  Filepath to pickled dictionary of the prepared data.

        #  Initialize the 'GaussPyDecompose' class and read in the parameter settings from 'gausspy+.ini'.
        decompose = GaussPyDecompose(config_file="gausspy+.ini")

        decompose.path_to_pickle_file = filename
        #  First smoothing parameter
        decompose.alpha1 = 1.13
        #  Second smoothing parameter
        decompose.alpha2 = 2.06
        #  We set the upper limit for the reduced chi-square deliberately to a low value to enforce the best fitting results for each individual spectrum.
        decompose.rchi2_limit = 2.0
        #  Suffix for the filename of the pickled dictionary with the decomposition results.
        decompose.suffix = "_g+"
        #  Start the decomposition.
        decompose.decompose()

        #  (Optional) Produce a FITS image showing the number of fitted components
        decompose.produce_component_map()
        #  (Optional) Produce a FITS image showing the reduced chi-square values
        decompose.produce_rchi2_map()

        #  (Optional) Plot some of the spectra and the decomposition results
示例#3
0
import os

from gausspyplus.decompose import GaussPyDecompose
from gausspyplus.plotting import plot_spectra

#  Initialize the 'GaussPyDecompose' class and read in the parameter settings from 'gausspy+.ini'.
decompose = GaussPyDecompose(config_file='gausspy+.ini')

#  The following lines will override the corresponding parameter settings defined in 'gausspy+.ini'.

#  Filepath to pickled dictionary of the prepared data.
decompose.path_to_pickle_file = os.path.join('decomposition_grs',
                                             'gpy_prepared',
                                             'grs-test_field.pickle')
#  First smoothing parameter
decompose.alpha1 = 2.58
#  Second smoothing parameter
decompose.alpha2 = 5.14
#  Suffix for the filename of the pickled dictionary with the decomposition results.
decompose.suffix = '_g+'
#  Start the decomposition.
decompose.decompose()

#  (Optional) Produce a FITS image showing the number of fitted components
decompose.produce_component_map()
#  (Optional) Produce a FITS image showing the reduced chi-square values
decompose.produce_rchi2_map()

#  (Optional) Plot some of the spectra and the decomposition results

#  Filepath to pickled dictionary of the prepared data.
示例#4
0
    def gpp_parameters(self):

        # This code creates a temporary fits file of the data called "gpp-temp.fits" that GaussPy+ will use to decompose.
        self.y_data = np.reshape(self.y_data, (self.y_data.shape[0], 1, 1))
        self.y_data.shape
        hdu = fits.PrimaryHDU(self.y_data)
        CRVAL3 = self.x_data[0]
        CDELT3 = self.x_data[1] - self.x_data[0]
        hdu1 = fits.HDUList([hdu])
        hdu1.writeto("gpp-temp.fits", overwrite=True)

        # This is taken directly from the GaussPy+ documentation, with the signal-to-noise ratio, minimum FWHM, and
        #	the gpp-temp.fits file used.
        prepare = GaussPyPrepare()
        prepare.path_to_file = os.path.abspath("gpp-temp.fits")
        prepare.p_limit = 0.02
        prepare.pad_channels = 2
        prepare.signal_mask = True
        prepare.min_channels = 100
        prepare.mask_out_ranges = []
        prepare.snr = self.sig
        prepare.significance = 5.0
        prepare.snr_noise_spike = self.sig
        data_location = (0, 0)
        prepared_spectrum = prepare.return_single_prepared_spectrum(
            data_location)

        decompose = GaussPyDecompose()

        decompose.two_phase_decomposition = True
        decompose.alpha1 = 2.58
        decompose.alpha2 = 5.14

        decompose.improve_fitting = True

        decompose.exclude_mean_outside_channel_range = True
        decompose.min_fwhm = self.min
        decompose.max_fwhm = 64.
        decompose.snr = self.sig
        decompose.snr_fit = None
        decompose.significance = 3.0
        decompose.snr_negative = None
        decompose.min_pvalue = 0.01
        decompose.max_amp_factor = 1.1
        decompose.refit_neg_res_peak = True
        decompose.refit_broad = True
        decompose.refit_blended = True
        decompose.separation_factor = 0.8493218
        decompose.fwhm_factor = 2.

        decompose.single_prepared_spectrum = prepared_spectrum
        decomposed_test = decompose.decompose()

        # This stores the parameters of each gaussian component into a single array, in hindsight
        # I should have made an array of arrays (each one containing the parameters of each component).
        self.params = np.concatenate(
            (np.array(decomposed_test["amplitudes_fit"][0]),
             (np.array(decomposed_test["fwhms_fit"][0]) * CDELT3),
             ((np.array(decomposed_test["means_fit"][0]) * CDELT3) + CRVAL3)))

        # This is the number of components that the spectrum has been decomposed into.
        self.components = int(len(self.params) / 3.0)