if figname is not None:
            pl.savefig(paths.fpath(figname), dpi=300, bbox_inches='tight',
                       bbox_extra_artists=[])

if __name__ == "__main__":

    import glob
    import radio_beam
    from astropy.table import Table

    myvtbl = Table.read(paths.tpath('core_velocities.txt'),
                        # write as ascii.fixed_width
                        format='ascii.fixed_width', delimiter='|')

    line_table = Table.read(paths.apath('full_line_table.csv'))
    all_line_ids = {"{0}_{1}".format(row['Species'], row['Resolved QNs']):
                    (row['Freq-GHz'] if row['Freq-GHz']
                     else row['Meas Freq-GHz'])*u.GHz
                    for row in line_table}
    all_line_ids.update(line_ids)

    for row in myvtbl:

        speclist = [pyspeckit.Spectrum(fn) for fn in
                    glob.glob(paths.spath("{0}_spw*_peak.fits".format(row['source'])))]
        if len(speclist) == 0:
            continue

        for sp in speclist:
            beam = radio_beam.Beam.from_fits_header(sp.header)
示例#2
0
import pyspeckit
from astropy import constants
from astropy import units as u
from astropy.table import Table
from astropy import table
from astropy.utils.console import ProgressBar
import pylab as pl
import pyregion
import velo_guesses
import radio_beam

import warnings
from numpy.ma.core import MaskedArrayFutureWarning
warnings.filterwarnings('ignore', category=MaskedArrayFutureWarning)

line_table = table.Table.read(paths.apath('full_line_table.csv'))
line_table.sort('Species')

regions = (pyregion.open(paths.rpath("cores.reg")))

for region in regions:
    name = region.attr[1]['text']

    spectral_files = glob.glob(paths.spath('{0}_spw[0123]_mean.fits'.format(name)))
    #background_spectral_files = glob.glob(paths.spath('{0}_spw[0123]_background_mean.fits'.format(name)))
    assert len(spectral_files) == 4#len(background_spectral_files) == 4
    spectra = pyspeckit.Spectra(spectral_files)
    #bgspectra = pyspeckit.Spectra(background_spectral_files)
    stats = spectra.stats()
    err = stats['std'] # overly conservative guess
import numpy as np
import paths
import pyspeckit
import pylab as pl
from astropy import constants
from astropy.io import fits
from astropy.table import Table,Column
from astropy import units as u
from astropy import log
import spectral_overlays

from line_parameters import frequencies, freq_name_mapping, yoffset

pruned_ppcat = Table.read(paths.tpath("dendrogram_continuum_catalog.ipac"),
                          format='ascii.ipac')
dendromask = fits.getdata(paths.apath('dendrograms_min1mJy_diff1mJy_mask_pruned.fits'))

minvelo = 45*u.km/u.s
maxvelo = 90*u.km/u.s

# array merged
data = {}

