예제 #1
0
파일: elc.py 프로젝트: harrygun/hec
def elltraj_test(p, a):

    #->>
    ln_a = np.linspace(-4.6, 0., 500)
    a = np.exp(ln_a)

    F, ee, pp = 0.5, 0.2, 0.1
    #F, ee, pp=1.686, 0., 0.

    l = shape_to_eigval(F, ee, pp)
    print 'testing lambda:', l

    traj = get_elliptraj_one(p, a, l, freeze=False)
    #print 'traj:', traj
    print 'traj shape:', traj.shape

    shape = eigval_to_shape(traj[:, 0], traj[:, 1], traj[:, 2])
    #print 'shape', shape

    # ->> plot <<- #
    nplt, ncol = 3, 3
    fig, ax = mpl.mysubplots(nplt,
                             ncol_max=ncol,
                             subp_size=5.,
                             gap_size=0.5,
                             return_figure=True)

    for i in range(3):
        #ax[i].plot(a, shape[i])
        ax[i].plot(a, traj[:, i] / a, 'k-')
        #ax[i].plot(a, traj[:,i+3], 'b-')

    pl.show()

    return
예제 #2
0
    #->> final density <<- #
    df=rd.rblock(p.original_density_fname, p.ngrid**3, \
                 dtype='float').reshape(p.ngrid, p.ngrid, p.ngrid)

    # ->> define some other useful variables <<- #
    lw1 = ['k-', 'r-', 'b-', 'g-']

    # ->> get the divergence of the displacement field <<- #

    #->>
    if False:
        print 'disp rk fname:', p.disp_transfunc_fname

        nplt, ncol = 1, 1
        fig,ax=mpl.mysubplots(nplt,ncol_max=ncol,subp_size=5.,\
                           gap_size=0.5,return_figure=True)

        lw1 = ['k-', 'r-', 'b-', 'g-']
        lw2 = ['k--', 'r--', 'b--', 'g--']

        cd_k, cd_p = [], []
        for i in range(3):

            k1, pk1 = psor.cross(disp[i], disp_model[i], boxsize=p.boxsize)
            k2, pk2 = psor.pk(disp_model[i], boxsize=p.boxsize)
            k3, pk3 = psor.pk(disp[i], boxsize=p.boxsize)

            cr = pk1 / np.sqrt(pk3 * pk2)

            cd_k.append(k1)
            cd_p.append(cr)
