Skip to content
Snippets Groups Projects
Commit 043aa390 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Added docstrings

parent 30f37e0b
No related branches found
No related tags found
No related merge requests found
"""
Debug a client request sequence from the same environment as the server
"""
from clients.util import get_client
from clients import ilastik_map_objects_simple
......
from os.path import basename, dirname
from os.path import basename, dirname
def main(request_func, in_abspath, params):
"""
Execute a sequence of client requests that load ilastik pixel and object classifiers, then infer on an image file
:param request_func: (func) function that implements HTTP client, dependent on which environment request are called from
:param in_abspath: (str) absolute path to image file to infer
:param params:
pixel_classifier_path: (str) absolute path to ilastik project file that defines a pixel classifier
object_classifier_path: (str) absolute path to ilastik project file that defines an object classifier
channel: (int) channel of the input image to process
:return: (str) absolute path where a new object map is written
"""
where = dirname(in_abspath)
in_file = basename(in_abspath)
......@@ -9,59 +20,59 @@ def main(request_func, in_abspath, params):
ob_ilp = params['object_classifier_path']
channel = params['channel']
# configure input and output paths
resp = request_func(
'PUT',
# configure input and output paths
resp = request_func(
'PUT',
'/paths/watch_input',
{
'path': where,
}
)
assert resp['status'] == 200, 'Error setting up image directory'
{
'path': where,
}
)
assert resp['status'] == 200, 'Error setting up image directory'
resp = request_func(
'PUT',
'/paths/watch_output',
{
'path': where,
}
)
assert resp['status'] == 200, 'Error setting up image directory'
# load pixel classifier
resp = request_func(
'PUT',
'/ilastik/px/load/',
{
'project_file': px_ilp,
'duplicate': False,
},
)
resp = request_func(
'PUT',
'/paths/watch_output',
{
'path': where,
}
)
assert resp['status'] == 200, 'Error setting up image directory'
# load pixel classifier
resp = request_func(
'PUT',
'/ilastik/px/load/',
{
'project_file': px_ilp,
'duplicate': False,
},
)
assert resp['status'], 'Error loading classifier: ' + px_ilp
id_px_mod = resp['content']['model_id']
# load object classifier
resp = request_func(
'PUT', '/ilastik/pxmap_to_obj/load/',
{
'project_file': ob_ilp,
'duplicate': False,
},
)
assert resp['status'] == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['content']['model_id']
# run inference
resp = request_func(
'PUT',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': in_file,
'channel': channel,
}
# load object classifier
resp = request_func(
'PUT', '/ilastik/pxmap_to_obj/load/',
{
'project_file': ob_ilp,
'duplicate': False,
},
)
assert resp['status'] == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['content']['model_id']
# run inference
resp = request_func(
'PUT',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': in_file,
'channel': channel,
}
)
assert resp['status'] == 200, 'Error calling workfow'
return resp['content']['object_map_filepath']
return resp['content']['object_map_filepath']
"""
Functionality needed to run a client request sequence (clients.*.main) in the ImageJ python 2.7 script environment
"""
import httplib
import json
import urllib
......@@ -9,6 +13,13 @@ PORT = 6221
uri = 'http://{}:{}/'.format(HOST, PORT)
def hit_endpoint(method, endpoint, params=None):
"""
Python 2.7 implementation of HTTP client
:param method: (str) either 'GET' or 'PUT'
:param endpoint: (str) endpoint of HTTP request
:param params: (dict) of parameters required by client request
:return: (dict) of response status and content, formatted as dict if request is successful
"""
connection = httplib.HTTPConnection(HOST, PORT)
if not method in ['GET', 'PUT']:
raise Exception('Can only handle GET and PUT requests')
......@@ -23,10 +34,16 @@ def hit_endpoint(method, endpoint, params=None):
content = json.loads(resp_str)
except Exception:
content = {'str': str(resp_str)}
return {'status': resp.status, 'content': content
}
return {'status': resp.status, 'content': content}
def run_request_sequence(imp, module, params):
def run_request_sequence(imp, func, params):
"""
Execute a sequence of client requests in the ImageJ scripting environment
:param imp: (ij.ImagePlus) input image
:param func: (func) function that implements client request sequence
:param params: (dict) parameters specific to client request
:return: (ij.ImagePlus) output image
"""
in_path = imp.getProp('Location')
out_path = func(hit_endpoint, in_path, params)
return ImagePlus(out_path)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment