Пример #1
0
def test_gmix_lists():
    gml = ngmix.gmix.GMixList()
    gml.append(ngmix.GMix(ngauss=3))
    gml.append(ngmix.GMix(ngauss=3))
    gml[1] = ngmix.GMix(ngauss=3)

    mgml = ngmix.gmix.MultiBandGMixList()
    mgml.append(gml)
    mgml.append(gml)

    mgml[1] = gml
Пример #2
0
def test_gmix_errors():
    with pytest.raises(ValueError):
        ngmix.GMix()

    with pytest.raises(ValueError):
        ngmix.GMixModel([1] * 6, "blah")

    with pytest.raises(ValueError):
        ngmix.GMix(pars=[1] * 10)

    with pytest.raises(ValueError):
        ngmix.GMix(ngauss=-1)

    with pytest.raises(ValueError):
        ngmix.GMixModel([1] * 10, "gauss")

    pars = [0, 0, 0, 0, 10, 1]
    gm = ngmix.GMixModel(pars, "gauss")
    with pytest.raises(ValueError):
        gm.get_sheared(0.1)

    with pytest.raises(TypeError):
        gm.convolve(3)

    with pytest.raises(ValueError):
        gm.make_image([1])

    obs = ngmix.Observation(np.zeros((10, 10)))
    with pytest.raises(ValueError):
        gm.fill_fdiff(obs, np.zeros((10, 10)), start=100000)

    with pytest.raises(TypeError):
        gm.make_galsim_object(gsparams=3)

    with pytest.raises(ValueError):
        gm = ngmix.GMixCoellip([1] * 3)

    with pytest.raises(ValueError):
        ngmix.gmix.get_model_name(-1)

    with pytest.raises(ValueError):
        ngmix.gmix.get_model_num('asdfsa')

    with pytest.raises(ValueError):
        ngmix.gmix.get_model_ngauss('asdfsa')

    with pytest.raises(ValueError):
        ngmix.gmix.get_model_npars('asdfsa')

    with pytest.raises(ValueError):
        tgm = gm.copy()
        tgm._model_name = 'sdfasd'
        tgm._set_fill_func()
Пример #3
0
def make_data(
    rng,
    counts=100.0,
    g1=0.0,
    g2=0.0,
    noise=0.0,
):

    pixel_scale = 0.263

    dims = [32] * 2
    cen = (np.array(dims) - 1) / 2

    dvdrow, dvdcol, dudrow, dudcol = pixel_scale, -0.02, 0.01, pixel_scale
    jacobian = ngmix.Jacobian(
        row=cen[0],
        col=cen[1],
        dvdrow=dvdrow,
        dvdcol=dvdcol,
        dudrow=dudrow,
        dudcol=dudcol,
    )

    pars1 = [
        -3.25 * pixel_scale,
        -3.25 * pixel_scale,
        0.05,
        0.025,
        0.55,
        0.4 * counts,
    ]
    pars2 = [
        3.0 * pixel_scale,
        0.5 * pixel_scale,
        -0.1,
        -0.05,
        0.27,
        0.6 * counts,
    ]

    gm1 = ngmix.GMixModel(pars1, "gauss")
    gm2 = ngmix.GMixModel(pars2, "gauss")

    full_pars = np.hstack([gm1.get_full_pars(), gm2.get_full_pars()])

    gm = ngmix.GMix(pars=full_pars)

    im0 = gm.make_image(dims, jacobian=jacobian)

    im = im0 + rng.normal(size=im0.shape, scale=noise)

    obs = ngmix.Observation(image=im, jacobian=jacobian)

    return obs, gm
