Beispiel #1
0
    fn_90GHz = paths.mergepath(
        'continuum/SgrB2_selfcal_full_TETC7m_selfcal5_ampphase_continuum_90GHz.image.pbcor.fits'
    )
    results_90GHz = photometry(
        fits.getdata(fn_90GHz), wcs.WCS(fits.getheader(fn_90GHz)), regs,
        radio_beam.Beam.from_fits_header(fits.getheader(fn_90GHz)))
    #fn_100GHz = paths.tmpath('SgrB2_nocal_TE_continuum_100GHz.image.pbcor.fits')
    fn_100GHz = paths.mergepath(
        'continuum/SgrB2_selfcal_full_TETC7m_selfcal5_ampphase_continuum_100GHz.image.pbcor.fits'
    )
    results_100GHz = photometry(
        fits.getdata(fn_100GHz), wcs.WCS(fits.getheader(fn_100GHz)), regs,
        radio_beam.Beam.from_fits_header(fits.getheader(fn_100GHz)))

    for name in results:
        results[name]['peak_col_20K'] = masscalc.col_conversion_factor(
            results[name]['peak'] * u.Jy, beam.sr)
        results[name]['peak_mass_20K'] = np.nan * u.g if np.isnan(
            results[name]['peak_col_20K']
        ) else masscalc.mass_conversion_factor() * results[name]['peak']
        results[name]['peak_col_40K'] = masscalc.col_conversion_factor(
            results[name]['peak'] * u.Jy, beam.sr, TK=40 * u.K)
        results[name]['peak_mass_40K'] = (
            np.nan * u.g if np.isnan(results[name]['peak_col_40K']) else
            masscalc.mass_conversion_factor(TK=40 * u.K) *
            results[name]['peak'])
        results[name]['peak_90GHz'] = results_90GHz[name]['peak']
        results[name]['peak_100GHz'] = results_100GHz[name]['peak']
        results[name]['sum_90GHz'] = results_90GHz[name]['sum']
        results[name]['sum_100GHz'] = results_100GHz[name]['sum']
        results[name]['bgmad_90GHz'] = results_90GHz[name]['bgmad']
        results[name]['bgmad_100GHz'] = results_100GHz[name]['bgmad']
Beispiel #2
0
radii = (0.2,0.4,0.6,0.8,1.0,1.5)*u.arcsec
columns = {k:[] for k in (keys)}

log.info("Doing photometry")
for ii, row in enumerate(ProgressBar(ppcat)):
    structure = dend[row['_idx']]
    assert structure.idx == row['_idx'] == ii
    dend_inds = structure.indices()
    columns['noise'].append(noise[dend_inds].mean())
    columns['is_leaf'].append(structure.is_leaf)
    peakflux = data[dend_inds].max()
    columns['peak_cont_flux'].append(peakflux)
    columns['min_cont_flux'].append(data[dend_inds].min())
    columns['mean_cont_flux'].append(data[dend_inds].mean())
    columns['peak_cont_mass'].append((masscalc.mass_conversion_factor()*peakflux).to(u.M_sun).value)
    columns['peak_cont_col'].append((masscalc.col_conversion_factor(beamomega=beam.sr.value)*peakflux).to(u.cm**-2).value)
    columns['beam_area'].append(beam.sr.value)
for k in columns:
    if k not in ppcat.keys():
        ppcat.add_column(Column(name=k, data=columns[k]))

cat_mask = (ppcat['is_leaf'] &
            (ppcat['peak_cont_flux']>6.5*ppcat['noise']) &
            (ppcat['mean_cont_flux']>3*ppcat['noise']) &
            (ppcat['min_cont_flux']>1*ppcat['noise']))
log.info("Keeping {0} of {1} core candidates ({2}%)".format(cat_mask.sum(), len(cat_mask), cat_mask.sum()/len(cat_mask)*100))
pruned_ppcat = ppcat[cat_mask]
mask = dend.index_map.copy()
log.info("Pruning mask image")
for ii in ProgressBar(list(range(len(ppcat)))):
    if ii not in pruned_ppcat['_idx']:
