domain_to_hdf#

domain_to_hdf(domain, name_of_file=None, path_to_save=None, key='df', mode='w', save_summary=True, return_dataframe=False)#

Export a domain object as a HDF5 (.h5) file. All object properties will be saved as columns in a datafrma that wil be stored in the HDF5 file under the group key. These columns include labels and collections associated with the object. Optionally, the function can return the pandas dataframe that was saved to the HDF5 file. If the domain contains shape objects, the dataframe will include the vertices of the shapes instead of the shape centroids. There will be an additional column ‘hole_id’ to identify vertices that belong to internal holes of shapes.

Parameters:
domainmuspan.domain

The domain object to be exported as csv.

name_of_filestr or None, optional

The name of the saved HDF5 file. If None, the domain’s name will be used. Default is None.

path_to_savestr or None, optional

The path to the folder where the file will be saved. If None, the current directory will be used. Default is None.

keystr, optional

The identifier for the group in the HDF5 file. Default is ‘df’.

modestr, optional

The file mode for saving the HDF5 file. The options are ‘w’ for writing to a new file or ‘a’ for appending to an existing .h5 file with the same filename. Default is ‘w’ (write).

save_summarybool, optional

If True, a summary message will be printed after saving the file. Default is True.

return_dataframebool, optional

If True, the pandas.dataframe will be returned. Default is False.

Returns:
pandas.DataFrame

The dataframe that was saved to the HDF5 file. Only returned if return_df is True.

Raises:
ValueError

If domain is not of type muspan.domain. If path_to_save is not a string or None. If name_of_file is not a string or None.

Examples

import muspan as ms

# load an example domain
example_domain = ms.datasets.load_example_domain('Xenium-Healthy-Colon')

# save the domain locally to the current working directory with a specified file name
path_to_save = '.'
name_of_file = 'saved_example_domain.h5'

# save the domain as a h5 file under the group 'df' with write mode
ms.io.domain_to_hdf(example_domain, name_of_file=name_of_file, path_to_save=path_to_save,key='df',mode='w')