Skip to content

Commit

Permalink
Turned 'get_lif_xml_metdata' into a top-level function to facilitate …
Browse files Browse the repository at this point in the history
…easier mocking
  • Loading branch information
tieneupin committed Feb 10, 2025
1 parent 3bf4ce8 commit 449e24b
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/cryoemservices/wrappers/clem_process_raw_lifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@
logger = logging.getLogger("cryoemservices.wrappers.clem_process_raw_lifs")


def get_lif_xml_metadata(
file: LifFile,
save_xml: Optional[Path] = None,
) -> ET.Element:
"""
Extracts and returns the metadata from the LIF file as a formatted XML Element.
It can be optionally saved as an XML file to the specified file path.
"""

# Use readlif function to get XML metadata
xml_root: ET.Element = file.xml_root # This one for navigating
xml_tree = ET.ElementTree(xml_root) # This one for saving

Check warning on line 43 in src/cryoemservices/wrappers/clem_process_raw_lifs.py

View check run for this annotation

Codecov / codecov/patch

src/cryoemservices/wrappers/clem_process_raw_lifs.py#L42-L43

Added lines #L42 - L43 were not covered by tests

# Skip saving the metadata if save_xml not provided
if save_xml:
xml_file = str(save_xml) # Convert Path to string
ET.indent(xml_tree, " ") # Format with proper indentation
xml_tree.write(xml_file, encoding="utf-8") # Save
logger.info(f"File metadata saved to {xml_file!r}")

Check warning on line 50 in src/cryoemservices/wrappers/clem_process_raw_lifs.py

View check run for this annotation

Codecov / codecov/patch

src/cryoemservices/wrappers/clem_process_raw_lifs.py#L47-L50

Added lines #L47 - L50 were not covered by tests

return xml_root

Check warning on line 52 in src/cryoemservices/wrappers/clem_process_raw_lifs.py

View check run for this annotation

Codecov / codecov/patch

src/cryoemservices/wrappers/clem_process_raw_lifs.py#L52

Added line #L52 was not covered by tests


def process_lif_substack(
file: Path,
scene_num: int,
Expand Down Expand Up @@ -213,28 +236,6 @@ def convert_lif_to_stack(
| |__ metadata <- Individual XML files saved here (not yet implemented)
"""

def get_lif_xml_metadata(
file: LifFile,
save_xml: Optional[Path] = None,
) -> ET.Element:
"""
Extracts and returns the metadata from the LIF file as a formatted XML Element.
It can be optionally saved as an XML file to the specified file path.
"""

# Use readlif function to get XML metadata
xml_root: ET.Element = file.xml_root # This one for navigating
xml_tree = ET.ElementTree(xml_root) # This one for saving

# Skip saving the metadata if save_xml not provided
if save_xml:
xml_file = str(save_xml) # Convert Path to string
ET.indent(xml_tree, " ") # Format with proper indentation
xml_tree.write(xml_file, encoding="utf-8") # Save
logger.info(f"File metadata saved to {xml_file!r}")

return xml_root

# Validate processor count input
num_procs = number_of_processes # Use shorter phrase in script
if num_procs < 1:
Expand Down

0 comments on commit 449e24b

Please sign in to comment.