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
6ec06eb3
Commit
6ec06eb3
authored
Apr 20, 2021
by
Edward Andò
Browse files
slight improvement in readability in ldic
parent
8e3008e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
scripts/spam-ldic
View file @
6ec06eb3
...
...
@@ -177,10 +177,10 @@ for im2number in range(1, len(args.inFiles)):
if
args
.
MASK1
:
assert
(
im1
.
shape
==
im1mask
.
shape
),
"
\n
im1 and im1mask must have the same size! Exiting."
REG
=
False
nodePositionsFile
=
None
PhiField
=
None
# Three cases to handle:
# 1. phi file is reg -> define nodes and apply reg
# 2. phi file is field -> take everything and check NS if passed
# 3. no phi file -> define nodes
if
args
.
PHIFILE
is
not
None
:
PhiFromFile
=
spam
.
helpers
.
readCorrelationTSV
(
args
.
PHIFILE
.
name
,
fieldBinRatio
=
args
.
PHIFILE_BIN_RATIO
)
if
PhiFromFile
is
None
:
...
...
@@ -201,60 +201,60 @@ for im2number in range(1, len(args.inFiles)):
print
(
"
\t\t
"
,
decomposedPhiInit
[
'z'
])
del
decomposedPhiInit
REG
=
True
# Create nodes
if
args
.
NS
is
None
:
print
(
f
"spam-ldic: You passed a registration file
{
args
.
PHIFILE
.
name
}
, I need -ns to be defined"
)
exit
()
nodePositions
,
nodesDim
=
spam
.
DIC
.
makeGrid
(
im1
.
shape
,
args
.
NS
)
numberOfNodes
=
nodePositions
.
shape
[
0
]
# We have a registration to apply to all points.
# This is done in 2 steps:
# 1. by copying the registration's little F to the Fs of all points
# 2. by calling the decomposePhi function to compute the translation of each point
# Now that we know how many points we want to correlate, initalise PhiField
PhiField
=
numpy
.
zeros
((
numberOfNodes
,
4
,
4
))
for
node
in
range
(
numberOfNodes
):
if
args
.
APPLY_F
==
"all"
:
PhiField
[
node
]
=
PhiInit
.
copy
()
elif
args
.
APPLY_F
==
"rigid"
:
PhiField
[
node
]
=
spam
.
deformation
.
computeRigidPhi
(
PhiInit
.
copy
())
else
:
PhiField
[
node
]
=
numpy
.
eye
(
4
)
# trasnlation application
PhiField
[
node
][
0
:
3
,
-
1
]
=
spam
.
deformation
.
decomposePhi
(
PhiInit
.
copy
(),
PhiCentre
=
PhiFromFile
[
"fieldCoords"
][
0
],
PhiPoint
=
nodePositions
[
node
])[
"t"
]
else
:
# we have a Phi field and not a registration
nodePositions
=
PhiFromFile
[
"fieldCoords"
]
numberOfNodes
=
nodePositions
.
shape
[
0
]
nodeSpacingFile
=
numpy
.
array
([
numpy
.
unique
(
nodePositions
[:,
i
])[
1
]
-
numpy
.
unique
(
nodePositions
[:,
i
])[
0
]
if
len
(
numpy
.
unique
(
nodePositions
[:,
i
]))
>
1
else
numpy
.
unique
(
nodePositions
[:,
i
])[
0
]
for
i
in
range
(
3
)])
PhiField
=
PhiFromFile
[
"PhiField"
]
# In case NS is also defined, complain, but if it's the same as the loaded data, continue
if
args
.
NS
is
not
None
:
# compare them
if
not
numpy
.
allclose
(
numpy
.
array
(
args
.
NS
),
nodeSpacingFile
,
atol
=
0.0
):
print
(
f
"spam-ldic: you passed a -ns=
{
args
.
NS
}
which contradicts the node spacing in your Phi Field TSV of
{
nodeSpacingFile
}
"
)
print
(
f
"
\t
hint 1: if you pass a Phi Field TSV you don't need to also define the node spacing"
)
print
(
f
"
\t
hint 2: if you want to use your Phi Field TSV
{
args
.
PHIFILE
.
name
}
on a finer node spacing, pass it with spam-passPhiField"
)
exit
()
else
:
print
(
f
"spam-ldic: passing -ns with a Phi Field TSV is not needed"
)
# If it's compatible, update args.NS
args
.
NS
=
nodeSpacingFile
# If the read Phi-file contains multiple lines it's an F field!
else
:
#print("spam-pixelSearch: Assuming loaded PhiFile is coherent with the current run.")
nodePositionsFile
=
PhiFromFile
[
"fieldCoords"
]
PhiField
=
PhiFromFile
[
"PhiField"
]
if
nodePositionsFile
is
None
:
else
:
# No Phi file at all
if
args
.
NS
is
None
:
print
(
"spam-
pixelSearch: You're in regular grid mode, but no -ns is set and no Phi Field TSV has been passed, exiting
."
)
print
(
"spam-
ldic: I don't have a phi file or -ns defined, so don't know how to define grid..
."
)
exit
()
nodePositions
,
nodesDim
=
spam
.
DIC
.
makeGrid
(
im1
.
shape
,
args
.
NS
)
numberOfNodes
=
nodePositions
.
shape
[
0
]
else
:
# nodePositionsFile is defined -- i.e., we read a regular PhiField TSV
nodeSpacingFile
=
numpy
.
array
([
numpy
.
unique
(
nodePositionsFile
[:,
i
])[
1
]
-
numpy
.
unique
(
nodePositionsFile
[:,
i
])[
0
]
if
len
(
numpy
.
unique
(
nodePositionsFile
[:,
i
]))
>
1
else
numpy
.
unique
(
nodePositionsFile
[:,
i
])[
0
]
for
i
in
range
(
3
)])
nodePositions
=
nodePositionsFile
if
args
.
NS
is
not
None
:
# compare them
if
not
numpy
.
allclose
(
numpy
.
array
(
args
.
NS
),
nodeSpacingFile
,
atol
=
0.0
):
print
(
f
"spam-pixelSearch: you passed a -ns=
{
args
.
NS
}
which contradicts the node spacing in your Phi Field TSV of
{
nodeSpacingFile
}
"
)
print
(
f
"
\t
hint 1: if you pass a Phi Field TSV you don't need to also define the node spacing"
)
print
(
f
"
\t
hint 2: if you want to use your Phi Field TSV
{
args
.
PHIFILE
.
name
}
on a finer node spacing, pass it with spam-passPhiField"
)
exit
()
else
:
print
(
f
"spam-pixelSearch: passing -ns with a Phi Field TSV is not needed"
)
else
:
args
.
NS
=
nodeSpacingFile
###############################################################
numberOfNodes
=
nodePositions
.
shape
[
0
]
if
PhiField
is
None
:
# Either REG mode, or not TSV at all
# Now that we know how many points we want to correlate, initalise PhiField
PhiField
=
numpy
.
zeros
((
numberOfNodes
,
4
,
4
))
for
node
in
range
(
numberOfNodes
):
PhiField
[
node
]
=
numpy
.
eye
(
4
)
if
REG
:
# If we were passed a registration Phi TSV, apply it to each point
for
node
in
range
(
numberOfNodes
):
if
args
.
APPLY_F
==
"all"
:
PhiField
[
node
]
=
PhiInit
.
copy
()
elif
args
.
APPLY_F
==
"rigid"
:
PhiField
[
node
]
=
spam
.
deformation
.
computeRigidPhi
(
PhiInit
.
copy
())
PhiField
[
node
][
0
:
3
,
-
1
]
=
spam
.
deformation
.
decomposePhi
(
PhiInit
.
copy
(),
PhiCentre
=
PhiFromFile
[
"fieldCoords"
][
0
],
PhiPoint
=
nodePositions
[
node
])[
"t"
]
finishedNodes
=
0
error
=
numpy
.
zeros
((
numberOfNodes
))
...
...
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