diff --git a/ImageD11/blobcorrector.py b/ImageD11/blobcorrector.py index 387f3b1c..1c21575c 100644 --- a/ImageD11/blobcorrector.py +++ b/ImageD11/blobcorrector.py @@ -73,7 +73,7 @@ def __init__(self, argsplinefile, orientation="edf"): self.tck2 = None if self.splinefile is not None: self.readfit2dspline(self.splinefile) - + self.dim = ( int(self.xmax-self.xmin), int(self.ymax-self.ymin)) # detector dimensions read from splinefile def correct(self, xin, yin): @@ -138,6 +138,33 @@ def make_pos_lut(self, dims): self.pixel_lut[1] * self.ysize ) return self.pos_lut + + def correct_px_lut(self, pks): + """Transform x,y in raw image coordinates into x,y of an + idealised image using a LUT. Faster than standard correct method for large peakfiles. + pks : ImageD11 columnfile with raw coordinates s_raw, f_raw add new colulmns sc, fc with corrected coordinates""" + + assert self.dim is not None + assert 's_raw' in pks.titles and 'f_raw' in pks.titles + + # make pixel_lut + substract xy grid coordinate (i,j) to keep only dx and dy arrays. + self.make_pixel_lut(self.dim) + i,j = numpy.mgrid[ 0:self.dim[0], 0:self.dim[1] ] + dx = self.pixel_lut[0] - i + dy = self.pixel_lut[1] - j + + # get integer pixel index (si,fi) of each peak + si = numpy.round(pks['s_raw']).astype(int) + fi = numpy.round(pks['f_raw']).astype(int) + + # apply dx dy correction on s_raw / f_raw + sc = (dx[ si, fi ] + pks.s_raw).astype(numpy.float32) + fc = (dy[ si, fi ] + pks.f_raw).astype(numpy.float32) + # add corrected arrays as new columns + pks.addcolumn(sc, 'sc') + pks.addcolumn(fc, 'fc') + + def distort(self, xin, yin): """ Distort a pair of points xnew, ynew to find where they @@ -338,4 +365,3 @@ def pixel_lut(self): # Hence, for now, # """ # pass -