nlUpgradeFile

Included in QATK.Core

nlUpgradeFile(source_path, destination_path=None, remove_backup=False)

Reads all objects from a source HDF5 file and re-saves them into a destination HDF5 file, which implicitly upgrades the serialization format of all outdated objects in the file. If the destination file is not specified, or the same as the source file, the source file will be moved to a backup file.

Parameters:
  • source_path (str) – The source path to resave from.

  • destination_path (str | None) – The destination path to resave into.

  • remove_backup (bool) – If True, the backup file created during the resaving process will be removed after the operation is complete.

Returns:

Path to the backup file that was created before overwriting the source file.

Return type:

str | None

Usage examples

To re-save and upgrade a hdf5 file my_file.hdf5 to the same location, while keeping a backup copy my_file.backup.hdf5, do

path_to_packup_file = nlUpgradeFile('my_file.hdf5')

To save the new file in a different location /my/directory/my_new_file.hdf5, do

nlUpgradeFile('my_file.hdf5', destination_path='/my/directory/my_new_file.hdf5')

To do an in-place upgrade without keeping a backup copy, do

nlUpgradeFile('my_file.hdf5', remove_backup=True)