Skip to content

Commit

Permalink
Update blobcorrector.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jbjacob94 authored Oct 31, 2023
1 parent ac2b683 commit aee79f1
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions ImageD11/blobcorrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (self.xmax-self.xmin, self.ymax-self.ymin) # detector dimensions read from splinefile
self.dim = ( int(self.xmax-self.xmin), int(self.ymax-self.ymin)) # detector dimensions read from splinefile


def correct(self, xin, yin):
Expand Down Expand Up @@ -140,31 +140,30 @@ def make_pos_lut(self, dims):


def correct_px_lut(self, pks):
"""Transform x,y in raw image coordinates into x,y of an
"""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"""
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 = np.round(pks['s_raw']).astype(int)
fi = np.round(pks['f_raw']).astype(int)
# apply dx dy correction on s_raw / f_raw
sc = (dx[ si, fi ] + pks.s_raw).astype(np.float32)
fc = (dy[ si, fi ] + pks.f_raw).astype(np.float32)
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):
"""
Expand Down Expand Up @@ -366,4 +365,3 @@ def pixel_lut(self):
# Hence, for now,
# """
# pass

0 comments on commit aee79f1

Please sign in to comment.