1818 r"(?P<time>" + r"\d{5}" + ")" ,
1919 r"(?P<plan>\w*)" ,
2020 r"(?P<name>[\s\w\d.-]*)" , # not great...
21- r"(?P<uid>\w{8})"
21+ r"(?P<uid>\w{8})" ,
2222]
2323
2424__folder_seed__ = " " .join (__folder_parts__ )
2929class BlueskyFolder :
3030 """container class for Bluesky acquisitions"""
3131
32- def __init__ (self , folder_path :pathlib .Path ):
32+ def __init__ (self , folder_path : pathlib .Path ):
3333 self .path = folder_path
3434 self .info = parse_folder_name (folder_path .name )
3535 if self .info is None :
@@ -46,7 +46,7 @@ def primary(self):
4646 # TODO: open procedure based on plan
4747 self ._primary = wt5_open (self .path / "primary.wt5" )
4848 return self ._primary
49-
49+
5050 @property
5151 def baseline (self ):
5252 raise NotImplementedError
@@ -59,12 +59,12 @@ def baseline_tree(self):
5959 def primary_tree (self ):
6060 return (self .path / "primary tree.txt" ).read_text ()
6161
62- @property
62+ @property
6363 def start (self ) -> dict :
6464 path = self .path / "bluesky_docs" / "start.json"
6565 return json .load (path .open ())
6666
67- @property
67+ @property
6868 def stop (self ) -> dict :
6969 path = self .path / "bluesky_docs" / "stop.json"
7070 return json .load (path .open ())
@@ -91,20 +91,19 @@ class FolderInfo(NamedTuple):
9191 def folder (self ):
9292 return __fseed__ .format (
9393 date = self .date .strftime ("%Y-%m-%d" ),
94- time = int (datetime . timedelta (
95- minutes = self . time . minute ,
96- seconds = self .time .second ,
97- hours = self . time . hour
98- ). total_seconds ()) ,
94+ time = int (
95+ datetime . timedelta (
96+ minutes = self . time . minute , seconds = self .time .second , hours = self . time . hour
97+ ). total_seconds ()
98+ ),
9999 plan = self .plan ,
100100 name = self .name ,
101- uid = self .uid
101+ uid = self .uid ,
102102 )
103103
104104
105- def match_identifier (dir :pathlib .Path , ** bluesky_identifier ) -> list [BlueskyFolder ]:
106- """walk a directory to find datasets that meet the criteria
107- """
105+ def match_identifier (dir : pathlib .Path , ** bluesky_identifier ) -> list [BlueskyFolder ]:
106+ """walk a directory to find datasets that meet the criteria"""
108107 for key in bluesky_identifier .keys ():
109108 assert key in FolderInfo ._fields
110109
@@ -113,9 +112,8 @@ def match_identifier(dir:pathlib.Path, **bluesky_identifier) -> list[BlueskyFold
113112 for info in map (
114113 lambda item : parse_folder_name (item .name ),
115114 filter (
116- lambda item : item .is_dir () and re .fullmatch (__folder_seed__ , item .name ),
117- dir .iterdir ()
118- )
115+ lambda item : item .is_dir () and re .fullmatch (__folder_seed__ , item .name ), dir .iterdir ()
116+ ),
119117 ):
120118 idict = info ._asdict ()
121119 if all (idict [k ] == bluesky_identifier [k ] for k in bluesky_identifier .keys ()):
@@ -124,18 +122,19 @@ def match_identifier(dir:pathlib.Path, **bluesky_identifier) -> list[BlueskyFold
124122 return keep
125123
126124
127- def parse_folder_name (folder :str ) -> FolderInfo | None :
125+ def parse_folder_name (folder : str ) -> FolderInfo | None :
128126 # TODO: match procedure is leaky (mainly due to name and plan), could be cleaned up
129- if ((uid_match := re .fullmatch (r"(?P<uid>\w{8})" , folder .split ()[- 1 ])) is not None ) \
130- and ((datetime_match := __datetime_seed__ .match (folder )) is not None ):
127+ if ((uid_match := re .fullmatch (r"(?P<uid>\w{8})" , folder .split ()[- 1 ])) is not None ) and (
128+ (datetime_match := __datetime_seed__ .match (folder )) is not None
129+ ):
131130 matchdict = uid_match .groupdict () | datetime_match .groupdict ()
132- matchdict ["name" ] = " " .join (folder .split ()[3 :- 1 ])
131+ matchdict ["name" ] = " " .join (folder .split ()[3 :- 1 ])
133132 return _to_object (matchdict )
134133 else :
135134 return None
136135
137136
138- def _to_object (mdict :dict ) -> FolderInfo :
137+ def _to_object (mdict : dict ) -> FolderInfo :
139138 date = datetime .date .fromisoformat (mdict .pop ("date" ))
140139 ts = int (mdict .pop ("time" )) # total seconds since date start
141140 time = datetime .time (hour = ts // 3600 , minute = (ts % 3600 ) // 60 , second = ts % 60 )
0 commit comments