8.6.1. pymodaq_data.h5modules package

pymodaq_data.h5modules.is_file_swmr_active(filepath)[source]

Check if an HDF5 file is currently being written with SWMR mode.

Parameters:

filepath (str or Path) – Path to the HDF5 file

Returns:

True if the file has swmr_active=True attribute, False otherwise

Return type:

bool

pymodaq_data.h5modules.open_h5_file_for_reading(filepath, swmr='auto', locking=None)[source]

Open an HDF5 file for reading, automatically handling SWMR mode.

This utility function handles the complexity of opening HDF5 files that may or may not be currently being written with SWMR mode.

Parameters:
  • filepath (str or Path) – Path to the HDF5 file

  • swmr (bool or 'auto', optional) –

    • ‘auto’ (default): Try to detect if SWMR is needed

    • True: Force SWMR reader mode

    • False: Open normally without SWMR

  • locking (bool or None, optional) – File locking mode. None uses h5py default. Set to False on Windows if you get locking errors.

Returns:

(h5py.File, is_swmr_active) - The file handle and whether SWMR is active

Return type:

tuple

Examples

>>> # Open a file being written by PyMoDAQ scan
>>> f, is_swmr = open_h5_file_for_reading("scan_data.h5")
>>> if is_swmr:
...     ds = f['path/to/data']
...     ds.id.refresh()  # Call refresh to see latest data
>>> f.close()