Skip to content

Commit 80de1f7

Browse files
Update xml metadata logic to fix BigDataViewer issues
1 parent ce7278a commit 80de1f7

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

flamingo_tools/data_conversion.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import multiprocessing as mp
22
import os
33
import re
4+
import xml.etree.ElementTree as ET
45

56
from glob import glob
67
from pathlib import Path
@@ -26,7 +27,7 @@ def _read_resolution_and_unit_flamingo(mdata_path):
2627
if resolution is None:
2728
raise RuntimeError
2829

29-
unit = "um"
30+
unit = "micrometer"
3031

3132
# NOTE: The resolution for the flamingo system is isotropic.
3233
# So we can just return the plane spacing value to get it.
@@ -59,7 +60,7 @@ def _read_start_position_flamingo(path):
5960
return start_position
6061

6162

62-
def read_metadata_flamingo(metadata_path, offset=None):
63+
def read_metadata_flamingo(metadata_path, offset=None, parse_affine=False):
6364
resolution, unit = None, None
6465

6566
resolution, unit = _read_resolution_and_unit_flamingo(metadata_path)
@@ -69,8 +70,9 @@ def _pos_to_trafo(pos):
6970
if offset is not None:
7071
pos -= offset
7172

72-
# FIXME: dirty hack
73-
# scale = 4
73+
# NOTE: the scale should be kept at 1.
74+
# This is only here for development purposes,
75+
# to support handling downsampled datasets.
7476
scale = 1
7577

7678
# The calibration: scale factors on the diagonals.
@@ -94,7 +96,14 @@ def _pos_to_trafo(pos):
9496
}
9597
return trafo
9698

97-
transformation = _pos_to_trafo(start_position)
99+
if parse_affine:
100+
transformation = _pos_to_trafo(start_position)
101+
else:
102+
transformation = [
103+
1.0, 0.0, 0.0, 0.0,
104+
0.0, 1.0, 0.0, 0.0,
105+
0.0, 0.0, 1.0, 0.0,
106+
]
98107
# We have to reverse the resolution because pybdv expects ZYX.
99108
return resolution[::-1], unit, transformation
100109

@@ -184,6 +193,20 @@ def flamingo_filename_parser(file_path, name_mapping):
184193
return timepoint, attributes, attribute_id
185194

186195

196+
def _write_missing_views(out_path):
197+
xml_path = Path(out_path).with_suffix(".xml")
198+
assert os.path.exists(xml_path)
199+
200+
tree = ET.parse(xml_path)
201+
root = tree.getroot()
202+
seqdesc = root.find("SequenceDescription")
203+
ET.SubElement(seqdesc, "MissingViews")
204+
205+
pybdv.metadata.indent_xml(root)
206+
tree = ET.ElementTree(root)
207+
tree.write(xml_path)
208+
209+
187210
def convert_lightsheet_to_bdv(
188211
root: str,
189212
out_path: str,
@@ -286,7 +309,11 @@ def convert_lightsheet_to_bdv(
286309
unit = "pixel"
287310

288311
else: # We have metadata and read it.
289-
resolution, unit, tile_transformation = read_metadata_flamingo(metadata_file, offset)
312+
# NOTE: we don't add the calibration transformation here, as this
313+
# leads to issues with the BigStitcher export.
314+
resolution, unit, tile_transformation = read_metadata_flamingo(
315+
metadata_file, offset, parse_affine=False
316+
)
290317

291318
print(f"Converting tp={timepoint}, channel={attributes['channel']}, tile={attributes['tile']}")
292319
try:
@@ -312,6 +339,14 @@ def convert_lightsheet_to_bdv(
312339
setup_id=setup_id,
313340
)
314341

342+
# We don't need to add additional xml metadata if we convert to ome-zarr.
343+
if convert_to_ome_zarr:
344+
return
345+
346+
# Add an empty missing views field.
347+
# This is expected by BigStitcher.
348+
_write_missing_views(out_path)
349+
315350

316351
# TODO expose more arguments via CLI.
317352
def convert_lightsheet_to_bdv_cli():
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from flamingo_tools.data_conversion import convert_lightsheet_to_bdv
2+
3+
4+
def main():
5+
root = "/mnt/lustre-emmy-hdd/usr/u12086/data/flamingo/Platynereis-H2B-TL"
6+
output = "./output"
7+
convert_lightsheet_to_bdv(
8+
root, out_path=output,
9+
metadata_file_name_pattern="*_Settings.txt"
10+
)
11+
12+
13+
main()

scripts/data_transfer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Current approach to the data transfer:
66
- Log in to SCC login node:
7-
$
7+
$ ssh -i ~/.ssh/id_rsa_scc [email protected]
88
- Go to "/scratch1/projects/cca/data/moser"
99
- Create subfolder <NAME> for cochlea to be copied
1010
- Log in via $ smbclient \\\\wfs-medizin.top.gwdg.de\\ukon-all\$\\ukon100 -U GWDG\\pape41"

0 commit comments

Comments
 (0)