diff --git a/examples/ilastik3d.py b/examples/ilastik3d.py new file mode 100644 index 0000000000000000000000000000000000000000..74daa29d7dcb975ff308cdd6612d12461fd84e13 --- /dev/null +++ b/examples/ilastik3d.py @@ -0,0 +1,79 @@ +from multiprocessing import Process +from pathlib import Path +import requests +from shutil import copyfile + +import uvicorn + +host = '127.0.0.1' +port = 5001 +px3d_ilp = '3d_model/px3d.ilp' +ob3d_ilp = '3d_model/ob3d.ilp' + +czi_root = Path('z:/rhodes/projects/proj0004-marine-photoactivation/data/exp0036') +czis = [ + 'A01-selection-test01.czi', + 'B01-selection-test01.czi' +] +channel = 4 + +if __name__ == '__main__': + server_process = Process( + target=uvicorn.run, + args=('api:app',), + kwargs={'host': host, 'port': port, 'log_level': 'debug'}, + daemon=True + ) + uri = f'http://{host}:{port}/' + server_process.start() + + resp_paths = requests.get(uri + 'paths') + paths = resp_paths.json() + + # load ilastik pixel model + resp_load_px = requests.put( + uri + 'models/ilastik/pixel_classification/load/', + params={'project_file': px3d_ilp}, + ) + assert resp_load_px.status_code == 200 + model_id_px = resp_load_px.json()['model_id'] + + # load ilastik object model + resp_load_ob = requests.put( + uri + 'models/ilastik/object_classification/load/', + params={'project_file': ob3d_ilp}, + ) + assert resp_load_ob.status_code == 200 + model_id_ob = resp_load_ob.json()['model_id'] + + # copy files from network storage to processing directory + for ff in czis: + infile = Path(czi_root) / ff + outfile = Path(paths['inbound_images']) / ff + copyfile(infile, outfile) + + # infer pixel maps + resp_infer_px = requests.put( + uri + f'infer/from_image_file', + params={ + 'model_id': model_id_px, + 'input_filename': ff, + 'channel': channel, + }, + ) + assert resp_infer_px == 200 + + # infer object maps + resp_infer_ob = requests.put( + uri + f'infer/from_image_file', + params={ + 'model_id': model_id_ob, + 'input_filename': ff, + 'channel': channel, + }, + ) + assert resp_infer_px == 200 + + resp_models = requests.get(uri + 'models') + + server_process.terminate() \ No newline at end of file