def testWpgToOPMDConverter(self):
        """ Test the conversion of wpg output to openPMD conform file."""

        # Get sample file.
        h5_input = generateTestFilePath('prop_out_0000001.h5')

        # Convert.
        convertToOPMD(h5_input)

        # New file name.
        opmd_h5_file = h5_input.replace(".h5", ".opmd.h5")

        # Make sure we clean up after test.
        self.__files_to_remove.append(opmd_h5_file)

        # Check new file was generated.
        self.assertTrue( os.path.isfile( opmd_h5_file ) )

        # Validate the new file.
        g = opmd_validator.open_file(opmd_h5_file)

        # Setup result array.
        result_array = numpy.array([0, 0])
        result_array += opmd_validator.check_root_attr(g, False)

        # Go through all the iterations, checking both the particles.
        # and the meshes
        extensions = {'ED-PIC': False, 'HYDRO1D': False}
        result_array += opmd_validator.check_iterations(g,False,extensions)

        # Assert that no errors nor warnings were issued.
        self.assertEqual( result_array[0], 0 )
        self.assertEqual( result_array[1], 0 )
Ejemplo n.º 2
0
    def testWpgToOPMDConverter(self):
        """ Test the conversion of wpg output to openPMD conform file."""

        # Get sample file.
        h5_input = generateTestFilePath('prop_out_0000001.h5')

        # Convert.
        convertToOPMD(h5_input)

        # New file name.
        opmd_h5_file = h5_input.replace(".h5", ".opmd.h5")

        # Make sure we clean up after test.
        self.__files_to_remove.append(opmd_h5_file)

        # Check new file was generated.
        self.assertTrue(os.path.isfile(opmd_h5_file))

        # Validate the new file.
        g = opmd_validator.open_file(opmd_h5_file)

        # Setup result array.
        result_array = numpy.array([0, 0])
        result_array += opmd_validator.check_root_attr(g, False)

        # Go through all the iterations, checking both the particles and the meshes
        extensions = {'ED-PIC': False, 'HYDRO1D': False}
        result_array += opmd_validator.check_iterations(g, False, extensions)

        # Assert that no errors nor warnings were issued.
        self.assertEqual(result_array[0], 0)
        self.assertEqual(result_array[1], 0)
Ejemplo n.º 3
0
    def _run(self):
        """ This method drives the WPG backengine.

        :return: 0 if WPG returns successfully, 1 if not.

        """

        # import should be here, not in header as it calls MPI_Init when imported. We want MPI to be
        # initialized at this stage only.
        from mpi4py import MPI

        # MPI info
        comm = MPI.COMM_WORLD
        thisProcess = comm.rank
        numProcesses = comm.size

        # Check if input path is a directory.
        if os.path.isdir(self.input_path):
            input_files = [ os.path.join( self.input_path, input_file ) for \
                            input_file in os.listdir( self.input_path ) ]
            input_files.sort(
            )  # Assuming the filenames have some kind of ordering scheme.
        else:
            if thisProcess == 0:  # other MPI processes (if any) have nothing to do
                propagate_s2e.propagate(self.input_path, self.output_path,
                                        self.parameters.beamline.get_beamline)
            return 0

        # If we have more than one input file, we should also have more than one output file, i.e.
        # output_path should be a directory.
        if os.path.isfile(self.output_path):
            raise IOError(
                "The given output path is a file but a directory is needed. Cowardly refusing to overwrite."
            )

        # Check if output dir exists, create if not.
        if not os.path.isdir(self.output_path):
            os.mkdir(self.output_path)

        # Loop over all input files and generate one run per source file.
        for i, input_file in enumerate(input_files):
            ### TODO: Transmit number of cpus.
            # process file on a corresponding process (round-robin)
            if i % numProcesses == thisProcess:
                output_file = os.path.join(self.output_path,
                                           'prop_out_%07d.h5' % (i))
                propagate_s2e.propagate(input_file, output_file,
                                        self.parameters.beamline.get_beamline)

                # Rewrite in openpmd conformant way.
                wpg_to_opmd.convertToOPMD(output_file)

        return 0
