Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions docs/tutorials/config-server-example.ipynb
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."
Copy link
Contributor

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?

]
},
{
"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
}