diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index 03dbfc8..4d7b098 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -106,3 +106,35 @@ class ROI: def __repr__(self): return f"ROI(bottom={self.bottom}, top={self.top}, left={self.left}, right={self.right})" + +######################## Setting up paths ######################## + +def heuristic_extract_pgroup(): + """ The function tries to guess the current p-group from the directory name.""" + cwd = os.getcwd() + if "/p" in cwd: + # Cut the string and look at the next five letters after /p + p_number = cwd.partition("/p")[2][:5] + + if not p_number.isdigit(): + raise KeyError("Automatic p-group extraction from the current working directory didn't work.") + else: + raise KeyError("Automatic p-group extraction from the current working directory didn't work.") + return p_number + +def heuristic_extract_base_path(): + """ The function tries to guess the full path where the raw data is saved.""" + p_number = heuristic_extract_pgroup() + base_path = f"/sf/cristallina/data/p{p_number}/raw/" + return base_path + +def heuristic_extract_smalldata_path(): + """ The function tries to guess the full path where the small data is saved.""" + p_number = heuristic_extract_pgroup() + small_data_path = f"/das/work/units/cristallina/p{p_number}/smalldata/" + return small_data_path + + + + + diff --git a/tests/test_utils.py b/tests/test_utils.py index 0d5f020..af6d24b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,7 @@ import pytest +import os -from cristallina.utils import ROI, print_run_info +from cristallina.utils import ROI, print_run_info, heuristic_extract_pgroup __author__ = "Alexander Steppke" @@ -19,3 +20,8 @@ def test_ROI(): assert r.width == 1 assert r.height == 2 + + +def test_extract_pgroup(): + os.chdir("/sf/cristallina/data/p19739") + assert heuristic_extract_pgroup() == '19739'