code: def export_phase_error_hdf5(h5path, identifier, index, phase, mphase,
                              model, n0, r0, spi_params):
      
      with h5py.File(h5path, mode="a") as h5:
          if identifier in h5:
              grp = h5[identifier]
          else:
              grp = h5.create_group(identifier)
          ds = grp.create_dataset("phase_error_{:05d}".format(index),
                                  data=mphase-phase)
          ds.attrs["index initial"] = n0
          ds.attrs["radius initial"] = r0
          ds.attrs["sim model"] = model
          ds.attrs["sim index"] = spi_params["sphere_index"]
          ds.attrs["sim radius"] = spi_params["radius"]
          ds.attrs["sim center"] = spi_params["center"]
          ds.attrs["fit iteration"] = index
          ds.attrs["fit iteration"] = index
docs: Export the phase error to an hdf5 file
  
      Parameters
      ----------
      h5path: str or pathlib.Path
          path to hdf5 output file
      identifier: str
          unique identifier of the input phase
          (e.g. `qpimage.QPImage["identifier"]`)
      index: int
          iteration index
      phase: 2d real-valued np.ndarray
          phase image
      mphase: 2d real-valued np.ndarray
          reference phase image
      model: str
          sphere model name
      n0: float
          initial object index
      r0: float
          initial object radius [m]
      spi_params: dict
          parameter dictionary of :func:`SpherePhaseInterpolator`