Example #1
0
    def to_complex_field(self):
        """
        Return the ComplexField stored on disk.

        .. note::
            The mesh stored on disk must be stored with ``mode=complex``

        Returns
        -------
        real : pmesh.pm.ComplexField
            an array-like object holding the mesh loaded from disk in Fourier
            space
        """
        if not self.isfourier:
            return NotImplemented
        pmread = self.pm

        if self.comm.rank == 0:
            self.logger.info("reading complex field from %s" % self.path)

        with FileMPI(comm=self.comm, filename=self.path)[self.dataset] as ds:
            complex2 = ComplexField(pmread)
            assert self.comm.allreduce(complex2.size) == ds.size
            start = numpy.sum(self.comm.allgather(complex2.size)[:self.comm.rank], dtype='intp')
            end = start + complex2.size
            complex2.unravel(ds[start:end])

        return complex2