sasdata.dataloader.readers.cansas_reader_HDF5 module

NXcanSAS data reader for reading HDF5 formatted CanSAS files.

class sasdata.dataloader.readers.cansas_reader_HDF5.Reader

Bases: FileReader

A class for reading in NXcanSAS data files. The current implementation has been tested to load data generated by multiple facilities, all of which are known to produce NXcanSAS standards compliant data. Any number of data sets may be present within the file and any dimensionality of data may be used. Currently 1D and 2D SAS data sets are supported, but should be immediately extensible to SESANS data.

Any number of SASdata groups may be present in a SASentry and the data within each SASdata group can be a single 1D I(Q), multi-framed 1D I(Q), 2D I(Qx, Qy) or multi-framed 2D I(Qx, Qy).

Dependencies:

The NXcanSAS HDF5 reader requires h5py => v2.5.0 or later.

__annotations__ = {}
__doc__ = '\n    A class for reading in NXcanSAS data files. The current implementation has\n    been tested to load data generated by multiple facilities, all of which are\n    known to produce NXcanSAS standards compliant data. Any number of data sets\n    may be present within the file and any dimensionality of data may be used.\n    Currently 1D and 2D SAS data sets are supported, but should be immediately\n    extensible to SESANS data.\n\n    Any number of SASdata groups  may be present in a SASentry and the data\n    within each SASdata group can be a single 1D I(Q), multi-framed 1D I(Q),\n    2D I(Qx, Qy) or multi-framed 2D I(Qx, Qy).\n\n    :Dependencies:\n        The NXcanSAS HDF5 reader requires h5py => v2.5.0 or later.\n    '
__module__ = 'sasdata.dataloader.readers.cansas_reader_HDF5'
_create_unique_key(dictionary: dict, name: str, numb: int | None = 0) str

Create a unique key value for any dictionary to prevent overwriting Recurses until a unique key value is found.

Parameters:
  • dictionary – A dictionary with any number of entries

  • name – The index of the item to be added to dictionary

  • numb – The number to be appended to the name, starts at 0

Returns:

The new name for the dictionary entry

_find_data_attributes(value)

A class to find the indices for Q, the name of the Qdev and Idev, and the name of the mask. :param value: SASdata/NXdata HDF5 Group

_get_unit(value: Dataset) str

Find the unit for a particular value within the h5py dictionary

Parameters:

value – attribute dictionary for a particular value set

Returns:

unit for the value passed to the method

_initialize_new_data_set(value=None)

A private class method to generate a new 1D or 2D data object based on the type of data within the set. Outside methods should call add_data_set() to be sure any existing data is stored properly.

Parameters:

parent_list – List of names of parent elements

_is_2d_not_multi_frame(value, i_base='', q_base='')

A private class to determine if the data set is 1d or 2d.

Parameters:
  • value – Nexus/NXcanSAS data group

  • basename – Approximate name of an entry to search for

Returns:

True if 2D, otherwise false

add_data_set()

Adds the current_dataset to the list of outputs after preforming final processing on the data and then calls a private method to generate a new data set.

add_intermediate()

This method stores any intermediate objects within the final data set after fully reading the set.

Parameters:

parent – The NXclass name for the h5py Group object that just finished being processed

allow_all = True
static as_list_or_array(data: Any) list | ndarray

Return value as a list if not already a list or array. :param iterable: :return:

cansas_version = 2.0
ext = ['.h5', '.H5']
final_data_cleanup()

Does some final cleanup and formatting on self.current_datainfo and all data1D and data2D objects and then combines the data and info into Data1D and Data2D objects

get_file_contents()

This is the general read method that all SasView data_loaders must have.

Parameters:

filename – A path for an HDF5 formatted CanSAS 2D data file.

Returns:

List of Data1D/2D objects and/or a list of errors.

process_1d_data_object(data_set: array, key: str, unit: str)

SASdata processor method for 1d data items :param data_set: data from HDF5 file :param key: canSAS_class attribute :param unit: unit attribute

process_2d_data_object(data_set: array, key: str, unit: str)
process_aperture(data_point: Any, key: str)

SASaperture processor :param data_point: Single point from an HDF5 data file :param key: class name data_point was taken from

process_collimation(data_point: Any, key: str, unit: str)

SAScollimation processor :param data_point: Single point from an HDF5 data file :param key: class name data_point was taken from :param unit: unit attribute from data set

process_detector(data_point: Any, key: str, unit: str)

SASdetector processor :param data_point: Single point from an HDF5 data file :param key: class name data_point was taken from :param unit: unit attribute from data set

process_process(data_point: Any, key: str)

SASprocess processor :param data_point: Single point from an HDF5 data file :param key: class name data_point was taken from

process_sample(data_point: Any, key: str)

SASsample processor :param data_point: Single point from an HDF5 data file :param key: class name data_point was taken from

process_source(data_point: Any, key: str, unit: str)

SASsource processor :param data_point: Single point from an HDF5 data file :param key: class name data_point was taken from :param unit: unit attribute from data set

process_trans_spectrum(data_set: array, key: str)

SAStransmission_spectrum processor :param data_set: data from HDF5 file :param key: canSAS_class attribute

read_children(data: dict, parent_list: list)

A recursive method for stepping through the hierarchical data file.

Parameters:
  • data – h5py Group object of any kind

  • parent – h5py Group parent name

reset_state()

Create the reader object and define initial states for class variables

type = ['NXcanSAS HDF5 Files (*.h5)|*.h5|']
type_name = 'NXcanSAS'
write(filename: str, dataset: Data1D | Data2D)

Export data in NXcanSAS format

Parameters:
  • filename – File path where the data will be saved

  • dataset – DataInfo object that will be converted to NXcanSAS

Returns:

None

sasdata.dataloader.readers.cansas_reader_HDF5.h5attr(node, key, default=None)