-
Notifications
You must be signed in to change notification settings - Fork 12
Add notebook on how to use the config client inside dodal #1860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacob720
wants to merge
1
commit into
main
Choose a base branch
from
config_server_notebook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "064a462a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "This is a simple tutorial on how to use the daq config server client inside dodal. \n", | ||
| "\n", | ||
| "The config server should already be installed in your venv. Import the client." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "fe773296", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from daq_config_server.client import ConfigServer" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "03719820", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "The config server is deployed centrally in Argus. The end point for this is https://daq-config.diamond.ac.uk, but you could also deploy an version of the config server elsewhere, such as on a beamline cluster.\n", | ||
| "\n", | ||
| "Initialise an instance of the client with the appropriate endpoint." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "0cbe84cf", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "CONFIG_SERVER_ENDPOINT = \"https://daq-config.diamond.ac.uk\"\n", | ||
| "\n", | ||
| "config_server = ConfigServer(url=CONFIG_SERVER_ENDPOINT)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "ae91dbfc", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "For some files, converters exist in the server that convert the contents of the file to a standard `dict` format or `Pydantic` model. For example, a model has been created for detector distance lookup tables." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "500c3dca", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from daq_config_server.models import DetectorXYLookupTable" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "4aa10347", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Now we can use the `get_file_contents` method to retrieve a config file's contents. Here you should provide the filepath of the file to read, and your desired return type." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "5cd7beb4", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "detector_config = config_server.get_file_contents(\n", | ||
| " \"/dls_sw/i03/software/daq_configuration/lookup/DetDistToBeamXYConverter.txt\",\n", | ||
| " DetectorXYLookupTable,\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "7434749f", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "detector_config.get_column_names()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "4d07b3a4", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "detector_config.columns" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "49046142", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "detector_config.rows" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "fcca77d6", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "detector_config.get_value(\"detector_distance_mm\", 800, \"beam_centre_y_mm\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "3436ca4a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "For more information on the config server see https://diamondlightsource.github.io/daq-config-server/main/index.html" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "mx-bluesky", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.11.3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add what kind of error error message you could get if file doesn't exist or return type doesn't match due to configuration being wrong on daq-config-server or requested the wrong thing on dodal side?