Skip to content

Commit c9b4ce2

Browse files
authored
Merge pull request #30 from AllenInstitute/forrest_leila_changes
forrest leila changes for cross modal registration
2 parents 6e9fce8 + 38170e6 commit c9b4ce2

13 files changed

+261
-188
lines changed

allen_utils/docker_setup.sh

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
docker pull atbigdawg:5000/fcollman/render-python:latest
2-
docker tag atbigdawg:5000/fcollman/render-python:latest fcollman/render-python:latest
1+
#docker pull atbigdawg:5000/fcollman/render-python:latest
2+
#docker tag atbigdawg:5000/fcollman/render-python:latest fcollman/render-python:latest
33
docker build -t fcollman/render-python-apps .
44
docker tag fcollman/render-python-apps atbigdawg:5000/fcollman/render-python-apps
55
docker push atbigdawg:5000/fcollman/render-python-apps
@@ -10,14 +10,11 @@ docker run -t --name renderapps \
1010
-v /nas2:/nas2 \
1111
-v /nas3:/nas3 \
1212
-v /nas4:/nas4 \
13+
-v /nas5:/nas5 \
1314
-v /data:/data \
1415
-v /pipeline:/pipeline \
1516
-v /pipeline/render-python-apps:/usr/local/render-python-apps \
1617
-v /etc/hosts:/etc/hosts \
17-
--dns 10.128.104.10 \
18-
-p 8888:8888 \
18+
-p 7777:7777 \
1919
-e "PASSWORD=$JUPYTERPASSWORD" \
20-
-i -t fcollman/render-python-apps \
21-
/bin/bash -c "/opt/conda/bin/jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py --notebook-dir=/pipeline/render-python-apps --no-browser --allow-root"
22-
23-
20+
-i -t fcollman/render-python-apps

allen_utils/reorg_setup.sh

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
docker pull atbigdawg:5000/fcollman/render-python:master
2-
docker tag atbigdawg:5000/fcollman/render-python:master fcollman/render-python
3-
docker build -t fcollman/render-python-apps:reorg .
4-
docker tag fcollman/render-python-apps:reorg fcollman/render-python-apps:reorg_testsharmi
5-
docker push atbigdawg:5000/fcollman/render-python-apps
6-
docker kill renderapps_testsharmi
7-
docker rm renderapps_testsharmi
8-
docker run -d --name renderapps_testsharmi \
1+
docker pull localhost:5000/fcollman/render-python:master
2+
docker tag localhost:5000/fcollman/render-python:master fcollman/render-python
3+
docker build -t sharmi/render-python-apps:reorg .
4+
#docker tag fcollman/render-python-apps:reorg fcollman/render-python-apps:reorg_testsharmi
5+
#docker push atbigdawg:5000/fcollman/render-python-apps
6+
docker kill renderapps_develop
7+
docker rm renderapps_develop
8+
docker run -d --name renderapps_develop \
99
-v /nas2:/nas2 \
1010
-v /nas:/nas \
1111
-v /nas3:/nas3 \
1212
-v /nas4:/nas4 \
1313
-v /data:/data \
1414
-v /pipeline:/pipeline \
15-
-v /pipeline/sharmi/Sharmi_tools/render-python-apps:/usr/local/render-python-apps \
15+
-v /pipeline/sharmi/Sharmi_tools/render-python-apps-branches/DEVELOP/render-python-apps:/usr/local/share/render-python-apps \
1616
-v /etc/hosts:/etc/hosts \
17-
-p 9999:9999 \
17+
-p 7777:7777 \
1818
-e "PASSWORD=$JUPYTERPASSWORD" \
19-
-i -t fcollman/render-python-apps:reorg_testsharmi
20-
21-
19+
-i -t sharmi/render-python-apps:reorg \
20+
/bin/bash -c "jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py --no-browser --allow-root --notebook-dir=/pipeline/sharmi/Sharmi_tools/render-python-apps-branches/DEVELOP/render-python-apps"

jupyter_notebook_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from IPython.lib import passwd
1717

1818
c.NotebookApp.ip = '*'
19-
c.NotebookApp.port = 8888
19+
c.NotebookApp.port = 7777
2020
c.NotebookApp.open_browser = False
2121
c.MultiKernelManager.default_kernel_name = 'python2'
2222

