from ch3cn_fits import (SpectralCube, pyspeckit, fits, u, np, line_name_dict,
                        line_aij, line_deg, frequencies, line_names, line_eu,
                        fit_tex, nupper_of_kkms, fit_all_tex)
import pyregion
from astropy import constants
import scipy.stats
import os
import paths
T = True
F = False

cubefn = paths.dpath('longbaseline/W51e2e_CH3CN_cutout.fits')
cube = SpectralCube.read(cubefn).minimal_subcube()
contcubeK = cube.to(
    u.K, u.brightness_temperature(cube.beam, cube.wcs.wcs.restfrq * u.Hz))
cubeK = cube.to(
    u.K, u.brightness_temperature(cube.beam, cube.wcs.wcs.restfrq * u.Hz))
med = cubeK.percentile(50, axis=0)
#cubeK.allow_huge_operations=True
#cubeK = cubeK - med

# determine where absorption...
skew = cubeK.apply_numpy_function(scipy.stats.skew, axis=0)

# BAD error estimate
err = cubeK.std(axis=0)
err[:] = 5 * u.K
peak = (cubeK).max(axis=0)
nadir = (cubeK).min(axis=0)
#mask = (peak > 200*u.K) & (skew > 0.1)
absorption_mask = (skew < -0.1)
from ch3cn_fits import SpectralCube, pyspeckit, fits, u, np
import os
import paths
T=True
F=False

cubefn = paths.dpath('longbaseline/W51northcax.SPW2_ALL_cutout.fits')
cubeKfn = paths.dpath('longbaseline/W51northcax.SPW2_ALL_cutout_medsub_K.fits')
medKfn = paths.dpath('longbaseline/W51northcax.SPW2_ALL_cutout_med_K.fits')
if not os.path.exists(cubeKfn):
    cube = SpectralCube.read(cubefn).minimal_subcube()
    contcubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
                                                      cube.wcs.wcs.restfrq*u.Hz))
    cube.allow_huge_operations = True
    cubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
                                                  cube.wcs.wcs.restfrq*u.Hz))
    med = cubeK.percentile(25, axis=0)
    cubeK.allow_huge_operations=True
    cubeK = cubeK - med
    med.write(medKfn)
    cubeK.write(cubeKfn)
else:
    cubeK = SpectralCube.read(cubeKfn)
    cubeK.allow_huge_operations = True
    med = fits.getdata(medKfn) * u.K
    contcubeK = cubeK + med
    contcubeK.allow_huge_operations = True

# BAD error estimate
err = cubeK.std(axis=0)
err[:] = 5*u.K
Ejemplo n.º 3
0
from ch3cn_fits import SpectralCube, pyspeckit, fits, u, np
import os
T=True
F=False

cubefn = '../../FITS/longbaseline/W51e8_CH3CN_cutout.fits'
if not os.path.exists(cubefn):
    cube = SpectralCube.read('../../FITS/longbaseline/W51e2cax.CH3CN_K3_nat_all.image.fits')
    scube = cube[:,1120:1440,2400:2760]
    scube.write(cubefn)
cube = SpectralCube.read(cubefn).minimal_subcube()
contcubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
                                                  cube.wcs.wcs.restfrq*u.Hz))
cubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
                                              cube.wcs.wcs.restfrq*u.Hz))
med = cubeK.percentile(25, axis=0)
cubeK.allow_huge_operations=True
cubeK = cubeK - med

# BAD error estimate
err = cubeK.std(axis=0)
err[:] = 5*u.K
peak = (cubeK).max(axis=0)
mask = (peak > 200*u.K)# & (peak > 6*err)
absorption_mask = cubeK.min(axis=0) < -150*u.K
mask = mask & (~absorption_mask)

pcube = pyspeckit.Cube(cube=cubeK[:400,:,:]) # crop out k=0,1

vguesses = 62*u.km/u.s
colguesses = np.ones_like(mask)*1e16