Skip to content

Commit

Permalink
(DiamondLightSource/hyperion#1474) Add cli tool to save pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
rtuck99 committed Jul 23, 2024
1 parent 061e59b commit 8b400c8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dev = [

[project.scripts]
dodal = "dodal.__main__:main"
save-panda = "dodal.devices.util.save_panda"

[project.urls]
GitHub = "https://github.com/DiamondLightSource/dodal"
Expand Down
54 changes: 54 additions & 0 deletions src/dodal/devices/util/save_panda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import sys
from argparse import ArgumentParser
from typing import cast

from bluesky import RunEngine
from ophyd_async.core import Device, save_device
from ophyd_async.panda import phase_sorter

from dodal.beamlines import module_name_for_beamline
from dodal.utils import make_all_devices


def _save_panda_to_file(RE: RunEngine, panda: Device, path: str):
def save_to_file():
yield from save_device(panda, path, sorter=phase_sorter)

RE(save_to_file())


def _main():
parser = ArgumentParser(description="Save an ophyd_async device to yaml")
parser.add_argument(
"--beamline", help="beamline to save from e.g. i03. Defaults to BEAMLINE"
)
parser.add_argument("device_name", help="name of the device e.g. panda")
parser.add_argument("output_file", help="output filename")
args = parser.parse_args()
beamline = args.beamline
device_name = args.device_name
output_file = args.output_file

print(f"Saving to {output_file} from {device_name} on {beamline}")

if beamline:
os.environ["BEAMLINE"] = beamline

RE = RunEngine()

print("Creating devices...")
module_name = module_name_for_beamline(beamline)
devices, exceptions = make_all_devices(
f"dodal.beamlines.{module_name}", include_skipped=False
)
panda = devices[device_name]

print("Saving to file...")
_save_panda_to_file(RE, cast(Device, panda), output_file)
print("Done.")
return 0


if __name__ == "__main__":
sys.exit(_main())

0 comments on commit 8b400c8

Please sign in to comment.