fab.beamtime

 1import os
 2import pandas as pd
 3from typing import Protocol
 4from dataclasses import dataclass
 5import glob
 6import seaborn as sns
 7
 8from .settings import cfg
 9
10import logging
11logger = logging.getLogger(__name__)
12tele_log = logging.getLogger('fab.telemetry')
13
14try:
15    import fabtrack
16except ModuleNotFoundError:
17    fabtrack = None
18
19def autodetect_beamtime():
20    ''' Attemps to autodetect the beamtime number from the current working directory.'''
21    try:
22        return int(os.getcwd().split('/')[7])
23    except IndexError as e:
24        raise ValueError("Could not autodetect beamtime number from current working directory") from e
25
26def beamtime_basepath(beamtime_num):
27    basepath = f"/asap3/*flash*/gpfs/*/*/data/{beamtime_num}"
28    basepath = glob.glob(basepath)[0]
29    
30    return basepath 
31
32class Beamtime:
33    """ Represents a beamtime at the FLASH facility
34
35        Properties:
36            id: The beamtime number
37            basepath: The basepath of the beamtime
38            runs: The fabtrack tracker of the beamtime, if fabtrack is installed
39    """
40
41    def __init__(self, beamtime_num):
42        self.id = beamtime_num
43        try:
44            self.basepath = beamtime_basepath(beamtime_num)
45        except IndexError as e:
46            self.basepath = "/asap3/flash/gpfs/" #placeholder
47
48        self.runs = None
49        if fabtrack is not None:
50            self.runs = fabtrack.RunTracker(beamtime_id=self.id)
51
52    def __repr__(self):
53        return f"Beamtime {self.id} at {self.basepath}"
54
55    def _ipython_display_(self):
56        display(self.runs)
logger = <Logger fab.beamtime (INFO)>
tele_log = <Logger fab.telemetry (INFO)>
def autodetect_beamtime():
20def autodetect_beamtime():
21    ''' Attemps to autodetect the beamtime number from the current working directory.'''
22    try:
23        return int(os.getcwd().split('/')[7])
24    except IndexError as e:
25        raise ValueError("Could not autodetect beamtime number from current working directory") from e

Attemps to autodetect the beamtime number from the current working directory.

def beamtime_basepath(beamtime_num):
27def beamtime_basepath(beamtime_num):
28    basepath = f"/asap3/*flash*/gpfs/*/*/data/{beamtime_num}"
29    basepath = glob.glob(basepath)[0]
30    
31    return basepath 
class Beamtime:
33class Beamtime:
34    """ Represents a beamtime at the FLASH facility
35
36        Properties:
37            id: The beamtime number
38            basepath: The basepath of the beamtime
39            runs: The fabtrack tracker of the beamtime, if fabtrack is installed
40    """
41
42    def __init__(self, beamtime_num):
43        self.id = beamtime_num
44        try:
45            self.basepath = beamtime_basepath(beamtime_num)
46        except IndexError as e:
47            self.basepath = "/asap3/flash/gpfs/" #placeholder
48
49        self.runs = None
50        if fabtrack is not None:
51            self.runs = fabtrack.RunTracker(beamtime_id=self.id)
52
53    def __repr__(self):
54        return f"Beamtime {self.id} at {self.basepath}"
55
56    def _ipython_display_(self):
57        display(self.runs)

Represents a beamtime at the FLASH facility

Properties:

id: The beamtime number basepath: The basepath of the beamtime runs: The fabtrack tracker of the beamtime, if fabtrack is installed

Beamtime(beamtime_num)
42    def __init__(self, beamtime_num):
43        self.id = beamtime_num
44        try:
45            self.basepath = beamtime_basepath(beamtime_num)
46        except IndexError as e:
47            self.basepath = "/asap3/flash/gpfs/" #placeholder
48
49        self.runs = None
50        if fabtrack is not None:
51            self.runs = fabtrack.RunTracker(beamtime_id=self.id)
id
runs