Skip to content

Commit

Permalink
bump up preadator package and added short cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
hamshkhawar committed Dec 15, 2023
1 parent 575f946 commit f0f3c69
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion formats/czi-extract-plugin/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ filepattern = "^2.0.4"
typer = "^0.7.0"
tqdm = "^4.64.1"
bfio = {version = "2.3.3", extras = ["all"]}
preadator="0.3.0.dev1"
preadator="0.4.0.dev2"
czifile="^2019.7.2"

[tool.poetry.group.dev.dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import json
import logging
import os
from concurrent.futures import as_completed
from multiprocessing import cpu_count
from pathlib import Path
from typing import Any
from typing import Optional

import filepattern as fp
import polus.plugins.formats.czi_extract.czi as cz
import preadator
import typer
from preadator import ProcessManager
from tqdm import tqdm

# Import environment variables
POLUS_EXT = os.environ.get("POLUS_EXT", ".ome.tif")
Expand Down Expand Up @@ -64,10 +66,7 @@ def main(
out_dir.exists()
), f"{out_dir} does not exist!! Please check output path again"

num_threads = max([cpu_count(), 2])

ProcessManager.num_processes(num_threads)
ProcessManager.init_processes(name="Czi Extraction")
num_workers = max([cpu_count(), 2])

files = fp.FilePattern(inp_dir, file_pattern)

Expand All @@ -90,9 +89,27 @@ def main(
out_json["outDir"].append(out_name)
json.dump(out_json, jfile, indent=2)

for file in files():
ProcessManager.submit_process(cz.extract_fovs, file[1][0], out_dir)
ProcessManager.join_processes()
with preadator.ProcessManager(
name="Convert czi to individual ome tif",
num_processes=num_workers,
threads_per_process=2,
) as pm:
threads = []
for file in files():
thread = pm.submit_process(cz.extract_fovs, file[1][0], out_dir)
threads.append(thread)
pm.join_processes()

for f in tqdm(
as_completed(threads),
total=len(threads),
mininterval=5,
desc="Extract czi",
initial=0,
unit_scale=True,
colour="cyan",
):
f.result()


if __name__ == "__main__":
Expand Down
18 changes: 18 additions & 0 deletions formats/czi-extract-plugin/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ def test_cli(download_czi, output_directory) -> None:
)

assert result.exit_code == 0


def test_short_cli(download_czi, output_directory) -> None:
"""Test the short cli command line."""
runner = CliRunner()
result = runner.invoke(
app,
[
"-i",
download_czi,
"-f",
".*.czi",
"-o",
output_directory,
],
)

assert result.exit_code == 0

0 comments on commit f0f3c69

Please sign in to comment.