예제 #3
0
def Testing_portal(p, data, import_data_type='field'):

    if True:
        if import_data_type == 'field':
            # ->>
            print 'boxsize=', p.boxsize
            dmean = np.mean(data)
            delta = data / dmean - 1.
            phi, phi_ij=ptt.Poisson3d(delta, boxsize=p.boxsize, return_hessian=True, \
                                      smooth_R=None, smooth_type=None)
            #phi, phi_ij=ptt.Poisson3d(delta, boxsize=p.boxsize, return_hessian=True, \
            #                          smooth_R=p.smooth_R, smooth_type=p.smooth_type)
            # ->>
            d = dmean * (1 + phi_ij[0, 0] + phi_ij[1, 1] + phi_ij[2, 2])
            print 'd shape:', d.shape, d.min(), d.max()
            print 'd err:', np.max(np.fabs((d - data) / data))

            # ->>
            da = dmean * (1. +
                          ptt.Laplacian(phi, boxsize=p.boxsize, Lap_type=1))
            print 'da shape:', da.shape, da.min(), da.max()
            print 'da err:', np.max(np.fabs((da - data) / data))

            if True:
                nplt = 3
                ncol = 3
                fig, ax = mpl.mysubplots(nplt,
                                         ncol_max=ncol,
                                         subp_size=2.,
                                         gap_size=0.15,
                                         return_figure=True)

                dd1, dd2, dd3 = data[100, :, :], d[100, :, :], da[100, :, :]
                print 'min, max:', dd1.min(), dd1.max(), dd2.min(), dd2.max(
                ), dd3.min(), dd3.max()

                ax[0].imshow(np.flipud(dd1),
                             norm=colors.LogNorm(vmin=dd1.min(),
                                                 vmax=dd1.max()))
                ax[1].imshow(np.flipud(dd2),
                             norm=colors.LogNorm(vmin=dd2.min(),
                                                 vmax=dd2.max()))

                #ax[2].imshow(np.flipud(dd3), norm=colors.LogNorm(vmin=dd3.min(), vmax=dd3.max()) )
                ax[2].imshow(np.flipud(phi[100, :, :]))

            pl.show()

    if True:

        if import_data_type == 'field':
            dmean = np.mean(data)
            delta = data / dmean - 1.

            #phi=ptt.Poisson3d(delta, boxsize=p.boxsize, smooth_R=None, smooth_type=None)
            #phi=ptt.Poisson3d(delta, boxsize=p.boxsize, smooth_R=p.smooth_R, smooth_type=p.smooth_type)

            phi, phi_i = ptt.Poisson3d(delta,
                                       boxsize=p.boxsize,
                                       smooth_R=None,
                                       smooth_type=None,
                                       return_gradient=True)
            print 'phi, phi_i shape:', phi.shape, phi_i.shape

            dl = p.boxsize / float(p.nbin)
            gd = np.array(np.gradient(phi)) / dl
            print gd.shape

            print 'gradient error 1:', [
                np.max(np.fabs((phi[i] - gd[i]) / phi[i])) for i in range(3)
            ]
            print 'gradient error 2:', [
                np.max(np.fabs((phi[i] - gd[i]) / gd[i])) for i in range(3)
            ]

            if True:
                # ->> testing <<- #

                if True:
                    nplt = 10
                    ncol = 4
                    fig, ax = mpl.mysubplots(nplt,
                                             ncol_max=ncol,
                                             subp_size=2.,
                                             gap_size=0.15,
                                             return_figure=True)
                    ax[0].imshow(np.flipud(phi[100, :, :]))

                    for i in range(3):
                        dd_ = np.fabs(gd[i, 100, :, :])
                        ax[i + 1].imshow(np.flipud(dd_),
                                         norm=colors.LogNorm(vmin=dd_.min(),
                                                             vmax=dd_.max()))

                    _dd = gd[0, 100, :, :]**2. + gd[1, 100, :, :]**2. + gd[
                        2, 100, :, :]**2.
                    ax[4].imshow(np.flipud(_dd),
                                 norm=colors.LogNorm(vmin=_dd.min(),
                                                     vmax=_dd.max()))

                    dd1 = data[100, :, :]
                    ax[5].imshow(np.flipud(dd1),
                                 norm=colors.LogNorm(vmin=dd1.min(),
                                                     vmax=dd1.max()))

                    #->> comparison <<- #

                    for i in range(3):
                        dd_ = np.fabs(phi_i[i, 100, :, :])
                        ax[i + 6].imshow(np.flipud(dd_),
                                         norm=colors.LogNorm(vmin=dd_.min(),
                                                             vmax=dd_.max()))

                    _dd = phi_i[0, 100, :, :]**2. + phi_i[
                        1, 100, :, :]**2. + phi_i[2, 100, :, :]**2.
                    ax[9].imshow(np.flipud(_dd),
                                 norm=colors.LogNorm(vmin=_dd.min(),
                                                     vmax=_dd.max()))

                    pl.show()

    if False:
        # ->> testing <<- #
        pl.plot(y[:, :, 100] * p.nbin, z[:, :, 100] * p.nbin, 'k.', alpha=0.3)

        #_dd=np.swapaxes(den[100,:,:], 0, 1)
        #_dd=den[100,:,:]
        _dd = np.flipud(den[100, :, :])
        #pl.pcolormesh(_dd, norm=colors.LogNorm(vmin=_dd.min(), vmax=_dd.max()), alpha=0.7)
        pl.imshow(_dd,
                  norm=colors.LogNorm(vmin=_dd.min(), vmax=_dd.max()),
                  alpha=0.8)

        pl.show()

    quit()
    return