Beispiel #3
0
#ln selfcal_allspw_selfcal_4ampphase_mfs_tclean_deeper_5mJy.image.pbcor.fits W51_te_continuum_best.fits
#ln selfcal_allspw_selfcal_4ampphase_mfs_tclean_deeper_5mJy.residual.fits W51_te_continuum_best_residual.fits
contfile = fits.open(paths.dpath('W51_te_continuum_best.fits'))
data = u.Quantity(contfile[0].data, unit=contfile[0].header['BUNIT'])
mywcs = wcs.WCS(contfile[0].header)
beam = radio_beam.Beam.from_fits_header(contfile[0].header)
pixel_scale = np.abs(mywcs.pixel_scale_matrix.diagonal().prod())**0.5 * u.deg
pixel_scale_as = pixel_scale.to(u.arcsec).value
ppbeam = (beam.sr / (pixel_scale**2)).decompose().value / u.beam

#pl.hist(data[np.isfinite(data)], bins=np.linspace(1e-4,0.1,100))

# over what threshold are we including flux when measuring total masses?
threshold = 10 * u.mJy / u.beam
threshold_column = (threshold * u.beam / u.Jy *
                    masscalc.col_conversion_factor(beam)).to(u.cm**-2)
threshold_column = masscalc.dust.colofsnu(nu=masscalc.centerfreq,
                                          snu=threshold * u.beam,
                                          beamomega=beam.sr).to(
                                              u.cm**-2,
                                              u.dimensionless_angles())
threshold_density = (masscalc.mass_conversion_factor(20) *
                     (threshold * u.beam).to(u.mJy).value / (4 / 3. * np.pi) /
                     (beam.sr.value * masscalc.distance**2)**(1.5) /
                     (2.8 * constants.m_p)).to(1 / u.cm**3)
definitely_signal = data > threshold
total_signal = data[definitely_signal].sum() / ppbeam
print("Total flux: {0}".format(total_signal))
print("Total mass(20K): {0}".format(
    total_signal * masscalc.mass_conversion_factor() * u.M_sun / u.Jy))
print("Threshold column (20K): {0:e}".format(threshold_column))
            }

    results = photometry(data, mywcs, regs, beam)

    fn_90GHz = paths.tmpath('SgrB2_nocal_TE_continuum_90GHz.image.pbcor.fits')
    results_90GHz = photometry(fits.getdata(fn_90GHz),
                               wcs.WCS(fits.getheader(fn_90GHz)), regs,
                               radio_beam.Beam.from_fits_header(fits.getheader(fn_90GHz)))
    fn_100GHz = paths.tmpath('SgrB2_nocal_TE_continuum_100GHz.image.pbcor.fits')
    results_100GHz = photometry(fits.getdata(fn_100GHz),
                               wcs.WCS(fits.getheader(fn_100GHz)), regs,
                               radio_beam.Beam.from_fits_header(fits.getheader(fn_100GHz)))

    for name in results:
        results[name]['peak_mass_20K'] = masscalc.mass_conversion_factor()*results[name]['peak']
        results[name]['peak_col_20K'] = masscalc.col_conversion_factor(results[name]['peak']*u.Jy, beam.sr)
        results[name]['peak_90GHz'] = results_90GHz[name]['peak']
        results[name]['peak_100GHz'] = results_100GHz[name]['peak']
        results[name]['sum_90GHz'] = results_90GHz[name]['sum']
        results[name]['sum_100GHz'] = results_100GHz[name]['sum']
        results[name]['bgmad_90GHz'] = results_90GHz[name]['bgmad']
        results[name]['bgmad_100GHz'] = results_100GHz[name]['bgmad']

    # invert the table to make it parseable by astropy...
    # (this shouldn't be necessary....)
    results_inv = {'name':{}}
    columns = {'name':[]}
    for k,v in results.items():
        results_inv['name'][k] = k
        columns['name'].append(k)
        for kk,vv in v.items():
radii = (0.2,0.4,0.6,0.8,1.0,1.5)*u.arcsec
columns = {k:[] for k in (keys)}

