Пример #1
0
        exportfits(imagename=file, fitsimage=file + '.fits')
    else:
        print(file + '.fits' + ' already exists. Not running exportfits.')

fits_files = glob.glob(data_path + '*.fits')

psf_file = [s for s in fits_files if ".psf.fits" in s][0]
orig_resid = [s for s in fits_files if ".residual.fits" in s][0]
model = [s for s in fits_files if ".model.fits" in s][0]

hdu = fits.open(psf_file)
data = hdu[0].data
header = hdu[0].header
beams = hdu[1]
beams_table = beams.data
beams = Beams.from_fits_bintable(beams)  #convert to radio_beam object
hdu.close()

center = np.unravel_index(np.argmax(data[0, plot_channel, :, :]),
                          data[0, plot_channel, :, :].shape)
cy, cx = center

cutout = data[0, plot_channel, cy - max_npix_peak:cy + max_npix_peak + 1,
              cx - max_npix_peak:cx + max_npix_peak + 1]

shape = cutout.shape
sy, sx = shape
Y, X = np.mgrid[0:sy, 0:sx]

center = np.unravel_index(np.argmax(cutout), cutout.shape)
cy, cx = center
Пример #2
0
def line_ids(fn):
    results = []
    Ulines = []

    sp = pyspeckit.Spectrum(fn)

    # this is a bit hackier than I like
    # we'll do all our measurements in Kelvin!
    beams = Beams.from_fits_bintable(fits.open(fn)[1])
    factors = jtok_factors(beams, sp.xarr.to(u.GHz))
    sp.data = sp.data * factors
    sp.unit = u.K

    # want km/s - reference will be ~middle of SPW
    sp.xarr.convert_to_unit(u.km / u.s)

    med = np.nanmedian(sp.data)

    mad = stats.mad_std(sp.data - med)
    detections = (sp.data - med) > 5 * mad

    labels, ct = label(detections)

    for labelid in range(1, ct + 1):
        ssp = sp[labels == labelid]
        try:
            ssp.xarr.convert_to_unit(u.GHz)
            ssp.specfit()
            ssp.specfit.parinfo
            frq = ssp.specfit.parinfo['SHIFT0'].value * ssp.xarr.unit
        except Exception as ex:
            print(ex)
            frq = ssp.xarr.to(u.GHz).mean()
        sq = Splatalogue.query_lines(
            frq * (1 + 0 / 3e5),
            frq * (1 + 75 / 3e5),  # 30/3e5 original lower bound
            only_astronomically_observed=True)
        if len(sq) > 0:
            tbl = utils.minimize_table(sq)
            try:
                total_intensity = ssp.data.sum() * np.abs(
                    ssp.xarr.to(u.km / u.s).cdelt())
            except ValueError:
                total_intensity = ssp.data.sum() * np.abs(
                    sp.xarr.to(u.km / u.s).cdelt())
            peak_intensity = ssp.data.max()
            tbl.add_column(Column(data=total_intensity, name='TotalIntensity'))
            tbl.add_column(Column(data=peak_intensity, name='PeakIntensity'))
            tbl.add_column(Column(data=mad, name='RMS'))
            tbl.add_column(
                Column(data=u.Quantity((-(frq.to(u.GHz).value - tbl['Freq']) /
                                        tbl['Freq'] * constants.c),
                                       u.km / u.s),
                       name='Velocity'))
            #             print(tbl.pprint(max_width=200))
            results.append(tbl)
        else:
            log.warning(f"Frequency {frq.to(u.GHz)} had no hits")
            Ulines.append(frq)

    try:
        match_table = table.vstack(results)
    except ValueError:
        pass
    else:
        #         match_table.remove_column('QNs')
        match_table = table.unique(match_table, keys='Species')
    match_table.sort('Freq')
    print(match_table.pprint(max_width=200))
    print(match_table['Species', 'Freq', 'Velocity'])
    #     match_table.write(f"line_fit_table_{suffix}.ipac", format='ascii.ipac', overwrite=True)
    return match_table
Пример #3
0
        factors.append(factor)
    factor = np.array(factors)
    return factor


for suffix in ('mean', 'max'):

    results = []
    Ulines = []

    for fn in glob.glob(f"spectra/*.{suffix}.fits"):
        sp = pyspeckit.Spectrum(fn)

        # this is a bit hackier than I like
        # we'll do all our measurements in Kelvin!
        beams = Beams.from_fits_bintable(fits.open(fn)[1])
        factors = jtok_factors(beams, sp.xarr.to(u.GHz))
        sp.data = sp.data * factors
        sp.unit = u.K

        # want km/s - reference will be ~middle of SPW
        sp.xarr.convert_to_unit(u.km / u.s)

        med = np.nanmedian(sp.data)

        mad = stats.mad_std(sp.data - med)
        detections = (sp.data - med) > 5 * mad

        labels, ct = label(detections)

        for labelid in range(1, ct + 1):