File writing callbacks

Human readable files

A callback (HumanReadableFileCallback) exists to write all documents to a separate human-readable file which contains the specified fields.

This callback will add units and honour precision for each field as well as add some metadata ie. the uid of each scan as well as the RB number, which is injected using the RB Number injection preprocessor

Example

An example of using this could be:

def some_plan() -> Generator[Msg, None, None]:
    ... # Set up prefix, reducers, controllers etc. here
    block = block_rw_rbv(float, "mot")

    dae = SimpleDae(
        prefix=prefix,
        controller=controller,
        waiter=waiter,
        reducer=reducer,
    )

    yield from ensure_connected(block, dae, force_reconnect=True)

    @subs_decorator(
        [
            HumanReadableFileCallback(
                [
                    block.name,
                    dae.good_frames.name,
                ],
            ),
            ... # Other callbacks ie. live table/plot here - you can use multiple!
        ]
    )
    def _inner() -> Generator[Msg, None, None]:
        num_points = 3
        yield from bps.mv(dae.number_of_periods, num_points)
        yield from bp.scan([dae], block, 0, 10, num=num_points)

    yield from _inner()

RE = get_run_engine()
RE(some_plan())

This will put the block and dae.good_frames data collected over the run into a .txt file, named after the uid of the scan, in C:\instrument\var\logs\bluesky\output_files\.

Optional parameters, not shown above, include:

  • output_dir parameter is optional, if not input the file will by default be placed in \\isis\inst$\ndx<inst>\user\bluesky_scans\<rbnumber>.

  • postfix an optional suffix to append to the end of the file name, to disambiguate scans. Default is no suffix.

The data is prepended on the first event with the names and units of each logged field, and then subsequently the data for each scan separated by a newline. All of this is separated by commas, though the metadata is not.

The file also contains metadata such as the bluesky version, plan type, and rb number.

Fit outputs

See Saving fit results to file (LiveFitLogger)

Plot PNGs

See Saving plots to PNG files

Bluesky Event documents

Note

This callback is added automatically and is not intended to be user-facing - it is primarily for developer diagnostics.

The DocLoggingCallback is a callback that the BlueSky RunEngine subscribes to unconditionally in RunEngine import level. After receiving each document, if they share the same start document (in the same run) then it will write them to the same file. These logs are stored under C:/instrument/var/logs/bluesky/raw_documents and are handled by the log rotation.

Each document is stored in a JSON format so can be both machine and human readable. It is in the format {"type": name, "document": document} whereby name is the type of the document, e.g start, stop, event, descriptor and the document is the document from BlueSky in JSON format. As these files are produced per BlueSky run, these will be useful for debugging.