Skip to content

Commit d3535b1

Browse files
Revert "feat: update dat.read() to interpret both dat formats"
This reverts commit f7b4ab0.
1 parent f7b4ab0 commit d3535b1

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

rawtools/dat.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def determine_bit_depth(fp, dims):
4545
"""
4646
file_size = os.stat(fp).st_size
4747
minimum_size = reduce(lambda x,y: x * y, dims) # get product of dimensions
48-
logging.info(f"Minimum calculated size of '{fp}' is {minimum_size} bytes")
48+
logging.debug(f"Minimum calculated size of '{fp}' is {minimum_size} bytes")
4949
expected_filesize = minimum_size * 2
5050
if file_size == minimum_size:
5151
return 'uint8'
@@ -63,13 +63,13 @@ def determine_bit_depth(fp, dims):
6363

6464
def __parse_object_filename(line, dat_format):
6565
if (dat_format == "Dragonfly"):
66-
pattern = r"<ObjectFileName>(?P<filename>.*\.raw)<\/ObjectFileName>"
66+
pattern = r"\s+<ObjectFileName>(?P<filename>.*\.raw)<\/ObjectFileName>$"
6767
elif (dat_format == "NSI"):
6868
pattern = r"^ObjectFileName\:\s+(?P<filename>.*\.raw)$"
6969

7070
match = re.match(pattern, line, flags=re.IGNORECASE)
7171
if match is not None:
72-
logging.info(f"Match: {match}")
72+
logging.debug(f"Match: {match}")
7373
return match.group('filename')
7474

7575
def __parse_resolution(line, dat_format):
@@ -84,15 +84,15 @@ def __parse_resolution(line, dat_format):
8484
"""
8585
# logging.debug(line.strip())
8686
if (dat_format == "Dragonfly"):
87-
pattern = r'<Resolution X="(?P<x>\d+)"\s+Y="(?P<y>\d+)"\s+Z="(?P<z>\d+)"'
87+
pattern = r'\s+<Resolution X="(?P<x>\d+)"\s+Y="(?P<y>\d+)"\s+Z="(?P<z>\d+)"'
8888
elif (dat_format == "NSI"):
8989
pattern_old = r'\s+<Resolution X="(?P<x>\d+)"\s+Y="(?P<y>\d+)"\s+Z="(?P<z>\d+)"'
9090
pattern = r'Resolution\:\s+(?P<x>\d+)\s+(?P<y>\d+)\s+(?P<z>\d+)'
9191

9292
# See if the DAT file is the newer version
9393
match = re.match(pattern, line, flags=re.IGNORECASE)
9494
# Otherwise, check the old version (XML)
95-
if match is None and dat_format == "NSI":
95+
if match is None:
9696
match = re.match(pattern_old, line, flags=re.IGNORECASE)
9797
if match is not None:
9898
logging.debug(f"XML format detected for '{line}'")
@@ -120,13 +120,13 @@ def __parse_slice_thickness(line, dat_format):
120120
121121
"""
122122
if (dat_format == "Dragonfly"):
123-
pattern = r"<Spacing\s+X=\"(?P<xth>\d+\.\d+)\"\s+Y=\"(?P<yth>\d+\.\d+)\"\s+Z=\"(?P<zth>\d+\.\d+)\""
123+
pattern = r"\s+<Spacing\s+X=\"(?P<xth>\d+\.\d+)\"\s+Y=\"(?P<yth>\d+\.\d+)\"\s+Z=\"(?P<zth>\d+\.\d+)\""
124124
elif (dat_format == "NSI"):
125125
pattern = r'\w+\:\s+(?P<xth>\d+\.\d+)\s+(?P<yth>\d+\.\d+)\s+(?P<zth>\d+\.\d+)'
126126

127127
match = re.match(pattern, line, flags=re.IGNORECASE)
128128
if match is not None:
129-
logging.info(f"Match: {match}")
129+
logging.debug(f"Match: {match}")
130130
dims = [ match.group('xth'), match.group('yth'), match.group('zth') ]
131131
if (dat_format == "Dragonfly"):
132132
# Change Dragonfly thickness units to match NSI format
@@ -139,31 +139,31 @@ def __parse_slice_thickness(line, dat_format):
139139

140140
def __parse_format(line, dat_format):
141141
if (dat_format == "Dragonfly"):
142-
pattern = r"<Format>(?P<format>\w+)<\/Format>"
142+
pattern = r"\s+<Format>(?P<format>\w+)<\/Format>$"
143143
elif (dat_format == "NSI"):
144-
pattern = r"Format\:\s+(?P<format>\w+)$"
144+
pattern = r"^Format\:\s+(?P<format>\w+)$"
145145

146146
match = re.match(pattern, line, flags=re.IGNORECASE)
147147
if match is not None:
148-
logging.info(f"Match: {match}")
148+
logging.debug(f"Match: {match}")
149149
return match.group('format')
150150

151151
def __parse_object_model(line, dat_format):
152152
if (dat_format == "Dragonfly"):
153-
pattern = r"<Unit>(?P<object_model>\w+)<\/Unit>"
153+
pattern = r"\s+<Unit>(?P<object_model>\w+)<\/Unit>$"
154154
elif (dat_format == "NSI"):
155155
pattern = r"^ObjectModel\:\s+(?P<object_model>\w+)$"
156156

157157
match = re.match(pattern, line, flags=re.IGNORECASE)
158158
if match is not None:
159-
logging.info(f"Match: {match}")
159+
logging.debug(f"Match: {match}")
160160
return match.group('object_model')
161161

162162
def __is_dragonfly_dat_format(line):
163-
pattern = r"<\?xml\sversion=\"1\.0\"\?>"
163+
pattern = r"^<\?xml\sversion=\"1\.0\"\?>$"
164164
match = re.match(pattern, line, flags=re.IGNORECASE)
165165
if match is not None:
166-
logging.info(f"Match: {match}")
166+
logging.debug(f"Match: {match}")
167167
return True
168168

169169

@@ -188,7 +188,6 @@ def read(fp):
188188

189189
if (object_filename := __parse_object_filename(line, dat_format)) is not None:
190190
data['ObjectFileName'] = object_filename
191-
192191

193192
if (resolution := __parse_resolution(line, dat_format)) is not None:
194193
data['xdim'], data['ydim'], data['zdim'] = resolution

0 commit comments

Comments
 (0)