Пример #1
0
    cube = cube - med
    cube.write(cubefn)
else:
    cube = SpectralCube.read(cubefn).minimal_subcube()
cubeK = cube.to(
    u.K, u.brightness_temperature(cube.beam, cube.wcs.wcs.restfrq * u.Hz))
err = cubeK[:30].std(axis=0)
peak = cubeK.max(axis=0)
mask = (peak > 1 * u.K) & (peak > 6 * err)

subcube = cubeK.spectral_slab(-50 * u.km / u.s, 200 * u.km / u.s)

pcube = pyspeckit.Cube(cube=subcube)

vguesses = subcube.spectral_axis[subcube.argmax(axis=0)]
colguesses = np.ones_like(mask) * 1e15
temguesses = np.ones_like(mask) * 150.
widths = np.ones_like(mask) * 5.0
guesses = np.array([vguesses.value, widths, temguesses, colguesses])

mask &= ((vguesses < 95 * u.km / u.s) & (vguesses > -25 * u.km / u.s))
# For laptop
#mask &= (peak>10*u.K)

start_point = np.unravel_index(np.nanargmax(peak * mask), peak.shape)

position_order = 1. / peak.value
position_order[np.isnan(peak)] = np.inf

pcube.fiteach(
    fittype='ch3cn',
    cube = cube - med
    cube.write(cubefn)
else:
    cube = SpectralCube.read(cubefn).minimal_subcube()
cubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
                                              cube.wcs.wcs.restfrq*u.Hz))
err = cubeK[:30].std(axis=0)
peak = cubeK.max(axis=0)
mask = (peak > 1*u.K) & (peak > 6*err)

subcube = cubeK.spectral_slab(-50*u.km/u.s, 200*u.km/u.s)

pcube = pyspeckit.Cube(cube=subcube)

vguesses = subcube.spectral_axis[subcube.argmax(axis=0)]
colguesses = np.ones_like(mask)*1e15
temguesses = np.ones_like(mask)*150.
widths = np.ones_like(mask)*5.0
guesses = np.array([vguesses.value, widths, temguesses, colguesses])

mask &= ((vguesses < 95*u.km/u.s) &
         (vguesses > -25*u.km/u.s))
# For laptop
#mask &= (peak>10*u.K)

start_point = np.unravel_index(np.nanargmax(peak*mask), peak.shape)

position_order = 1./peak.value
position_order[np.isnan(peak)] = np.inf

pcube.fiteach(fittype='ch3cn', guesses=guesses, integral=False,
# 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

if os.path.exists('e2e_CH3CN_Emission_fits.fits'):
    pcube.load_model_fit('e2e_CH3CN_Emission_fits.fits', npars=4)
else:
    vguesses = 62 * u.km / u.s
    colguesses = np.ones_like(mask) * 1e16
    temguesses = np.ones_like(mask) * 250.
    widths = np.ones_like(mask) * 2.0
    #guesses = np.array([vguesses.value, widths, temguesses, colguesses])
    guesses = [62, 2.0, 250., 1e16]

    # For laptop
    #mask &= (peak>10*u.K)

    start_point = (43, 43
                   )  #np.unravel_index(np.nanargmax(peak*mask), peak.shape)

    position_order = 1. / peak.value
    position_order[np.isnan(peak)] = np.inf

    sp = pcube.get_spectrum(*start_point)
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
temguesses = np.ones_like(mask)*250.
widths = np.ones_like(mask)*2.0
#guesses = np.array([vguesses.value, widths, temguesses, colguesses])
guesses = [62, 2.0, 250., 1e16]

# For laptop
#mask &= (peak>10*u.K)

start_point = (43,43)#np.unravel_index(np.nanargmax(peak*mask), peak.shape)

position_order = 1./peak.value
position_order[np.isnan(peak)] = np.inf

sp = pcube.get_spectrum(*start_point)
sp.plotter()