コード例 #1
0
ファイル: test_solver_utils.py プロジェクト: mpcsdspa/pysph
class TestOutputHdf5(TestOutputNumpy):
    @skipUnless(has_h5py(), "h5py module is not present")
    def setUp(self):
        super(TestOutputHdf5, self).setUp()

    def _get_filename(self, fname):
        return join(self.root, fname) + '.hdf5'
コード例 #2
0
ファイル: output.py プロジェクト: xubonan/pysph
def dump(filename,
         particles,
         solver_data,
         detailed_output=False,
         only_real=True,
         mpi_comm=None,
         compress=False):
    """
    Dump the given particles and solver data to the given filename.

    Parameters
    ----------

    filename: str
        Filename to dump to.

    particles: sequence(ParticleArray)
        Sequence of particle arrays to dump.

    solver_data: dict
        Additional information to dump about solver state.

    detailed_output: bool
        Specifies if all arrays should be dumped.

    only_real: bool
        Only dump the real particles.

    mpi_comm: mpi4pi.MPI.Intracomm
        An MPI communicator to use for parallel commmunications.

    compress: bool
        Specify if the  file is to be compressed or not.

    If `mpi_comm` is not passed or is set to None the local particles alone
    are dumped, otherwise only rank 0 dumps the output.

    """
    if filename.endswith(output_formats):
        fname = os.path.splitext(filename)[0]
    else:
        fname = filename
        filename = fname + '.hdf5'
    if filename.endswith('hdf5') and has_h5py():
        file_format = 'hdf5'
        output = HDFOutput(detailed_output, only_real, mpi_comm, compress)
    else:
        output = NumpyOutput(detailed_output, only_real, mpi_comm, compress)
        file_format = 'npz'
    filename = fname + '.' + file_format
    output.dump(filename, particles, solver_data)
コード例 #3
0
ファイル: output.py プロジェクト: xubonan/pysph
    def _load(self, fname):
        if has_h5py():
            import h5py
        else:
            msg = "Install python-h5py to load this file"
            raise ImportError(msg)

        ret = {}
        with h5py.File(fname, 'r') as f:
            solver_grp = f['solver_data']
            particles_grp = f['particles']
            ret["solver_data"] = self._get_solver_data(solver_grp)
            ret["arrays"] = self._get_particles(particles_grp)
        return ret