Esempio n. 1
0
    def generate_kweight(self, regen = False):
        r"""Pregenerate the k weights array.

        Parameters
        ==========
        regen : boolean, optional
            If True, force regeneration of the weights, to be used if
            parameters have been changed,
        """

        # Perform some sanity checks
        self._check_input()

        # If already generated return array now.
        if(self._kweightgen == True and not regen):
            return
        
        spacing = self._w / self._n
        
        kvec = fftutil.rfftfreqn(self._n, spacing / (2*math.pi))
        
        self._kweight = self.powerspectrum(kvec)**0.5 * self._n.prod() / (2.0 * self._w.prod() )**0.5

        if not np.isfinite(self._kweight.flat[0]):
            self._kweight.flat[0] = 0.0

        self._kweightgen = True
Esempio n. 2
0
    def generate_kweight(self, regen=False):
        r"""Pregenerate the k weights array.

        Parameters
        ==========
        regen : boolean, optional
            If True, force regeneration of the weights, to be used if
            parameters have been changed,
        """

        # Perform some sanity checks
        self._check_input()

        # If already generated return array now.
        if (self._kweightgen == True and not regen):
            return

        spacing = self._w / self._n

        kvec = fftutil.rfftfreqn(self._n, spacing / (2 * math.pi))

        self._kweight = self.powerspectrum(kvec)**0.5 * self._n.prod() / (
            2.0 * self._w.prod())**0.5

        if not np.isfinite(self._kweight.flat[0]):
            self._kweight.flat[0] = 0.0

        self._kweightgen = True
Esempio n. 3
0
    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.
        rfv = RandomField(npix=n, wsize=d)
        rfv.powerspectrum = psv

        vf0 = rfv.getfield()

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

        df = vf0

        # Construct the line of sight velocity field.
        # TODO: is the s=rfv._n the correct thing here?
        vf = np.fft.irfftn(mu2arr * np.fft.rfftn(vf0), s=rfv._n)

        # return (df, vf, rfv, kvec)
        return (df, vf)  # , rfv)
Esempio n. 4
0
    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.
        rfv = RandomField(npix=n, wsize=d)
        rfv.powerspectrum = psv

        vf0 = rfv.getfield()

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

        df = vf0

        # Construct the line of sight velocity field.
        # TODO: is the s=rfv._n the correct thing here?
        vf = np.fft.irfftn(mu2arr * np.fft.rfftn(vf0), s=rfv._n)

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