-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.py
53 lines (45 loc) · 1.85 KB
/
metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# ---------------------------------------------------------------------
# File: metadata.py
# Author: Jan Kukacka
# Date: 1/2021
# ---------------------------------------------------------------------
# Functions for extracting metadata from scan files
# ---------------------------------------------------------------------
import xml.etree.ElementTree as ET
from functools import lru_cache
@lru_cache(100)
def get_wavelength_count(metadata_filename):
'''
Extracts wavelength count for a scan from its metadata.
# Arguments
- metadata_fileaname: full filename (including path) to a xml metadata file
(usually Scan_n.msot).
'''
meta = ET.parse(metadata_filename)
scan_node = meta.getroot().find('ScanNode')
n_wavelengths = len(list(scan_node.find('Wavelengths').iter('Wavelength')))
return n_wavelengths
@lru_cache(20)
def get_oa_to_us_match(metadata_filename):
'''
Function reads the given metadata file and for each oa pulse returns a
matching US frame.
# Arguments
- metadata_fileaname: full filename (including path) to a xml metadata file
(usually Scan_n.msot).
# Returns
- list of length n_pulses with indices to corresponding US frames.
Negative numbers mean no matching US frame exists. US frame numbers
use zero-based indexing.
'''
meta = ET.parse(metadata_filename)
scan_node = meta.getroot().find('ScanNode')
n_wavelengths = len(list(scan_node.find('Wavelengths').iter('Wavelength')))
frames = scan_node.find('ScanFrames')
result = []
for frame_index, frame in enumerate(frames.iter('DataModelScanFrame')):
## Get US frame for each single-wavelenth OA image
us_frame_index = frame.find('Frame').get('ultraSound-frame-offset')
us_frame_index = int(us_frame_index) - 1
result.append(us_frame_index)
return result