Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
- fix: files with more than one basin without a name could not be
opened (regression in 0.28.3), and basins without a name or
description could not be copied
- fix: running dcnum on its own output within the same second failed
because of duplicate log names; a counter is appended to the names
of the "dcnum-job" and "dcnum-log" logs if necessary
- docs: comment on intended behavior of `fill_holes` (mask
post-processing), Haralick texture features, and the sparsemed
background assignment after cleansing
Expand Down
15 changes: 13 additions & 2 deletions dcnum/logic/ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ def run_pipeline(self):
self.state = "cleanup"

with HDF5Writer(self.path_temp_out) as hw:
# Make sure that the log names are unique. The logs of the
# input file are copied to the output file, and when dcnum is
# run on its own output within the same second, the names of
# the logs would be identical.
logs_out = hw.h5.get("logs", {})
log_suffix = time_string
ii = 1
while (f"dcnum-job-{log_suffix}" in logs_out
or f"dcnum-log-{log_suffix}" in logs_out):
log_suffix = f"{time_string}-{ii}"
ii += 1
# pipeline metadata
hw.h5.attrs["pipeline:dcnum generation"] = self.ppdict["gen_id"]
hw.h5.attrs["pipeline:dcnum data"] = self.ppdict["dat_id"]
Expand All @@ -500,7 +511,7 @@ def run_pipeline(self):
hw.h5.attrs["experiment:event count"] = self.event_count
hw.h5.attrs["imaging:pixel size"] = self.draw.pixel_size
# Add job information to resulting .rtdc file
hw.store_log(f"dcnum-job-{time_string}",
hw.store_log(f"dcnum-job-{log_suffix}",
json.dumps({
"dcnum version": version_tuple,
"job": self.job.__getstate__(),
Expand Down Expand Up @@ -570,7 +581,7 @@ def run_pipeline(self):
if self.path_log.exists():
with HDF5Writer(self.path_temp_out) as hw:
hw.store_log(
f"dcnum-log-{time_string}",
f"dcnum-log-{log_suffix}",
self.path_log.read_text().strip().split("\n"))

# Rename the output file
Expand Down
29 changes: 29 additions & 0 deletions tests/test_logic_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,35 @@ def test_duplicate_pipeline():
assert np.all(h5["events/image"][0] == im0)


def test_duplicate_pipeline_same_second(monkeypatch):
"""Running dcnum on its own output within the same second

In dcnum 0.31.2, this failed, because the logs of the input file
(copied to the output file) had the same names as the new logs.
"""
gmtime = time.gmtime()
monkeypatch.setattr(time, "gmtime", lambda *args: gmtime)
time_string = time.strftime("%Y-%m-%d-%H.%M.%S", time.gmtime())

path_orig = retrieve_data("fmt-hdf5_cytoshot_full-features_2023.zip")
path_out1 = path_orig.with_name("out1.rtdc")
path_out2 = path_orig.with_name("out2.rtdc")
for path_in, path_out in [(path_orig, path_out1),
(path_out1, path_out2)]:
job = logic.DCNumPipelineJob(path_in=path_in,
path_out=path_out,
debug=True)
with logic.DCNumJobRunner(job=job) as runner:
runner.run()
assert runner.state == "done"

with read.HDF5Data(path_out2) as hd:
logs = sorted(hd.logs)
for prefix in ["dcnum-job", "dcnum-log"]:
assert f"{prefix}-{time_string}" in logs
assert f"{prefix}-{time_string}-1" in logs


def test_duplicate_pipeline_redo_index_mapping():
"""Test running the same pipeline twice

Expand Down
Loading