for row in pruned_ppcat:
    name = row['_idx']
    data[name] = {}

    fn = paths.merge_spath("dendro{name:03d}_spw{ii}_mean_7m12m.fits")
    bgfn = paths.merge_spath("dendro{name:03d}_spw{ii}_background_mean_7m12m.fits")

    data[name] = spectral_overlays.spectral_overlays(fn, name=name,
示例#4
0
    from glue.plugins.pv_slicer import PVSliceWidget
except ImportError:
    from glue.plugins.tools.pv_slicer import PVSliceWidget
from glue import qglue

import matplotlib
import numpy as np
from astropy import units as u
from astropy import coordinates
from astropy import wcs
from astropy.io import ascii
from paths import mpath, apath, fpath, molpath, hpath
import pvextractor

catalog = astropy_tabular_data(
    apath('fitted_line_parameters_Chi2Constraints.ipac'), format='ascii.ipac')
catalog.label = 'FittedLineParameters'
catalog.style.color = 'green'
catalog.style.marker = 'o'
cube = load_data(hpath('APEX_H2CO_303_202_bl.fits'))
cube.label = 'H2CO 303/202'
cube2 = load_data(molpath('APEX_SiO_54.fits'))
cube2.label = 'SiO'
cube3 = load_data(hpath('APEX_13CO_matched_H2CO.fits'))
cube3.label = '13CO'
higaltem = load_data('/Users/adam/work/gc/gcmosaic_temp_conv36.fits')

dc = DataCollection([cube, catalog, cube2, cube3, higaltem])
dc.merge(cube, cube2, cube3)

dc.add_link(LinkSame(cube.id['Galactic Longitude'], catalog.id['GLON']))
示例#5
0
    plot_one_component(linewidths*FWHM, tem9,  'k-',  alpha=0.5, linewidth=2, label='$dv/dr=20$',
                       figname=paths.fpath("despotic/TvsSigma_dvdr20_only.pdf"))
    plot_one_component(linewidths*FWHM, tem3,  'r--', alpha=0.5, linewidth=2, label='$n=10^5$',
                       figname=paths.fpath("despotic/TvsSigma_n5_only.pdf"))
    plot_one_component(linewidths*FWHM, tem5,  'b--', alpha=0.5, linewidth=2, label='$n=10^6$',
                       figname=paths.fpath("despotic/TvsSigma_n6_only.pdf"))
    plot_one_component(linewidths*FWHM, tem6,  'r-',  alpha=0.5, linewidth=2, label='$n=10^5$ $L=1$',
                       figname=paths.fpath("despotic/TvsSigma_n5_L1_only.pdf"))
    plot_one_component(linewidths*FWHM, tem8,  'r-.', alpha=0.5, linewidth=2, label='$n=10^5$ $T_D(rad)=25$',
                       figname=paths.fpath("despotic/TvsSigma_n5_td25_only.pdf"))
    plot_one_component(linewidths2*FWHM, tem13, 'g-', alpha=0.5, linewidth=2, label=r'$n=10^{4.25}\sigma_5^{-2}$, $L=5\sigma_5^{0.7}$',
                       figname=paths.fpath("despotic/TvsSigma_isobar_L0.7_only.pdf"))


    from astropy.table import Table
    pcfittable = Table.read(paths.apath('fitted_line_parameters_Chi2Constraints.ipac'),
                            format='ascii.ipac')

    lolim = pcfittable['tmax1sig_chi2'] > 340
    maps = np.char.startswith(pcfittable['Source_Name'], 'Map')
    ok = ~np.isnan(pcfittable['tmin1sig_chi2']) & (pcfittable['width'] < 40) & (pcfittable['h2coratio321303']/pcfittable['eh2coratio321303'] > 5) & pcfittable['is_good'].astype('bool')
    flags = {'is_map': maps,
             'is_lolim': lolim,
             'is_ok': ok}
    # Don't plot these for now...
    pcfittable = pcfittable[(~lolim) & ok]
    maps = np.char.startswith(pcfittable['Source_Name'], 'Map')
    lolim_conservative = pcfittable['tmax1sig_chi2'] > 150

    mask = maps&~lolim_conservative
    ax.errorbar(pcfittable['width'][mask]*(8*np.log(2))**0.5,
示例#6
0
try:
    from glue.plugins.pv_slicer import PVSliceWidget
except ImportError:
    from glue.plugins.tools.pv_slicer import PVSliceWidget
from glue import qglue

import matplotlib
import numpy as np
from astropy import units as u
from astropy import coordinates
from astropy import wcs
from astropy.io import ascii
from paths import mpath,apath,fpath,molpath,hpath
import pvextractor

catalog = astropy_tabular_data(apath('fitted_line_parameters_Chi2Constraints.ipac'),
                               format='ascii.ipac')
catalog.label='FittedLineParameters'
catalog.style.color = 'green'
catalog.style.marker = 'o'
cube = load_data(hpath('APEX_H2CO_303_202_bl.fits'))
cube.label='H2CO 303/202'
cube2 = load_data(molpath('APEX_SiO_54.fits'))
cube2.label='SiO'
cube3 = load_data(hpath('APEX_13CO_matched_H2CO.fits'))
cube3.label='13CO'
higaltem = load_data('/Users/adam/work/gc/gcmosaic_temp_conv36.fits')

dc = DataCollection([cube, catalog, cube2, cube3, higaltem])
dc.merge(cube,cube2,cube3)
        'r-.',
        alpha=0.5,
        linewidth=2,
        label='$n=10^5$ $T_D(rad)=25$',
        figname=paths.fpath("despotic/TvsSigma_n5_td25_only.pdf"))
    plot_one_component(
        linewidths2 * FWHM,
        tem13,
        'g-',
        alpha=0.5,
        linewidth=2,
        label=r'$n=10^{4.25}\sigma_5^{-2}$, $L=5\sigma_5^{0.7}$',
        figname=paths.fpath("despotic/TvsSigma_isobar_L0.7_only.pdf"))

    pcfittable = Table.read(
        paths.apath('fitted_line_parameters_Chi2Constraints.ipac'),
        format='ascii.ipac')

    lolim = pcfittable['tmax1sig_chi2'] > 340
    maps = np.char.startswith(pcfittable['Source_Name'], 'Map')
    ok = ~np.isnan(pcfittable['tmin1sig_chi2']) & (
        pcfittable['width'] <
        40) & (pcfittable['h2coratio321303'] / pcfittable['eh2coratio321303'] >
               5) & pcfittable['is_good'].astype('bool')
    flags = {'is_map': maps, 'is_lolim': lolim, 'is_ok': ok}
    # Don't plot these for now...
    pcfittable = pcfittable[(~lolim) & ok]
    maps = np.char.startswith(pcfittable['Source_Name'], 'Map')
    lolim_conservative = pcfittable['tmax1sig_chi2'] > 150

    mask = maps & ~lolim_conservative
"""
Piecewise interpolator from ratio 303_202 / 321_220 to kinetic temperature
(inferred from a set of dendrogram analyses)
"""
from astropy.table import Table, Column
import numpy as np
from numpy.polynomial.polynomial import Polynomial
from paths import apath
from h2co_modeling.temperature_mapper import tm

fit_table = Table.read(apath('piecewise_tvsratio_fit.ipac'), format='ascii.ipac')

# old, wrong version # Define a piecewise interpolated function...
# old, wrong version pwtem = lambda x: np.piecewise(x,
# old, wrong version                                [(x>r['MinBound']) & (x<r['MaxBound'])
# old, wrong version                                 for r in fit_table],
# old, wrong version                                [Polynomial([r['const'], r['xcoef'], r['x2coef']])
# old, wrong version                                 for r in fit_table] + [lambda y: np.nan]

# Grabbed from dendrotem_plot on Jan 15, 2015
#pwtem = lambda x: np.polyval([190.12665966, 276.45454806,  11.09564855], x)
pwtem = lambda x: tm(x, density=1e4)
"""
Piecewise interpolator from ratio 303_202 / 321_220 to kinetic temperature
(inferred from a set of dendrogram analyses)
"""
from astropy.table import Table, Column
import numpy as np
from numpy.polynomial.polynomial import Polynomial
from paths import apath
from h2co_modeling.temperature_mapper import tm

fit_table = Table.read(apath('piecewise_tvsratio_fit.ipac'),
                       format='ascii.ipac')

# old, wrong version # Define a piecewise interpolated function...
# old, wrong version pwtem = lambda x: np.piecewise(x,
# old, wrong version                                [(x>r['MinBound']) & (x<r['MaxBound'])
# old, wrong version                                 for r in fit_table],
# old, wrong version                                [Polynomial([r['const'], r['xcoef'], r['x2coef']])
# old, wrong version                                 for r in fit_table] + [lambda y: np.nan]

# Grabbed from dendrotem_plot on Jan 15, 2015
#pwtem = lambda x: np.polyval([190.12665966, 276.45454806,  11.09564855], x)
pwtem = lambda x: tm(x, density=1e4)
示例#10
0
import matplotlib
import copy
from paths import mpath,apath,fpath,molpath,hpath
from astropy import units as u
from astropy import coordinates
from astropy.io import ascii, fits
from astropy import log
from astropy.wcs import WCS
from astropy import wcs
from piecewise_rtotem import pwtem
import paths
import matplotlib
matplotlib.rc_file(paths.pcpath('pubfiguresrc'))

# obsolete x,y = np.loadtxt(apath('orbit_K14.dat')).T
table = ascii.read(apath('orbit_K14_2.dat'), format='basic', comment="#", guess=False) 
coords = coordinates.SkyCoord(table['l']*u.deg, table['b']*u.deg, frame='galactic')
P = pvextractor.Path(coords, width=300*u.arcsec)

dl = (table['l'][1:]-table['l'][:-1])
db = (table['b'][1:]-table['b'][:-1])
dist = (dl**2+db**2)**0.5
cdist = np.zeros(dist.size+1)
cdist[1:] = dist.cumsum()

reftime = -2
bricktime = 0.3
time = table['t']

# how much time per pixel?
dtdx = (table['t'].max() - table['t'].min()) / cdist.max()
示例#11
0
import matplotlib
import copy
from paths import mpath,apath,fpath,molpath,hpath
from astropy import units as u
from astropy import coordinates
from astropy.io import ascii, fits
from astropy import log
from astropy.wcs import WCS
from astropy import wcs
from piecewise_rtotem import pwtem
import paths
import matplotlib
matplotlib.rc_file(paths.pcpath('pubfiguresrc'))

# obsolete x,y = np.loadtxt(apath('orbit_K14.dat')).T
table = ascii.read(apath('orbit_K14_2.dat'), format='basic', comment="#", guess=False)
coords = coordinates.SkyCoord(table['l']*u.deg, table['b']*u.deg, frame='galactic')
P = pvextractor.Path(coords, width=300*u.arcsec)
width = ""
P = pvextractor.Path(coords, width=500*u.arcsec)
width = "500arcsec"
P = pvextractor.Path(coords, width=200*u.arcsec)
width = "200arcsec"

dl = (table['l'][1:]-table['l'][:-1])
db = (table['b'][1:]-table['b'][:-1])
dist = (dl**2+db**2)**0.5
cdist = np.zeros(dist.size+1)
cdist[1:] = dist.cumsum()

reftime = -2

### Add columns to the outflow table from the core table ###
newcol = Column([core_phot_tbl['peak_mass'][core_phot_tbl['SourceID'] == name][0]
                 if any(core_phot_tbl['SourceID'] == name) else np.nan
                 for name in outflow_tbl['SourceID']],
                name='CoreMass')
outflow_tbl.add_column(newcol)

newcol = Column([cores_merge['T_corrected_peakmass'][cores_merge['SourceID'] == name][0]
                 if any(cores_merge['SourceID'] == name) else np.nan
                 for name in outflow_tbl['SourceID']],
                name='TCorrectedCoreMass')
outflow_tbl.add_column(newcol)

#should already be in the file
# newcol = Column([cores_merge['mean_velo'][cores_merge['SourceID'] == name][0]
#                  if any(cores_merge['SourceID'] == name) else np.nan
#                  for name in outflow_tbl['SourceID']],
#                 name='CoreVelocity')
# outflow_tbl.add_column(newcol)



outflow_tbl.write(paths.tpath('outflows_with_cores.ipac'), format='ascii.ipac',
                  overwrite=True)

# exec other merge now
with open(paths.apath('merge_spectral_fits_with_photometry.py')) as source_file:
    exec(source_file.read(), globals(), locals())
示例#13
0
import numpy as np
import pylab as pl
from astropy import wcs
from astropy.io import fits
from spectral_cube import SpectralCube
from astropy import units as u
from astropy import table
import paths

lines = table.Table.read(paths.apath('lines.txt'), format='ascii')
linenames = [
    "{0} {1}".format(x, y) for x, y in zip(lines['species'], lines['qn'])
]

for ii, line in enumerate(lines):

    if line['diffuse'] == 'n':
        continue

    band = int(line['band']) if line['band'] != 'None' else None
    if band is None:
        continue
    spw = int(line['spw'])

    mom0 = fits.open(
        paths.dpath('moments/{0}_moment0.fits'.format(line['species_txt'])))
    mx = fits.open(
        paths.dpath('moments/{0}_max.fits'.format(line['species_txt'])))

    mywcs = wcs.WCS(mx[0].header)
    core_phot_tbl['peak_mass'][core_phot_tbl['SourceID'] == name][0] if any(
        core_phot_tbl['SourceID'] == name) else np.nan
    for name in outflow_tbl['SourceID']
],
                name='CoreMass')
outflow_tbl.add_column(newcol)

newcol = Column([
    cores_merge['T_corrected_peakmass'][cores_merge['SourceID'] == name][0]
    if any(cores_merge['SourceID'] == name) else np.nan
    for name in outflow_tbl['SourceID']
],
                name='TCorrectedCoreMass')
outflow_tbl.add_column(newcol)

#should already be in the file
# newcol = Column([cores_merge['mean_velo'][cores_merge['SourceID'] == name][0]
#                  if any(cores_merge['SourceID'] == name) else np.nan
#                  for name in outflow_tbl['SourceID']],
#                 name='CoreVelocity')
# outflow_tbl.add_column(newcol)

outflow_tbl.write(paths.tpath('outflows_with_cores.ipac'),
                  format='ascii.ipac',
                  overwrite=True)

# exec other merge now
with open(
        paths.apath('merge_spectral_fits_with_photometry.py')) as source_file:
    exec(source_file.read(), globals(), locals())
示例#15
0
from astropy import units as u
from astropy import coordinates
from astropy.io import ascii
from astropy import log
from astropy.wcs import WCS
import paths
import matplotlib
matplotlib.rc_file(paths.pcpath('pubfiguresrc'))

import shapely.geometry as geom
import dendrograms
reload(dendrograms)
from dendrograms import dend, dendsm, catalog, catalogsm

