mirror of https://github.com/silx-kit/pyFAI.git
v0.7.8: add recalibration tool
This commit is contained in:
parent
fd6ca27ff4
commit
7fc734b8f9
1
MANIFEST
1
MANIFEST
|
@ -52,6 +52,7 @@ scripts/diff_tomo.py
|
|||
scripts/drawMask_pymca
|
||||
scripts/integrate_exp.py
|
||||
scripts/pyFAI-calib
|
||||
scripts/pyFAI-recalib
|
||||
scripts/pyFAI-saxs
|
||||
scripts/pyFAI-waxs
|
||||
scripts/refine_wavelength.py
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
version = "0.7.7"
|
||||
version = "0.7.8"
|
||||
import sys, logging
|
||||
logging.basicConfig()
|
||||
|
||||
|
|
|
@ -73,14 +73,13 @@ class Recalibration(object):
|
|||
"""
|
||||
class doing the re-calibration of frames
|
||||
"""
|
||||
def __init__(self, dataFiles=None, darkFiles=None, flatFiles=None, pixelSize=None, splineFile=None, gaussianWidth=None):
|
||||
def __init__(self, dataFiles=None, darkFiles=None, flatFiles=None, splineFile=None, gaussianWidth=None):
|
||||
"""
|
||||
"""
|
||||
self.dataFiles = dataFiles or []
|
||||
self.darkFiles = darkFiles or []
|
||||
self.flatFiles = flatFiles or []
|
||||
self.pointfile = None
|
||||
self.pixelSize = pixelSize
|
||||
self.gaussianWidth = gaussianWidth
|
||||
self.labelPattern = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
|
||||
self.splineFile = splineFile
|
||||
|
@ -100,8 +99,6 @@ class Recalibration(object):
|
|||
"data= " + ", ".join(self.dataFiles),
|
||||
"dark= " + ", ".join(self.darkFiles),
|
||||
"flat= " + ", ".join(self.flatFiles)]
|
||||
if self.pixelSize:
|
||||
lst.append("pixels= " + ", ".join(self.pixelSize))
|
||||
lst += ["spline= %s" % self.splineFile,
|
||||
"gaussian= %s" % self.gaussianWidth]
|
||||
return os.linesep.join(lst)
|
||||
|
@ -172,8 +169,10 @@ class Recalibration(object):
|
|||
if options.wavelength:
|
||||
self.ai.wavelength = 1e-10 * float(options.wavelength)
|
||||
if options.distance:
|
||||
self.ai.distance = 1e-3 * float(options.distance)
|
||||
|
||||
# print "setting distance to %s" % options.distance
|
||||
self.ai.dist = 1e-3 * float(options.distance)
|
||||
# print 1e-3 * float(options.distance), self.ai.distance
|
||||
print self.ai
|
||||
|
||||
|
||||
def preprocess(self):
|
||||
|
@ -188,7 +187,7 @@ class Recalibration(object):
|
|||
self.outfile = self.dataFiles[0]
|
||||
self.peakPicker = PeakPicker(self.outfile)
|
||||
self.basename = os.path.splitext(self.outfile)[0]
|
||||
self.peakPicker.gui()
|
||||
self.peakPicker.gui(log=True)
|
||||
self.peakPicker.fig.canvas.draw()
|
||||
|
||||
def extract_cpt(self):
|
||||
|
@ -196,38 +195,52 @@ class Recalibration(object):
|
|||
tth = 2.0 * numpy.arcsin(self.ai.wavelength / (2.0e-10 * d))
|
||||
tth.sort()
|
||||
tth = tth[numpy.where(numpy.isnan(tth) - 1)]
|
||||
dtth = numpy.zeros_like(tth)
|
||||
dtth[:-1] = tth[1:] - tth[:-1]
|
||||
dtth[-1] = dtth[-2]
|
||||
dtth = numpy.zeros((tth.size, 2))
|
||||
delta = tth[1:] - tth[:-1]
|
||||
dtth[:-1, 0] = delta
|
||||
dtth[-1, 0] = delta[-1]
|
||||
dtth[1:, 1] = delta
|
||||
dtth[0, 1] = delta[0]
|
||||
dtth = dtth.min(axis= -1)
|
||||
ttha = self.ai.twoThetaArray(self.peakPicker.data.shape)
|
||||
for i in range(tth.size):
|
||||
mask = abs(ttha - tth[i]) <= dtth[i] / 4.0
|
||||
size = mask.sum(dtype=int)
|
||||
if size > 0:
|
||||
self.peakPicker.massif_contour(mask)
|
||||
self.peakPicker.fig.canvas.draw()
|
||||
all_points = numpy.where(mask)
|
||||
size = all_points[0].size
|
||||
keep = int(numpy.ceil(numpy.sqrt(size)))
|
||||
allpt = numpy.zeros((size, 2), dtype=numpy.int)
|
||||
|
||||
mean = self.peakPicker.data[mask].mean(dtype=numpy.float64)
|
||||
std = self.peakPicker.data[mask].std(dtype=numpy.float64)
|
||||
mask2 = (self.peakPicker.data > mean + std)
|
||||
size2 = mask2.sum(dtype=int)
|
||||
keep = int(numpy.ceil(numpy.sqrt(size2)))
|
||||
all_points = numpy.where(mask2)
|
||||
allpt = numpy.zeros((size2, 2), dtype=numpy.int)
|
||||
allpt[:, 0] = all_points[0]
|
||||
allpt[:, 1] = all_points[1]
|
||||
res = []
|
||||
cnt = 0
|
||||
logger.info("Extracting datapoint for ring %s (2theta = %.2f deg)" % (i, numpy.degrees(tth[i])))
|
||||
logger.info("Extracting datapoint for ring %s (2theta = %.2f deg); searching for %i pts out of %i with I>%.1f" % (i, numpy.degrees(tth[i]), keep, size2, mean + std,))
|
||||
|
||||
while True:
|
||||
idx = numpy.random.randint(0, size)
|
||||
idx = numpy.random.randint(0, size2)
|
||||
out = self.peakPicker.massif.nearest_peak(allpt[idx])
|
||||
if mask[out[0], out[1]]:
|
||||
if out not in res:
|
||||
p0, p1 = out
|
||||
if mask[p0, p1]:
|
||||
if (out not in res) and (self.peakPicker.data[p0, p1] > mean):
|
||||
res.append(out)
|
||||
cnt = 0
|
||||
if len(res) >= keep or cnt > 2 * keep:
|
||||
if len(res) >= keep or cnt > keep:
|
||||
print len(res), cnt
|
||||
break
|
||||
else:
|
||||
cnt += 1
|
||||
self.peakPicker.points.append(res, tth[i])
|
||||
self.peakPicker.display_points()
|
||||
self.peakPicker.control_points.save(self.basename + ".npt")
|
||||
|
||||
self.peakPicker.fig.canvas.draw()
|
||||
self.peakPicker.points.save(self.basename + ".npt")
|
||||
self.data = self.peakPicker.points.getList()
|
||||
|
||||
def refine(self):
|
||||
if os.name == "nt" and self.peakPicker is not None:
|
||||
|
@ -235,12 +248,13 @@ class Recalibration(object):
|
|||
self.peakPicker.closeGUI()
|
||||
print self.splineFile
|
||||
if self.splineFile:
|
||||
self.geoRef = GeometryRefinement(self.data, dist=0.1, splineFile=self.splineFile)
|
||||
self.geoRef = GeometryRefinement(self.data, dist=self.ai.dist, poni1=self.ai.poni1, poni2=self.ai.poni2,
|
||||
rot1=self.ai.rot1, rot2=self.ai.rot2, rot3=self.ai.rot3,
|
||||
splineFile=self.splineFile)
|
||||
else:
|
||||
self.geoRef = GeometryRefinement(self.data, dist=0.1, pixel1=self.pixelSize[0], pixel2=self.pixelSize[1])
|
||||
paramfile = self.basename + ".poni"
|
||||
if os.path.isfile(paramfile):
|
||||
self.geoRef.load(paramfile)
|
||||
self.geoRef = GeometryRefinement(self.data, dist=self.ai.dist, poni1=self.ai.poni1, poni2=self.ai.poni2,
|
||||
rot1=self.ai.rot1, rot2=self.ai.rot2, rot3=self.ai.rot3,
|
||||
pixel1=self.ai.pixel1, pixel2=self.ai.pixel2)
|
||||
print self.geoRef
|
||||
previous = sys.maxint
|
||||
finished = False
|
||||
|
@ -333,8 +347,8 @@ if __name__ == "__main__":
|
|||
c.parse()
|
||||
c.preprocess()
|
||||
c.extract_cpt()
|
||||
print c.peakPicker.points
|
||||
# print c.peakPicker.points
|
||||
# c.gui_peakPicker()
|
||||
# c.refine()
|
||||
# c.postProcess()
|
||||
# raw_input("Press enter to quit")
|
||||
c.refine()
|
||||
c.postProcess()
|
||||
raw_input("Press enter to quit")
|
||||
|
|
Loading…
Reference in New Issue