log.info("Doing photometry")
for ii, row in enumerate(ProgressBar(ppcat)):
    structure = dend[row['_idx']]
    assert structure.idx == row['_idx'] == ii
    dend_inds = structure.indices()
    columns['noise'].append(noise[dend_inds].mean())
    columns['is_leaf'].append(structure.is_leaf)
    peakflux = data[dend_inds].max()
    columns['peak_cont_flux'].append(peakflux)
    columns['min_cont_flux'].append(data[dend_inds].min())
    columns['mean_cont_flux'].append(data[dend_inds].mean())
    columns['peak_cont_mass'].append((masscalc.mass_conversion_factor()*peakflux).to(u.M_sun).value)
    columns['peak_cont_col'].append((masscalc.col_conversion_factor(beamomega=beam.sr.value)*peakflux).to(u.cm**-2).value)
    columns['beam_area'].append(beam.sr.value)
for k in columns:
    if k not in ppcat.keys():
        ppcat.add_column(Column(name=k, data=columns[k]))

cat_mask = (ppcat['is_leaf'] &
            (ppcat['peak_cont_flux']>8*ppcat['noise']) &
            (ppcat['mean_cont_flux']>5*ppcat['noise']) &
            (ppcat['min_cont_flux']>1*ppcat['noise']))
pruned_ppcat = ppcat[cat_mask]
mask = dend.index_map.copy()
log.info("Pruning mask image")
for ii in ProgressBar(list(range(len(ppcat)))):
    if ii not in pruned_ppcat['_idx']:
        mask[mask == ii] = -1
#ln selfcal_allspw_selfcal_4ampphase_mfs_tclean_deeper_5mJy.residual.fits W51_te_continuum_best_residual.fits
contfile = fits.open(paths.dpath('W51_te_continuum_best.fits'))
data = u.Quantity(contfile[0].data, unit=contfile[0].header['BUNIT'])
mywcs = wcs.WCS(contfile[0].header)
beam = radio_beam.Beam.from_fits_header(contfile[0].header)
pixel_scale = np.abs(mywcs.pixel_scale_matrix.diagonal().prod())**0.5 * u.deg
pixel_scale_as = pixel_scale.to(u.arcsec).value
ppbeam = (beam.sr/(pixel_scale**2)).decompose().value / u.beam

#pl.hist(data[np.isfinite(data)], bins=np.linspace(1e-4,0.1,100))

# over what threshold are we including flux when measuring total masses?
threshold = 10*u.mJy/u.beam
# threshold above which 20 K is very thick
thick_threshold = (20*u.K).to(u.mJy, u.brightness_temperature(beam, masscalc.centerfreq)) / u.beam
threshold_column = (threshold * u.beam/u.Jy * masscalc.col_conversion_factor(beam)).to(u.cm**-2)
threshold_column = masscalc.dust.colofsnu(nu=masscalc.centerfreq,
                                          snu=threshold*u.beam,
                                          beamomega=beam.sr).to(u.cm**-2,
                                                                u.dimensionless_angles())
threshold_density = (masscalc.mass_conversion_factor(20) * (threshold*u.beam).to(u.mJy).value /
                     (4/3.*np.pi) /
                     (beam.sr.value*masscalc.distance**2)**(1.5) /
                     (2.8*constants.m_p)).to(1/u.cm**3)
