示例#1
0
    def _add_lattice(self, lattice, cuba_keys):
        """Add lattice to the file.

        Parameters
        ----------
        lattice : Lattice
            lattice to be added
        cuba_keys : dict
            Dictionary of CUBAs with their related CUBA keys that
            are added to the H5CUDS container.

        Returns
        ----------
        H5Lattice
            The lattice newly added to the file.

        """
        name = lattice.name
        lattice_root = self._root.lattice

        group = tables.Group(lattice_root, name=name, new=True)
        h5_lattice = H5Lattice.create_new(group, lattice.primitive_cell,
                                          lattice.size, lattice.origin)
        h5_lattice.data = lattice.data

        if cuba_keys is not None:
            for item in lattice.iter(item_type=CUBA.NODE):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.NODE]
                })
                h5_lattice.update([item])
        else:
            h5_lattice.update(lattice.iter(item_type=CUBA.NODE))
示例#2
0
    def _add_mesh(self, mesh, cuba_keys):
        """Add a mesh to the file.

        Parameters
        ----------
        mesh_container : ABCMesh, optional
            mesh to be added. If none is give,
            then an empty mesh is added.
        cuba_keys : dict
            Dictionary of CUBAs with their related CUBA keys that
            are added to the H5CUDS container.

        Returns
        ----------
        H5Mesh
            The mesh newly added to the file.

        """
        name = mesh.name
        mesh_root = self._root.mesh

        group = tables.Group(mesh_root, name=name, new=True)
        h5_mesh = H5Mesh(group, self._handle)
        h5_mesh.data = mesh.data

        if cuba_keys is not None:
            for item in mesh.iter(item_type=CUBA.POINT):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.POINT]
                })
                h5_mesh.add([item])

            for item in mesh.iter(item_type=CUBA.EDGE):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.EDGE]
                })
                h5_mesh.add([item])

            for item in mesh.iter(item_type=CUBA.FACE):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.FACE]
                })
                h5_mesh.add([item])

            for item in mesh.iter(item_type=CUBA.CELL):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.CELL]
                })
                h5_mesh.add([item])
        else:
            h5_mesh.add(mesh.iter())
示例#3
0
def load_radiation_loss(
        elements: Union[int, List[int]]) -> Tuple[list, list, np.ndarray]:
    if isinstance(elements, int):
        elements = [elements]
    with tables.open_file(NIST_STAR_HDF5_PATH) as h5file:
        electron_group = tables.Group(h5file.root, "electrons")
        table = h5file.get_node(electron_group, "radiation_loss")
        coord = np.asarray(elements) - 1
        data = table.read_coordinates(coord)
        list_NC = []
        list_BD = []
        group_NC = tables.Group(electron_group, "NC")
        group_BD = tables.Group(electron_group, "BD")
        for element in elements:
            name = get_z_name(element)
            array_NC = h5file.get_node(group_NC, name).read()
            array_BD = h5file.get_node(group_BD, name).read()
            list_NC.append(array_NC)
            list_BD.append(array_BD)
    return list_NC, list_BD, data
示例#4
0
    def __init__(self, material: AlphaMaterials):
        """

        """
        with tables.open_file(NIST_STAR_HDF5_PATH) as h5file:
            group = tables.Group(h5file.root, "helium_ions")
            data = h5file.get_node(group, material.name).read()
            energy = h5file.get_node(group, "energy").read()
            self.default_energy = energy
            self.splines = {}
            for name in data.dtype.names:
                self.splines[name] = make_log_log_spline(energy, data[name])
示例#5
0
 def load(path, particle="proton"):
     with tables.open_file(path) as h5file:
         group = tables.Group(h5file.root, particle)
         energy_node = h5file.get_node(group, "energy")
         energy = energy_node.read()
         theta_node = h5file.get_node(group, "theta")
         theta = theta_node.read()
         shift_node = h5file.get_node(group, "shift")
         shift = shift_node.read()
         return DataMeshLoader(
             h5file.get_node(group, "mean").read(),
             h5file.get_node(group, "variance").read(), energy, theta,
             shift, NormilizerContainer(h5file, group))
示例#6
0
    def _add_particles(self, particles, cuba_keys):
        """Add particle container to the file.

        Parameters
        ----------
        particles : ABCParticles
            Particle container to be added.
        cuba_keys : dict
            Dictionary of CUBAs with their related CUBA keys that
            are added to the H5CUDS container.

        Returns
        -------
        particles : H5Particles
            A newly created container proxying the data in the HDF5 file.

        """
        name = particles.name
        particles_root = self._root.particle

        group = tables.Group(particles_root, name=name, new=True)
        h5_particles = H5Particles(group)
        h5_particles.data = particles.data

        if cuba_keys is not None:
            for item in particles.iter(item_type=CUBA.PARTICLE):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.PARTICLE]
                })
                h5_particles.add([item])

            for item in particles.iter(item_type=CUBA.BOND):
                item.data = DataContainer({
                    key: item.data[key]
                    for key in item.data if key in cuba_keys[CUBA.BOND]
                })
                h5_particles.add([item])
        else:
            h5_particles.add(particles.iter())
示例#7
0
 def load(path, particle="proton"):
     with tables.open_file(path) as h5file:
         group = tables.Group(h5file.root, particle)
         return NormilizerContainer(h5file, group)