setting up xtreme plugins
This commit is contained in:
177
.gitignore
vendored
Normal file
177
.gitignore
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
**/*_venv
|
||||
**/.idea
|
||||
*.log
|
||||
**/__pycache__
|
||||
**/.DS_Store
|
||||
**/out
|
||||
**/.vscode
|
||||
**/.pytest_cache
|
||||
**/*.egg*
|
||||
|
||||
# file writer data
|
||||
**.h5
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/**/_build/
|
||||
docs/**/autodoc/
|
||||
docs/**/_autosummary/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
**.prof
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
93
README.md
93
README.md
@@ -1,92 +1,3 @@
|
||||
# X-Treme Bec
|
||||
# X-Treme BEC
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.psi.ch/bec/xtreme-bec.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.psi.ch/bec/xtreme-bec/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
X-Treme specific plugins and configs for BEC
|
||||
1
bec_plugins/__init__.py
Normal file
1
bec_plugins/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .bec_client import *
|
||||
1
bec_plugins/bec_client/__init__.py
Normal file
1
bec_plugins/bec_client/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .plugins import *
|
||||
0
bec_plugins/bec_client/hli/__init__.py
Normal file
0
bec_plugins/bec_client/hli/__init__.py
Normal file
245
bec_plugins/bec_client/hli/spec_hli.py
Normal file
245
bec_plugins/bec_client/hli/spec_hli.py
Normal file
@@ -0,0 +1,245 @@
|
||||
from bec_client.scan_manager import ScanReport
|
||||
from bec_utils.devicemanager import Device
|
||||
|
||||
# pylint:disable=undefined-variable
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
def dscan(
|
||||
motor1: Device, m1_from: float, m1_to: float, steps: int, exp_time: float, **kwargs
|
||||
) -> ScanReport:
|
||||
"""Relative line scan with one device.
|
||||
|
||||
Args:
|
||||
motor1 (Device): Device that should be scanned.
|
||||
m1_from (float): Start position relative to the current position.
|
||||
m1_to (float): End position relative to the current position.
|
||||
steps (int): Number of steps.
|
||||
exp_time (float): Exposure time.
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> dscan(dev.motor1, -5, 5, 10, 0.1)
|
||||
"""
|
||||
return scans.line_scan(
|
||||
motor1, m1_from, m1_to, steps=steps, exp_time=exp_time, relative=True, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def d2scan(
|
||||
motor1: Device,
|
||||
m1_from: float,
|
||||
m1_to: float,
|
||||
motor2: Device,
|
||||
m2_from: float,
|
||||
m2_to: float,
|
||||
steps: int,
|
||||
exp_time: float,
|
||||
**kwargs
|
||||
) -> ScanReport:
|
||||
"""Relative line scan with two devices.
|
||||
|
||||
Args:
|
||||
motor1 (Device): First device that should be scanned.
|
||||
m1_from (float): Start position of the first device relative to its current position.
|
||||
m1_to (float): End position of the first device relative to its current position.
|
||||
motor2 (Device): Second device that should be scanned.
|
||||
m2_from (float): Start position of the second device relative to its current position.
|
||||
m2_to (float): End position of the second device relative to its current position.
|
||||
steps (int): Number of steps.
|
||||
exp_time (float): Exposure time
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> d2scan(dev.motor1, -5, 5, dev.motor2, -8, 8, 10, 0.1)
|
||||
"""
|
||||
return scans.line_scan(
|
||||
motor1,
|
||||
m1_from,
|
||||
m1_to,
|
||||
motor2,
|
||||
m2_from,
|
||||
m2_to,
|
||||
steps=steps,
|
||||
exp_time=exp_time,
|
||||
relative=True,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
||||
def ascan(motor1, m1_from, m1_to, steps, exp_time, **kwargs):
|
||||
"""Absolute line scan with one device.
|
||||
|
||||
Args:
|
||||
motor1 (Device): Device that should be scanned.
|
||||
m1_from (float): Start position.
|
||||
m1_to (float): End position.
|
||||
steps (int): Number of steps.
|
||||
exp_time (float): Exposure time.
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> ascan(dev.motor1, -5, 5, 10, 0.1)
|
||||
"""
|
||||
return scans.line_scan(
|
||||
motor1, m1_from, m1_to, steps=steps, exp_time=exp_time, relative=False, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def a2scan(motor1, m1_from, m1_to, motor2, m2_from, m2_to, steps, exp_time, **kwargs):
|
||||
"""Absolute line scan with two devices.
|
||||
|
||||
Args:
|
||||
motor1 (Device): First device that should be scanned.
|
||||
m1_from (float): Start position of the first device.
|
||||
m1_to (float): End position of the first device.
|
||||
motor2 (Device): Second device that should be scanned.
|
||||
m2_from (float): Start position of the second device.
|
||||
m2_to (float): End position of the second device.
|
||||
steps (int): Number of steps.
|
||||
exp_time (float): Exposure time
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> a2scan(dev.motor1, -5, 5, dev.motor2, -8, 8, 10, 0.1)
|
||||
"""
|
||||
return scans.line_scan(
|
||||
motor1,
|
||||
m1_from,
|
||||
m1_to,
|
||||
motor2,
|
||||
m2_from,
|
||||
m2_to,
|
||||
steps=steps,
|
||||
exp_time=exp_time,
|
||||
relative=False,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
||||
def dmesh(motor1, m1_from, m1_to, m1_steps, motor2, m2_from, m2_to, m2_steps, exp_time, **kwargs):
|
||||
"""Relative mesh scan (grid scan) with two devices.
|
||||
|
||||
Args:
|
||||
motor1 (Device): First device that should be scanned.
|
||||
m1_from (float): Start position of the first device relative to its current position.
|
||||
m1_to (float): End position of the first device relative to its current position.
|
||||
m1_steps (int): Number of steps for motor1.
|
||||
motor2 (Device): Second device that should be scanned.
|
||||
m2_from (float): Start position of the second device relative to its current position.
|
||||
m2_to (float): End position of the second device relative to its current position.
|
||||
m2_steps (int): Number of steps for motor2.
|
||||
exp_time (float): Exposure time
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> dmesh(dev.motor1, -5, 5, 10, dev.motor2, -8, 8, 10, 0.1)
|
||||
"""
|
||||
return scans.grid_scan(
|
||||
motor1,
|
||||
m1_from,
|
||||
m1_to,
|
||||
m1_steps,
|
||||
motor2,
|
||||
m2_from,
|
||||
m2_to,
|
||||
m2_steps,
|
||||
exp_time=exp_time,
|
||||
relative=True,
|
||||
)
|
||||
|
||||
|
||||
def amesh(motor1, m1_from, m1_to, m1_steps, motor2, m2_from, m2_to, m2_steps, exp_time, **kwargs):
|
||||
"""Absolute mesh scan (grid scan) with two devices.
|
||||
|
||||
Args:
|
||||
motor1 (Device): First device that should be scanned.
|
||||
m1_from (float): Start position of the first device.
|
||||
m1_to (float): End position of the first device.
|
||||
m1_steps (int): Number of steps for motor1.
|
||||
motor2 (Device): Second device that should be scanned.
|
||||
m2_from (float): Start position of the second device.
|
||||
m2_to (float): End position of the second device.
|
||||
m2_steps (int): Number of steps for motor2.
|
||||
exp_time (float): Exposure time
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> amesh(dev.motor1, -5, 5, 10, dev.motor2, -8, 8, 10, 0.1)
|
||||
"""
|
||||
return scans.grid_scan(
|
||||
motor1,
|
||||
m1_from,
|
||||
m1_to,
|
||||
m1_steps,
|
||||
motor2,
|
||||
m2_from,
|
||||
m2_to,
|
||||
m2_steps,
|
||||
exp_time=exp_time,
|
||||
relative=False,
|
||||
)
|
||||
|
||||
|
||||
def umv(*args) -> ScanReport:
|
||||
"""Updated absolute move (i.e. blocking) for one or more devices.
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> umv(dev.samx, 1)
|
||||
>>> umv(dev.samx, 1, dev.samy, 2)
|
||||
"""
|
||||
return scans.umv(*args, relative=False)
|
||||
|
||||
|
||||
def umvr(*args) -> ScanReport:
|
||||
"""Updated relative move (i.e. blocking) for one or more devices.
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> umvr(dev.samx, 1)
|
||||
>>> umvr(dev.samx, 1, dev.samy, 2)
|
||||
"""
|
||||
return scans.umv(*args, relative=True)
|
||||
|
||||
|
||||
def mv(*args) -> ScanReport:
|
||||
"""Absolute move for one or more devices.
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> mv(dev.samx, 1)
|
||||
>>> mv(dev.samx, 1, dev.samy, 2)
|
||||
"""
|
||||
return scans.mv(*args, relative=False)
|
||||
|
||||
|
||||
def mvr(*args) -> ScanReport:
|
||||
"""Relative move for one or more devices.
|
||||
|
||||
Returns:
|
||||
ScanReport: Status object.
|
||||
|
||||
Examples:
|
||||
>>> mvr(dev.samx, 1)
|
||||
>>> mvr(dev.samx, 1, dev.samy, 2)
|
||||
"""
|
||||
return scans.mv(*args, relative=True)
|
||||
0
bec_plugins/bec_client/plugins/__init__.py
Normal file
0
bec_plugins/bec_client/plugins/__init__.py
Normal file
0
bec_plugins/bec_client/startup/__init__.py
Normal file
0
bec_plugins/bec_client/startup/__init__.py
Normal file
42
bec_plugins/bec_client/startup/post_startup.py
Normal file
42
bec_plugins/bec_client/startup/post_startup.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
Post startup script for the BEC client. This script is executed after the
|
||||
IPython shell is started. It is used to load the beamline specific
|
||||
information and to setup the prompts.
|
||||
|
||||
The script is executed in the global namespace of the IPython shell. This
|
||||
means that all variables defined here are available in the shell.
|
||||
|
||||
If needed, bec command-line arguments can be parsed here. For example, to
|
||||
parse the --session argument, add the following lines to the script:
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--session", help="Session name", type=str, default="my_default_session")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.session == "my_session":
|
||||
print("Loading my_session session")
|
||||
from bec_plugins.bec_client.plugins.my_session import *
|
||||
else:
|
||||
print("Loading default session")
|
||||
from bec_plugins.bec_client.plugins.default_session import *
|
||||
"""
|
||||
|
||||
# pylint: disable=invalid-name, unused-import, import-error, undefined-variable, unused-variable, unused-argument, no-name-in-module
|
||||
|
||||
from bec_lib.core import bec_logger
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
logger.info("Using the XTreme startup script.")
|
||||
|
||||
|
||||
# SETUP BEAMLINE INFO
|
||||
from bec_client.plugins.SLS.sls_info import OperatorInfo, SLSInfo
|
||||
|
||||
bec._beamline_mixin._bl_info_register(SLSInfo)
|
||||
bec._beamline_mixin._bl_info_register(OperatorInfo)
|
||||
|
||||
# SETUP PROMPTS
|
||||
bec._ip.prompts.username = "XTreme"
|
||||
bec._ip.prompts.status = 1
|
||||
24
bec_plugins/bec_client/startup/pre_startup.py
Normal file
24
bec_plugins/bec_client/startup/pre_startup.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
Pre-startup script for BEC client. This script is executed before the BEC client
|
||||
is started. It can be used to set up the BEC client configuration. The script is
|
||||
executed in the global namespace of the BEC client. This means that all
|
||||
variables defined here are available in the BEC client.
|
||||
|
||||
To set up the BEC client configuration, use the ServiceConfig class. For example,
|
||||
to set the configuration file path, add the following lines to the script:
|
||||
|
||||
import pathlib
|
||||
from bec_lib.core import ServiceConfig
|
||||
|
||||
current_path = pathlib.Path(__file__).parent.resolve()
|
||||
CONFIG_PATH = f"{current_path}/<path_to_my_config_file.yaml>"
|
||||
|
||||
config = ServiceConfig(CONFIG_PATH)
|
||||
|
||||
If this startup script defined a ServiceConfig object, the BEC client will use
|
||||
it to configure itself. Otherwise, the BEC client will use the default config.
|
||||
"""
|
||||
|
||||
|
||||
CONFIG_PATH = "/sls/X07MA/data/x07maop/SW/bec/bec/bec_client_config.yaml"
|
||||
config = ServiceConfig(CONFIG_PATH)
|
||||
0
bec_plugins/device_server/__init__.py
Normal file
0
bec_plugins/device_server/__init__.py
Normal file
11
bec_plugins/device_server/startup.py
Normal file
11
bec_plugins/device_server/startup.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
|
||||
|
||||
def setup_epics_ca():
|
||||
os.environ["EPICS_CA_AUTO_ADDR_LIST"] = "NO"
|
||||
os.environ["EPICS_CA_ADDR_LIST"] = "129.129.112.255 sls-x07ma-cagw.psi.ch:5836"
|
||||
os.environ["PYTHONIOENCODING"] = "latin1"
|
||||
|
||||
|
||||
def run():
|
||||
setup_epics_ca()
|
||||
0
bec_plugins/scan_server/__init__.py
Normal file
0
bec_plugins/scan_server/__init__.py
Normal file
176
bec_plugins/scan_server/scan_plugins/otf_scan.py
Normal file
176
bec_plugins/scan_server/scan_plugins/otf_scan.py
Normal file
@@ -0,0 +1,176 @@
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
|
||||
from bec_lib.core import bec_logger
|
||||
from scan_server.scans import FlyScanBase, ScanArgType, ScanBase
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
|
||||
class OTFScan(FlyScanBase):
|
||||
scan_name = "otf_scan"
|
||||
scan_report_hint = "table"
|
||||
required_kwargs = ["e1", "e2", "time"]
|
||||
arg_input = []
|
||||
arg_bundle_size = len(arg_input)
|
||||
|
||||
def __init__(self, *args, parameter=None, **kwargs):
|
||||
"""Scans the energy from e1 to e2 in <time> minutes.
|
||||
|
||||
Examples:
|
||||
>>> scans.otf_scan(e1=700, e2=740, time=4)
|
||||
|
||||
"""
|
||||
super().__init__(parameter=parameter, **kwargs)
|
||||
self.axis = []
|
||||
self.scan_motors = []
|
||||
self.num_pos = 0
|
||||
self.mono = self.caller_kwargs.get("mono", "mono")
|
||||
self.otf_device = self.caller_kwargs.get("otf", "otf")
|
||||
|
||||
def scan_core(self):
|
||||
yield from self.stubs.set(
|
||||
device=self.mono, value=self.caller_kwargs["e1"], wait_group="flyer"
|
||||
)
|
||||
yield from self.stubs.wait(device=[self.mono], wait_group="flyer", wait_type="move")
|
||||
yield from self.stubs.kickoff(
|
||||
device=self.otf_device,
|
||||
parameter={
|
||||
key: val for key, val in self.caller_kwargs.items() if key in ["e1", "e2", "time"]
|
||||
},
|
||||
)
|
||||
yield from self.stubs.wait(device=[self.otf_device], wait_group="kickoff", wait_type="move")
|
||||
yield from self.stubs.complete(device=self.otf_device)
|
||||
target_diid = self.DIID - 1
|
||||
|
||||
while True:
|
||||
yield from self.stubs.read_and_wait(group="primary", wait_group="readout_primary")
|
||||
status = self.stubs.get_req_status(
|
||||
device=self.otf_device, RID=self.metadata["RID"], DIID=target_diid
|
||||
)
|
||||
progress = self.stubs.get_device_progress(
|
||||
device=self.otf_device, RID=self.metadata["RID"]
|
||||
)
|
||||
if progress:
|
||||
self.num_pos = progress
|
||||
if status:
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
class HystScan(ScanBase):
|
||||
scan_name = "hyst_scan"
|
||||
scan_report_hint = "table"
|
||||
required_kwargs = []
|
||||
arg_input = [
|
||||
ScanArgType.DEVICE,
|
||||
ScanArgType.FLOAT,
|
||||
ScanArgType.FLOAT,
|
||||
ScanArgType.DEVICE,
|
||||
ScanArgType.FLOAT,
|
||||
ScanArgType.FLOAT,
|
||||
]
|
||||
arg_bundle_size = 3
|
||||
scan_type = "step"
|
||||
default_ramp_rate = 2
|
||||
|
||||
def __init__(self, *args, parameter=None, **kwargs):
|
||||
"""
|
||||
A hysteresis scan.
|
||||
|
||||
scans.hyst_scan(field_motor, start_field, end_field, mono, energy1, energy2)
|
||||
|
||||
Examples:
|
||||
>>> scans.hyst_scan(dev.field_x, 0, 0.5, dev.mono, 600, 640, ramp_rate=2)
|
||||
|
||||
"""
|
||||
super().__init__(parameter=parameter, **kwargs)
|
||||
self.axis = []
|
||||
self.flyer = list(self.caller_args.keys())[0]
|
||||
self.energy_motor = list(self.caller_args.keys())[1]
|
||||
self.scan_motors = [self.energy_motor, self.flyer]
|
||||
self.flyer_positions = self.caller_args[self.flyer]
|
||||
self._current_scan_motor_index = 0
|
||||
self._scan_motor_direction = 1
|
||||
self.ramp_rate = self.caller_kwargs.get("ramp_rate", self.default_ramp_rate)
|
||||
|
||||
def _calculate_positions(self) -> None:
|
||||
self.positions = [[pos] for pos in self.caller_args[self.energy_motor]]
|
||||
|
||||
def prepare_positions(self):
|
||||
self._calculate_positions()
|
||||
self.num_pos = 0
|
||||
yield None
|
||||
self._check_limits()
|
||||
|
||||
def _at_each_point(self):
|
||||
yield from self.stubs.read(group="primary", wait_group="primary", pointID=self.pointID)
|
||||
self.pointID += 1
|
||||
|
||||
def _get_next_scan_motor_position(self):
|
||||
while True:
|
||||
yield self.positions[self._current_scan_motor_index][0]
|
||||
|
||||
if len(self.positions) - 1 == self._current_scan_motor_index or (
|
||||
self._current_scan_motor_index == 0 and self._scan_motor_direction < 0
|
||||
):
|
||||
self._scan_motor_direction *= -1
|
||||
self._current_scan_motor_index += self._scan_motor_direction
|
||||
|
||||
def scan_core(self):
|
||||
# yield from self._move_and_wait(self.positions[0])
|
||||
status = yield from self.stubs.send_rpc_and_wait(
|
||||
"field_x", "ramprate.set", self.default_ramp_rate
|
||||
)
|
||||
status.wait()
|
||||
yield from self.stubs.set(
|
||||
device=self.flyer, value=self.flyer_positions[0], wait_group="flyer"
|
||||
)
|
||||
yield from self.stubs.wait(device=[self.flyer], wait_group="flyer", wait_type="move")
|
||||
|
||||
status = yield from self.stubs.send_rpc_and_wait("field_x", "ramprate.set", self.ramp_rate)
|
||||
status.wait()
|
||||
# send the slow motor on its way
|
||||
yield from self.stubs.set(
|
||||
device=self.flyer,
|
||||
value=self.flyer_positions[1],
|
||||
wait_group="flyer",
|
||||
)
|
||||
|
||||
flyer_done = False
|
||||
pos_generator = self._get_next_scan_motor_position()
|
||||
target_DIID = self.DIID - 1
|
||||
dev = self.device_manager.devices
|
||||
while not flyer_done:
|
||||
flyer_done = bool(
|
||||
self.stubs.get_req_status(
|
||||
device=self.flyer, DIID=target_DIID, RID=self.metadata["RID"]
|
||||
)
|
||||
)
|
||||
|
||||
val = next(pos_generator)
|
||||
logger.info(f"Moving mono to {val}.")
|
||||
yield from self.stubs.set(device=self.energy_motor, value=val, wait_group="mono")
|
||||
yield from self.stubs.wait(
|
||||
device=[self.energy_motor], wait_group="mono", wait_type="move"
|
||||
)
|
||||
|
||||
monitored_devices = [dev.name for dev in dev.monitored_devices([])]
|
||||
yield from self.stubs.read_and_wait(
|
||||
device=[self.flyer, self.scan_motors[0], *monitored_devices],
|
||||
wait_group="readout_primary",
|
||||
pointID=self.pointID,
|
||||
)
|
||||
# time.sleep(1)
|
||||
self.pointID += 1
|
||||
self.scan_motors[0]
|
||||
self.num_pos += 1
|
||||
|
||||
status = yield from self.stubs.send_rpc_and_wait(
|
||||
"field_x", "ramprate.set", self.default_ramp_rate
|
||||
)
|
||||
status.wait()
|
||||
|
||||
def return_to_start(self):
|
||||
yield None
|
||||
11
deployment/autodeploy_versions
Normal file
11
deployment/autodeploy_versions
Normal file
@@ -0,0 +1,11 @@
|
||||
# This file is used to select the BEC and Ophyd Devices version for the auto deployment process.
|
||||
# Do not edit this file unless you know what you are doing!
|
||||
|
||||
# The version can be a git tag, branch or commit hash.
|
||||
|
||||
# BEC version to use
|
||||
BEC_AUTODEPLOY_VERSION="master"
|
||||
|
||||
# ophyd_devices version to use
|
||||
OPHYD_DEVICES_AUTODEPLOY_VERSION="master"
|
||||
|
||||
18
deployment/bec-server-config.yaml
Normal file
18
deployment/bec-server-config.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
mongodb:
|
||||
host: localhost
|
||||
port: 27017
|
||||
scibec:
|
||||
host: http://[::1]
|
||||
port: 3030
|
||||
beamline: "XTREME"
|
||||
service_config:
|
||||
general:
|
||||
reset_queue_on_cancel: True
|
||||
enforce_ACLs: False
|
||||
file_writer:
|
||||
plugin: default_NeXus_format
|
||||
base_path: ./
|
||||
|
||||
28
deployment/deploy.sh
Executable file
28
deployment/deploy.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
# deployment script to be translated to Ansible
|
||||
|
||||
# NOT NEEDED since the beamline repo will be autodeployed
|
||||
# BEAMLINE_REPO=gitlab.psi.ch:bec/csaxs-bec.git
|
||||
# git clone git@$BEAMLINE_REPO
|
||||
|
||||
module add psi-python38/2020.11
|
||||
|
||||
# start redis
|
||||
docker run --network=host --name redis-bec -d redis
|
||||
# alternative:
|
||||
# conda install -y redis; redis-server &
|
||||
|
||||
|
||||
# get the target versions for ophyd_devices and BEC
|
||||
source ./csaxs-bec/deployment/autodeploy_versions
|
||||
|
||||
git clone -b $OPHYD_DEVICES_AUTODEPLOY_VERSION https://gitlab.psi.ch/bec/ophyd_devices.git
|
||||
git clone -b $BEC_AUTODEPLOY_VERSION https://gitlab.psi.ch/bec/bec.git
|
||||
|
||||
# install BEC
|
||||
cd bec
|
||||
source ./bin/install_bec_dev.sh
|
||||
|
||||
cd ../
|
||||
# start the BEC server
|
||||
bec-server start --config ./xtreme-bec/deployment/bec-server-config.yaml
|
||||
|
||||
21
setup.cfg
Normal file
21
setup.cfg
Normal file
@@ -0,0 +1,21 @@
|
||||
[metadata]
|
||||
name = bec_plugins
|
||||
description = BEC plugins to modify the behaviour of services within the BEC framework
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://gitlab.psi.ch/bec/bec
|
||||
project_urls =
|
||||
Bug Tracker = https://gitlab.psi.ch/bec/bec/issues
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
Development Status :: 3 - Alpha
|
||||
Topic :: Scientific/Engineering
|
||||
|
||||
[options]
|
||||
package_dir =
|
||||
= .
|
||||
packages = find:
|
||||
python_requires = >=3.8
|
||||
|
||||
[options.packages.find]
|
||||
where = .
|
||||
Reference in New Issue
Block a user