コード例 #1
0
ファイル: gaussianfield.py プロジェクト: hirax-array/cora
    def getfield(self):
        r"""Generate a new realisation of the 3d field.

        Returns
        -------
        field : ndarray
            A realisation of the power spectrum. Shape is self._n.
        """

        self.generate_kweight()
        s = self._kweight.shape

        # Fill array
        f = np.random.standard_normal(s) + 1.0J * np.random.standard_normal(s)
        f *= self._kweight

        # TODO: is self._n argument here correct?
        r = fftutil.irfftn(f)
        return r
コード例 #2
0
ファイル: gaussianfield.py プロジェクト: radiocosmology/cora
    def getfield(self):
        r"""Generate a new realisation of the 3d field.

        Returns
        -------
        field : ndarray
            A realisation of the power spectrum. Shape is self._n.
        """

        self.generate_kweight()
        s = self._kweight.shape
        
        # Fill array
        f = np.random.standard_normal(s) + 1.0J * np.random.standard_normal(s)
        f *= self._kweight
        
        # TODO: is self._n argument here correct?
        r = fftutil.irfftn(f)
        return r
コード例 #3
0
ファイル: corr.py プロジェクト: tanderson23/cora
    def _realisation_dv(self, d, n):
        """Generate the density and line of sight velocity fields in a
        3d cube.
        """

        if not self._vv_only:
            raise Exception(
                "Doesn't work for independent fields, I need to think a bit more first."
            )

        def psv(karray):
            """Assume k0 is line of sight"""
            k = (karray ** 2).sum(axis=3) ** 0.5
            return self.ps_vv(k) * self.velocity_damping(karray[..., 0])

        # Generate an underlying random field realisation of the
        # matter distribution.

        print("Gen field.")
        rfv = gaussianfield.RandomField(npix=n, wsize=d)
        rfv.powerspectrum = psv

        vf0 = rfv.getfield()

        # Construct an array of \mu^2 for each Fourier mode.
        print("Construct kvec")
        spacing = rfv._w / rfv._n
        kvec = fftutil.rfftfreqn(rfv._n, spacing / (2 * math.pi))
        print("Construct mu2")
        mu2arr = kvec[..., 0] ** 2 / (kvec ** 2).sum(axis=3)
        mu2arr.flat[0] = 0.0
        del kvec

        df = vf0

        print("FFT vel")
        # Construct the line of sight velocity field.
        # TODO: is the s=rfv._n the correct thing here?
        vf = fftutil.irfftn(mu2arr * fftutil.rfftn(vf0))

        # return (df, vf, rfv, kvec)
        return (df, vf)  # , rfv)
コード例 #4
0
ファイル: corr.py プロジェクト: HaMetBacon/cora
    def _realisation_dv(self, d, n):
        """Generate the density and line of sight velocity fields in a
        3d cube.
        """

        if not self._vv_only:
            raise Exception("Doesn't work for independent fields, I need to think a bit more first.")

        def psv(karray):
            """Assume k0 is line of sight"""
            k = (karray**2).sum(axis=3)**0.5
            return self.ps_vv(k) * self.velocity_damping(karray[..., 0])

        # Generate an underlying random field realisation of the
        # matter distribution.

        print "Gen field."
        rfv = gaussianfield.RandomField(npix = n, wsize = d)
        rfv.powerspectrum = psv

        vf0 = rfv.getfield()

        # Construct an array of \mu^2 for each Fourier mode.
        print "Construct kvec"
        spacing = rfv._w / rfv._n
        kvec = fftutil.rfftfreqn(rfv._n, spacing / (2*math.pi))
        print "Construct mu2"
        mu2arr = kvec[...,0]**2 / (kvec**2).sum(axis=3)
        mu2arr.flat[0] = 0.0
        del kvec

        df = vf0

        print "FFT vel"
        # Construct the line of sight velocity field.
        # TODO: is the s=rfv._n the correct thing here?
        vf = fftutil.irfftn(mu2arr * fftutil.rfftn(vf0))

        #return (df, vf, rfv, kvec)
        return (df, vf) #, rfv)