Skip to content

Commit 03ca0af

Browse files
authored
Merge pull request #210 from fmi-faim/z-mapping
Expose create_z_mapping as public method
2 parents 807fc95 + d909abd commit 03ca0af

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/faim_ipa/hcs/cellvoyager/acquisition.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def __init__(
328328

329329
def _parse_files(self) -> pd.DataFrame:
330330
files = super()._parse_files()
331-
z_mapping = self._create_z_mapping()
331+
z_mapping = self.create_z_mapping(self._trace_log_files, self._acquisition_dir)
332332
# merge files left with mapping on path
333333
merged = files.merge(z_mapping, how="left", left_on=["path"], right_on=["path"])
334334
if np.any(merged["z_pos"].isna()):
@@ -358,12 +358,15 @@ def _parse_files(self) -> pd.DataFrame:
358358
merged["Z"] = merged["z_pos"]
359359
return merged
360360

361-
def _create_z_mapping(self) -> pd.DataFrame:
361+
@staticmethod
362+
def create_z_mapping(
363+
trace_log_files: list[str | Path], acquisition_dir: Path | str | None = None
364+
) -> pd.DataFrame:
362365
z_pos = []
363366
filenames = []
364367
missing = []
365368
value = None
366-
for trace_file in self._trace_log_files:
369+
for trace_file in trace_log_files:
367370
with open(trace_file) as log:
368371
for line in log:
369372
tokens = line.split(",")
@@ -387,9 +390,17 @@ def _create_z_mapping(self) -> pd.DataFrame:
387390
):
388391
filename = tokens[8]
389392
if value is None:
390-
missing.append(join(self._acquisition_dir, filename))
393+
missing.append(
394+
join(acquisition_dir, filename)
395+
if acquisition_dir
396+
else filename
397+
)
391398
else:
392-
filenames.append(join(self._acquisition_dir, filename))
399+
filenames.append(
400+
join(acquisition_dir, filename)
401+
if acquisition_dir
402+
else filename
403+
)
393404
z_pos.append(value)
394405
elif (
395406
(len(tokens) > 7)

tests/hcs/cellvoyager/test_z_adjusted_stack_acquisition.py

+9
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ def test_get_well_acquisitions(cv_acquisition, trace_log_file):
133133
assert tile.position.z in [0, 1, 2, 3, 4, 5]
134134

135135

136+
def test_create_z_mapping(trace_log_file):
137+
with pytest.warns():
138+
mapping = ZAdjustedStackAcquisition.create_z_mapping(
139+
trace_log_files=[trace_log_file]
140+
)
141+
assert len(mapping) == 96
142+
assert set(mapping["z_pos"]) == {0, 1, 3, 4, 6, 7, 9, 10, 12, 15}
143+
144+
136145
def test_incomplete_tracelog(cv_acquisition, incomplete_trace_log_file):
137146
with pytest.raises(ValueError, match="At least one invalid z position"):
138147
ZAdjustedStackAcquisition(

0 commit comments

Comments
 (0)