BCDA-APS / bluesky_training

Bluesky training, including instrument package
https://bcda-aps.github.io/bluesky_training/
Other
11 stars 0 forks source link

BUG: newSpecFile() does not reset the scan ID #271

Closed prjemian closed 2 weeks ago

prjemian commented 4 months ago

As Zhan Zhang (APS) reported:

newSpecFile('zztestbp', scan_id=1) Is that the right one to use? I don't recall all the details, but I think the scan_id=1 was ignored when calling specwriter.newfile(fname, **kwargs)

prjemian commented 4 months ago

I can reproduce this situation (when scan ID is not tied to a PV):

In [1]: RE.md["scan_id"]
Out[1]: 701

In [2]: newSpecFile("dev_spec_file.dat", scan_id=1)
I Wed-16:46:00 - SPEC file name : 02_21_dev_spec_file_dat.dat
I Wed-16:46:00 - File will be created at end of next bluesky scan.

In [3]: RE.md["scan_id"]
Out[3]: 701

In [4]: RE.md["scan_id"] = 1

In [5]: RE.md["scan_id"]
Out[5]: 1

That's a bug.

prjemian commented 4 months ago

That code needs better unit testing. And for the new case when RE is tied to a PV.

prjemian commented 2 weeks ago

Tests for this already exist: https://github.com/BCDA-APS/bluesky_training/blob/7f2b0592c6fef6c7836b9d405d738f2c05dee2d2/bluesky/tests/test_newSpecFile.py#L57-L61

prjemian commented 2 weeks ago

Checking manually to make sure this test case is covered. The setup:

from bluesky import RunEngine
RE = RunEngine()
from instrument.callbacks.spec_data_file_writer import newSpecFile, specwriter

manual test:

In [3]: RE.md["scan_id"] = 1234

In [4]: newSpecFile('zztestbp', scan_id=1)

In [5]: RE.md["scan_id"]
Out[5]: 1234

Confirmed: :fly:

prjemian commented 2 weeks ago

Actually: newSpecFile('zztestbp', scan_id=1, RE=RE) works. Since this was a bug report from a user, the design should change.