definitely_signal = data > threshold
definitely_thick_if_20K = data > thick_threshold
total_signal = data[definitely_signal].sum() / ppbeam
print("Total pixels > 10mJy/beam: {0} = {1}; r_eff = {2}"
      .format(definitely_signal.sum(), definitely_signal.sum()/ppbeam,
              ((definitely_signal.sum()*(pixel_scale*masscalc.distance)**2)**0.5).to(u.pc,
                                                                                     u.dimensionless_angles())))
    shreg = pyregion.ShapeList([reg])
    name = reg.attr[1]['text']
    log.info(name)

    mask = shreg.get_mask(hdu=contfile[0])

    data = contfile[0].data
    results[name] = {'peak': data[mask].max(),
                     'sum': data[mask].sum(),
                     'npix': mask.sum(),
                     'beam_area': beam.sr,
                     'RA': reg.coord_list[0],
                     'Dec': reg.coord_list[1],
                    }
    results[name]['peak_mass'] = masscalc.mass_conversion_factor()*results[name]['peak']
    results[name]['peak_col'] = masscalc.col_conversion_factor(beamomega=beam.sr.value)*results[name]['peak']


    for image, imname in ((contfile,''), (radio_image,'KUband')):
        data = image[0].data.squeeze()
        mywcs = wcs.WCS(image[0].header).celestial

        beam = radio_beam.Beam.from_fits_header(image[0].header)
        pixel_scale = np.abs(mywcs.pixel_scale_matrix.diagonal().prod())**0.5 * u.deg
        pixel_scale_as = pixel_scale.to(u.arcsec).value
        ppbeam = (beam.sr/(pixel_scale**2)).decompose().value

        keys = ['{1}cont_flux{0}arcsec'.format(rr.value, imname) for rr in radii]
        for k in keys:
            results[name][k] = []
        log.info("Doing aperture photometry on {0}".format(imname))
    shreg = pyregion.ShapeList([reg])
    name = reg.attr[1]['text']
    log.info(name)

    mask = shreg.get_mask(hdu=contfile[0])

    data = contfile[0].data
    results[name] = {'peak': data[mask].max(),
                     'sum': data[mask].sum(),
                     'npix': mask.sum(),
                     'beam_area': beam.sr,
                     'RA': reg.coord_list[0],
                     'Dec': reg.coord_list[1],
                    }
    results[name]['peak_mass'] = masscalc.mass_conversion_factor()*results[name]['peak']
    results[name]['peak_col'] = masscalc.col_conversion_factor(beamomega=beam.sr.value)*results[name]['peak']


    ppbeam_dict = {}
    for image, imname in ((contfile,''), (radio_image,'KUband')):
        data = image[0].data.squeeze()
        mywcs = wcs.WCS(image[0].header).celestial

        beam = radio_beam.Beam.from_fits_header(image[0].header)
        pixel_scale = np.abs(mywcs.pixel_scale_matrix.diagonal().prod())**0.5 * u.deg
        pixel_scale_as = pixel_scale.to(u.arcsec).value
        ppbeam = (beam.sr/(pixel_scale**2)).decompose().value
        if imname == '':
            ppbeam_dict['mm'] = ppbeam
        else:
            ppbeam_dict[imname] = ppbeam
Beispiel #9
0
log.info("Doing photometry")
for ii, row in enumerate(ProgressBar(ppcat)):
    structure = dend[row['_idx']]
    assert structure.idx == row['_idx'] == ii
    dend_inds = structure.indices()
    columns['noise'].append(noise[dend_inds].mean())
    columns['is_leaf'].append(structure.is_leaf)
    peakflux = data[dend_inds].max()
    columns['peak_cont_flux'].append(peakflux)
    columns['min_cont_flux'].append(data[dend_inds].min())
    columns['mean_cont_flux'].append(data[dend_inds].mean())
    columns['peak_cont_mass'].append(
        (masscalc.mass_conversion_factor() * peakflux).to(u.M_sun).value)
    columns['peak_cont_col'].append(
        (masscalc.col_conversion_factor(beamomega=beam.sr.value) *
         peakflux).to(u.cm**-2).value)
    columns['beam_area'].append(beam.sr.value)
for k in columns:
    if k not in ppcat.keys():
        ppcat.add_column(Column(name=k, data=columns[k]))

cat_mask = (ppcat['is_leaf'] & (ppcat['peak_cont_flux'] > 8 * ppcat['noise']) &
            (ppcat['mean_cont_flux'] > 5 * ppcat['noise']) &
            (ppcat['min_cont_flux'] > 1 * ppcat['noise']))
pruned_ppcat = ppcat[cat_mask]
mask = dend.index_map.copy()
log.info("Pruning mask image")
for ii in ProgressBar(list(range(len(ppcat)))):
    if ii not in pruned_ppcat['_idx']:
        mask[mask == ii] = -1