Assume data is obained from databroker, and save the data to hdf file. This function can handle stopped/aborted scans. .. note:: This function should become part of suitcase Parameters ---------- fpath: str path to save hdf file data : pandas.core.frame.DataFra
(
fpath,
data,
datashape,
det_list=("xspress3_ch1", "xspress3_ch2", "xspress3_ch3"),
pos_list=("zpssx[um]", "zpssy[um]"),
scaler_list=("sclr1_ch3", "sclr1_ch4"),
fname_add_version=False,
fly_type=None,
subscan_dims=None,
base_val=None,
)
| 3421 | |
| 3422 | |
| 3423 | def write_db_to_hdf( |
| 3424 | fpath, |
| 3425 | data, |
| 3426 | datashape, |
| 3427 | det_list=("xspress3_ch1", "xspress3_ch2", "xspress3_ch3"), |
| 3428 | pos_list=("zpssx[um]", "zpssy[um]"), |
| 3429 | scaler_list=("sclr1_ch3", "sclr1_ch4"), |
| 3430 | fname_add_version=False, |
| 3431 | fly_type=None, |
| 3432 | subscan_dims=None, |
| 3433 | base_val=None, |
| 3434 | ): |
| 3435 | """ |
| 3436 | Assume data is obained from databroker, and save the data to hdf file. |
| 3437 | This function can handle stopped/aborted scans. |
| 3438 | |
| 3439 | .. note:: This function should become part of suitcase |
| 3440 | |
| 3441 | Parameters |
| 3442 | ---------- |
| 3443 | fpath: str |
| 3444 | path to save hdf file |
| 3445 | data : pandas.core.frame.DataFrame |
| 3446 | data from data broker |
| 3447 | datashape : tuple or list |
| 3448 | shape of two D image |
| 3449 | det_list : list, tuple, optional |
| 3450 | list of detector channels |
| 3451 | pos_list : list, tuple, optional |
| 3452 | list of pos pv |
| 3453 | scaler_list : list, tuple, optional |
| 3454 | list of scaler pv |
| 3455 | fname_add_version : bool |
| 3456 | True: if file already exists, then file version is added to the file name |
| 3457 | so that it becomes unique in the current directory. The version is |
| 3458 | added to <fname>.h5 in the form <fname>_(1).h5, <fname>_(2).h5, etc. |
| 3459 | False: the exception is thrown if the file exists. |
| 3460 | """ |
| 3461 | interpath = "xrfmap" |
| 3462 | |
| 3463 | if os.path.exists(fpath): |
| 3464 | if fname_add_version: |
| 3465 | fpath = _get_fpath_not_existing(fpath) |
| 3466 | else: |
| 3467 | raise IOError(f"'write_db_to_hdf': File '{fpath}' already exists.") |
| 3468 | |
| 3469 | with h5py.File(fpath, "a") as f: |
| 3470 | sum_data = None |
| 3471 | new_v_shape = datashape[0] # to be updated if scan is not completed |
| 3472 | spectrum_len = 4096 # standard |
| 3473 | |
| 3474 | for n, c_name in enumerate(det_list): |
| 3475 | if c_name in data: |
| 3476 | detname = "det" + str(n + 1) |
| 3477 | dataGrp = f.create_group(interpath + "/" + detname) |
| 3478 | |
| 3479 | logger.info("read data from %s" % c_name) |
| 3480 | channel_data = data[c_name] |
no test coverage detected