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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Versions follow [Semantic Versioning](https://semver.org) (`<major>.<minor>.<pat

## Unreleased

### Fixed

- `preprocess` removes only the subdirectory of `--interim_dir` it keeps its intermediate files in, instead of `--interim_dir` and everything in it, and also removes it when it fails or stops early with `--channel-means-only` ([#135](https://github.com/DuguidLab/mesoscopy/issues/135)).

## [0.17.1] - 2026-10-12

### Changed
Expand Down
29 changes: 29 additions & 0 deletions src/mesoscopy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
# SOFTWARE.
from __future__ import annotations

import contextlib
import csv
import tempfile
import typing
from collections import OrderedDict
from collections.abc import Iterator
from pathlib import Path

import h5py
Expand Down Expand Up @@ -183,6 +186,32 @@ def store_interim(
return zarr.load(interim_path)


@contextlib.contextmanager
def interim_workdir(interim_dir: str | Path, prefix: str = "") -> Iterator[str]:
"""Create a fresh directory for interim files inside an interim directory, removed on exit.

Only the fresh directory is removed, so files already in the interim directory are kept. The interim directory
itself is removed only if it was created here and is left empty.

Args:
interim_dir (str or PathLike object): Directory to create the fresh directory in. Created if missing.
prefix (str, optional): Prefix for the fresh directory name. Defaults to "".

Yields:
str: Path to the fresh directory.
"""
parent = Path(interim_dir)
created = not parent.is_dir()
parent.mkdir(parents=True, exist_ok=True)
try:
with tempfile.TemporaryDirectory(prefix=prefix, dir=parent) as workdir:
yield workdir
finally:
if created:
with contextlib.suppress(OSError):
parent.rmdir()


def load_deltaf(path: str, nwb: bool = False) -> tuple[str, np.ndarray, np.ndarray]:
"""Load preprocessed dF/F from an HDF5 or NWB file.

Expand Down
Loading
Loading