From 8ebe87345b87d27a3ceb6a26e68c4ee89d82c70a Mon Sep 17 00:00:00 2001 From: NikoOinonen <42408893+NikoOinonen@users.noreply.github.com> Date: Thu, 23 May 2024 09:52:08 +0300 Subject: [PATCH] Make scanner work when scan_dim is not passed as a tuple but other array-like. (#281) --- ppafm/ocl/relax.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/ppafm/ocl/relax.py b/ppafm/ocl/relax.py index fdc1e058..fd17fc56 100644 --- a/ppafm/ocl/relax.py +++ b/ppafm/ocl/relax.py @@ -176,7 +176,7 @@ def prepareBuffers(self, FEin_np=None, lvec=None, FEin_cl=None, FEin_shape=None, # see: https://stackoverflow.com/questions/39533635/pyopencl-3d-rgba-image-from-numpy-array if scan_dim is not None: - self.scan_dim = scan_dim + self.scan_dim = tuple(scan_dim) fsize = np.dtype(np.float32).itemsize f4size = fsize * 4 nxy = self.scan_dim[0] * self.scan_dim[1] @@ -194,14 +194,7 @@ def prepareBuffers(self, FEin_np=None, lvec=None, FEin_cl=None, FEin_shape=None, nbytes += bsz * self.nDimConvOut self.cl_WZconv = cl.Buffer(self.ctx, mf.READ_ONLY, fsize * self.nDimConv) nbytes += fsize * self.nDimConv - self.FEconv = np.empty( - self.scan_dim[:2] - + ( - self.nDimConvOut, - 4, - ), - dtype=np.float32, - ) + self.FEconv = self.prepareFEConv() if bZMap: self.cl_zMap = cl.Buffer(self.ctx, mf.WRITE_ONLY, nxy * fsize) @@ -257,6 +250,9 @@ def tryReleaseBuffers(self): except: pass + def prepareFEConv(self): + return np.empty(self.scan_dim[:2] + (self.nDimConvOut, 4), dtype=np.float32) + def preparePosBasis(self, start=(-5.0, -5.0), end=(5.0, 5.0)): self.start = start self.end = end @@ -474,16 +470,6 @@ def run_getFEinStrokesTilted(self, FEout=None, FEin=None, lvec=None, nz=None): self.queue.finish() return FEout - def prepareFEConv(self): - return np.empty( - self.scan_dim[:2] - + ( - self.nDimConvOut, - 4, - ), - dtype=np.float32, - ) - def run_convolveZ(self, FEconv=None, nz=None): """ convolve 3D forcefield in FEout with 1D weight mask WZconv