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

Client now outside the server repo

parent aaa18478
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="requests.models.Response.__getitem__" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/imagej.iml" filepath="$PROJECT_DIR$/.idea/imagej.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
import httplib
import json
import urllib
import sys
print(sys.version)
HOST = '127.0.0.1'
PORT = 8000
uri = 'http://{}:{}/'.format(HOST, PORT)
def hit_endpoint(method, endpoint, params=None, verbose=False):
connection = httplib.HTTPConnection(HOST, PORT)
if not method in ['GET', 'PUT']:
raise Exception('Can only handle GET and PUT requests')
if params:
url = endpoint + '?' + urllib.urlencode(params)
else:
url = endpoint
connection.request(method, url)
resp = connection.getresponse()
resp_str = resp.read()
if verbose:
print(method + ' ' + url + ', status ' + str(resp.status) + ':\n' + resp_str)
return json.loads(resp_str)
import os
import sys
from ij import IJ
# add directory of current script to search path
scripts_dir = os.path.dirname(sys.argv[0])
sys.path.append(scripts_dir)
from ilastik_obmaps import ilastik_map_objects_simple
CHANNEL_TO_ILASTIK = 1 # i.e. index of color channel from confocal stack
OBJECT_CLASS_FOR_PHOTOACTIVATION = 1
ROOT = 'c:/Users/rhodes/projects/proj0004-marine-photoactivation/data/exp0021/'
PIXEL_CLASSIFIER_PATH = ROOT + 'ilastik/px-01.ilp'
OBJECT_CLASSIFIER_PATH = ROOT + 'ilastik/obj-04.ilp'
DEBUG = True
#obmap = ilastik_map_objects_simple(
# IJ.getImage(),
# PIXEL_CLASSIFIER_PATH,
# OBJECT_CLASSIFIER_PATH,
# CHANNEL_TO_ILASTIK
#)
# pipeline: remove any existing overlay
IJ.run("Remove Overlay")
resp = hit_endpoint(
'GET',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': basename(abspath),
'channel': channel,
}
)
imp_czi = IJ.getImage()
#czi_fn = imp_czi.getTitle()
#czi_desc = czi_fn.split('.')[0]
#imp_czi.setDisplayMode(IJ.GRAYSCALE)
IJ.run("Make Subset...", "channels=" + str(CHANNEL_TO_ILASTIK))
imp_to_ilastik = IJ.getImage()
#obmap = ilastik_map_objects_simple(
# imp_to_ilastik,
# PIXEL_CLASSIFIER_PATH,
# OBJECT_CLASSIFIER_PATH,
# CHANNEL_TO_ILASTIK
#)
from client import hit_endpoint
from os.path import basename, dirname
from ij import IJ
from ij import ImagePlus
def setup(where, px_ilp):
# configure input and output paths
resp = hit_endpoint(
'PUT',
'/paths/watch_input',
{
'path': where,
}
)
assert resp.status_code == 200, 'Error setting up image directory'
resp = hit_endpoint(
'PUT',
'/paths/watch_output',
{
'path': where,
}
)
assert resp.status_code == 200, 'Error setting up image directory'
# load pixel classifier
resp = hit_endpoint(
'PUT',
'/ilastik/pixel_classification/load/',
{
'project_file': px_ilp,
'duplicate': False,
},
)
assert resp.status_code == 200, 'Error loading pixel classifier: ' + {px_ilp}
return resp['model_id']
def ilastik_map_objects_simple(imp, px_ilp, ob_ilp, channel):
"""
:param pixel_classifier: (str)
:param object_classifier: (str)
:return: ImagePlus
"""
# get info from input ImagePlus
abspath = imp.getProp('Location')
# assert imp is not z-stack
id_px_mod = setup(dirname(abspath), px_ilp)
# load object classifier
resp = hit_endpoint(
'PUT', '/ilastik/pxmap_to_obj/load/',
{
'project_file': ob_ilp,
'duplicate': False,
},
)
assert resp.status_code == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['model_id']
# run inference
resp = hit_endpoint(
'PUT',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': basename(abspath),
'channel': channel,
}
)
assert resp.status_code == 200, 'Error calling workfow'
obmap = resp.json()['object_map_filepath']
return obmap # obviously need imp
def ilastik_map_objects_with_zmask(imp, px_ilp, ob_ilp, pxmap_threshold, pxmap_foreground_channel, segmentation_channel, patches_channel, zmask_filters):
"""
:param pixel_classifier: (str)
:param object_classifier: (str)
:return: ImagePlus
"""
# get info from input ImagePlus
abspath = imp.getProp('Location')
# assert imp is not z-stack
id_px_mod = setup(dirname(abspath), px_ilp)
# load object classifier
resp = hit_endpoint(
'PUT', '/ilastik/seg_to_obj/load/',
{
'project_file': ob_ilp,
'duplicate': False,
},
)
assert resp.status_code == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['model_id']
# run inference
resp = hit_endpoint(
'PUT',
'/chaeo/classify_zstack/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': basename(abspath),
'pxmap_threshold': pxmap_threshold,
'pxmap_foreground_channel': pxmap_foreground_channel,
'segmentation_channel': segmentation_channel,
'patches_channel': patches_channel,
'zmask_filters': zmask_filters,
}
)
assert resp.status_code == 200, 'Error calling workfow'
obmap = resp.json()['output_path']
return obmap # obviously need imp
The clients.imagej package tracks client scripts and their dependencies, which are intended to run inside ImageJ's
Jython interpreter.
\ 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