renderapps/TrakEM2/ImportTrakEM2Annotations.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ def run(self):
174174
pot_render_tilespecs = self.render.run(renderapi.tilespec.get_tile_specs_from_z,
175175
self.args['EMstack'],
176176
ts.z)
177-
mml=ts.ip.get(0,None)
178-
if mml is None:
179-
mml = ts.channels[0].ip[0]
177+
try:
178+
mml=ts.ip.get(0)
179+
except KeyError:
180+
mml = ts.channels[0].ip.get(0)
180181

181182

182-
filepath = (os.path.split(mml.imageUrl)[1]).split('_flip')[0]
183-
pot_filepaths = [(os.path.split(t.ip[0].imageUrl)[1]).split(
183+
filepath = (os.path.split(mml['imageUrl'])[1]).split('_flip')[0]
184+
pot_filepaths = [(os.path.split(t.ip.get(0)['imageUrl'])[1]).split(
184185
'_flip')[0] for t in pot_render_tilespecs]
185186
render_tilespecs.append(next(t for t, fp in zip(
186187
pot_render_tilespecs, pot_filepaths) if fp == filepath))

renderapps/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from . import wrinkle_detection
1616
from . import rough_align
1717
from . import synapse_detection
18+
from . import intensity_correction
1819

1920
__all__ = ['cross_modal_registration', 'dataimport', 'materialize', 'pointmatch',
2021
'module','shapely',
2122
'registration', 'section_polygons', 'stack',
22-
'stitching', 'tile', 'TrakEM2','transfer','wrinkle_detection','datamanagement','rough_align','synapse_detection']
23+
'stitching', 'tile', 'TrakEM2','transfer','wrinkle_detection','datamanagement','rough_align','synapse_detection','intensity_correction']

renderapps/cross_modal_registration/import_EM_registration_projects_multi.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def run(self):
5050

5151
buffersize = self.args['buffersize']
5252
self.args['minX'] = self.args['minX'] - buffersize
53-
self.args['minY'] = self.args['minY'] - buffersize
54-
self.args['maxX'] = self.args['maxX'] + buffersize
55-
self.args['maxY'] = self.args['maxY'] + buffersize
53+
self.args['minY'] = self.args['minY'] - buffersize
54+
self.args['maxX'] = self.args['maxX'] + buffersize
55+
self.args['maxY'] = self.args['maxY'] + buffersize
5656
#width = self.args['maxX']-self.args['minX']
5757
#height = self.args['maxY']-self.args['minY']
5858

renderapps/cross_modal_registration/make_EM_LM_registration_projects_multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def run(self):
5050

5151

5252
#buffersize = 3000
53-
buffersize = self.args['buffersize']
53+
buffersize = self.args['buffersize']
5454
self.args['minX'] = self.args['minX'] - buffersize
5555
self.args['minY'] = self.args['minY'] - buffersize
5656
self.args['maxX'] = self.args['maxX'] + buffersize

renderapps/module/render_module.py

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class EMLMRegistrationMultiParameters(TEM2ProjectTransfer):
8383
required=False, description='maximum z (default to EM stack bounds)')
8484
buffersize= argschema.fields.Int(
8585
required=False, default=0, description='Buffer size to add')
86+
LMstack_index = argschema.fields.Int(required=False, default=0,
87+
description="index of LMstack list to create point matches between")
8688

8789
class RenderModuleException(Exception):
8890
"""Base Exception class for render module"""

renderapps/registration/find_principal_tile_overlaps.py

+29-15
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,51 @@ class CrossStackTilePairFile(argschema.schemas.mm.Schema):
4141
qstack = argschema.fields.Str(required=True)
4242
neighborPairs = argschema.fields.Nested(TilePair,many=True)
4343

