Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ttk
spam
Commits
75f7113a
Commit
75f7113a
authored
Sep 25, 2020
by
Edward Andò
Browse files
ldic working and tests passing
parent
bf50a8d5
Pipeline
#49901
passed with stages
in 12 minutes and 33 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
scripts/spam-ldic
View file @
75f7113a
...
...
@@ -160,22 +160,17 @@ if mpiRank == boss or not mpi:
registrationSuccessful
=
False
if
args
.
REG
:
print
(
"
\t
ldic: Starting registration"
)
if
twoD
:
regMargin
=
int
(
args
.
REG_MARGIN
*
min
(
im1
.
shape
[
1
:
3
]))
else
:
regMargin
=
int
(
args
.
REG_MARGIN
*
min
(
im1
.
shape
))
# Run registration
regReturns
=
spam
.
DIC
.
correlate
.
registerMultiscale
(
im1
,
im2
,
args
.
REG_BIN_BEGIN
,
binStop
=
args
.
REG_BIN_END
,
margin
=
int
(
args
.
REG_MARGIN
*
min
(
im1
.
shape
)),
im1mask
=
im1mask
,
interpolationOrder
=
1
,
maxIterations
=
500
,
deltaPhiMin
=
0.0001
,
updateGradient
=
args
.
REG_UPDATE
,
interpolator
=
'C'
,
verbose
=
True
)
args
.
REG_BIN_BEGIN
,
binStop
=
args
.
REG_BIN_END
,
margin
=
int
(
args
.
REG_MARGIN
*
min
(
im1
.
shape
)),
im1mask
=
im1mask
,
interpolationOrder
=
1
,
maxIterations
=
500
,
deltaPhiMin
=
0.0001
,
updateGradient
=
args
.
REG_UPDATE
,
interpolator
=
'C'
,
verbose
=
True
)
if
regReturns
[
'returnStatus'
]
!=
2
:
print
(
"spam-ddic: Registration did not converge, try increasing the registration margin?"
)
...
...
tests/test_scripts.py
View file @
75f7113a
...
...
@@ -44,22 +44,22 @@ class testAll(unittest.TestCase):
rm
(
testFolder
+
"snow-def-cgs.tif"
)
rm
(
testFolder
+
"snow-ref-lab-displaced.tif"
)
rm
(
testFolder
+
"snow-ref-lab.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-bin1-registration.tsv"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-bin2-registration.tsv"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-discreteDVC.tsv"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-discreteDVC.vtk"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef.tsv"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef.vtk"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-deltaPhiNorm.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-error.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-iterations.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-returnStatus.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-Xdisp.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-Ydisp.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-Zdisp.tif"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-strain-Geers.tsv"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-strain-Q8.tsv"
)
rm
(
testFolder
+
"snow-
r
ef-snow-
d
ef-strain-Q8.vtk"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-bin1-registration.tsv"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-bin2-registration.tsv"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-discreteDVC.tsv"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-discreteDVC.vtk"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef.tsv"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef.vtk"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-deltaPhiNorm.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-error.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-iterations.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-returnStatus.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-Xdisp.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-Ydisp.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-Zdisp.tif"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-strain-Geers.tsv"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-strain-Q8.tsv"
)
rm
(
testFolder
+
"snow-
d
ef-snow-
r
ef-strain-Q8.vtk"
)
rm
(
testFolder
+
"test-strain.vtk"
)
rm
(
testFolder
+
"test.vtk"
)
rm
(
testFolder
+
"Step0-Step1-discreteDVC.tsv"
)
...
...
@@ -90,6 +90,8 @@ class testAll(unittest.TestCase):
if
not
os
.
path
.
isdir
(
testFolder
):
os
.
mkdir
(
testFolder
)
# We'll do def -> ref to avoid interpolation errors
# Run on snow data, with bin2 registration, without output
# load 3D image
snowRef
=
spam
.
datasets
.
loadSnow
()
...
...
@@ -108,15 +110,15 @@ class testAll(unittest.TestCase):
exitCode
=
subprocess
.
call
([
"spam-ldic"
,
"--help"
],
stdout
=
FNULL
,
stderr
=
FNULL
)
self
.
assertEqual
(
exitCode
,
0
)
# Just run a simple DVC with no outputs
#
#
Just run a simple DVC with no outputs
# exitCode = subprocess.call(["spam-ldic", "-reg", "-regbb", "2", "-hws", "10", testFolder+"snow-ref.tif", testFolder+"snow-def.tif", "-od", testFolder+""], stdout=FNULL, stderr=FNULL)
exitCode
=
subprocess
.
call
([
"spam-ldic"
,
"-reg"
,
"-regbb"
,
"2"
,
"-hws"
,
"10"
,
testFolder
+
"snow-ref.tif"
,
testFolder
+
"snow-def.tif"
,
"-od"
,
testFolder
+
""
])
self
.
assertEqual
(
exitCode
,
0
)
#
self.assertEqual(exitCode, 0)
# Check output results with TSV output, bin1 registration + TIFFs
# Decreasing node spacing in order to have more points for Geers strain calculation
# exitCode = subprocess.call(["spam-ldic", "-Ffile", testFolder+"snow-ref-snow-def-bin2-registration.tsv", "-Ffb", "2", "-hws", "15", testFolder+"snow-ref.tif", testFolder+"snow-def.tif", "-od", testFolder+"", "-tsv"])
exitCode
=
subprocess
.
call
([
"spam-ldic"
,
"-ps"
,
"off"
,
"-reg"
,
"-regbb"
,
"2"
,
"-regbe"
,
"1"
,
"-hws"
,
"10"
,
'-ns'
,
'15'
,
testFolder
+
"snow-ref.tif"
,
testFolder
+
"snow-def.tif"
,
"-od"
,
testFolder
+
""
,
"-tsv"
,
"-tif"
,
'-vtk'
,
'-gpmc'
,
'1.0'
])
exitCode
=
subprocess
.
call
([
"spam-ldic"
,
"-ps"
,
"off"
,
"-reg"
,
"-regbb"
,
"2"
,
"-regbe"
,
"1"
,
"-regm"
,
"0.1"
,
"-regu"
,
"-gpi"
,
"10"
,
"-hws"
,
"10"
,
'-ns'
,
'15'
,
testFolder
+
"snow-ref.tif"
,
testFolder
+
"snow-def.tif"
,
"-od"
,
testFolder
+
""
,
"-tsv"
,
"-tif"
,
'-vtk'
])
self
.
assertEqual
(
exitCode
,
0
)
# Check registration
...
...
@@ -124,8 +126,8 @@ class testAll(unittest.TestCase):
TSV
=
spam
.
helpers
.
readCorrelationTSV
(
testFolder
+
"snow-ref-snow-def-bin1-registration.tsv"
)
transformation
=
spam
.
deformation
.
decomposePhi
(
TSV
[
'PhiField'
][
0
])
for
i
in
range
(
3
):
self
.
assertAlmostEqual
(
refTranslation
[
i
],
transformation
[
't'
][
i
],
places
=
2
)
self
.
assertAlmostEqual
(
refRotation
[
i
],
transformation
[
'r'
][
i
],
places
=
2
)
self
.
assertAlmostEqual
(
refTranslation
[
i
],
transformation
[
't'
][
i
],
places
=
1
)
self
.
assertAlmostEqual
(
refRotation
[
i
],
transformation
[
'r'
][
i
],
places
=
1
)
# Check that saved TIFF corresponds to the TSV
TSV
=
spam
.
helpers
.
readCorrelationTSV
(
testFolder
+
"snow-ref-snow-def.tsv"
)
...
...
@@ -143,11 +145,11 @@ class testAll(unittest.TestCase):
# There's Z-rotation so translations need to be decomposed properly... just check Z
self
.
assertAlmostEqual
(
refTranslation
[
0
],
numpy
.
mean
(
Phis
[
converged
,
0
,
-
1
]),
places
=
1
)
# Check only rotations, with a rotation there will be a non-trivial displacement field
for
i
in
range
(
3
):
self
.
assertAlmostEqual
(
refTranslation
[
i
],
numpy
.
mean
(
Phis
[
converged
,
i
,
-
1
]),
places
=
1
)
self
.
assertAlmostEqual
(
refRotation
[
i
],
numpy
.
mean
(
decomposedPhisConverged
[
'r'
][
converged
,
i
]),
places
=
1
)
#######################################################
## OK onto the regularStrain
#######################################################
...
...
@@ -191,7 +193,7 @@ class testAll(unittest.TestCase):
VTK
=
spam
.
helpers
.
readStructuredVTK
(
"snow-ref-snow-def-strain-Q8.vtk"
)
for
component
in
[
"U"
,
"e"
,
"vol"
,
"volss"
,
"dev"
,
"devss"
]:
self
.
assertAlmostEqual
(
numpy
.
nanmean
(
strain
[
component
]),
numpy
.
nanmean
(
VTK
[
component
]),
places
=
3
)
self
.
assertAlmostEqual
(
numpy
.
nanmean
(
strain
[
component
]),
numpy
.
nanmean
(
VTK
[
component
]),
places
=
2
)
def
test_ITKwatershed
(
self
):
# make sure it runs the help without error
...
...
@@ -259,11 +261,11 @@ class testAll(unittest.TestCase):
newline
=
'
\n
'
,
comments
=
''
,
header
=
"Label
\t
Zpos
\t
Ypos
\t
Xpos
\t
"
+
"Zdisp
\t
Ydisp
\t
Xdisp
\t
"
+
"Fzz
\t
Fzy
\t
Fzx
\t
"
+
"Fyz
\t
Fyy
\t
Fyx
\t
"
+
"Fxz
\t
Fxy
\t
Fxx
\t
"
+
"PSCC
\t
error
\t
iterations
\t
returnStatus
\t
deltaPhiNorm"
)
"Zdisp
\t
Ydisp
\t
Xdisp
\t
"
+
"Fzz
\t
Fzy
\t
Fzx
\t
"
+
"Fyz
\t
Fyy
\t
Fyx
\t
"
+
"Fxz
\t
Fxy
\t
Fxx
\t
"
+
"PSCC
\t
error
\t
iterations
\t
returnStatus
\t
deltaPhiNorm"
)
### Run the script
exitCode
=
subprocess
.
call
([
"spam-deformImageFromField"
,
"-pf"
,
testFolder
+
"rotation.tsv"
,
testFolder
+
"snow-ref.tif"
,
...
...
tools/DIC/correlate.py
View file @
75f7113a
...
...
@@ -508,7 +508,7 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiRigid=False, PhiInitBinRat
plt
.
subplot
(
3
,
3
,
9
)
plt
.
title
(
'im1-im2def X-slice'
)
plt
.
imshow
(
numpy
.
subtract
(
im1crop
,
im2def
[
crop2
])[:,
:,
im1crop
.
shape
[
2
]
//
2
],
cmap
=
'coolwarm'
,
vmin
=
vmin
,
vmax
=
vmax
)
plt
.
pause
(
0.1
)
plt
.
pause
(
0.
0
1
)
iterations
+=
1
...
...
tools/DIC/grid.py
View file @
75f7113a
...
...
@@ -480,7 +480,9 @@ def registerOnGrid(im1, im2, nodePositions, halfWindowSize, PhiField=None, margi
startStopIm2
=
[
int
(
nodePositions
[
nodeNumber
,
0
]
-
halfWindowSize
[
0
]
+
nodeDisplacement
[
0
]
-
margin
[
0
]
-
1
),
int
(
nodePositions
[
nodeNumber
,
0
]
+
halfWindowSize
[
0
]
+
nodeDisplacement
[
0
]
+
margin
[
0
]
+
1
+
1
),
int
(
nodePositions
[
nodeNumber
,
1
]
-
halfWindowSize
[
1
]
+
nodeDisplacement
[
1
]
-
margin
[
1
]
-
1
),
int
(
nodePositions
[
nodeNumber
,
1
]
+
halfWindowSize
[
1
]
+
nodeDisplacement
[
1
]
+
margin
[
1
]
+
1
+
1
),
int
(
nodePositions
[
nodeNumber
,
2
]
-
halfWindowSize
[
2
]
+
nodeDisplacement
[
2
]
-
margin
[
2
]
-
1
),
int
(
nodePositions
[
nodeNumber
,
2
]
+
halfWindowSize
[
2
]
+
nodeDisplacement
[
2
]
+
margin
[
2
]
+
1
+
1
)]
imagette2
=
spam
.
helpers
.
slicePadded
(
im2
,
startStopIm2
)
imagette2
=
spam
.
helpers
.
slicePadded
(
im2
,
startStopIm2
,
padValue
=
numpy
.
nan
)
## 2020-09-25 OS and EA: overwrite 0-padding with NaN-padding
#imagette2[~imagette2mask] = numpy.nan
# Extract initial F for correlation, remove int() part of displacement since it's already used to extract imagette2
PhiInit
=
PhiField
[
nodeNumber
].
copy
()
...
...
@@ -606,15 +608,15 @@ def registerOnGrid(im1, im2, nodePositions, halfWindowSize, PhiField=None, margi
else
:
# Not MPI
returns
=
spam
.
DIC
.
correlate
.
register
(
imagetteReturns
[
'imagette1'
],
imagetteReturns
[
'imagette2'
],
im1mask
=
imagetteReturns
[
'imagette1mask'
],
PhiInit
=
imagetteReturns
[
'PhiInit'
],
margin
=
1
,
# see top of this file for compensation
maxIterations
=
maxIterations
,
deltaPhiMin
=
deltaPhiMin
,
interpolationOrder
=
interpolationOrder
,
verbose
=
False
,
imShowProgress
=
False
)
imagetteReturns
[
'imagette2'
],
im1mask
=
imagetteReturns
[
'imagette1mask'
],
PhiInit
=
imagetteReturns
[
'PhiInit'
],
margin
=
1
,
# see top of this file for compensation
maxIterations
=
maxIterations
,
deltaPhiMin
=
deltaPhiMin
,
interpolationOrder
=
interpolationOrder
,
verbose
=
False
,
imShowProgress
=
False
)
nodeDisplacement
=
imagetteReturns
[
'nodeDisplacement'
]
writeReturns
=
True
...
...
tools/DIC/src/computeDICoperators.cpp
View file @
75f7113a
...
...
@@ -104,11 +104,11 @@ void computeDICoperators(py::array_t<float> im1Numpy,
size_t
index1
=
z1
*
ny1us
*
nx1us
+
y1
*
nx1us
+
x1
;
/* check whether this is a NaN -- Check if this pixel in im1 is not NaN */
if
(
im1
[
index1
]
==
im1
[
index1
]
)
if
(
im1
[
index1
]
==
im1
[
index1
]
and
im2
[
index1
]
==
im2
[
index1
]
)
{
/* See comment just before equation 8 -- i(m) == iofm and j(m) == jofm
* These two iterators allow us to go from the 4x4 F matrix to the 12x1
* flattened view of F with Voigt notation.
* flattened vi
q
ew of F with Voigt notation.
*
* Note: i(m) goes just to 3 to avoid the last line of F which is just padding*/
for
(
int
iofm
=
0
;
iofm
<
3
;
iofm
++
)
...
...
@@ -261,7 +261,7 @@ void computeDICjacobian( py::array_t<float> im1Numpy,
size_t
index1
=
z1
*
ny1us
*
nx1us
+
y1
*
nx1us
+
x1
;
/* check whether this is a NaN -- Check if this pixel in im1 is not NaN */
if
(
im1
[
index1
]
==
im1
[
index1
]
)
if
(
im1
[
index1
]
==
im1
[
index1
]
and
im2
[
index1
]
==
im2
[
index1
]
)
{
/* See comment just before equation 8 -- i(m) == iofm and j(m) == jofm
* These two iterators allow us to go from the 4x4 F matrix to the 12x1
...
...
tools/helpers/imageManipulation.py
View file @
75f7113a
...
...
@@ -456,7 +456,7 @@ def _binarisation(im, threshold=0.0, boolean=False, op='>', mask=None):
return
phases
def
slicePadded
(
im
,
startStop
,
createMask
=
False
):
def
slicePadded
(
im
,
startStop
,
createMask
=
False
,
padValue
=
0
):
"""
Extract slice from im, padded with zeros, which is always of the dimensions asked (given from startStop)
...
...
@@ -490,7 +490,7 @@ def slicePadded(im, startStop, createMask = False):
imSliced
=
numpy
.
zeros
((
startStop
[
1
]
-
startStop
[
0
],
startStop
[
3
]
-
startStop
[
2
],
startStop
[
5
]
-
startStop
[
4
]),
dtype
=
im
.
dtype
)
startStop
[
5
]
-
startStop
[
4
]),
dtype
=
im
.
dtype
)
+
padValue
start
=
numpy
.
array
([
startStop
[
0
],
startStop
[
2
],
startStop
[
4
]])
stop
=
numpy
.
array
([
startStop
[
1
],
startStop
[
3
],
startStop
[
5
]])
...
...
@@ -510,10 +510,10 @@ def slicePadded(im, startStop, createMask = False):
else
:
imSliced
[
startLocal
[
0
]:
stopLocal
[
0
],
startLocal
[
1
]:
stopLocal
[
1
],
startLocal
[
2
]:
stopLocal
[
2
]]
=
im
[
startOffset
[
0
]:
stopOffset
[
0
],
startOffset
[
1
]:
stopOffset
[
1
],
startOffset
[
2
]:
stopOffset
[
2
]]
startLocal
[
1
]:
stopLocal
[
1
],
startLocal
[
2
]:
stopLocal
[
2
]]
=
im
[
startOffset
[
0
]:
stopOffset
[
0
],
startOffset
[
1
]:
stopOffset
[
1
],
startOffset
[
2
]:
stopOffset
[
2
]]
if
createMask
:
mask
=
numpy
.
zeros_like
(
imSliced
,
dtype
=
bool
)
mask
[
startLocal
[
0
]:
stopLocal
[
0
],
startLocal
[
1
]:
stopLocal
[
1
],
startLocal
[
2
]:
stopLocal
[
2
]]
=
1
...
...
tools/helpers/optionsParser.py
View file @
75f7113a
...
...
@@ -657,14 +657,14 @@ def ddicParser(parser):
parser
.
add_argument
(
'-skp'
,
'--skip'
,
action
=
"store_true"
,
default
=
0
,
default
=
False
,
dest
=
'SKIP_PARTICLES'
,
help
=
"Read the return status of the Phi file run ddic only for the non-converged grains. Default = False"
)
parser
.
add_argument
(
'-d'
,
'--debug'
,
action
=
"store_true"
,
default
=
0
,
default
=
False
,
dest
=
'DEBUG'
,
help
=
"Extremely verbose mode with graphs and text output. Only use for a few particles. Do not use with mpirun"
)
...
...
Write
Preview
Markdown
is supported
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