本文整理汇总了Python中pyFAI.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_ai
def set_ai(self):
poni = str(self.poni.text()).strip()
if poni and os.path.isfile(poni):
self.ai = pyFAI.load(poni)
detector = str(self.detector.currentText()).lower().strip() or "detector"
self.ai.detector = pyFAI.detectors.detector_factory(detector)
wavelength = str(self.wavelength.text()).strip()
if wavelength:
try:
fwavelength = float(wavelength)
except ValueError:
logger.error("Unable to convert wavelength to float: %s" % wavelength)
else:
if fwavelength <= 0 or fwavelength > 1e-6:
logger.warning("Wavelength is in meter ... unlikely value %s" % fwavelength)
self.ai.wavelength = fwavelength
splineFile = str(self.splineFile.text()).strip()
if splineFile and os.path.isfile(splineFile):
self.ai.detector.splineFile = splineFile
self.ai.pixel1 = self._float("pixel1", 1)
self.ai.pixel2 = self._float("pixel2", 1)
self.ai.dist = self._float("dist", 1)
self.ai.poni1 = self._float("poni1", 0)
self.ai.poni2 = self._float("poni2", 0)
self.ai.rot1 = self._float("rot1", 0)
self.ai.rot2 = self._float("rot2", 0)
self.ai.rot3 = self._float("rot3", 0)
if self.chi_discontinuity_at_0.isChecked():
self.ai.setChiDiscAtZero()
mask_file = str(self.mask_file.text()).strip()
if mask_file and os.path.exists(mask_file) and bool(self.do_mask.isChecked()):
try:
mask = fabio.open(mask_file).data
except Exception as error:
logger.error("Unable to load mask file %s, error %s" % (mask_file, error))
else:
self.ai.mask = mask
dark_files = [i.strip() for i in str(self.dark_current.text()).split(",")
if os.path.isfile(i.strip())]
if dark_files and bool(self.do_dark.isChecked()):
d0 = fabio.open(dark_files[0]).data
darks = numpy.zeros(d0.shape[0], d0.shape[1], len(dark_files), dtype=numpy.float32)
for i, f in enumerate(dark_files):
darks[:, :, i] = fabio.open(f).data
self.ai.darkcurrent = darks.mean(axis= -1)
flat_files = [i.strip() for i in str(self.flat_field.text()).split(",")
if os.path.isfile(i.strip())]
if flat_files and bool(self.do_flat.isChecked()):
d0 = fabio.open(flat_files[0]).data
flats = numpy.zeros(d0.shape[0], d0.shape[1], len(flat_files), dtype=numpy.float32)
for i, f in enumerate(flat_files):
flats[:, :, i] = fabio.open(f).data
self.ai.darkcurrent = flats.mean(axis= -1)
print self.ai
示例2: loadgeometry
def loadgeometry(ponifilepath=None):
"""Loads the detector geometry information from a poni file or from hard coded information
Parameters
----------
ponifilepath: str
File path to the .poni file
Returns
-------
a: an object which contains the geometry information for the detector
"""
if ponifilepath is None:
distance = 0.204666698799
poni1 = 0.205911555168
poni2 = 0.207264947729
rot1 = 0.0105322341791
rot2 = 0.0104587423844
rot3 = -3.27539683464e-08
spline_file = None
wavelength = 1.839e-11
detector = "Perkin"
# This is the PyFAI geometry stuff
a = geo.Geometry(dist=distance, poni1=poni1, poni2=poni2, rot1=rot1,
rot2=rot2, rot3=rot3, pixel1=200e-6, pixel2=200e-6,
splineFile=None, detector=detector,
wavelength=wavelength)
else:
a = pyFAI.load(ponifilepath)
return a
示例3: __init__
def __init__(self, poni, img):
self.ponifile = poni
self.ai = pyFAI.load(poni)
self.img = fabio.open(img)
self.r = None
self.I = None
self.resynth = None
self.delta = None
示例4: loadgeometry
def loadgeometry(ponifilepath=None):
"""Loads the detector geometry information from a poni file or from hard coded information
Parameters
----------
ponifilepath: str
File path to the .poni file
Returns
-------
Azimuthal integrator object:
an object which contains the geometry information for the detector
"""
if ponifilepath is None:
filepath = tkFileDialog.askopenfilename()
a = pyFAI.load(ponifilepath)
else:
a = pyFAI.load(ponifilepath)
return a
示例5: q_from_xy
def q_from_xy(x, y, ai=None, calfile=None):
if ai is None: ai = pyFAI.load(calfile)
try:
return ai.qFunction(np.array([y,]),np.array([x,]))[0]
except:
return 0
示例6: set_ai
def set_ai(self):
poni = str(self.poni.text()).strip()
if poni and op.isfile(poni):
self.ai = pyFAI.load(poni)
detector = str(self.detector.currentText()).lower().strip() or "detector"
self.ai.detector = pyFAI.detectors.detector_factory(detector)
wavelength = str(self.wavelength.text()).strip()
if wavelength:
try:
fwavelength = float(wavelength)
except ValueError:
logger.error("Unable to convert wavelength to float: %s" % wavelength)
else:
if fwavelength <= 0 or fwavelength > 1e-6:
logger.warning("Wavelength is in meter ... unlikely value %s" % fwavelength)
self.ai.wavelength = fwavelength
splineFile = str(self.splineFile.text()).strip()
if splineFile and op.isfile(splineFile):
self.ai.detector.splineFile = splineFile
self.ai.pixel1 = self._float("pixel1", 1)
self.ai.pixel2 = self._float("pixel2", 1)
self.ai.dist = self._float("dist", 1)
self.ai.poni1 = self._float("poni1", 0)
self.ai.poni2 = self._float("poni2", 0)
self.ai.rot1 = self._float("rot1", 0)
self.ai.rot2 = self._float("rot2", 0)
self.ai.rot3 = self._float("rot3", 0)
if self.chi_discontinuity_at_0.isChecked():
self.ai.setChiDiscAtZero()
mask_file = str(self.mask_file.text()).strip()
if mask_file and bool(self.do_mask.isChecked()):
if op.exists(mask_file):
try:
mask = fabio.open(mask_file).data
except Exception as error:
logger.error("Unable to load mask file %s, error %s" % (mask_file, error))
else:
self.ai.mask = mask
# elif mask_file==FROM_PYMCA:
# self.ai.mask = mask
dark_files = [i.strip() for i in str(self.dark_current.text()).split(",")
if op.isfile(i.strip())]
if dark_files and bool(self.do_dark.isChecked()):
self.ai.set_darkfiles(dark_files)
flat_files = [i.strip() for i in str(self.flat_field.text()).split(",")
if op.isfile(i.strip())]
if flat_files and bool(self.do_flat.isChecked()):
self.ai.set_flatfiles(flat_files)
print self.ai
示例7: integrate_xrd_row
def integrate_xrd_row(rowxrd2d, calfile, unit='q', steps=2048,
wedge_limits=None, mask=None, dark=None,
flip=True):
'''
Uses pyFAI (poni) calibration file to produce 1D XRD data from a row of 2D XRD images
Must provide pyFAI calibration file
rowxrd2d : 2D diffraction images for integration
calfile : poni calibration file
unit : unit for integration data ('2th'/'q'); default is 'q'
steps : number of steps in integration data; default is 10000
wedge_limits : azimuthal slice limits
mask : mask array for image
dark : dark image array
flip : vertically flips image to correspond with Dioptas poni file calibration
'''
if not HAS_pyFAI:
print('pyFAI not imported. Cannot calculate 1D integration.')
return
try:
ai = pyFAI.load(calfile)
except:
print('calibration file "%s" could not be loaded.' % calfile)
return
if type(dark) is str:
try:
dark = np.array(tifffile.imread(xrd2dbkgd))
except:
dark = None
dir = -1 if flip else 1
attrs = dict(mask=mask, dark=dark, method='csr',
polarization_factor=0.999, correctSolidAngle=True)
if unit.startswith('2th'):
attrs.update({'unit':'2th_deg'})
else:
attrs.update({'unit':'q_A^-1'})
if wedge_limits is not None:
attrs.update({'azimuth_range':wedge_limits})
# print("Calc XRD 1D for row", ai, steps, attrs)
q, xrd1d = [], []
for i, xrd2d in enumerate(rowxrd2d):
row_q,row_xrd1d = calcXRD1d(xrd2d[::dir,:], ai, steps, attrs)
q += [row_q]
xrd1d += [row_xrd1d]
return np.array(q), np.array(xrd1d)
示例8: integrate_simple
def integrate_simple(poni_file, image_file, curve_file, nbins=1000):
"""Simple azimuthal integration for a single frame (very inefficient)
:param poni_file: configuration of the geometry
:param image_file:
:param curve_file: output file
:param nbins: number of output bins
"""
ai = pyFAI.load(poni_file)
img = fabio.open(image_file).data
ai.integrate1d(img, nbins, filename=curve_file, unit="2th_deg", method="splitpixel")
return {"out_file": curve_file}
示例9: twth_from_xy
def twth_from_xy(x, y, ai=None, calfile=None, ang_units='degrees'):
if ai is None: ai = pyFAI.load(calfile)
try:
twth = ai.tth(np.array([y,]),np.array([x,]))
except:
return 0
if ang_units.startswith('rad'):
return twth[0]
else:
return np.degrees(twth[0])
示例10: eta_from_xy
def eta_from_xy(x, y, ai=None, calfile=None, ang_units='degrees'):
if ai is None: ai = pyFAI.load(calfile)
try:
eta = ai.chi(np.array([y,]),np.array([x,]))
except:
return 0
if ang_units.startswith('rad'):
return eta[0]
else:
return np.degrees(eta[0])
示例11: integrate_xrd
def integrate_xrd(xrd_map, AI=None, calfile=None, unit='q', steps=10000,
save=True, aname = 'default', prefix = 'XRD', path = '~/',
mask=None, dark=None, verbose=False):
if HAS_pyFAI:
if AI is None:
try:
ai = pyFAI.load(calfile)
except IOError:
print('No calibration parameters specified.')
return
else:
ai = calculate_ai(AI)
if unit == 'q':
iunit = 'q_A^-1'
elif unit == '2th':
iunit='2th_deg'
else:
print('Unknown unit: %s. Using q.' % unit)
unit = 'q'
iunit = 'q_A^-1'
t0 = time.time()
if save:
counter = 1
while os.path.exists('%s/%s-%s-%03d.xy' % (path,prefix,aname,counter)):
counter += 1
fname = '%s/%s-%s-%03d.xy' % (path,prefix,aname,counter)
print('\nSaving %s data in file: %s\n' % (unit,fname))
qI = ai.integrate1d(xrd_map,steps,unit=iunit,mask=mask,dark=dark,filename=fname)
else:
qI = ai.integrate1d(xrd_map,steps,unit=iunit,mask=mask,dark=dark)
t1 = time.time()
if verbose:
print('\ttime to integrate data = %0.3f s' % ((t1-t0)))
if verbose:
print('Parameters for 1D integration:')
print(ai)
else:
print('pyFAI not imported. Cannot calculate 1D integration without it.')
return
return qI
示例12: integrate_xrd
def integrate_xrd(xrd2d, calfile, unit='q', steps=2048, file='', wedge_limits=None,
mask=None, dark=None, is_eiger=True, save=False, verbose=False):
'''
Uses pyFAI (poni) calibration file and 2D XRD image to produce 1D XRD data
Must provide pyFAI calibration file
xrd2d : 2D diffraction images for integration
calfile : poni calibration file
unit : unit for integration data ('2th'/'q'); default is 'q'
steps : number of steps in integration data; default is 10000
wedge_limits : azimuthal slice limits
file : filename for saving data; if '' (default) will not save
mask : mask array for image
dark : dark image array
'''
if HAS_pyFAI:
try:
ai = pyFAI.load(calfile)
except:
print('Provided calibration file could not be loaded.')
return
else:
print('pyFAI not imported. Cannot calculate 1D integration.')
return
attrs = {}
if unit.startswith('2th'):
attrs.update({'unit':'2th_deg'})
else:
attrs.update({'unit':'q_A^-1'})
if wedge_limits is not None:
attrs.update({'azimuth_range':wedge_limits})
if mask:
if np.shape(mask) == np.shape(xrd2d): attrs.update({'mask':mask})
if dark:
if np.shape(dark) == np.shape(xrd2d): attrs.update({'dark':dark})
if file is not '':
if verbose:
print('\nSaving %s data to file: %s' % (unit,file))
attrs.update({'filename':file})
return calcXRD1d(xrd2d, ai, steps, attrs)
示例13: calc_cake
def calc_cake(xrd2d, calfile, unit='q', mask=None, dark=None,
xsteps=2048, ysteps=2048, verbose=False):
if HAS_pyFAI:
try:
ai = pyFAI.load(calfile)
except:
print('Provided calibration file could not be loaded.')
return
else:
print('pyFAI not imported. Cannot calculate 1D integration.')
attrs = {}
if unit.startswith('2th'):
attrs.update({'unit':'2th_deg'})
else:
attrs.update({'unit':'q_A^-1'})
if mask:
if np.shape(mask) == np.shape(xrd2d): attrs.update({'mask':mask})
if dark:
if np.shape(dark) == np.shape(xrd2d): attrs.update({'dark':dark})
return calcXRDcake(xrd2d, ai, xsteps, ysteps, attrs)
示例14: integrate_xrd
def integrate_xrd(xrd_map, ai=None,AI=None, calfile=None, unit='q', steps=10000,
save=False, file='~/test.xy', mask=None, dark=None, verbose=False):
if HAS_pyFAI:
if ai is None:
if AI is None:
try:
ai = pyFAI.load(calfile)
except IOError:
print('No calibration parameters specified.')
return
else:
ai = calculate_ai(AI)
attrs = {}
if unit == '2th':
attrs.update({'unit':'2th_deg'})
else:
attrs.update({'unit':'q_A^-1'})
if mask:
attrs.update({'mask':mask})
if dark:
attrs.update({'dark':dark})
if save:
print('Saving %s data to file: %s\n' % (unit,file))
attrs.update({'filename':file})
if verbose:
t0 = time.time()
qI = ai.integrate1d(xrd_map,steps,**attrs)
if verbose:
t1 = time.time()
print('\tTime to integrate data = %0.3f s' % ((t1-t0)))
else:
print('pyFAI not imported. Cannot calculate 1D integration without it.')
return
return qI
示例15: openPONI
def openPONI(self,event):
wildcards = 'pyFAI calibration file (*.poni)|*.poni|All files (*.*)|*.*'
dlg = wx.FileDialog(self, message='Choose pyFAI calibration file',
defaultDir=os.getcwd(),
wildcard=wildcards, style=wx.FD_OPEN)
path, read = None, False
if dlg.ShowModal() == wx.ID_OK:
read = True
path = dlg.GetPath().replace('\\', '/')
dlg.Destroy()
if read:
try:
print('Loading calibration file: %s' % path)
ai = pyFAI.load(path)
except:
print('Not recognized as a pyFAI calibration file.')
return
self.addLAMBDA(ai._wavelength,units='m')