# obsolete x,y = np.loadtxt(apath('orbit_K14.dat')).T
table = ascii.read(apath('orbit_K14_2.dat'),
                   format='basic',
                   comment="#",
                   guess=False)
coords = coordinates.SkyCoord(table['l'] * u.deg,
                              table['b'] * u.deg,
                              frame='galactic')
P = pvextractor.Path(coords, width=300 * u.arcsec)

dl = (table['l'][1:] - table['l'][:-1])
db = (table['b'][1:] - table['b'][:-1])
dist = (dl**2 + db**2)**0.5
cdist = np.zeros(dist.size + 1)
cdist[1:] = dist.cumsum()

vmin, vmax = 10, 150
import paths
import pyspeckit
import pylab as pl
from astropy import constants
from astropy.io import fits
from astropy.table import Table, Column
from astropy import units as u
from astropy import log
import spectral_overlays

from line_parameters import frequencies, freq_name_mapping, yoffset

pruned_ppcat = Table.read(paths.tpath("dendrogram_continuum_catalog.ipac"),
                          format='ascii.ipac')
dendromask = fits.getdata(
    paths.apath('dendrograms_min1mJy_diff1mJy_mask_pruned.fits'))

minvelo = 45 * u.km / u.s
maxvelo = 90 * u.km / u.s

# array merged
data = {}

for row in pruned_ppcat:
    name = row['_idx']
    data[name] = {}

    fn = paths.merge_spath("dendro{name:03d}_spw{ii}_mean_7m12m.fits")
    bgfn = paths.merge_spath(
        "dendro{name:03d}_spw{ii}_background_mean_7m12m.fits")