Commit 8e3008e1 authored by Edward Andò's avatar Edward Andò
Browse files

-ns optional when Phi field is passed

parent 105ff16b
Pipeline #65068 failed with stages
in 12 minutes and 8 seconds
......@@ -134,8 +134,15 @@ if args.PHIFILE is not None:
# If the read Phi-file contains multiple lines it's an F field!
else:
print("spam-ldic: Assuming loaded PhiFile is coherent with the current run (i.e., labels are the same).")
#print("spam-ddic: Assuming loaded PhiFile is coherent with the current run (i.e., labels are the same).")
PhiField = PhiFromFile["PhiField"]
# Also check that the node positions are approx the same as from the labelled image above:
if not numpy.allclose(PhiFromFile["fieldCoords"], centresOfMass, atol=0.1):
print(PhiFromFile["fieldCoords"])
print(centresOfMass)
print(f"spam-ddic: Input PhiField positions from {args.PHIFILE.name} are not within 1px of the centre of mass of the labels from {args.lab1.name}, this seems dangerous.")
print(f"\tplease consider using spam-passPhiField to apply your PhiField to a new labelled image")
exit()
def correlateOneLabel(label):
......
......@@ -85,16 +85,6 @@ else:
if twoD:
interpolator = 'python'
### Grid creation
nodePositions, nodesDim = spam.DIC.makeGrid(im1.shape, args.NS)
# start setting up
numberOfNodes = nodePositions.shape[0]
boundingBoxes = numpy.zeros((numberOfNodes, 6), dtype=int)
# -1 and +1 here are to compensate a margin = 1 in the call to spam.DIC.register
boundingBoxes[:, 0::2] = nodePositions - args.HWS - 1
boundingBoxes[:, 1::2] = nodePositions + args.HWS + 1
margin = [-args.MARGIN[0], args.MARGIN[0],
-args.MARGIN[1], args.MARGIN[1],
-args.MARGIN[2], args.MARGIN[2]]
......@@ -187,30 +177,20 @@ for im2number in range(1, len(args.inFiles)):
if args.MASK1:
assert(im1.shape == im1mask.shape), "\nim1 and im1mask must have the same size! Exiting."
# Initialise field of Fs with the identity matrix
PhiField = numpy.zeros((nodePositions.shape[0], 4, 4))
for node in range(nodePositions.shape[0]):
PhiField[node] = numpy.eye(4)
# define empty rigid displacements for registration:
#if args.REGSUB: rigidDisp = numpy.zeros((nodePositions.shape[0], 3))
##################################################################
# Rough estimates of displacement:
# Option 1: Do a registration (single-image correlation)
# Option 2: Load a previous registration
# Option 3: Perform a displacement-only pixel search
# Option X: (one day) Perform FFT correlation
##################################################################
# Option 2 - load previous DVC
#################################
REG = False
nodePositionsFile = None
PhiField = None
if args.PHIFILE is not None:
PhiFromFile = spam.helpers.readCorrelationTSV(args.PHIFILE.name, fieldBinRatio=args.PHIFILE_BIN_RATIO)
if PhiFromFile is None:
print(f"\tFailed to read your TSV file passed with -pf {args.PHIFILE.name}")
exit()
# If the read Phi-file has only one line -- it's a single point registration!
if PhiFromFile['fieldCoords'].shape[0] == 1:
PhiInit = PhiFromFile['PhiField'][0]
print("\tI read a registration from a file in binning {}".format(args.PHIFILE_BIN_RATIO))
PhiInit = PhiFromFile['PhiField'][0]
print(f"\tI read a registration from a file in binning {args.PHIFILE_BIN_RATIO}")
decomposedPhiInit = spam.deformation.decomposePhi(PhiInit)
print("\tTranslations (px)")
......@@ -219,32 +199,62 @@ for im2number in range(1, len(args.inFiles)):
print("\t\t", decomposedPhiInit['r'])
print("\tZoom")
print("\t\t", decomposedPhiInit['z'])
del decomposedPhiInit
REG = True
# 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
for node in range(nodePositions.shape[0]):
PhiField[node] = PhiInit.copy()
PhiField[node][0:3, -1] = spam.deformation.decomposePhi(PhiInit.copy(), PhiCentre=PhiFromFile["fieldCoords"][0], PhiPoint=nodePositions[node])["t"]
## Now recompute F to be only rigid, and calculate rigid-body translations for each point
#if args.REGSUB:
#PhiInitRigid = spam.deformation.computeRigidPhi(PhiInit.copy())
#for node in range(nodePositions.shape[0]):
#rigidDisp[node] = spam.deformation.decomposePhi(PhiInitRigid.copy(),
#PhiCentre=regCentre,
#PhiPoint=nodePositions[node])["t"]
# If the read Phi-file contains multiple lines it's an F field!
else:
print("spam-ldic: Assuming loaded PhiFile is coherent with the current run.")
PhiField = PhiFromFile["PhiField"]
#print("spam-pixelSearch: Assuming loaded PhiFile is coherent with the current run.")
nodePositionsFile = PhiFromFile["fieldCoords"]
PhiField = PhiFromFile["PhiField"]
if nodePositionsFile is None:
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.")
exit()
nodePositions, nodesDim = spam.DIC.makeGrid(im1.shape, args.NS)
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"\thint 1: if you pass a Phi Field TSV you don't need to also define the node spacing")
print(f"\thint 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))
......
......@@ -71,44 +71,10 @@ im2 = tifffile.imread(args.im2.name)
if len(im2.shape) == 2: im2 = im2[numpy.newaxis, ...]
###############################################################
### Main switch for LAB or GRID mode
###############################################################
####If there is a labelled image, load that...
if args.LAB1 is not None:
lab1 = tifffile.imread(args.LAB1.name).astype(spam.label.labelType)
boundingBoxes = spam.label.boundingBoxes(lab1)
nodePositions = spam.label.centresOfMass(lab1, boundingBoxes=boundingBoxes)
numberOfNodes = nodePositions.shape[0]
im1mask = None
im2mask = None
### Otherwise we are in node spacing and half-window size mode
else:
nodePositions, nodesDim = spam.DIC.makeGrid(im1.shape, args.NS)
# start setting up
numberOfNodes = nodePositions.shape[0]
if args.MASK1:
im1mask = tifffile.imread(args.MASK1.name) != 0
if len(im1mask.shape) == 2:
im1mask = im1mask[numpy.newaxis, ...]
else:
im1mask = None
if args.MASK2:
im2mask = tifffile.imread(args.MASK2.name) != 0
if len(im2mask.shape) == 2:
im2mask = im2mask[numpy.newaxis, ...]
else:
im2mask = None
###############################################################
# Now that we know how many points we want to correlate, initalise PhiField
PhiField = numpy.zeros((nodePositions.shape[0], 4, 4))
for node in range(nodePositions.shape[0]):
PhiField[node] = numpy.eye(4)
REG = False
nodePositionsFile = None
PhiField = None
if args.PHIFILE is not None:
PhiFromFile = spam.helpers.readCorrelationTSV(args.PHIFILE.name, fieldBinRatio=args.PHIFILE_BIN_RATIO)
......@@ -130,61 +96,94 @@ if args.PHIFILE is not None:
print("\t\t", decomposedPhiInit['z'])
del decomposedPhiInit
REG = True
# 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
for node in range(nodePositions.shape[0]):
PhiField[node] = PhiInit.copy()
PhiField[node][0:3, -1] = spam.deformation.decomposePhi(PhiInit.copy(), PhiCentre=PhiFromFile["fieldCoords"][0], PhiPoint=nodePositions[node])["t"]
# If the read Phi-file contains multiple lines it's an F field!
else:
if args.PHIFILE_DIRECT:
print("spam-pixelSearch: Assuming loaded PhiFile is coherent with the current run.")
PhiField = PhiFromFile["PhiField"]
else:
# We don't trust this completely, re-interpolate it onto the grid
# Read the coordinates and values of the input F field
fieldCoords = PhiFromFile["fieldCoords"]
fieldValues = PhiFromFile["PhiField"]
#print("spam-pixelSearch: Assuming loaded PhiFile is coherent with the current run.")
nodePositionsFile = PhiFromFile["fieldCoords"]
PhiField = PhiFromFile["PhiField"]
# Create the k-d tree of the coordinates of the input F field
from scipy.spatial import KDTree
nNeighbours = args.NEIGHBOURS
fieldTree = KDTree(fieldCoords)
###############################################################
### Main switch for LAB or GRID mode
###############################################################
####If there is a labelled image, load that...
if args.LAB1 is not None:
lab1 = tifffile.imread(args.LAB1.name).astype(spam.label.labelType)
boundingBoxes = spam.label.boundingBoxes(lab1)
nodePositions = spam.label.centresOfMass(lab1, boundingBoxes=boundingBoxes)
numberOfNodes = nodePositions.shape[0]
im1mask = None
im2mask = None
# Loop over each point of the current grid
for node in range(nodePositions.shape[0]):
# if verbose: print "\nWorking on node {} {:0.2f}%".format( node, (node/float(numberofPoints))*100)
# reset F to zero, since we'll be doing an additive interpolation at the bottom here
PhiField[node][0:3, 0:3] = 0
if nodePositionsFile is not None:
if not numpy.allclose(nodePositionsFile, nodePositions, atol=1.0):
print(f"spam-pixelSearch: Input PhiField positions from {args.PHIFILE.name} are not within 1px of the centre of mass of the labels from {args.LAB1}, this seems dangerous.")
print(f"\tplease consider using spam-passPhiField to apply your PhiField to a new labelled image")
exit()
# Calculate the distance of the point of the current grid to the points of the input F field
distance, indices = fieldTree.query(nodePositions[node], k=nNeighbours)
### Otherwise we are in node spacing and half-window size mode
else:
if args.MASK1 is not None:
im1mask = tifffile.imread(args.MASK1.name) != 0
if len(im1mask.shape) == 2:
im1mask = im1mask[numpy.newaxis, ...]
else:
im1mask = None
# Check if we've hit the same point in the two grids
if numpy.any(distance == 0):
if args.MASK2 is not None:
im2mask = tifffile.imread(args.MASK2.name) != 0
if len(im2mask.shape) == 2:
im2mask = im2mask[numpy.newaxis, ...]
else:
im2mask = None
# Copy F of that point to the F in the current grid point
PhiField[node] = fieldValues[indices][numpy.where(distance == 0)].copy()
# If not, consider the closest neighbours
else:
if nodePositionsFile is None:
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.")
exit()
nodePositions, nodesDim = spam.DIC.makeGrid(im1.shape, args.NS)
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"\thint 1: if you pass a Phi Field TSV you don't need to also define the node spacing")
print(f"\thint 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
# Compute the "Inverse Distance Weighting" since the closest points should have the major influence
weightSumInv = sum(1/distance)
###############################################################
# Loop over each neighbour
for neighbour in range(nNeighbours):
numberOfNodes = nodePositions.shape[0]
# Calculate it's weight
weightInv = (1/distance[neighbour])/float(weightSumInv)
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)
# Fill the F of the current grid point with the weighted F components of the ith nearest neighbour in the input F field
PhiField[node][:-1] += fieldValues[indices[neighbour]][:-1]*weightInv
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"]
### This vvv is the pixelSearchOnGrid function from grid.py
......
......@@ -258,25 +258,27 @@ if args.TSV:
# 3 node positions,
# F[0:3,0:3]
# Pixel-search CC
TSVheader = "NodeNumber\tZpos\tYpos\tXpos\tFzz\tFzy\tFzx\tZdisp\tFyz\tFyy\tFyx\tYdisp\tFxz\tFxy\tFxx\tXdisp\tpixelSearchCC\treturnStatus\terror\tdeltaPhiNorm\titerations"
outMatrix = numpy.array([numpy.array(range(guidingPoints.shape[0])),
guidingPoints[:, 0], guidingPoints[:, 1], guidingPoints[:, 2],
PhiField[:, 0, 0], PhiField[:, 0, 1], PhiField[:, 0, 2], PhiField[:, 0, 3],
PhiField[:, 1, 0], PhiField[:, 1, 1], PhiField[:, 1, 2], PhiField[:, 1, 3],
PhiField[:, 2, 0], PhiField[:, 2, 1], PhiField[:, 2, 2], PhiField[:, 2, 3],
pixelSearchCC,
returnStatus,
error,
deltaPhiNorm,
iterations]).T
numpy.savetxt(args.OUT_DIR+"/"+args.PREFIX+".tsv",
outMatrix,
fmt='%.7f',
delimiter='\t',
newline='\n',
comments='',
header=TSVheader)
#if args.LAB1 is None:
TSVheader = "NodeNumber\tZpos\tYpos\tXpos\tFzz\tFzy\tFzx\tZdisp\tFyz\tFyy\tFyx\tYdisp\tFxz\tFxy\tFxx\tXdisp\tpixelSearchCC\treturnStatus\terror\tdeltaPhiNorm\titerations"
outMatrix = numpy.array([numpy.array(range(guidingPoints.shape[0])),
guidingPoints[:, 0], guidingPoints[:, 1], guidingPoints[:, 2],
PhiField[:, 0, 0], PhiField[:, 0, 1], PhiField[:, 0, 2], PhiField[:, 0, 3],
PhiField[:, 1, 0], PhiField[:, 1, 1], PhiField[:, 1, 2], PhiField[:, 1, 3],
PhiField[:, 2, 0], PhiField[:, 2, 1], PhiField[:, 2, 2], PhiField[:, 2, 3],
pixelSearchCC,
returnStatus,
error,
deltaPhiNorm,
iterations]).T
numpy.savetxt(args.OUT_DIR+"/"+args.PREFIX+".tsv",
outMatrix,
fmt='%.7f',
delimiter='\t',
newline='\n',
comments='',
header=TSVheader)
# Collect data into VTK output
if args.VTK:
......@@ -306,4 +308,4 @@ if args.VTK:
'pixelSearchCC': pixelSearchCC
}
spam.helpers.writeGlyphsVTK(guidingPoints, VTKglyphDict, fileName=args.OUT_DIR + "/" + args.PREFIX + ".vtk")
\ No newline at end of file
spam.helpers.writeGlyphsVTK(guidingPoints, VTKglyphDict, fileName=args.OUT_DIR + "/" + args.PREFIX + ".vtk")
......@@ -50,8 +50,8 @@ class testAll(unittest.TestCase):
rm(testFolder+"balls-5a-pixelSearch.tsv")
rm(testFolder+"balls-5b-ddic.tsv")
rm(testFolder+"balls-5b-ddic.vtk")
rm(testFolder+"balls-5c-pixelSearchPropagate.tsv")
rm(testFolder+"balls-5d-ddic.tsv")
#rm(testFolder+"balls-5c-pixelSearchPropagate.tsv")
#rm(testFolder+"balls-5d-ddic.tsv")
rm(testFolder+"balls-5d-ddic.vtk")
rm(testFolder+"balls-6a-pixelSearch.tsv")
rm(testFolder+"extreme-im1-extreme-im2-ddic.tsv")
......@@ -251,7 +251,7 @@ class testAll(unittest.TestCase):
exitCode = subprocess.call(["spam-pixelSearch",
"-pf", testFolder + "snow-grid-registration.tsv",
"-sr", "-2", "2", "-2", "2", "-2", "2",
"-glt", "5000", "-hws", "10",
"-glt", "5000", "-hws", "10", "-ns", "20",
testFolder + "snow-ref.tif", testFolder + "snow-def.tif",
"-od", testFolder + "",
"-pre", "snow-grid-3a",
......@@ -271,7 +271,7 @@ class testAll(unittest.TestCase):
"{}".format(int(refTranslation[0]-2)), "{}".format(int(refTranslation[0]+2)),
"{}".format(int(refTranslation[1]-2)), "{}".format(int(refTranslation[1]+2)),
"{}".format(int(refTranslation[2]-2)), "{}".format(int(refTranslation[2]+2)),
"-glt", "5000", "-hws", "10",
"-glt", "5000", "-hws", "10", "-ns", "20",
testFolder + "snow-ref.tif", testFolder + "snow-def.tif",
"-od", testFolder + "",
"-pre", "snow-grid-3b",
......@@ -301,6 +301,7 @@ class testAll(unittest.TestCase):
stdout=FNULL, stderr=FNULL)
self.assertEqual(exitCode, 0)
PSresult3c = spam.helpers.readCorrelationTSV(testFolder + "snow-grid-3c-pixelSearch.tsv", readPixelSearchCC=True)
print(numpy.median(PSresult3c['pixelSearchCC'][PSresult3c['returnStatus']==1]))
self.assertTrue(0.95 < numpy.median(PSresult3c['pixelSearchCC'][PSresult3c['returnStatus']==1]))
#print(PSresult3b['PhiField'][numpy.logical_and(PSresult3b['returnStatus']==1, PSresult3c['returnStatus']==1),0:3,-1]-PSresult3c['PhiField'][numpy.logical_and(PSresult3b['returnStatus']==1, PSresult3c['returnStatus']==1),0:3,-1])
self.assertTrue(0 == numpy.sum( PSresult3b['PhiField'][numpy.logical_and(PSresult3b['returnStatus']==1, PSresult3c['returnStatus']==1)]
......@@ -333,7 +334,7 @@ class testAll(unittest.TestCase):
"{}".format(int(refTranslation[0]-2)), "{}".format(int(refTranslation[0]+2)),
"{}".format(int(refTranslation[1]-2)), "{}".format(int(refTranslation[1]+2)),
"{}".format(int(refTranslation[2]-2)), "{}".format(int(refTranslation[2]+2)),
"-glt", "5000", "-hws", "10",
"-glt", "5000", "-hws", "10", "-ns", "20",
testFolder + "snow-ref.tif", testFolder + "snow-def-onlyDisp.tif",
"-od", testFolder + "",
"-pre", "snow-grid-3e",
......@@ -386,7 +387,7 @@ class testAll(unittest.TestCase):
"-sp", "{}".format(snowRef.shape[0]//2), "{}".format(snowRef.shape[1]//2), "{}".format(snowRef.shape[2]//2),
"{}".format(int(refTranslation[0])), "{}".format(int(refTranslation[1])), "{}".format(int(refTranslation[2])),
"-sr", "-2", "2", "-2", "2", "-2", "2",
"-glt", "5000", "-hws", "15",
"-glt", "5000", "-hws", "15", "-ns", "30",
testFolder + "snow-ref.tif", testFolder + "snow-def-onlyDisp.tif",
"-od", testFolder + "",
"-pre", "snow-grid-4a"
......@@ -437,7 +438,7 @@ class testAll(unittest.TestCase):
### Step 5b: load pixelSearch results with same grid + ug
exitCode = subprocess.call(["spam-ldic",
"-pf", testFolder + "snow-grid-3a-pixelSearch.tsv",
"-glt", "5000", "-hws", "10",
"-glt", "5000", "-hws", "10", "-ns", "20",
testFolder + "snow-ref.tif", testFolder + "snow-def.tif",
"-od", testFolder + "",
"-pre", "snow-grid-5b",
......@@ -482,7 +483,7 @@ class testAll(unittest.TestCase):
### Step 5d: load pixelSearchPropagate results with same grid + ug
exitCode = subprocess.call(["spam-ldic",
"-pf", testFolder + "snow-grid-4a-pixelSearchPropagate.tsv",
"-glt", "5000", "-hws", "15",
"-glt", "5000", "-hws", "15", "-ns", "30",
testFolder + "snow-ref.tif", testFolder + "snow-def-onlyDisp.tif",
"-od", testFolder + "",
"-pre", "snow-grid-5d",
......@@ -954,6 +955,9 @@ class testAll(unittest.TestCase):
self.assertTrue(numpy.isclose(numpy.median(DDICresult5d['PhiField'][1:,2,-1]), translationStep2[2], atol=0.3))
self.assertTrue(numpy.median(DDICresult5d['returnStatus']) == 2)
### 5e ddic result passed to same label image with spam-passPhiField (ideally it would be differently labelled)
#...
#######################################################
### 6. Rerun ddic -- Step0 -> Step2 with prev result
#######################################################
......@@ -974,6 +978,7 @@ class testAll(unittest.TestCase):
self.assertTrue(0 == numpy.sum(PSresult5a['PhiField'][1:,0:3,-1]-PSresult6a['PhiField'][1:,0:3,-1]))
#######################################################
### 7. Check -skp
#######################################################
......@@ -1039,7 +1044,7 @@ class testAll(unittest.TestCase):
#self.assertAlmostEqual(VTK[3]['yy'].mean(), (1.01 - 1.00), places=3)
#self.assertAlmostEqual(VTK[3]['zz'].mean(), (1.01 - 1.00), places=3)
def _test_all_help(self):
def test_all_help(self):
FNULL = open(os.devnull, 'w')
exitCode = subprocess.call(["spam-reg", "--help"], stdout=FNULL, stderr=FNULL)
self.assertEqual(exitCode, 0)
......
......@@ -77,6 +77,14 @@ def ldicParser(parser):
dest='PHIFILE_BIN_RATIO',
help="Ratio of binning level between loaded Phi file and current calculation. If the input Phi file has been obtained on a 500x500x500 image and now the calculation is on 1000x1000x1000, this should be 2. Default = 1")
parser.add_argument('-F',
'--apply-F',
type=str,
default='all',
dest='APPLY_F',
help="Apply the F part of Phi guess? Accepted values are:\n\t\"all\": apply all of F" +
"\n\t\"rigid\": apply rigid part (mostly rotation) \n\t\"no\": don't apply it \"all\" is default")
# PFD now assumed to be true
#parser.add_argument('-pfd',
#'--phiFile-direct',
......@@ -280,26 +288,31 @@ def ldicParser(parser):
raise
# Catch interdependent node spacing and correlation window sizes
if args.NS is None:
print("\nUsing default node spacing: "),
if args.HWS is None:
print("2x default half window size"),
args.HWS = [10]
print("({}) which is".format(args.HWS[0])),
args.NS = [args.HWS[0] * 2]
else:
print("2x user-set half window size"),
if len(args.HWS) == 1:
print("({}) which is".format(args.HWS[0])),
args.NS = [int(args.HWS[0] * 2)]
elif len(args.HWS) == 3:
print("({} -- selecting smallest) which is".format(args.HWS)),
args.NS = [int(min(args.HWS) * 2)]
print(args.NS)
#if args.NS is None:
#print("\nUsing default node spacing: "),
#if args.HWS is None:
#print("2x default half window size"),
#args.HWS = [10]
#print("({}) which is".format(args.HWS[0])),
#args.NS = [args.HWS[0] * 2]
#else:
#print("2x user-set half window size"),
#if len(args.HWS) == 1:
#print("({}) which is".format(args.HWS[0])),
#args.NS = [int(args.HWS[0] * 2)]
#elif len(args.HWS) == 3:
#print("({} -- selecting smallest) which is".format(args.HWS)),
#args.NS = [int(min(args.HWS) * 2)]
#print(args.NS)
if args.HWS is None:
print("spam-ldic: HWS must be defined.")
exit()
# Catch 3D options
if len(args.NS) == 1:
args.NS = [args.NS[0], args.NS[0], args.NS[0]]
## Catch 3D options
if args.NS is not None:
if len(args.NS) == 1:
args.NS = [args.NS[0], args.NS[0], args.NS[0]]
if len(args.HWS) == 1:
args.HWS = [args.HWS[0], args.HWS[0], args.HWS[0]]
......@@ -312,7 +325,7 @@ def ldicParser(parser):
# Catch and overwrite 2D options
if twoD:
args.NS[0] = 1
if args.NS is not None: args.NS[0] = 1
args.HWS[0] = 0
args.MARGIN[0] = 0
......@@ -339,6 +352,9 @@ def ldicParser(parser):
#args.TSV = True
# Nor prefix here because LDIC can still do an image series and needs to update the name
if args.APPLY_F not in ["all", "rigid", "no",]:
print("-F should be 'all' 'rigid' or 'no'")
exit()
return args
......@@ -1988,20 +2004,6 @@ def pixelSearch(parser):
dest='PHIFILE_BIN_RATIO',
help="Ratio of binning level between loaded Phi file and current calculation. If the input Phi file has been obtained on a 500x500x500 image and now the calculation is on 1000x1000x1000, this should be 2. Default = 1")
parser.add_argument('-pfd',
'--phiFile-direct',
action="store_true",
#default=1,
dest='PHIFILE_DIRECT',
help="Trust the Phi file completely? This option ignores and overrides -pfni and requires same nodes in same positions. Default = False")
parser.add_argument('-pfni',
'--neighbours-for-phi-field-interpolation',
type=int,
default=6,
dest='NEIGHBOURS',
help="Number of neighbours for field interpolation. Default = 6")
parser.add_argument('-F',
'--apply-F',
type=str,
......@@ -2157,33 +2159,38 @@ def pixelSearch(parser):
else:
# We are in grid, with a nodeSpacing and halfWindowSize
# Catch interdependent node spacing and correlation window sizes
if args.NS is None:
print("\nUsing default node spacing: "),