44-
def find_tile_pair(render,stack,ts,ref_stack):
45-
46-
ts_geom = tilespec_to_bounding_box_polygon(ts)
47-
48-
width = ts.maxX-ts.minX
49-
height = ts.maxY-ts.minY
50-
minx = ts.minX
51-
miny = ts.minY
52-
p = {}
53-
p['id']=ts.tileId
54-
p['groupId']=ts.layout.sectionId
55-
56-
paired = render.run(renderapi.tilespec.get_tile_specs_from_box,ref_stack,ts.z,minx,miny,width,height)
44+
def find_principal_overlapping_tile(ts,search_ts,ts_geom=None):
45+
if ts_geom is None:
46+
ts_geom = tilespec_to_bounding_box_polygon(ts)
5747
overlap_tuples = []
58-
for ts2 in paired:
48+
for ts2 in search_ts:
5949
ts2_geom = tilespec_to_bounding_box_polygon(ts2)
6050
overlap = ts_geom.intersection(ts2_geom)
6151
frac_overlap = overlap.area/ts_geom.area
6252
overlap_tuples.append((ts2,frac_overlap))
6353
if len(overlap_tuples)==0:
64-
raise RenderModuleException("tile {} in stack {} has no overlaps in stack paired={} {}".format(ts.tileId,stack,ref_stack,paired))
54+
raise RenderModuleException("tile {} has no overlaps in {}".format(ts.tileId,paired))
6555
sorted_overlaps_tuples = sorted(overlap_tuples,key= lambda x: x[1])
6656
#print ts.tileId,sorted_overlaps_tuples[0][1],sorted_overlaps_tuples[-1][1]
6757
ts2 = sorted_overlaps_tuples[-1][0]
58+
return ts2
59+
60+
def get_principal_overlapping_pair(ts,paired,ts_geom=None):
61+
if ts_geom == None:
62+
ts_geom = tilespec_to_bounding_box_polygon(ts)
63+
p = {}
64+
p['id']=ts.tileId
65+
p['groupId']=ts.layout.sectionId
66+
67+
ts2 = find_principal_overlapping_tile(ts,paired,ts_geom)
68+
6869
q = {}
6970
q['id']=ts2.tileId
7071
q['groupId']=ts2.layout.sectionId
7172
pair = {'p':p,'q':q}
7273
#print sorted_overlaps_tuples,ts2.tileId,ts.tileId
7374
return pair
7475

76+
def find_tile_pair(render,stack,ts,ref_stack):
77+
78+
79+
ts_geom = tilespec_to_bounding_box_polygon(ts)
80+
width = ts.maxX-ts.minX
81+
height = ts.maxY-ts.minY
82+
minx = ts.minX
83+
miny = ts.minY
84+
85+
paired = render.run(renderapi.tilespec.get_tile_specs_from_box,ref_stack,ts.z,minx,miny,width,height)
86+
87+
return get_principal_overlapping_pair(ts,paired,ts_geom=ts_geom)
88+
7589
def create_principal_overlap_tile_pair(render,stack,ref_stack,pool_size=20,queryParameters={}):
7690
tilespecs = render.run(renderapi.tilespec.get_tile_specs_from_stack ,stack)
7791

renderapps/registration/fit_transforms_by_point_match.py

