-
Notifications
You must be signed in to change notification settings - Fork 12
Use config server for OAV config files #1748
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
48
commits into
main
Choose a base branch
from
mx_bluesky_1448_use_config_server
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
Show all changes
48 commits
Select commit
Hold shift + click to select a range
b4dbd8e
Add mock config server fixture
jacob720 bf08ced
Use config server to read beamlineParmaeters
jacob720 91fc322
Remove tests for removed functions
jacob720 386b521
Convert test beamlineParameters files
jacob720 acd5805
Fix test
jacob720 28b7823
Fix lint
jacob720 84f0836
Fix
jacob720 afd4fbc
Require latest daq-config-server
jacob720 2d92790
PR comments WIP
jacob720 e3f6fad
Parameterise config server URL
jacob720 3dbb881
Refactor get_beamline_parameters
jacob720 9517b6a
Update lockfile
jacob720 bc858b2
Use server deployed on i03 beamline cluster for i03 config
jacob720 9529dc1
typo
jacob720 4aac691
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 cba50ab
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 eaa20a2
WIP
jacob720 0d29dbe
Reset cache between tests
jacob720 feae3b6
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 d4fda7b
Fix
jacob720 a947f60
Fix lint
jacob720 d5bd077
Fix lint
jacob720 4b4a3f1
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 357a6c9
PR comments and coverage
jacob720 286a17c
Lint
jacob720 3d05eb2
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 07b3d6e
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 df01066
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 7599d49
Merge branch 'main' into mx_bluesky_1504_migrate_beamline_parameters_…
jacob720 6c8fbfd
Use config server for OAV config json
jacob720 8268b27
Add fixture for config server
jacob720 4bd6ac7
Convert OAV test config files to json
jacob720 77ed7ab
Read OAV config correctly
jacob720 cb965ae
Use pydantic models for config where appropriate
jacob720 19525be
Add mock config server
jacob720 d095ba8
Use mock config server in tests and delete test config files
jacob720 8718ae3
Fix tests
jacob720 d5374a3
tidy
jacob720 9c3ba7b
Fix imports
jacob720 4f76bcf
Fix for github.com/DiamondLightSource/daq-config-server/pull/156
jacob720 2743475
Move config files back
jacob720 c054435
Fix display config
jacob720 e2eaa15
Fix system tests
jacob720 20d30e1
Fix lint
jacob720 4692851
Merge branch 'main' into mx_bluesky_1448_use_config_server
jacob720 dcb61d1
Fix lint
jacob720 1eeb265
Inject config client into OAVConfig and OAVConfigBeamCentre
jacob720 80d9022
Rename test file
jacob720 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
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
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
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
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
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 |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| import json | ||
| from abc import abstractmethod | ||
| from collections import ChainMap | ||
| from dataclasses import dataclass | ||
| from typing import Any, Generic, TypeVar | ||
| from xml.etree import ElementTree | ||
| from xml.etree.ElementTree import Element | ||
|
|
||
| from daq_config_server import ConfigClient | ||
| from daq_config_server.models import DisplayConfig | ||
|
|
||
| # GDA currently assumes this aspect ratio for the OAV window size. | ||
| # For some beamline this doesn't affect anything as the actual OAV aspect ratio | ||
| # matches. Others need to take it into account to rescale the values stored in | ||
|
|
@@ -34,20 +35,24 @@ def __init__( | |
| ): | ||
| self.oav_config_json: str = oav_config_json | ||
| self.context = context | ||
| config_server = ConfigClient(url="https://daq-config.diamond.ac.uk") | ||
|
|
||
| self.global_params, self.context_dicts = self.load_json(self.oav_config_json) | ||
| self.global_params, self.context_dicts = self.load_json( | ||
| config_server, self.oav_config_json | ||
| ) | ||
| self.active_params: ChainMap = ChainMap( | ||
| self.context_dicts[self.context], self.global_params | ||
| ) | ||
| self.update_self_from_current_context() | ||
|
|
||
| @staticmethod | ||
| def load_json(filename: str) -> tuple[dict[str, Any], dict[str, dict]]: | ||
| """Loads the json from the specified file, and returns a dict with all the | ||
| def load_json( | ||
| config_server: ConfigClient, filename: str | ||
| ) -> tuple[dict[str, Any], dict[str, dict]]: | ||
| """Loads the specified file from the config server, and returns a dict with all the | ||
| individual top-level k-v pairs, and one with all the subdicts. | ||
| """ | ||
| with open(filename) as f: | ||
| raw_params: dict[str, Any] = json.load(f) | ||
| raw_params: dict[str, Any] = config_server.get_file_contents(filename, dict) | ||
| global_params = { | ||
| k: raw_params.pop(k) | ||
| for k, v in list(raw_params.items()) | ||
|
|
@@ -116,21 +121,20 @@ class ZoomParamsCrosshair(ZoomParams): | |
|
|
||
|
|
||
| class OAVConfigBase(Generic[ParamType]): | ||
| def __init__(self, zoom_params_file: str): | ||
| self.zoom_params = self._get_zoom_params(zoom_params_file) | ||
|
|
||
| def _get_zoom_params(self, zoom_params_file: str): | ||
| tree = ElementTree.parse(zoom_params_file) | ||
| root = tree.getroot() | ||
| return root.findall(".//zoomLevel") | ||
| def __init__(self, zoom_params_file: str, config_client: ConfigClient): | ||
| self.zoom_params = config_client.get_file_contents(zoom_params_file, dict)[ | ||
| "JCameraManSettings" | ||
| ] | ||
|
|
||
| def _read_zoom_params(self) -> dict: | ||
| um_per_pix = {} | ||
| for node in self.zoom_params: | ||
| zoom = str(_get_element_as_float(node, "level")) | ||
| um_pix_x = _get_element_as_float(node, "micronsPerXPixel") | ||
| um_pix_y = _get_element_as_float(node, "micronsPerYPixel") | ||
| um_per_pix[zoom] = (um_pix_x, um_pix_y) | ||
| zoom_levels: list[dict] = self.zoom_params["levels"]["zoomLevel"] | ||
| for level in zoom_levels: | ||
| zoom = level["level"] | ||
| um_per_pix[zoom] = ( | ||
| float(level["micronsPerXPixel"]), | ||
| float(level["micronsPerYPixel"]), | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just like to point out here that I think |
||
| return um_per_pix | ||
|
|
||
| @abstractmethod | ||
|
|
@@ -157,23 +161,17 @@ def __init__( | |
| self, | ||
| zoom_params_file: str, | ||
| display_config_file: str, | ||
| config_client: ConfigClient, | ||
| ): | ||
| self.display_config = self._get_display_config(display_config_file) | ||
| super().__init__(zoom_params_file) | ||
|
|
||
| def _get_display_config(self, display_config_file: str): | ||
| with open(display_config_file) as f: | ||
| file_lines = f.readlines() | ||
| return file_lines | ||
| self.display_config = config_client.get_file_contents( | ||
| display_config_file, DisplayConfig | ||
| ) | ||
| super().__init__(zoom_params_file, config_client) | ||
|
|
||
| def _read_display_config(self) -> dict: | ||
| crosshairs = {} | ||
| for i in range(len(self.display_config)): | ||
| if self.display_config[i].startswith("zoomLevel"): | ||
| zoom = self.display_config[i].split(" = ")[1].strip() | ||
| x = int(self.display_config[i + 1].split(" = ")[1]) | ||
| y = int(self.display_config[i + 2].split(" = ")[1]) | ||
| crosshairs[zoom] = (x, y) | ||
| for zoom, values in self.display_config.zoom_levels.items(): | ||
| crosshairs[str(zoom)] = (values.crosshair_x, values.crosshair_y) | ||
| return crosshairs | ||
|
|
||
| def get_parameters(self) -> dict[str, ZoomParamsCrosshair]: | ||
|
|
||
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 |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| # Add run_engine to be used in tests | ||
| pytest_plugins = ["dodal.testing.fixtures.run_engine"] | ||
| pytest_plugins = [ | ||
| "dodal.testing.fixtures.run_engine", | ||
| "dodal.testing.fixtures.config_server", | ||
| ] |
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
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
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,6 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def use_beamline_i03(monkeypatch): | ||
| monkeypatch.setenv("BEAMLINE", "i03") |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
I think I would probably have gone down the pydantic model route, but seeing as in either case we have to do this dict build to get the data structure we want from the file, I don't think it makes much difference in the end.
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.
I think you're right, will write an issue and do this separately so we can get this merged