Skip to content

Commit 641a4ac

Browse files
refactor: Change default filename structure order to {instrument}-{scan_id}-{device_name} (#1268)
Co-authored-by: Abigail Emery <[email protected]>
1 parent 693f67a commit 641a4ac

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/blueapi/utils/path_provider.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from event_model import RunStart, RunStop
44
from ophyd_async.core import PathInfo, PathProvider
55

6-
DEFAULT_TEMPLATE = "{device_name}-{instrument}-{scan_id}"
6+
DEFAULT_TEMPLATE = "{instrument}-{scan_id}-{device_name}"
77

88

99
class StartDocumentPathProvider(PathProvider):
1010
"""A PathProvider that sources from metadata in a RunStart document.
1111
1212
This uses metadata from a RunStart document to determine file names and data session
13-
directories. The file naming defaults to "{device_name}-{instrument}-{scan_id}", so
13+
directories. The file naming defaults to "{instrument}-{scan_id}-{device_name}}", so
1414
the file name is incremented by scan number. A template can be included in the
1515
StartDocument to allow for custom naming conventions.
1616
@@ -36,9 +36,9 @@ def run_stop(self, name: str, stop_document: RunStop) -> None:
3636
def __call__(self, device_name: str | None = None) -> PathInfo:
3737
"""Returns the directory path and filename for a given data_session.
3838
39-
The default template for file naming is: "{device_name}-{instrument}-{scan_id}"
39+
The default template for file naming is: "{instrument}-{scan_id}-{device_name}"
4040
however, this can be changed by providing a template in the start document. For
41-
example: "template": "custom-{device_name}--{scan_id}".
41+
example: "template": "custom-{device_name}-{scan_id}".
4242
4343
If you do not provide a data_session_directory it will default to "/tmp".
4444
"""

tests/system_tests/test_blueapi_system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def on_event(event: AnyEvent) -> None:
477477

478478
stream_resource = resource.get_nowait()
479479
assert stream_resource["run_start"] == start_doc["uid"]
480-
assert stream_resource["uri"] == f"file://localhost/tmp/det-adsim-{scan_id}.h5"
480+
assert stream_resource["uri"] == f"file://localhost/tmp/adsim-{scan_id}-det.h5"
481481

482482
tiled_url = f"http://localhost:8407/api/v1/metadata/{start_doc['uid']}"
483483
response = requests.get(tiled_url)

tests/unit_tests/utils/test_path_provider.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_start_document_path_provider_with_default_template_returns_correct_path
4646

4747
assert path == PathInfo(
4848
directory_path=PosixPath("/p01/ab123"),
49-
filename="det-p01-22",
49+
filename="p01-22-det",
5050
create_dir_depth=0,
5151
)
5252

@@ -61,7 +61,7 @@ def start_doc_custom_template() -> dict:
6161
"instrument": "p01",
6262
"data_session_directory": "/p01/ab123",
6363
"scan_id": 22,
64-
"data_file_path_template": "{device_name}-{instrument}-{scan_id}-custom",
64+
"data_file_path_template": "{instrument}-{scan_id}-{device_name}-custom",
6565
"plan_type": "generator",
6666
"plan_name": "count",
6767
"detectors": ["det"],
@@ -88,7 +88,7 @@ def test_start_document_path_provider_with_custom_template_returns_correct_path_
8888

8989
assert path == PathInfo(
9090
directory_path=PosixPath("/p01/ab123"),
91-
filename="det-p01-22-custom",
91+
filename="p01-22-det-custom",
9292
create_dir_depth=0,
9393
)
9494

@@ -199,7 +199,7 @@ def test_start_document_path_provider_sets_data_session_directory_default_to_tmp
199199
path = pp("det")
200200

201201
assert path == PathInfo(
202-
directory_path=PosixPath("/tmp"), filename="det-p01-22", create_dir_depth=0
202+
directory_path=PosixPath("/tmp"), filename="p01-22-det", create_dir_depth=0
203203
)
204204

205205

@@ -321,7 +321,7 @@ def test_start_document_path_provider_nested_runs_use_info_from_last_start_doc(
321321
pp.run_start(name="start", start_document=start_doc_1)
322322
start_doc_1_path_info = PathInfo(
323323
directory_path=PosixPath("/p01/ab123"),
324-
filename="det-p01-50",
324+
filename="p01-50-det",
325325
create_dir_depth=0,
326326
)
327327

@@ -332,7 +332,7 @@ def test_start_document_path_provider_nested_runs_use_info_from_last_start_doc(
332332
pp.run_start(name="start", start_document=start_doc_2)
333333
start_doc_2_path_info = PathInfo(
334334
directory_path=PosixPath("/p02/ab123"),
335-
filename="det-p02-51",
335+
filename="p02-51-det",
336336
create_dir_depth=0,
337337
)
338338

0 commit comments

Comments
 (0)