-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper.py
45 lines (33 loc) · 1.93 KB
/
wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
from cytomine.models import Job
from subprocess import call
from biaflows import CLASS_PRTTRK
from biaflows.helpers import BiaflowsJob, prepare_data, upload_data, upload_metrics
def main(argv):
with BiaflowsJob.from_cli(argv) as nj:
problem_cls = CLASS_PRTTRK
is_2d = False
nj.job.update(status=Job.RUNNING, progress=0, statusComment="Initialisation...")
in_images, gt_images, in_path, gt_path, out_path, tmp_path = prepare_data(problem_cls, nj, is_2d=is_2d, **nj.flags)
# 2. Call the image analysis workflow
nj.job.update(progress=25, statusComment="Launching workflow...")
command = "/usr/bin/xvfb-run ./ImageJ-linux64 -macro macro.ijm " \
"\"input={}, output={}, ij_radius={}, ij_threshold={}, ij_erode_radius={}\" -batch".format(
in_path, out_path, nj.parameters.ij_radius, nj.parameters.ij_threshold, nj.parameters.ij_erode_radius)
return_code = call(command, shell=True, cwd="/fiji") # waits for the subprocess to return
if return_code != 0:
err_desc = "Failed to execute the ImageJ macro (return code: {})".format(return_code)
nj.job.update(progress=100, statusComment=err_desc)
raise ValueError(err_desc)
# 4. Create and upload annotations
nj.job.update(progress=70, statusComment="Uploading extracted annotation...")
upload_data(problem_cls, nj, in_images, out_path, **nj.flags, is_2d=is_2d, monitor_params={
"start": 70, "end": 90, "period": 0.1
})
# 5. Compute and upload the metrics
nj.job.update(progress=90, statusComment="Computing and uploading metrics (if necessary)...")
upload_metrics(problem_cls, nj, in_images, gt_path, out_path, tmp_path, **nj.flags)
# 6. End the job
nj.job.update(status=Job.TERMINATED, progress=100, statusComment="Finished.")
if __name__ == "__main__":
main(sys.argv[1:])