Ejemplo n.º 4
0
    def testWpgToOPMDConverter(self):
        """ Test the conversion of wpg output to openPMD conform file."""

        # Get sample file.
        h5_input = generateTestFilePath('prop_out/prop_out_0000011.h5')

        # Convert.
        convertToOPMD(h5_input)

        # New file name.
        opmd_h5_file = h5_input.replace(".h5", ".opmd.h5")
        self.__files_to_remove.append(opmd_h5_file)

        # Check new file was generated.
        self.assertTrue(os.path.isfile(opmd_h5_file))

        # Read the file back in through the API.
        series = opmd.Series(opmd_h5_file, opmd.Access_Type.read_only)

        self.assertIsInstance(series, opmd.Series)

        # Check attributes are present.
        try:
            series.author
            series.date
            series.software
            series.software_version
            series.get_attribute("radius of curvature in x")
            series.get_attribute("z coordinate")
            series.get_attribute("Rx_Unit_Dimension")
            series.get_attribute("Rx_UnitSI")
            series.get_attribute("radius of curvature in y")
            series.get_attribute("Ry_Unit_Dimension")
            series.get_attribute("Ry_UnitSI")
            series.get_attribute("Delta radius of curvature in x")
            series.get_attribute("DRx_Unit_Dimension")
            series.get_attribute("DRx_UnitSI")
            series.get_attribute("Delta radius of curvature in y")
            series.get_attribute("DRy_Unit_Dimension")
            series.get_attribute("DRy_UnitSI")
            series.get_attribute("photon energy")
            series.get_attribute("photon energy unit dimension")
            series.get_attribute("photon energy UnitSI")

        except RuntimeError:
            self.fail("Error while querying attribute.")
        except:
            raise

        # Check the beamline serialization
        self.assertIsInstance(series.get_attribute("beamline"), str)
    def saveH5(self):
        """
        Method to save the object to a file.

        :param output_path:   The file where to save the wavefront data.
        :type output_path:    str, default 'prop_out.h5'

        """

        # Write data to hdf file using wpg interface function.
        self.__wavefront.store_hdf5(self.output_path)

        # Write openPMD file if requested.
        if self.parameters.use_opmd:
            wpg_to_opmd.convertToOPMD( self.output_path )
Ejemplo n.º 6
0
    def testLoadOPMDWavefront(self):
        """ Test if loading a wavefront from openpmd-hdf into a WPG structure works."""

        # Get sample file.
        h5_input = generateTestFilePath('prop_out/prop_out_0000011.h5')

        # Convert.
        convertToOPMD(h5_input)

        # New file name.
        opmd_h5_file = h5_input.replace(".h5", ".opmd.h5")
        self.__files_to_remove.append(opmd_h5_file)

        # Reconstruct the series.
        series = opmd.Series(opmd_h5_file, opmd.Access_Type.read_only)
        wavefront = wpg.Wavefront()
    def backengine(self):
        """ This method drives the WPG backengine.

        :return: 0 if WPG returns successfully, 1 if not.

        """

        # MPI info
        comm = MPI.COMM_WORLD
        thisProcess = comm.rank
        numProcesses = comm.size

        # Check if input path is a directory.
        if os.path.isdir(self.input_path):
            input_files = [ os.path.join( self.input_path, input_file ) for \
                            input_file in os.listdir( self.input_path ) ]
            input_files.sort() # Assuming the filenames have some kind of ordering scheme.
        else:
            if thisProcess == 0: # other MPI processes (if any) have nothing to do
                propagateSE.propagate(self.input_path, self.output_path)
            return 0

        # If we have more than one input file, we should also have more than one output file, i.e.
        # output_path should be a directory.
        if os.path.isfile(self.output_path):
            raise IOError("The given output path is a file but a directory is needed. Cowardly refusing to overwrite.")

        # Check if output dir exists, create if not.
        if not os.path.isdir(self.output_path):
            os.mkdir(self.output_path)

        # Loop over all input files and generate one run per source file.
        for i,input_file in enumerate(input_files):
            ### TODO: Transmit number of cpus.
            # process file on a corresponding process (round-robin)
            if i % numProcesses == thisProcess:
                output_file = os.path.join( self.output_path, 'prop_out_%07d.h5' % (i) )
                propagateSE.propagate(input_file, output_file)

                # Rewrite in openpmd conformant way.
                wpg_to_opmd.convertToOPMD( output_file )

        return 0