Esempio n. 1
0
    def write_attributes(
            self, h5file_group: Union[Group, File]) -> None:  # type: ignore
        """
        Attribute data consists of

         1. `__init__` parameters that are of type str or numerical. These are directly written into `h5py.Group.attrs`
         2. lists are stored under `<h5py.Group>/__lists`
         3. dicts are stored under `<h5py.Group>/__dicts`
        """
        h5file_group.attrs.create(
            "__type", self.io_data.typename
        )  # Record the type of the current class instance
        attributes = self.io_data.attributes
        for attr_name, attr_value in attributes.items():
            if isinstance(
                    attr_value, dict
            ):  # h5py does not serialize dicts automatically, so have to do it manually
                group_name = "__dicts/" + attr_name
                h5file_group.create_group(group_name)
                io.write(attr_value,
                         self.filename,
                         file_handle=h5file_group[group_name])
            elif isinstance(attr_value, (list, tuple)):
                group_name = "__lists/" + attr_name
                h5file_group.create_group(group_name)
                io.write(attr_value,
                         self.filename,
                         file_handle=h5file_group[group_name])
            else:
                h5file_group.attrs[attr_name] = attr_value
Esempio n. 2
0
    def filewrite(self, filename):
        """Convenience method bound to the class. Simply accesses the `write` function.

        Parameters
        ----------
        filename: str
        """
        io.write(self, filename)
Esempio n. 3
0
    def filewrite(self, filename):
        """Convenience method bound to the class. Simply accesses the `write` function.

        Parameters
        ----------
        filename: str
        """
        import scqubits.io_utils.fileio as io
        io.write(self, filename)
Esempio n. 4
0
 def write_objects(
         self, h5file_group: Union[Group, File]) -> None:  # type: ignore
     """
     Writes data representing a Python object other than ndarray, list and dict, contained in `self.iodata` to the
     provided `h5py.Group`  und `<h5py.Group>/__objects`.
     """
     h5file_group = h5file_group.create_group("__objects")
     for obj_name in self.io_data.objects.keys():
         new_h5group = h5file_group.create_group(obj_name)
         io.write(self.io_data.objects[obj_name],
                  self.filename,
                  file_handle=new_h5group)
Esempio n. 5
0
    def write_objects(self, h5file_group):
        """
        Writes data representing a Python object other than ndarray, list and dict, contained in `self.iodata` to the
        provided `h5py.Group`  und `<h5py.Group>/__objects`.

        Parameters
        ----------
        h5file_group: h5py.Group
        """
        h5file_group = h5file_group.create_group("__objects")
        for obj_name in self.io_data.objects.keys():
            new_h5group = h5file_group.create_group(obj_name)
            io.write(self.io_data.objects[obj_name], self.filename, file_handle=new_h5group)