Read data from databroker and save to Atom class which GUI can take. .. note:: Requires the databroker package from NSLS2 Parameters ---------- run_id_uid : int or str ID or UID of a run create_each_det : bool True: load data from all detector channels
(
run_id_uid, *, create_each_det=False, working_directory=None, file_overwrite_existing=False
)
| 1624 | |
| 1625 | |
| 1626 | def render_data_to_gui( |
| 1627 | run_id_uid, *, create_each_det=False, working_directory=None, file_overwrite_existing=False |
| 1628 | ): |
| 1629 | """ |
| 1630 | Read data from databroker and save to Atom class which GUI can take. |
| 1631 | |
| 1632 | .. note:: Requires the databroker package from NSLS2 |
| 1633 | |
| 1634 | Parameters |
| 1635 | ---------- |
| 1636 | run_id_uid : int or str |
| 1637 | ID or UID of a run |
| 1638 | create_each_det : bool |
| 1639 | True: load data from all detector channels |
| 1640 | False: load only the sum of all channels |
| 1641 | working_directory : str |
| 1642 | path to the directory where data files are saved |
| 1643 | file_overwrite_existing : bool |
| 1644 | True: overwrite data file if it exists |
| 1645 | False: create unique file name by adding version number |
| 1646 | """ |
| 1647 | |
| 1648 | run_id, run_uid = fetch_run_info(run_id_uid) # May raise RuntimeError |
| 1649 | |
| 1650 | data_sets = OrderedDict() |
| 1651 | img_dict = OrderedDict() |
| 1652 | |
| 1653 | # Don't create unique file name if the existing file is to be overwritten |
| 1654 | fname_add_version = not file_overwrite_existing |
| 1655 | |
| 1656 | # Create file name here, so that working directory may be attached to the file name |
| 1657 | prefix = "scan2D_" |
| 1658 | fname = f"{prefix}{run_id}.h5" |
| 1659 | if working_directory: |
| 1660 | fname = os.path.join(working_directory, fname) |
| 1661 | |
| 1662 | # It is better to use full run UID to fetch the data. |
| 1663 | data_from_db = fetch_data_from_db( |
| 1664 | run_uid, |
| 1665 | fpath=fname, |
| 1666 | fname_add_version=fname_add_version, |
| 1667 | file_overwrite_existing=file_overwrite_existing, |
| 1668 | create_each_det=create_each_det, |
| 1669 | # Always create data file (processing results |
| 1670 | # are going to be saved in the file) |
| 1671 | output_to_file=True, |
| 1672 | ) |
| 1673 | |
| 1674 | if not len(data_from_db): |
| 1675 | logger.warning(f"No detector data was found in Run #{run_id} ('{run_uid}').") |
| 1676 | return |
| 1677 | else: |
| 1678 | logger.info(f"Data from {len(data_from_db)} detectors were found in Run #{run_id} ('{run_uid}').") |
| 1679 | if len(data_from_db) > 1: |
| 1680 | logger.warning(f"Selecting only the latest run (UID '{run_uid}') with from Run ID #{run_id}.") |
| 1681 | |
| 1682 | # If the experiment contains data from multiple detectors (for example two separate |
| 1683 | # Xpress3 detectors) that need to be treated separately, only the data from the |
no test coverage detected