Exemplo n.º 1
0
def fit_spectra(full_spectra, full_noise, flux_unit, init_model):
    PSF = moffat_psf(fwhm=2.4, size=9)
    fitter = Imfit(init_model, PSF, quiet=True)
    models = []
    for i in xrange(0, full_spectra.shape[-1]):
#         print '#'*50, i
        f__l = full_spectra[..., i] / flux_unit
        err__l = full_noise[..., i] / flux_unit
        fitter.fit(f__l, err__l)
        if fitter.nValidPixels < 1000:
            print '(%d) Too many masked pixels.' % i
        if fitter.nPegged < 0:
            print '(%d) Pegged parameters.' % i
        m = fitter.getModelDescription()
#         print m.bulge.I_e.value, m.bulge.r_e.value, m.disk.I_0.value, m.disk.h.value
        models.append(m)
    return models
Exemplo n.º 2
0
def get_images(db):
    K = fitsQ3DataCube(db, smooth=False)
    mask = ~K.qMask
    qSignal = np.ma.array(K.qSignal, mask=mask)
    qNoise = np.ma.array(K.qNoise, mask=mask)
    
#     PA, ba = K.getEllipseParams()
    
    model = galaxy_model(K.x0, K.y0, bulge=True, disk=True,
                         I_e=1, r_e=12, n=1.5, PA_b=90.0, ell_b=0.5,
                         I_0=1, h=12, PA_d=90, ell_d=0.5)
    PSF = moffat_psf(fwhm=2.4, size=9)
    fitter = Imfit(model, PSF, quiet=True)
    fitter.fit(qSignal, qNoise)
    model_image = fitter.getModelImage()
    model = fitter.getModelDescription()
    bulge_image, disk_image = create_model_images(qSignal.shape, PSF, model)
    bulge_image = np.ma.array(bulge_image, mask=mask)
    disk_image = np.ma.array(disk_image, mask=mask)
    bulge_frac = bulge_image / model_image
    disk_frac = disk_image / model_image
    bulge_noise = np.sqrt(bulge_frac) * qNoise
    disk_noise = np.sqrt(disk_frac) * qNoise
    return model, qSignal, qNoise, model_image, bulge_image, bulge_noise, disk_image, disk_noise
Exemplo n.º 3
0
l_obs_1p = t_1p['wl'][:]
flag_bad_1p = (t_1p['flag'] > 0.0) | (t_1p['chi2'] > 20.0)

box_radius = c.attrs['box_radius']
target_vd = c.attrs['target_vd']
PSF_FWHM = c.attrs['PSF_FWHM']
galaxyName = c.attrs['object_name']
flux_unit = c.attrs['flux_unit']
flag_bad = (t['flag'] > 0.0) | (t['chi2'] > 20.0)
flag_ok = ~flag_bad
fit_l_obs = t['wl']
masked_wl = load_line_mask('data/starlight/Mask.mE', fit_l_obs)

initial_params = np.array(c.initialParams, dtype=t.dtype)
initial_model = BDModel.fromParamVector(initial_params)
psf = moffat_psf(PSF_FWHM, c.attrs['PSF_beta'], size=c.attrs['PSF_size'])
bulge_model_im, disk_model_im = create_model_images(initial_model, c.total.f_obs.shape[1:], psf) 
bulge_model_im *= flux_unit
disk_model_im *= flux_unit

l1 = find_nearest_index(fit_l_obs, 5635.0)
x0 = t['x0'][0]
y0 = t['y0'][0]

total_im = c.total.f_obs[l1] * flux_unit
model_im = disk_model_im + bulge_model_im
residual_im = (total_im - model_im)  / total_im

colnames = [
            'I_e',
            'I_0',
Exemplo n.º 4
0
    frame = InitialModelFrame(None, wx.ID_ANY, image, noise, psf, model_file,
                              'Initial Model Finder', plot_title)
    frame.Show()
    app.MainLoop()
################################################################################


args = parse_args()
if args.verbose:
    logger.setLevel(-1)
    logger.debug('Verbose output enabled.')

cube = args.cube[0]
model_file = args.cube[0] + '.initmodel'
title = path.basename(cube)

logger.info('Loading cube: %s' % cube)
K = fitsQ3DataCube(args.cube[0])

logger.info('Creating PSF (FWHM=%f, beta=%f, size=%d)' % (args.psfFWHM, args.psfBeta, args.psfSize))
psf = moffat_psf(args.psfFWHM, args.psfBeta, size=args.psfSize)

flags = ~K.qMask | (K.qSignal <= 0.0) | (K.qNoise <= 0.0)
flux = np.ma.array(K.qSignal, mask=flags)
noise = np.ma.array(K.qNoise, mask=flags)

logger.info('Running GUI...')
run_app(flux, noise, psf, model_file, title)
logger.info('Exiting GUI.')