-
Notifications
You must be signed in to change notification settings - Fork 22
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
282-standardise-handling-of-read-config-and-hinted-signals-for-standarddetector #468
base: main
Are you sure you want to change the base?
282-standardise-handling-of-read-config-and-hinted-signals-for-standarddetector #468
Conversation
06c7a13
to
b137fea
Compare
…ing-of-read-config-and-hinted-signals-for-standarddetector
…hinted-signals-for-standarddetector
…hinted-signals-for-standarddetector
@@ -29,13 +31,14 @@ def __init__( | |||
path_provider: PathProvider, | |||
name_provider: NameProvider, | |||
shape_provider: ShapeProvider, | |||
**scalar_datasets_paths: str, | |||
plugins: Sequence[NDArrayBaseIO] | None = None, |
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.
Could: be positional args
plugins: Sequence[NDArrayBaseIO] | None = None, | |
*plugins: NDArrayBaseIO, |
try: | ||
for plugin in self._plugins: | ||
tree = ET.parse((await plugin.nd_attributes_file.get_value())) | ||
root = tree.getroot() | ||
for child in root: | ||
datakey = child.attrib["name"] | ||
self._datasets.append( | ||
HDFDataset( | ||
datakey, | ||
f"/entry/instrument/NDAttributes/{datakey}", | ||
(), | ||
convert_ad_dtype_to_np( | ||
ADBaseDataType((child.attrib.get("datatype", None))) | ||
), | ||
multiplier, | ||
) | ||
) | ||
except ET.ParseError: | ||
raise ValueError("Error parsing XML") |
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.
Thinking about this more, please can we
- Only parse plugins with stuff that looks like XML
- We can then ditch the error catching
try: | |
for plugin in self._plugins: | |
tree = ET.parse((await plugin.nd_attributes_file.get_value())) | |
root = tree.getroot() | |
for child in root: | |
datakey = child.attrib["name"] | |
self._datasets.append( | |
HDFDataset( | |
datakey, | |
f"/entry/instrument/NDAttributes/{datakey}", | |
(), | |
convert_ad_dtype_to_np( | |
ADBaseDataType((child.attrib.get("datatype", None))) | |
), | |
multiplier, | |
) | |
) | |
except ET.ParseError: | |
raise ValueError("Error parsing XML") | |
for plugin in self._plugins: | |
maybe_xml = await plugin.nd_attributes_file.get_value() | |
# This is the check that ADCore does to see if it is an XML string | |
# rather than a filename to parse | |
if "<Attributes>" in maybe_xml: | |
root = ET.parse(maybe_xml).getroot() | |
for child in root: | |
datakey = child.attrib["name"] | |
self._datasets.append( | |
HDFDataset( | |
datakey, | |
f"/entry/instrument/NDAttributes/{datakey}", | |
(), | |
convert_ad_dtype_to_np( | |
ADBaseDataType((child.attrib.get("datatype", None))) | |
), | |
multiplier, | |
) | |
) |
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.
Please can we have some tests for these functions? I would like to see the deleted test recreated using the new functions
convert_ad_dtype_to_np( | ||
ADBaseDataType((child.attrib.get("datatype", None))) | ||
), |
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.
This is not quite right, so I went reading the areaDetector code. Turns out to be more complicated than I thought.
There are 3 cases to consider:
- NDAttributeParam with type DOUBLE, INT, INT64, STRING
- NDAttributePV with type DBR_NATIVE
- NDAttributePV with type DBR_LONG, DBR_STRING, ...
I think we can solve with the following lookup:
_ndattribute_to_ad_datatype = {
"FLOAT": ADBaseDataType.Float64,
"DBR_DOUBLE: ADBaseDataType.Float64,
...
}
if datatype in ["STRING", "DBR_STRING"]:
np_datatype = "s40"
elif datatype == "DBR_NATIVE":
raise ValueError("Don't support DBR_NATIVE yet")
else:
ad_datatype = _ndattribute_to_ad_datatype[datatype]
np_datatype = convert_ad_dtype_to_np(datatype)
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 used this comment to figure out the datatype https://github.com/areaDetector/ADCore/blob/1a9135976b4bc75bfdfe1ed7516a3e7d29e08e6b/ADApp/ADSrc/asynNDArrayDriver.cpp#L263
tests/epics/adcore/test_writers.py
Outdated
async def test_stats_describe_when_plugin_configured_in_memory(RE, detectors): | ||
for detector in detectors: | ||
await detector.connect(mock=True) | ||
detector.set_name(type(detector).__name__) | ||
RE(setup_ndstats_sum(detector)) | ||
xml = await detector.hdf.nd_attributes_file.get_value() | ||
for element in xml: | ||
assert str(element.tag) == "Attribute" | ||
assert ( | ||
str(element.attrib) | ||
== f"{{'name': '{detector.name}-sum', 'type': 'PARAM', '" | ||
+ "source': 'NDPluginStatsTotal', 'addr': '0', 'datatype': 'DBR_LONG'," | ||
+ " 'description': 'Sum of the array'}" | ||
) | ||
|
||
|
||
async def test_nd_attributes_plan_stub(RE, detectors): | ||
for detector in detectors: | ||
await detector.connect(mock=True) | ||
detector.set_name(type(detector).__name__) | ||
param = adcore.NDAttributeParam( | ||
name=f"{detector.name}-sum", | ||
param="sum", | ||
datatype=adcore.NDAttributeDataType.DOUBLE, | ||
description=f"Sum of {detector.name} frame", | ||
) | ||
pv = adcore.NDAttributePv( | ||
name="Temperature", | ||
signal=epics_signal_r(str, "LINKAM:TEMP"), | ||
description="The sample temperature", | ||
) | ||
RE(setup_ndattributes(detector.hdf, [pv, param])) | ||
xml = await detector.hdf.nd_attributes_file.get_value() | ||
assert str(xml[0].tag) == "Attribute" | ||
assert ( | ||
str(xml[0].attrib) | ||
== "{'name': 'Temperature', 'type': 'EPICS_PV', '" | ||
+ "source': 'ca://LINKAM:TEMP', 'datatype': 'DBR_NATIVE'," | ||
+ " 'description': 'The sample temperature'}" | ||
) | ||
assert str(xml[1].tag) == "Attribute" | ||
assert ( | ||
str(xml[1].attrib) | ||
== f"{{'name': '{detector.name}-sum', 'type': 'PARAM', '" | ||
+ "source': 'sum', 'addr': '0', 'datatype': 'DBR_DOUBLE'," | ||
+ f" 'description': 'Sum of {detector.name} frame'}}" | ||
) | ||
|
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 have included tests here that are equivalent to the ones I have removed.
No description provided.