Пример #4
0
def _make_output(*, cat, psf_ngauss, res, nband, ngauss_per, time):
    """
    combine the input catalog with the rsult

    we will add
    flags

    coadd_flags
    coadd_psf_pars[6]
    pars[ngauss_per*6]

    band_flags[nband]
    band_psf_pars[nband, 6]
    band_pars[nband, ngauss_per*6]
    """

    resfields = ('flags', 'numiter', 'sky')

    nobj = cat.size
    output = _make_output_struct(
        nobj=nobj,
        nband=nband,
        ngauss_per=ngauss_per,
        psf_ngauss=psf_ngauss,
    )

    output['number'] = cat['number']
    output['time'] = time

    output = _add_extra(output, cat)

    if 'fof_id' in cat.dtype.names:
        output['fof_id'] = cat['fof_id']

    output['fof_size'] = nobj

    output['flags'] = res['flags']

    # if the user never tried the fit this will not be present
    if 'coadd_result' in res:
        cres = res['coadd_result']
        for n in resfields:
            if n in cres:
                output['coadd_%s' % n] = cres[n]

        pgmix = res['coadd_psf_gmix']
        ppars = pgmix.get_full_pars()
        output['coadd_psf_T'] = pgmix.get_T()
        for i in range(nobj):
            output['coadd_psf_pars'][i, :] = ppars

        gmix = res['coadd_gmix']
        if gmix is not None:
            pars = gmix.get_full_pars()
            output['coadd_pars'] = pars.reshape(output['coadd_pars'].shape)

            for i in range(nobj):
                ipars = output['coadd_pars'][i]
                igm = ngmix.GMix(pars=ipars)
                output['coadd_T'][i] = igm.get_T()
                output['coadd_flux'][i] = igm.get_flux()

        if 'band_results' in res:
            for band in range(nband):
                bres = res['band_results'][band]
                for n in resfields:
                    if n in bres:
                        output['band_%s' % n][:, band] = bres[n]

                pgmix = res['band_psf_gmix'][band]
                bppars = pgmix.get_full_pars()
                output['band_psf_T'][:, band] = pgmix.get_T()
                for i in range(nobj):
                    output['band_psf_pars'][i, :, band] = bppars

                bgmix = res['band_gmix'][band]
                if bgmix is not None:
                    bpars = bgmix.get_full_pars()
                    bpars = bpars.reshape(nobj, 6 * ngauss_per)
                    output['band_pars'][:, :, band] = bpars

                    for i in range(nobj):
                        ipars = output['band_pars'][i, :, band]
                        igm = ngmix.GMix(pars=ipars)
                        output['band_flux'][i, band] = igm.get_flux()

    return output
Пример #5
0
def make_data(
    rng,
    counts=100.0,
    g1=0.0,
    g2=0.0,
    noise=0.0,
):

    pixel_scale = 0.263
    psf_fwhm = 0.9

    dims = [32]*2
    cen = (np.array(dims)-1)/2

    dvdrow, dvdcol, dudrow, dudcol = pixel_scale, -0.02, 0.01, pixel_scale
    jacobian = ngmix.Jacobian(
        row=cen[0],
        col=cen[1],
        dvdrow=dvdrow,
        dvdcol=dvdcol,
        dudrow=dudrow,
        dudcol=dudcol,
    )

    T1 = 0.2
    T2 = 0.05

    pars1 = [
        -3.25*pixel_scale, -3.25*pixel_scale, 0.1, 0.05, T1, 0.4*counts,
    ]
    pars2 = [
        3.0*pixel_scale, 0.5*pixel_scale, -0.2, -0.1, T2, 0.6*counts,
    ]

    gm1 = ngmix.GMixModel(pars1, "gauss")
    gm2 = ngmix.GMixModel(pars2, "gauss")

    full_pars = np.hstack([gm1.get_full_pars(), gm2.get_full_pars()])

    gm0 = ngmix.GMix(pars=full_pars)

    Tpsf = ngmix.moments.fwhm_to_T(psf_fwhm)
    psf_pars = [0.0, 0.0, 0.01, -0.005, Tpsf, 1.0]
    psf = ngmix.GMixModel(pars=psf_pars, model="turb")
    psf_im = psf.make_image(dims, jacobian=jacobian)

    gm = gm0.convolve(psf)

    im0 = gm.make_image(dims, jacobian=jacobian)

    im = im0 + rng.normal(size=im0.shape, scale=noise)

    # to fit with psfs, the psf observation must be set and it
    # must have a gaussian mixture set
    psf_obs = ngmix.Observation(
        image=psf_im, jacobian=jacobian, gmix=psf,
    )

    obs = ngmix.Observation(image=im, jacobian=jacobian, psf=psf_obs)

    return obs, gm0