Exemplo n.º 1
0
    def run(self):
        """
        Run the algorithm, which computes and returns the power spectrum
        """
        from nbodykit import measurestats

        # only need one mu bin if 1d case is requested
        if self.mode == "1d": self.Nmu = 1

        # measure
        y3d, stats1, stats2 = measurestats.compute_3d_power(self.fields, self.pm, comm=self.comm)

        # get the number of objects (in a safe manner)
        N1 = stats1.get('Ntot', -1)
        N2 = stats2.get('Ntot', -1)

        # binning in k out to the minimum nyquist frequency 
        # (accounting for possibly anisotropic box)
        dk = 2*numpy.pi/y3d.BoxSize.min() if self.dk is None else self.dk
        kedges = numpy.arange(self.kmin, numpy.pi*y3d.Nmesh.min()/y3d.BoxSize.max() + dk/2, dk)

        # project on to the desired basis
        muedges = numpy.linspace(0, 1, self.Nmu+1, endpoint=True)
        edges = [kedges, muedges]
        result, pole_result = measurestats.project_to_basis(self.comm, y3d.x, y3d, edges, 
                                                            poles=self.poles, 
                                                            los=self.los,
                                                            hermitian_symmetric=True)

        # compute the metadata to return
        Lx, Ly, Lz = y3d.BoxSize
        meta = {'Lx':Lx, 'Ly':Ly, 'Lz':Lz, 'volume':Lx*Ly*Lz, 'N1':N1, 'N2':N2}

        # return all the necessary results
        return edges, result, pole_result, meta
Exemplo n.º 2
0
    def run(self):
        """
        Run the algorithm, which computes and returns the power spectrum
        """
        from nbodykit import measurestats
        if self.comm.rank == 0: self.logger.info('importing done')

        # explicity store an open stream
        # this prevents the cache from being destroyed while the
        # algorithm instance is active
        if self.keep_cache:
            self._datacache = self.catalog.data.keep_cache()
            self._rancache = self.catalog.randoms.keep_cache()

        # measure
        kws = {
            'factor_hexadecapole': self.factor_hexadecapole,
            'paintbrush': self.paintbrush
        }
        pm, poles, meta = measurestats.compute_bianchi_poles(
            self.comm, self.max_ell, self.catalog, self.Nmesh, **kws)
        k3d = pm.k

        # binning in k out to the minimum nyquist frequency
        # (accounting for possibly anisotropic box)
        dk = 2 * numpy.pi / pm.BoxSize.min() if self.dk is None else self.dk
        kedges = numpy.arange(
            self.kmin,
            numpy.pi * pm.Nmesh.min() / pm.BoxSize.max() + dk / 2, dk)

        # project on to 1d k basis
        muedges = numpy.linspace(0, 1, 2, endpoint=True)
        edges = [kedges, muedges]
        poles_final = []
        for p in poles:

            # result is (k, mu, power, modes)
            result, _ = measurestats.project_to_basis(pm.comm,
                                                      k3d,
                                                      p,
                                                      edges,
                                                      hermitian_symmetric=True)
            poles_final.append(numpy.squeeze(result[2]))

        # return (k, poles, modes)
        poles_final = numpy.vstack(poles_final)
        k = numpy.squeeze(result[0])
        modes = numpy.squeeze(result[-1])
        result = k, poles_final, modes

        # compute the metadata to return
        Lx, Ly, Lz = pm.BoxSize
        meta.update({'Lx': Lx, 'Ly': Ly, 'Lz': Lz, 'volume': Lx * Ly * Lz})

        # return all the necessary results
        return kedges, result, meta
Exemplo n.º 3
0
    def run(self):
        """
        Run the algorithm, which computes and returns the power spectrum
        """
        from nbodykit import measurestats

        if self.comm.rank == 0:
            self.logger.info("importing done")

        # explicity store an open stream
        # this prevents the cache from being destroyed while the
        # algorithm instance is active
        if self.keep_cache:
            self._datacache = self.catalog.data.keep_cache()
            self._rancache = self.catalog.randoms.keep_cache()

        # measure
        kws = {"factor_hexadecapole": self.factor_hexadecapole, "paintbrush": self.paintbrush}
        pm, poles, meta = measurestats.compute_bianchi_poles(self.comm, self.max_ell, self.catalog, self.Nmesh, **kws)
        k3d = pm.k

        # binning in k out to the minimum nyquist frequency
        # (accounting for possibly anisotropic box)
        dk = 2 * numpy.pi / pm.BoxSize.min() if self.dk is None else self.dk
        kedges = numpy.arange(self.kmin, numpy.pi * pm.Nmesh.min() / pm.BoxSize.max() + dk / 2, dk)

        # project on to 1d k basis
        muedges = numpy.linspace(0, 1, 2, endpoint=True)
        edges = [kedges, muedges]
        poles_final = []
        for p in poles:

            # result is (k, mu, power, modes)
            result, _ = measurestats.project_to_basis(pm.comm, k3d, p, edges, hermitian_symmetric=True)
            poles_final.append(numpy.squeeze(result[2]))

        # return (k, poles, modes)
        poles_final = numpy.vstack(poles_final)
        k = numpy.squeeze(result[0])
        modes = numpy.squeeze(result[-1])
        result = k, poles_final, modes

        # compute the metadata to return
        Lx, Ly, Lz = pm.BoxSize
        meta.update({"Lx": Lx, "Ly": Ly, "Lz": Lz, "volume": Lx * Ly * Lz})

        # return all the necessary results
        return kedges, result, meta
Exemplo n.º 4
0
    def run(self):
        """
        Run the algorithm, which computes and returns the correlation function
        """
        from nbodykit import measurestats

        if self.comm.rank == 0: self.logger.info('importing done')

        # only need one mu bin if 1d case is requested
        if self.mode == "1d": self.Nmu = 1

        # measure
        y3d, stats1, stats2 = measurestats.compute_3d_corr(self.fields, self.pm, comm=self.comm)

        # get the number of objects (in a safe manner)
        N1 = stats1.get('Ntot', -1)
        N2 = stats2.get('Ntot', -1)

        # make the bin edges
        dr = y3d.BoxSize[0] / y3d.Nmesh[0]
        redges = numpy.arange(0, y3d.BoxSize[0] + dr * 0.5, dr)

        # project on to the desired basis
        muedges = numpy.linspace(0, 1, self.Nmu+1, endpoint=True)
        edges = [redges, muedges]
        result, pole_result = measurestats.project_to_basis(self.comm, y3d.x, y3d, edges,
                                                            poles=self.poles,
                                                            los=self.los,
                                                            hermitian_symmetric=False)

        # compute the metadata to return
        Lx, Ly, Lz = y3d.BoxSize
        meta = {'Lx':Lx, 'Ly':Ly, 'Lz':Lz, 'volume':Lx*Ly*Lz, 'N1':N1, 'N2':N2}

        # return all the necessary results
        return edges, result, pole_result, meta