Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
imagejan committed May 2, 2024
1 parent d20b810 commit 98dec57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# criteria for file selection in case of multiple channels/slices per position
file_selection:
mode: standard
channel: C01

# choose method how to segment, filter, and sample the objects
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ authors = [
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"cellpose",
"confuse",
"faim-ipa",
"rich",
"scikit-image",
"tqdm",
Expand All @@ -55,7 +56,7 @@ cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=faim_w
no-cov = "cov --no-cov {args}"

[[tool.hatch.envs.test.matrix]]
python = ["38", "39", "310", "311"]
python = ["39", "310", "311", "312"]

[tool.coverage.run]
branch = true
Expand Down
24 changes: 20 additions & 4 deletions src/faim_wako_searchfirst/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,30 @@ def run(folder: Union[str, Path], configfile: Union[str, Path]):
config_copy.write_text(config.dump())

# Select files
file_selection_config = config["file_selection"].get()
if "mode" in file_selection_config:
mode = file_selection_config.pop("mode")
if mode == "stitched" and "field" not in file_selection_config:
file_selection_config["field"] = "F0001"
else:
mode = "standard"
tif_files = _select_files(
folder=folder_path,
**(config["file_selection"].get()),
**file_selection_config,
)

logger.info(f"Found {len(tif_files)} matching files.")

# Process
process = partial(_process_tif, config=config, logger=logger)
process = partial(_process_tif, config=config, logger=logger, mode=mode)
with ThreadPoolExecutor() as executor:
futures = [executor.submit(process, tif_file) for tif_file in tif_files]
for _ in tqdm(as_completed(futures), total=len(futures)):
pass
logger.info("Done processing.")


def _process_tif(tif_file, config, logger):
def _process_tif(tif_file, config, logger, mode="standard"):
# Setup
# Segment
segment_method = config["process"]["segment"].get(str)
Expand All @@ -90,7 +97,13 @@ def _process_tif(tif_file, config, logger):
sample_fn = getattr(sample, sample_method)

# Read image
# if mode=="standard":
img = imread(tif_file)
# elif mode=="stitched":
# extract well name from tif_file
# create StackAcquisition, get WellAcquisition for current well
# get stitched well image with DaskTileStitcher
# else: error

# Segment
labels = segment_fn(
Expand Down Expand Up @@ -123,10 +136,13 @@ def _process_tif(tif_file, config, logger):

def _select_files(
folder: Path,
time: str = "T[0-9][0-9][0-9][0-9]",
field: str = "F[0-9][0-9][0-9]",
plane: str = "Z[0-9][0-9]",
channel: str = "C01",
) -> List[Path]:
"""Filter all TIFs in folder starting with folder name - and containing channel ID."""
return sorted(folder.rglob(folder.name + "*" + channel + ".tif"))
return sorted(folder.glob(folder.name + "_*_" + time + field + "L[0-9][0-9]A[0-9][0-9]" + plane + channel + ".tif"))


def _save_segmentation_image(folder_path, filename, img, labels):
Expand Down

0 comments on commit 98dec57

Please sign in to comment.