Skip to content

Commit

Permalink
More user friendly function calling.
Browse files Browse the repository at this point in the history
Signed-off by: David Rowenhorst <[email protected]>
  • Loading branch information
drowenhorst-nrl committed May 13, 2024
1 parent 09eeff0 commit 73002c9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
9 changes: 6 additions & 3 deletions pyebsdindex/nlpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


36 changes: 27 additions & 9 deletions pyebsdindex/opencl/nlpar_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion pyebsdindex/opencl/nlpar_clray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 73002c9

Please sign in to comment.