Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ttk
spam
Commits
770b7f0f
Commit
770b7f0f
authored
Jan 05, 2021
by
Edward Andò
Browse files
pixel search OK for label mode too
parent
bb62b7c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/spam-pixelSearch
View file @
770b7f0f
...
...
@@ -245,15 +245,6 @@ def getImagettes(nodePosition, Phi, searchRange, boundingBox, im1, im2, im1mask,
imagette1mask
=
None
initialDisplacement
=
Phi
[
0
:
3
,
3
].
astype
(
int
)
# point in im2 that we are searching around
#searchCentre = nodePosition + initialDisplacement # <-- this is only true in global coordinates
searchCentre
=
nodePosition
-
boundingBox
[
0
::
2
]
-
searchRange
[
0
::
2
]
#searchCentre = halfWindowSize - searchRange[0::2]
#Add initial displacement to searchRange
#searchRange[0::2] += initialDisplacement
#searchRange[1::2] += initialDisplacement
# Catch bad bounding boxes:
if
numpy
.
all
((
boundingBox
[
1
::
2
]
-
boundingBox
[
0
::
2
])
>
[
0
,
0
,
0
])
and
numpy
.
all
(
boundingBox
[
1
::
2
]
-
boundingBox
[
0
::
2
]
!=
[
0
,
0
,
0
]):
...
...
@@ -342,28 +333,8 @@ def getImagettes(nodePosition, Phi, searchRange, boundingBox, im1, im2, im1mask,
'imagette1mask'
:
imagette1mask
,
'imagette2'
:
imagette2
,
'returnStatus'
:
returnStatus
,
'initialDisplacement'
:
initialDisplacement
,
'searchRange'
:
searchRange
,
'searchCentre'
:
searchCentre
}
mpi
=
False
if
mpi
:
import
mpi4py.MPI
mpiComm
=
mpi4py
.
MPI
.
COMM_WORLD
mpiSize
=
mpiComm
.
Get_size
()
mpiRank
=
mpiComm
.
Get_rank
()
mpiStatus
=
mpi4py
.
MPI
.
Status
()
boss
=
mpiSize
-
1
numberOfWorkers
=
mpiSize
-
1
workersActive
=
numpy
.
zeros
(
numberOfWorkers
)
else
:
# not mpi
numberOfWorkers
=
1
workersActive
=
numpy
.
array
([
0
])
'pixelSearchOffset'
:
searchRange
[
0
::
2
]
}
# Create pixelSearchCC vector
...
...
@@ -373,13 +344,13 @@ returnStatus = numpy.ones((numberOfNodes), dtype=int)
# Add nodes to a queue -- mostly useful for MPI
q
=
queue
.
Queue
()
if
args
.
LAB1
is
not
None
:
firstNode
=
1
;
finishedNodes
=
1
else
:
firstNode
=
0
;
finishedNodes
=
0
if
args
.
LAB1
is
not
None
:
firstNode
=
1
else
:
firstNode
=
0
for
node
in
range
(
firstNode
,
numberOfNodes
):
q
.
put
(
node
)
finishedNodes
=
0
writeReturns
=
False
...
...
@@ -389,9 +360,7 @@ pbar = progressbar.ProgressBar(widgets=widgets, maxval=numberOfNodes)
pbar
.
start
()
while
finishedNodes
!=
numberOfNodes
:
# If there are workers not working, satify their requests...
# Note: this condition is alyas true if we are not in MPI and there are jobs to do
if
workersActive
.
sum
()
<
numberOfWorkers
and
not
q
.
empty
():
worker
=
numpy
.
where
(
workersActive
==
False
)[
0
][
0
]
if
not
q
.
empty
():
# Get the next node off the queue
nodeNumber
=
q
.
get
()
...
...
@@ -399,65 +368,52 @@ while finishedNodes != numberOfNodes:
imagetteReturns
=
{}
gottenLabel
=
spam
.
label
.
getLabel
(
lab1
,
nodeNumber
,
boundingBoxes
=
boundingBoxes
,
centresOfMass
=
nodePositions
,
maskOtherLabels
=
True
,
labelDilate
=
args
.
LABEL_DILATE
,
margin
=
1
+
args
.
LABEL_DILATE
)
if
gottenLabel
is
not
None
:
imagetteReturns
[
'imagette1'
]
=
im1
[
gottenLabel
[
'slice'
]]
# 2020-07-05 try applying F to im1 this is expected to help with pixel searching
PhiNoDisp
=
PhiField
[
nodeNumber
].
copy
()
PhiNoDisp
[
0
:
3
,
-
1
]
=
0.0
initialDisplacement
=
numpy
.
round
(
PhiField
[
nodeNumber
,
0
:
3
,
3
]).
astype
(
int
)
imagette1
=
spam
.
helpers
.
slicePadded
(
im1
,
gottenLabel
[
'boundingBox'
]
+
numpy
.
array
([
0
,
1
,
0
,
1
,
0
,
1
]))
imagette1def
=
spam
.
DIC
.
applyPhi
(
imagette1
,
PhiNoDisp
,
PhiPoint
=
gottenLabel
[
'centreOfMassREL'
])
maskette1def
=
spam
.
DIC
.
applyPhi
(
gottenLabel
[
'subvol'
],
PhiNoDisp
,
PhiPoint
=
gottenLabel
[
'centreOfMassREL'
],
interpolationOrder
=
0
)
imagette1def
[
maskette1def
==
0
]
=
numpy
.
nan
imagetteReturns
[
'imagette1'
]
=
imagette1def
imagetteReturns
[
'imagette1mask'
]
=
gottenLabel
[
'subvol'
]
# 2020-09-25 OS and EA: Prepare startStop array for imagette 2 to be extracted with new slicePadded
startStopIm2
=
[
int
(
gottenLabel
[
'boundingBox'
][
0
]
-
max
(
args
.
LABEL_DILATE
,
0
)
+
searchRange
[
0
]
),
int
(
gottenLabel
[
'boundingBox'
][
1
]
+
max
(
args
.
LABEL_DILATE
,
0
)
+
searchRange
[
1
]
+
1
),
int
(
gottenLabel
[
'boundingBox'
][
2
]
-
max
(
args
.
LABEL_DILATE
,
0
)
+
searchRange
[
2
]
),
int
(
gottenLabel
[
'boundingBox'
][
3
]
+
max
(
args
.
LABEL_DILATE
,
0
)
+
searchRange
[
3
]
+
1
),
int
(
gottenLabel
[
'boundingBox'
][
4
]
-
max
(
args
.
LABEL_DILATE
,
0
)
+
searchRange
[
4
]
),
int
(
gottenLabel
[
'boundingBox'
][
5
]
+
max
(
args
.
LABEL_DILATE
,
0
)
+
searchRange
[
5
]
+
1
)]
startStopIm2
=
[
int
(
gottenLabel
[
'boundingBox'
][
0
]
-
max
(
args
.
LABEL_DILATE
,
0
)
+
initialDisplacement
[
0
]
+
searchRange
[
0
]
),
int
(
gottenLabel
[
'boundingBox'
][
1
]
+
max
(
args
.
LABEL_DILATE
,
0
)
+
initialDisplacement
[
0
]
+
searchRange
[
1
]
+
1
),
int
(
gottenLabel
[
'boundingBox'
][
2
]
-
max
(
args
.
LABEL_DILATE
,
0
)
+
initialDisplacement
[
1
]
+
searchRange
[
2
]
),
int
(
gottenLabel
[
'boundingBox'
][
3
]
+
max
(
args
.
LABEL_DILATE
,
0
)
+
initialDisplacement
[
1
]
+
searchRange
[
3
]
+
1
),
int
(
gottenLabel
[
'boundingBox'
][
4
]
-
max
(
args
.
LABEL_DILATE
,
0
)
+
initialDisplacement
[
2
]
+
searchRange
[
4
]
),
int
(
gottenLabel
[
'boundingBox'
][
5
]
+
max
(
args
.
LABEL_DILATE
,
0
)
+
initialDisplacement
[
2
]
+
searchRange
[
5
]
+
1
)]
imagetteReturns
[
'imagette2'
]
=
spam
.
helpers
.
slicePadded
(
im2
,
startStopIm2
)
imagetteReturns
[
'searchRange'
]
=
searchRange
.
copy
()
imagetteReturns
[
'searchCentre'
]
=
nodePositions
[
nodeNumber
]
-
boundingBoxes
[
nodeNumber
,
0
::
2
]
-
searchRange
[
0
::
2
]
-
numpy
.
array
([
max
(
args
.
LABEL_DILATE
,
0
)]
*
3
)
imagetteReturns
[
'initialDisplacement'
]
=
PhiField
[
nodeNumber
,
0
:
3
,
3
].
astype
(
int
)
imagetteReturns
[
'pixelSearchOffset'
]
=
searchRange
[
0
::
2
]
-
numpy
.
array
([
max
(
args
.
LABEL_DILATE
,
0
)]
*
3
)
imagetteReturns
[
'returnStatus'
]
=
1
print
(
imagetteReturns
[
'imagette1'
].
shape
)
print
(
imagetteReturns
[
'imagette1mask'
].
shape
)
print
(
imagetteReturns
[
'imagette2'
].
shape
)
print
(
gottenLabel
[
'boundingBox'
])
print
(
startStopIm2
)
#
print(imagetteReturns['imagette1'].shape)
#
print(imagetteReturns['imagette1mask'].shape)
#
print(imagetteReturns['imagette2'].shape)
#
print(gottenLabel['boundingBox'])
#
print(startStopIm2)
else
:
imagetteReturns
[
'returnStatus'
]
=
0
else
:
imagetteReturns
=
getImagettes
(
nodePositions
[
nodeNumber
],
PhiField
[
nodeNumber
].
copy
(),
searchRange
.
copy
(),
boundingBoxes
[
nodeNumber
],
im1
,
im2
,
im1mask
,
args
.
MASK_COVERAGE
,
greyThreshold
)
# If getImagettes was successful (size check and mask coverage check)
if
imagetteReturns
[
'returnStatus'
]
==
1
:
if
mpi
:
# build message for pixel search worker
m
=
{
'nodeNumber'
:
nodeNumber
,
'im1'
:
imagetteReturns
[
'imagette1'
],
'im2'
:
imagetteReturns
[
'imagette2'
],
'im1mask'
:
imagetteReturns
[
'imagette1mask'
],
'searchRange'
:
imagetteReturns
[
'searchRange'
],
'searchCentre'
:
imagetteReturns
[
'searchCentre'
],
'initialDisplacement'
:
imagetteReturns
[
'initialDisplacement'
],
}
# print "\tBoss: sending node {} to worker {}".format( nodeNumber, worker )
mpiComm
.
send
(
m
,
dest
=
worker
,
tag
=
1
)
# Mark this worker as working
workersActive
[
worker
]
=
True
# NOTE: writeReturns is defined later when receiving messages
else
:
# Not MPI
returns
=
spam
.
DIC
.
correlate
.
pixelSearch
(
imagetteReturns
[
'imagette1'
],
imagetteReturns
[
'imagette2'
],
imagette1mask
=
imagetteReturns
[
'imagette1mask'
],
searchRange
=
imagetteReturns
[
'searchRange'
],
searchCentre
=
imagetteReturns
[
'searchCentre'
])
initialDisplacement
=
imagetteReturns
[
'initialDisplacement'
]
print
(
returns
)
writeReturns
=
True
else
:
# Regardless of MPI or single proc
# Failed to extract imagettes or something
returns
=
spam
.
DIC
.
correlate
.
pixelSearch
(
imagetteReturns
[
'imagette1'
],
imagetteReturns
[
'imagette2'
],
imagette1mask
=
imagetteReturns
[
'imagette1mask'
])
pixelSearchOffset
=
imagetteReturns
[
'pixelSearchOffset'
]
writeReturns
=
True
# Failed to extract imagettes or something
else
:
pixelSearchCC
[
nodeNumber
]
=
0.0
finishedNodes
+=
1
PhiField
[
nodeNumber
,
0
:
3
,
0
:
3
]
=
numpy
.
eye
(
3
)
...
...
@@ -465,28 +421,17 @@ while finishedNodes != numberOfNodes:
returnStatus
[
nodeNumber
]
=
imagetteReturns
[
'returnStatus'
]
# Otherwise spend time looking waiting for replies from workers
elif
mpi
:
message
=
mpiComm
.
recv
(
source
=
mpi4py
.
MPI
.
ANY_SOURCE
,
tag
=
2
,
status
=
mpiStatus
)
tag
=
mpiStatus
.
Get_tag
()
if
tag
==
2
:
worker
=
message
[
0
]
nodeNumber
=
message
[
1
]
returns
=
message
[
2
]
initialDisplacement
=
message
[
3
]
# print "\tBoss: received node {} from worker {}".format( nodeNumber, worker )
workersActive
[
worker
]
=
False
writeReturns
=
True
else
:
print
(
"
\t
Boss: Don't recognise tag "
,
tag
)
#elif mpi:
#message = mpiComm.recv(source=mpi4py.MPI.ANY_SOURCE, tag=2, status=mpiStatus)
# If we have new DVC returns, save them in our output matrices
if
writeReturns
:
finishedNodes
+=
1
writeReturns
=
False
# set translation for this node
PhiField
[
nodeNumber
,
0
:
3
,
3
]
+=
numpy
.
array
(
returns
[
't'
])
PhiField
[
nodeNumber
,
0
:
3
,
3
]
+=
numpy
.
array
(
returns
[
0
])
+
pixelSearchOffset
pixelSearchCC
[
nodeNumber
]
=
returns
[
'cc'
]
pixelSearchCC
[
nodeNumber
]
=
returns
[
1
]
widgets
[
0
]
=
progressbar
.
FormatLabel
(
" CC={:0>7.5f} "
.
format
(
pixelSearchCC
[
nodeNumber
]))
pbar
.
update
(
finishedNodes
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment