contcubeK = cubeK + med
    contcubeK.allow_huge_operations = True

# 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)


min_background = 100
background_guess = med.value
background_guess[background_guess < min_background] = min_background
guesses = np.empty((4,)+cubeK.shape[1:], dtype='float')
guesses[0,:] = background_guess
guesses[1,:] = -1
guesses[2,:] = 61
guesses[3,:] = 1.5

vcontcube_K7 = contcubeK.with_spectral_unit(u.km/u.s,
                                            rest_value=220.53932*u.GHz,
                                            velocity_convention='radio').spectral_slab(50*u.km/u.s,
                                                                                       72*u.km/u.s)
pcube_cont_K7 = pyspeckit.Cube(cube=vcontcube_K7)
start_point = (302,341) # np.unravel_index(np.nanargmax(peak*mask), peak.shape)
sp = pcube_cont_K7.get_spectrum(start_point[0], start_point[1])
sp.plotter()
sp.specfit(fittype='vheightgaussian', guesses=guesses[:,302,341],
           limitedmax=[T,T,T,T,T], limitedmin=[T,T,T,T,T],
# 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)
#mask = mask & (~absorption_mask)

min_background = 100
background_guess = med.value
background_guess[background_guess < min_background] = min_background
guesses = np.empty((4, ) + cubeK.shape[1:], dtype='float')
guesses[0, :] = background_guess
guesses[1, :] = -100
guesses[2, :] = 56
guesses[3, :] = 1.5

vcontcube_K7 = contcubeK.with_spectral_unit(
    u.km / u.s, rest_value=220.53932 * u.GHz,
    velocity_convention='radio').spectral_slab(42 * u.km / u.s,
                                               72 * u.km / u.s)
pcube_cont_K7 = pyspeckit.Cube(cube=vcontcube_K7)
start_point = (43, 43)  # np.unravel_index(np.nanargmax(peak*mask), peak.shape)
sp = pcube_cont_K7.get_spectrum(start_point[0], start_point[1])
sp.plotter()
sp.specfit(
    fittype='vheightgaussian',