MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / read_data_from_hdf5

Function read_data_from_hdf5

pyxrf/model/fileio.py:1045–1117  ·  view source on GitHub ↗

Read raw fluorescence data from HDF5 file. The data is returned in the same form as the data saved by ``save_data_to_hdf5``. Parameters ---------- fpath : str Full path to the HDF5 file representation : str Representation for the raw dataset. Available optio

(fpath, *, representation="numpy_array", load_each_channel=True)

Source from the content-addressed store, hash-verified

1043
1044
1045def read_data_from_hdf5(fpath, *, representation="numpy_array", load_each_channel=True):
1046 """
1047 Read raw fluorescence data from HDF5 file. The data is returned in the same form as
1048 the data saved by ``save_data_to_hdf5``.
1049
1050 Parameters
1051 ----------
1052 fpath : str
1053 Full path to the HDF5 file
1054 representation : str
1055 Representation for the raw dataset. Available options: 'numpy_array' and 'dask_array'.
1056 load_each_channel : boolean
1057 Indicates if data for individual detector channels need to be loaded.
1058
1059 Returns
1060 -------
1061 data : dict
1062 Dictionary that contains loaded data. The structure of the dictionary is similar
1063 to the structure of ``data`` parameter of the function ``save_data_to_hdf5``.
1064 metadata : dict
1065 Metadata dictionary.
1066 """
1067 fpath = os.path.expanduser(fpath)
1068 fpath = os.path.abspath(fpath)
1069
1070 supported_representations = ("numpy_array", "dask_array")
1071 if representation not in supported_representations:
1072 raise ValueError(
1073 f"Value '{representation}' of the parameter 'representation' is not supported. "
1074 f"Supported values: {supported_representations}"
1075 )
1076
1077 working_directory, file_name = os.path.split(fpath)
1078 img_dict, data_sets, scan_metadata = load_data_from_hdf5(
1079 working_directory, file_name, load_each_channel=load_each_channel
1080 )
1081
1082 # Load RAW data
1083 data = {}
1084 for k in data_sets:
1085 if re.search("_sum$", k):
1086 data["det_sum"] = data_sets[k]
1087 elif re.search(r"_det\d+$", k):
1088 m = re.search(r"\d+$", k)
1089 n = m.group(0)
1090 data[f"det{n}"] = data_sets[k]
1091 # Represent datasets as dask or numpy arrays
1092 for k in data:
1093 data_dask, _ = prepare_xrf_map(data[k].raw_data)
1094 if representation == "numpy_array":
1095 data[k] = data_dask[:, :, :].compute()
1096 else:
1097 data[k] = data_dask
1098
1099 for key, dataset in img_dict.items():
1100 if key == "positions":
1101 pos_names = list(dataset.keys())
1102 pos_data = np.zeros(shape=[len(pos_names), *dataset[pos_names[0]].shape])

Callers 3

test_save_data_to_hdf5_2Function · 0.85
test_save_data_to_hdf5_3Function · 0.85
test_save_data_to_hdf5_4Function · 0.85

Calls 4

load_data_from_hdf5Function · 0.85
prepare_xrf_mapFunction · 0.85
itemsMethod · 0.80
keysMethod · 0.80

Tested by 3

test_save_data_to_hdf5_2Function · 0.68
test_save_data_to_hdf5_3Function · 0.68
test_save_data_to_hdf5_4Function · 0.68