-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add transformations to from_xml (#208)
* feat: add transformations to from_xml * docs * update tests * skip on 3.7
- Loading branch information
1 parent
46bae0c
commit 51b6f2e
Showing
6 changed files
with
529 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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,45 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from ome_types._conversion import OME_2016_06_URI | ||
|
||
if TYPE_CHECKING: | ||
from ome_types._conversion import AnyElementTree | ||
|
||
|
||
NSMAP = {"": OME_2016_06_URI, "ome": OME_2016_06_URI} | ||
|
||
|
||
# See note before using... | ||
def fix_micro_manager_instrument(tree: AnyElementTree) -> AnyElementTree: | ||
"""Fix MicroManager Instrument and Detector IDs and References. | ||
Some versions of OME-XML produced by MicroManager have invalid IDs (and references) | ||
for Instruments and Detectors. This function fixes those IDs and references. | ||
NOTE: as of v0.4.0, bad IDs and references are caught during ID validation anyway, | ||
so this is mostly an example of a fix function, and could be used to prevent | ||
the warning from being raised. | ||
""" | ||
for i_idx, instrument in enumerate(tree.findall("Instrument", NSMAP)): | ||
old_id = instrument.get("ID") | ||
if old_id.startswith("Microscope"): | ||
new_id = f"Instrument:{i_idx}" | ||
instrument.set("ID", new_id) | ||
for ref in tree.findall(f".//InstrumentRef[@ID='{old_id}']", NSMAP): | ||
ref.set("ID", new_id) | ||
|
||
for d_idx, detector in enumerate(instrument.findall(".//Detector", NSMAP)): | ||
old_id = detector.get("ID") | ||
if not old_id.startswith("Detector:"): | ||
new_id = f"Detector:{old_id if old_id.isdigit() else d_idx}" | ||
detector.set("ID", new_id) | ||
for ref in tree.findall(f".//DetectorSettings[@ID='{old_id}']", NSMAP): | ||
ref.set("ID", new_id) | ||
|
||
return tree | ||
|
||
|
||
ALL_FIXES = [fix_micro_manager_instrument] | ||
__all__ = ["ALL_FIXES", "fix_micro_manager_instrument"] |
This file contains 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.