NLPAR Examples#
[2]:
from pyebsdindex import nlpar
#from pyebsdindex import nlpar_cpu as nlpar
[ ]:
file0 = '~/Desktop/SLMtest/scan2v3.up1'
[4]:
nlobj = nlpar.NLPAR(file0,lam=0.9, searchradius=3)
As always, the search radius is the 1/2 window search size. So the full window will be (2*searchradius+1)^2 or in this case 7x7 patterns (including the center pattern of interest).
Estimating a value for lambda#
A value of 0.9 is a pretty good guess for lambda for relatively noisy 80x80 patterns. But one can get a customized value of lambda by running an optimization that examines what value of lambda would provide a certain amount of reduction in the weight of the pattern of interest for a nearest-neighborhood search window. The idea being that for most scans, nearly all the neighboring patterns are nearly identical other than noise. Thus - the weigh of the pattern of interest is a measure of how much the neighboring patterns are contributing. Three optimized weights are considered (by default: [0.5, 0.34, 0.25]). Hueristically we have found that the 0.34 provides a reasonable estimate – the other two values are provided as something that represents a resonable range for lambda (lower lambda is less neighbor averaging, higher is more neighbor averaging).
Note, this will also calculate a per-point estimation of the noise in each pattern (sigma) which will be automatically stored in the nlobj for use in the NLPAR calculations.
chunksize = int (default: 0) These are the number of rows from the EBSD scan to process at one time. The default (set to 0) is to examine the number of columns in the scan, and estimate a chunk size that is approximately 4GB. No promises.automask = True (default: True) will place a circular mask around the pattern (using the diamter of the shorter of the two pattern edges). autoupdate = True (default: True) will update the lambda value in the nlobj class with the optimized version.backsub = True (default: False) will perform a basic background subtraction on the patterns before elvaluation. Average pattern is calculated per pattern chunk.saturation_protect = True (default:True) this will exclude the pixels that have the maximum brightness value from the calculation (maximum value again calculated per pattern chunk).[5]:
nlobj.opt_lambda(chunksize = 0, automask = True, autoupdate=True, backsub = False)
The number of scan columns is set to one, which is unusual, and may indicate that
the number of columns is not saved as metadata in the pattern file. Consider manually
entering the number of columns/rows with ``nlobj.ncols={number of your scan columns}`` and
``nlobj.nrows={number of your scan rows}``.
The number of scan columns is set to one, which is unusual, and may indicate that
the number of columns is not saved as metadata in the pattern file. Consider manually
entering the number of columns/rows with ``nlobj.ncols={number of your scan columns}`` and
``nlobj.nrows={number of your scan rows}``.
Range of lambda values: [0.001 0.001 0.41923828]
Optimal Choice: 0.001
[5]:
array([0.001 , 0.001 , 0.41923828])
Executing NLPAR#
Now that there are reasonable estimates for sigma and lambda, one can execute NLPAR. With the default values and using ‘UP’ EDAX files, a new file will be created to store the result with the pattern [filename]lam[x.xx]sr[x]dt[x.x].up[1/2].
The user can override the filename if they want - but should not overwrite the original data filename (no protections are provided).
[6]:
nlobj.searchradius = 4
nlobj.calcnlpar(chunksize=0,searchradius=None,lam = None, saturation_protect=True,automask=True,
filename=None, fileout=None, backsub = False)
lambda: 0.9039062 search radius: 4 dthresh: 0.0
tiles complete: 36/36
[6]:
'/Users/dave/Desktop/SLMtest/scan2v3_NLPAR_l0.90sr4.up1'
[5]:
nlobj.calcnlpar(chunksize=0,searchradius=None,lam = None, saturation_protect=True,automask=True,
filename=None, fileout='/tmp/dave.up1', backsub = False)
Chunk size set to nrows: 278
0.90292966 3 0.0
Block 0
Block 278
Block 556
Block 834
[6]:
nlobj.calcnlpar(chunksize=0,searchradius=11,lam = 1.2, saturation_protect=True,automask=True,
filename=None, fileout='/tmp/dave2.up1', backsub = False)
Chunk size set to nrows: 278
1.2 11 0.0
Block 0
Block 278
Block 556
Block 834
[ ]: