Skip to content

Commit fd81a87

Browse files
committed
fix(bg): hide incomplete date entries
1 parent c48afb7 commit fd81a87

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/ZooProcess_lib/ZooscanFolder.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from .LegacyMeta import LutFile, ProjectMeta, ScanMeta
1111
from .tools import parse_csv
1212

13-
1413
SEP_ENDING = "_sep.gif"
1514
MEASURE_ENDING = "_meas.txt"
1615

@@ -254,6 +253,21 @@ def read(self):
254253
date_entry["raw_background_1"] = a_file
255254
if a_file.name.endswith("_back_large_raw_2.tif"):
256255
date_entry["raw_background_2"] = a_file
256+
# Remove incomplete entries, as seen e.g. in:
257+
# 20240911_0908_background_large_manual.tif
258+
# 20240911_0908_back_large_1.tif
259+
# 20240911_0908_back_large_2.tif
260+
# 20240911_0908_back_large_manual_log.txt
261+
# 20240911_0908_back_large_raw_1.tif
262+
# 20240911_0908_back_large_raw_2.tif
263+
# 20240911_1037_back_large_raw_1.tif <- This one is a mistake
264+
for a_date in list(self.content.keys()):
265+
file_set = self.content[a_date]
266+
if (
267+
file_set["raw_background_1"] is None
268+
or file_set["raw_background_2"] is None
269+
):
270+
del self.content[a_date]
257271

258272
def read_groups(self) -> Dict[str, List[DirEntry]]:
259273
"""
@@ -290,7 +304,7 @@ def get_dates(self) -> List[str]:
290304
"""
291305
return list(self.content.keys())
292306

293-
def _last_date_before(self, max_date: datetime) -> List[str]:
307+
def _last_dates_before(self, max_date: datetime) -> List[Tuple[datetime, str]]:
294308
sorted_dates = sorted(
295309
[
296310
(datetime.strptime(a_date, "%Y%m%d_%H%M"), a_date)
@@ -301,21 +315,22 @@ def _last_date_before(self, max_date: datetime) -> List[str]:
301315
return not_after
302316

303317
def get_last_background_before(self, max_date: datetime) -> Optional[Path]:
304-
not_after = self._last_date_before(max_date)
318+
not_after = self._last_dates_before(max_date)
305319
if len(not_after) == 0:
306320
return None
307321
last_date, last_date_str = not_after[-1]
308322
return self.content[last_date_str]["final_background"]
309323

310324
def get_last_raw_backgrounds_before(self, max_date: datetime) -> List[Path]:
311-
not_after = self._last_date_before(max_date)
325+
not_after = self._last_dates_before(max_date)
312326
if len(not_after) == 0:
313327
return []
314328
last_date, last_date_str = not_after[-1]
315-
return [
329+
bg1, bg2 = (
316330
self.content[last_date_str]["raw_background_1"],
317331
self.content[last_date_str]["raw_background_2"],
318-
]
332+
)
333+
return [bg1, bg2]
319334

320335
def get_raw_background_file(self, scan_date: str, index: Union[int, str]) -> Path:
321336
"""Return a conventional file path for a scanned background image"""

0 commit comments

Comments
 (0)