예제 #4
0
파일: test_cic.py 프로젝트: harrygun/ZA_rec
    pos = (s['pos']/1.e3).reshape(nbin**3,3)
    print 'pos.shape', pos.shape, 'pos boundary:', pos[...,0].min(), pos[...,0].max()


    ''' ->> run CIC density estimation <<- '''
    npart=pos.shape[0]
    d=mcic.cic(npart, nbin, pos, pmass=1.e5)
    print d.shape, d.min(), d.max()


    if True:
        #fig=pl.figure(figsize=(20, 20))
        #ax=fig.add_subplot(111)

        nplt, ncol=2, 2
        fig,ax=mpl.mysubplots(nplt,ncol_max=ncol,subp_size=8.,gap_size=0.15,return_figure=True)


	data=d[...,100] +1e-3
        ax[0].imshow(np.flipud(data), norm=colors.LogNorm(vmin=data.min(),vmax=data.max()) )


        # ->> read field <<- #
        dd=rd.rgrid(root+fname_field, ngrid=nbin, dtype='float', comp=1)
	data_1 = dd[...,100]
        ax[1].imshow(np.flipud(data_1), norm=colors.LogNorm(vmin=data_1.min(),vmax=data_1.max()) )


        fig.savefig('dtest_cmp.png')

예제 #5
0
def lag_rec_ZA(p,
               mpart,
               dmap,
               smooth_R=None,
               smooth_type=None,
               rect_type='ZA_displaced'):
    # -> reconstruction of initial state, return density map <<- #

    # ->> get displacement field <<- #
    phi, si = get_ZA_displacement(p,
                                  dmap,
                                  smooth_R=smooth_R,
                                  smooth_type=smooth_type)
    print '->> phi, si shape:', phi.shape, si.shape

    npt = p.nbin**3.

    if rect_type == 'ZA_displaced_shifted':
        #->> get particles <<- #
        #pos_disp=np.copy(np.swapaxes(displaced_ZA(p,si,mpart).reshape(3, p.nbin**3),0,1))
        #pos_shift=np.copy(np.swapaxes(shifted_ZA(p, si).reshape(3, p.nbin**3),0,1))

        pos_disp = displaced_ZA(p, si, mpart)
        pos_shift = shifted_ZA(p, si)

        print 'particle shape:', mpart.shape, pos_disp.shape, pos_shift.shape

        #->> converting density map <<- #
        d_disp = mcic.cic(p.cp,
                          npt,
                          p.nbin,
                          p.boxsize,
                          pos_disp,
                          pmass=p.particle_mass)
        d_shift = mcic.cic(p.cp,
                           npt,
                           p.nbin,
                           p.boxsize,
                           pos_shift,
                           pmass=p.particle_mass)

        _test_draw_ = True
        if _test_draw_:
            shift_ = pos_shift.reshape(p.nbin, p.nbin, p.nbin, 3)

            nplt, ncol = 4, 2
            fig, ax = mpl.mysubplots(nplt,
                                     ncol_max=ncol,
                                     subp_size=7.,
                                     gap_size=1,
                                     return_figure=True)

            ax[0].imshow(d_shift[:, :, 100])
            ax[1].plot(shift_[:, :, 100, 1], shift_[:, :, 100, 2], 'k.')

            ax[2].imshow(1. + d_disp[:, :, 100], norm=colors.LogNorm())
            ax[3].imshow(1. + dmap[:, :, 100], norm=colors.LogNorm())

            pl.show()

        d_rec = d_disp - d_shift

        return d_rec, d_disp, d_shift, pos_disp, pos_shift

    elif rect_type == 'ZA_displaced':

        return

    else:
        raise Exception
        """