diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index eb09fb6..9e146f7 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -421,6 +421,24 @@ def heuristic_extract_smalldata_path(): small_data_path = f"/das/work/p{str(p_number)[0:2]}/p{p_number}/smalldata/" return small_data_path +def stand_table(pgroup=None): + """Reads the stand table. If no pgroup given it tries to guess it from the current path. + For other pgrous, add pgroup= as optional parameter.""" + if pgroup: + # P group might be added as 'p12345' or just 12345, so both cases should be taken care of + if 'p' in str(pgroup): + # Cut the string and look at the next five letters after the last /p + p_index = pgroup.rfind("/p") + p_number = pgroup[p_index + 2 : p_index + 7] + base_path = f"/sf/cristallina/data/p{p_number}/raw/" + else: + base_path = f"/sf/cristallina/data/p{pgroup}/raw/" + else: + base_path = heuristic_extract_base_path() + + stand_file = base_path.replace('raw','res') + 'output.h5' + stand_table = pd.read_hdf(stand_file) + return stand_table ######################## Little useful functions ######################## diff --git a/tests/test_utils.py b/tests/test_utils.py index d138888..db6c616 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,7 @@ import os import numpy as np import cristallina.utils as utils -from cristallina.utils import ROI, print_run_info, heuristic_extract_pgroup, gauss, find_nearest, xray_transmission +from cristallina.utils import ROI, print_run_info, heuristic_extract_pgroup, gauss, find_nearest, xray_transmission,stand_table def test_print(capsys): @@ -47,4 +47,7 @@ def test_xray_transmission(): T = xray_transmission(9000, 100e-6, material = 'Si') assert T == 0.342385039732607 - +def test_stand_table(): + # Load run from a p-group where we have saved the stand table. First run recorded was number 27, so check that. + table = stand_table(21563) + assert table['run'][0] == 27 \ No newline at end of file