+52-35
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"project": "M246930_Scnn1a_4_f1",
1616
"client_scripts": "/pipeline/render/render-ws-java-client/src/main/scripts"
1717
},
18-
"dst_stack": "FA_STI_DCV_FF_Session1",
19-
"src_stack": "REG_STI_DCV_FF_Session3",
20-
"output_stack": "FA_REG_STI_DCV_FF_Session3",
21-
"matchcollection": "M246930_Scnn1a_4_f1_DAPI3_TO_DAPI1",
18+
"dst_stack": "EMSite2_take2_EMA",
19+
"src_stack": "Session1_DRP_STI_DCV_FF",
20+
"output_stack": "TEST_Site2_take2_EMA_STI_DCV_FF_allSession_1",
21+
"matchcollection": "M246930_Scnn1a_4_f1_DAPI1_EMsite2_ptMatch",
2222
"num_local_transforms": 0,
2323
"transform_type": "affine"
2424
}
@@ -41,22 +41,22 @@ class FitTransformsByPointMatchParameters(RenderParameters):
4141
num_local_transforms = Int(required=True,
4242
description="number of local transforms to preserver, \
4343
assumes point matches written down after such local transforms")
44-
setz = Boolean(required=False, default = True,
45-
description="whether to change z's to the destination stack")
4644
transform_type = Str(required = False, default = 'affine',
4745
validate = mm.validate.OneOf(["affine","rigid"]),
4846
description = "type of transformation to fit")
4947
pool_size = Int(required=False, default=20,
5048
description= 'degree of parallelism (default 20)')
51-
49+
setz = Boolean(required=False, default = True,
50+
description="whether to change z's to the destination stack")
51+
5252
logger = logging.getLogger(__name__)
5353

5454
def fit_transforms_by_pointmatch(render,
5555
src_stack,
5656
dst_stack,
5757
matchcollection,
5858
num_local_transforms,
59-
setz,
59+
setz,
6060
Transform):
6161
print src_stack,dst_stack,matchcollection,num_local_transforms
6262
tilespecs_p = renderapi.tilespec.get_tile_specs_from_stack(src_stack, render=render)
@@ -66,29 +66,44 @@ def fit_transforms_by_pointmatch(render,
6666
for k,tsp in enumerate(tilespecs_p):
6767
pid=tsp.tileId
6868
pgroup = tsp.layout.sectionId
69-
match = renderapi.pointmatch.get_matches_involving_tile(matchcollection,pgroup,pid,render=render)[0]
70-
if match['qId']==pid:
71-
pid = match['qId']
72-
qid = match['pId']
73-
p_pts = np.array(match['matches']['q']).T
74-
q_pts = np.array(match['matches']['p']).T
75-
else:
76-
pid = match['pId']
77-
qid = match['qId']
78-
p_pts = np.array(match['matches']['p']).T
79-
q_pts = np.array(match['matches']['q']).T
80-
81-
tsq = next(ts for ts in tilespecs_q if ts.tileId == qid)
82-
tforms = tsq.tforms[num_local_transforms:]
83-
dst_pts = renderapi.transform.estimate_dstpts(tforms,q_pts)
84-
p_pts_global = renderapi.transform.estimate_dstpts(tsp.tforms[num_local_transforms:],p_pts)
85-
final_tform = Transform()
86-
final_tform.estimate(p_pts,dst_pts)
87-
tsp.tforms=tsp.tforms[0:num_local_transforms]+[final_tform]
88-
89-
if setz == True:
90-
tsp.z = tsq.z
91-
69+
try:
70+
matches = renderapi.pointmatch.get_matches_involving_tile(matchcollection,pgroup,pid,render=render)
71+
dst_pts_list = []
72+
p_pts_list = []
73+
for match in matches:
74+
if match['qId']==pid:
75+
pid = match['qId']
76+
qid = match['pId']
77+
p_pts = np.array(match['matches']['q']).T
78+
q_pts = np.array(match['matches']['p']).T
79+
else:
80+
pid = match['pId']
81+
qid = match['qId']
82+
p_pts = np.array(match['matches']['p']).T
83+
q_pts = np.array(match['matches']['q']).T
84+
try:
85+
tsq = next(ts for ts in tilespecs_q if ts.tileId == qid)
86+
tforms = tsq.tforms[num_local_transforms:]
87+
dst_pts = renderapi.transform.estimate_dstpts(tforms,q_pts)
88+
dst_pts_list.append(dst_pts)
89+
p_pts_list.append(p_pts)
90+
except:
91+
pass
92+
#p_pts_global = renderapi.transform.estimate_dstpts(tsp.tforms[num_local_transforms:],p_pts)
93+
if len(dst_pts_list)>0:
94+
dst_pts = np.vstack(dst_pts_list)
95+
p_pts = np.vstack(p_pts_list)
96+
final_tform = Transform()
97+
final_tform.estimate(p_pts,dst_pts)
98+
tsp.tforms=tsp.tforms[0:num_local_transforms]+[final_tform]
99+
if setz == True:
100+
tsp.z = tsq.z
101+
tilespecs_out.append(tsp)
102+
103+
except IndexError as e:
104+
pass
105+
except StopIteration as e:
106+
pass
92107
# print pid,qid
93108
# print "p_pts"
94109
# print p_pts
@@ -98,8 +113,9 @@ def fit_transforms_by_pointmatch(render,
98113
# print p_pts_global
99114
# if k==1:
100115
# break
116+
101117

102-
return tilespecs_p
118+
return tilespecs_out
103119

104120

105121
class FitTransformsByPointMatch(RenderModule):
@@ -122,17 +138,18 @@ def run(self):
122138
self.args['matchcollection'],
123139
self.args['num_local_transforms'],
124140
self.args['setz'],
125-
Transform)
141+
Transform)
126142

127143
outstack = self.args['output_stack']
128144

129145
self.render.run(renderapi.stack.delete_stack, outstack)
130146
self.render.run(renderapi.stack.create_stack, outstack)
131-
147+
sv=self.render.run(renderapi.stack.get_stack_metadata, self.args['dst_stack'])
148+
132149
renderapi.client.import_tilespecs_parallel(outstack,tilespecs,
133150
render=self.render,
134151
close_stack=True)
135-
152+
self.render.run(renderapi.stack.set_stack_metadata,outstack, sv)
136153
self.render.run(renderapi.stack.set_stack_state,
137154
outstack, state='COMPLETE')
138155

0 commit comments

Comments
 (0)