Esempio n. 1
0
def test_model_image(imsize, nproc, count, chunk=8):
    psf = None
    model_orig = create_model()
    imfit = Imfit(model_orig,
                  psf=psf,
                  quiet=True,
                  nproc=nproc,
                  chunk_size=chunk)
    shape = (imsize, imsize)
    imfit.getModelImage(shape)
    t1 = time.time()
    imfit._modelObject._testCreateModelImage(count)
    return time.time() - t1
Esempio n. 2
0
def test_fitting():
    psf = gaussian_psf(2.5, size=9)
    model_orig = create_model()
    imfit = Imfit(model_orig, psf=psf, quiet=False)

    noise_level = 0.1
    shape = (100, 100)
    image = imfit.getModelImage(shape)
    noise = image * noise_level
    image += (np.random.random(shape) * noise)
    mask = np.zeros_like(image, dtype='bool')
    
    imfit.fit(image, noise, mask)
    model_fitted = imfit.getModelDescription()

    orig_params = get_model_param_array(model_orig)
    fitted_params = get_model_param_array(model_fitted)

    assert_allclose(orig_params, fitted_params, rtol=noise_level)
Esempio n. 3
0
def test_fitting():
    psf = gaussian_psf(2.5, size=9)
    model_orig = create_model()
    imfit = Imfit(model_orig, psf=psf, quiet=False)

    noise_level = 0.1
    shape = (100, 100)
    image = imfit.getModelImage(shape)
    noise = image * noise_level
    image += (np.random.random(shape) * noise)
    mask = np.zeros_like(image, dtype='bool')

    imfit.fit(image, noise, mask)
    model_fitted = imfit.getModelDescription()

    orig_params = get_model_param_array(model_orig)
    fitted_params = get_model_param_array(model_fitted)

    assert_allclose(orig_params, fitted_params, rtol=noise_level)
Esempio n. 4
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
Esempio n. 5
0
for i, f in enumerate(flux):
    star = path.basename(cubes[i])
    print 'Fitting PSF %d of %d (%s)' % (i, len(flux), star)
    imfit = Imfit(model, quiet=True)
    imfit.fit(f, mode='NM', use_model_for_errors=False, use_cash_statistics=False)
    _goodfraction = float(imfit.nValidPixels) / float(f.size)
    print '    Good pixels: %.1f %%' % (_goodfraction  * 100)
    good.append(_goodfraction)
    print '    Fit converged? %s' % imfit.fitConverged
    flag.append(not imfit.fitConverged)
    print '    Fit statistic: %f' % imfit.fitStatistic
    chi2.append(imfit.fitStatistic)

    _fitmodel = imfit.getModelDescription()
    fitmodel.append(_fitmodel)
    model_f = imfit.getModelImage()
    modelflux.append(model_f)

    imradius = 10
    x0 = int(_fitmodel.x0.value)
    y0 = int(_fitmodel.y0.value)
    xslice = slice(x0 - imradius, x0 + imradius)
    yslice = slice(y0 - imradius, y0 + imradius)

    plt.ioff()
    fig = plt.figure(1, figsize=(10, 7))
    plt.clf()
    gs = plt.GridSpec(2, 3, height_ratios=[2.0, 3.0])
    ax = plt.subplot(gs[0,0])
    im = ax.imshow(f[yslice, xslice], vmin=0.0, vmax=1.1, cmap='OrRd')
    plt.colorbar(im, ax=ax)
Esempio n. 6
0
def rad_prof(model, bins):
    imfit = Imfit(model, quiet=False)
    image = imfit.getModelImage((model.y0.value * 2, model.x0.value * 2))
    return radialProfile(image, bins, x0, y0, pa=0.0, ba=1.0)
Esempio n. 7
0
def create_image(shape, PSF, model):
    imfit = Imfit(model, PSF, quiet=True)
    image = imfit.getModelImage(shape)
    return image
Esempio n. 8
0
def model_image(model, shape, PSF=None, nproc=None):
    imfit = Imfit(model, PSF, quiet=True, nproc=nproc)
    return imfit.getModelImage(shape)
Esempio n. 9
0
    pf = psfflux[i] - psfbg[i]
    pf[pf <= 0] = np.ma.masked
    print 'Fitting PSF %d of %d (%s \AA)' % (i, fill_flux.shape[0], wl)
    imfit = Imfit(model, quiet=True)
    imfit.fit(pf, mode='NM', use_model_for_errors=False)
    _goodfraction = float(imfit.nValidPixels) / float(psfflux[i].size)
    goodfraction.append(_goodfraction)
    flagged = not imfit.fitConverged or _goodfraction < 0.5
    psfflags.append(flagged)
    print '    Fit statistic: %f' % imfit.fitStatistic
    print '    Reduced fit statistic: %f' % imfit.reducedFitStatistic
    print '    Valid pix: %.1f %%' % (_goodfraction * 100.0)
    print '    Flagged? %s' % flagged
    chi2.append(imfit.fitStatistic)
    fitmodel = imfit.getModelDescription()
    modelimage = imfit.getModelImage()
    psfmodels.append(fitmodel)
    print fitmodel

    if debug:
        pf = psfflux[i] - psfbg[i]
        norm = pf.max()
        residual = pf - modelimage
    
        plt.ioff()
        plt.clf()
        fig = plt.figure(1, figsize=(10, 7))
        gs = plt.GridSpec(2, 3, height_ratios=[2.0, 3.0])
        ax = plt.subplot(gs[0,0])
        im = ax.imshow(pf / norm, vmin=0.0, vmax=1.1, cmap='OrRd')
        plt.colorbar(im, ax=ax)