From 73002c9769ae9eb2a3e4c03d40925a45c29ae995 Mon Sep 17 00:00:00 2001 From: David Rowenhorst Date: Mon, 13 May 2024 16:31:52 -0400 Subject: [PATCH] More user friendly function calling. Signed-off by: David Rowenhorst --- pyebsdindex/nlpar.py | 9 +++++--- pyebsdindex/opencl/nlpar_cl.py | 36 +++++++++++++++++++++++-------- pyebsdindex/opencl/nlpar_clray.py | 8 ++++++- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/pyebsdindex/nlpar.py b/pyebsdindex/nlpar.py index 5f09e3d..2c82c40 100644 --- a/pyebsdindex/nlpar.py +++ b/pyebsdindex/nlpar.py @@ -188,7 +188,7 @@ def getoutfileobj(self): return None def opt_lambda(self,chunksize=0,saturation_protect=True,automask=True, backsub = False, - target_weights=[0.5, 0.34, 0.25], dthresh=0.0, autoupdate=True): + target_weights=[0.5, 0.34, 0.25], dthresh=0.0, autoupdate=True, **kwargs): target_weights = np.asarray(target_weights) @@ -294,7 +294,7 @@ def d2norm(d2, n2, dij, sigma): return np.mean(lamopt_values, axis = 0).flatten() def calcnlpar(self, chunksize=0, searchradius=None, lam = None, dthresh = None, saturation_protect=True, automask=True, - filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False): + filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False, **kwargs): if lam is not None: self.lam = lam @@ -785,6 +785,9 @@ def _calcchunks(self, patdim, ncol, nrow, target_bytes=2e9, col_overlap=0, row_o return ncolchunks, nrowchunks, colchunks, rowchunks - + # def asciiupdate(self, nrow, ncol, completematrix): + # cm = completematrix + # ncdisplay = min(ncol, 80) + # nrow diff --git a/pyebsdindex/opencl/nlpar_cl.py b/pyebsdindex/opencl/nlpar_cl.py index 850145f..9df0d2e 100644 --- a/pyebsdindex/opencl/nlpar_cl.py +++ b/pyebsdindex/opencl/nlpar_cl.py @@ -15,12 +15,28 @@ def __init__( self, **kwargs): nlpar.NLPAR.__init__(self, **kwargs) self.useCPU = False + + def opt_lambda(self,saturation_protect=True, automask=True, backsub=False, + target_weights=[0.5, 0.34, 0.25], dthresh=0.0, autoupdate=True, **kwargs): + return self.opt_lambda_cl(saturation_protect=saturation_protect, + automask=automask, + backsub=backsub, + target_weights=target_weights, + dthresh=dthresh, + autoupdate=autoupdate, **kwargs) + def calcnlpar(self, **kwargs): + return self.calcnlpar_cl(**kwargs) + + def calcsigma(self,nn=1, saturation_protect=True,automask=True, **kwargs): return self.calcsigma_cl(nn=nn, saturation_protect=saturation_protect, automask=automask, **kwargs)[0] + def opt_lambda_cpu(self, **kwargs): + return nlpar.NLPAR.opt_lambda(self, **kwargs) - + def calcnlpar_cpu(self, **kwargs): + return nlpar.NLPAR.calcnlpar(self, **kwargs) def calcsigma_cpu(self,nn=1, saturation_protect=True,automask=True, **kwargs): return nlpar.NLPAR.calcsigma(self, nn=nn, @@ -160,14 +176,16 @@ def calcsigma_cl(self,nn=1,saturation_protect=True,automask=True, normalize_d=Fa count_local = cl.Buffer(ctx, mf.READ_WRITE, size=int(mxchunk * nnn * 4)) countchunk = np.zeros((mxchunk, nnn), dtype=np.float32) - for colchunk in range(chunks[0]): - cstart = chunks[2][colchunk, 0] - cend = chunks[2][colchunk, 1] - ncolchunk = cend - cstart - for rowchunk in range(chunks[1]): - rstart = chunks[3][rowchunk, 0] - rend = chunks[3][rowchunk, 1] - nrowchunk = rend - rstart + for rowchunk in range(chunks[1]): + rstart = chunks[3][rowchunk, 0] + rend = chunks[3][rowchunk, 1] + nrowchunk = rend - rstart + + for colchunk in range(chunks[0]): + cstart = chunks[2][colchunk, 0] + cend = chunks[2][colchunk, 1] + ncolchunk = cend - cstart + data, xyloc = patternfile.read_data(patStartCount=[[cstart, rstart], [ncolchunk, nrowchunk]], convertToFloat=False, returnArrayOnly=True) diff --git a/pyebsdindex/opencl/nlpar_clray.py b/pyebsdindex/opencl/nlpar_clray.py index 4aca04b..9a8d217 100644 --- a/pyebsdindex/opencl/nlpar_clray.py +++ b/pyebsdindex/opencl/nlpar_clray.py @@ -21,7 +21,13 @@ def __init__( self, **kwargs): nlpar_cl.NLPAR.__init__(self, **kwargs) self.useCPU = False - def calcnlpar_cl(self,chunksize=0, searchradius=None, lam = None, dthresh = None, saturation_protect=True, automask=True, + def calcnlpar(self, **kwargs): + return self.calcnlpar_clray(**kwargs) + + def calcnlpar_clsq(self, **kwargs): + return nlpar_cl.NLPAR.calcnlpar_cl(self, **kwargs) + + def calcnlpar_clray(self, searchradius=None, lam = None, dthresh = None, saturation_protect=True, automask=True, filename=None, fileout=None, reset_sigma=False, backsub = False, rescale = False, gpuid = None, **kwargs): if lam is not None: