本文整理汇总了Python中pyFAI.azimuthalIntegrator.AzimuthalIntegrator.setPyFAI方法的典型用法代码示例。如果您正苦于以下问题:Python AzimuthalIntegrator.setPyFAI方法的具体用法?Python AzimuthalIntegrator.setPyFAI怎么用?Python AzimuthalIntegrator.setPyFAI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyFAI.azimuthalIntegrator.AzimuthalIntegrator
的用法示例。
在下文中一共展示了AzimuthalIntegrator.setPyFAI方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_geo
# 需要导入模块: from pyFAI.azimuthalIntegrator import AzimuthalIntegrator [as 别名]
# 或者: from pyFAI.azimuthalIntegrator.AzimuthalIntegrator import setPyFAI [as 别名]
def load_geo(cal_params):
from pyFAI.azimuthalIntegrator import AzimuthalIntegrator
ai = AzimuthalIntegrator()
ai.setPyFAI(**cal_params)
return ai
示例2: test_smoke_load
# 需要导入模块: from pyFAI.azimuthalIntegrator import AzimuthalIntegrator [as 别名]
# 或者: from pyFAI.azimuthalIntegrator.AzimuthalIntegrator import setPyFAI [as 别名]
def test_smoke_load():
with open(pyfai_path) as f:
pyfai_dict = yaml.load(f)
ai = AzimuthalIntegrator()
ai.setPyFAI(**pyfai_dict)
示例3: CalibrationModel
# 需要导入模块: from pyFAI.azimuthalIntegrator import AzimuthalIntegrator [as 别名]
# 或者: from pyFAI.azimuthalIntegrator.AzimuthalIntegrator import setPyFAI [as 别名]
class CalibrationModel(object):
def __init__(self, img_model=None):
"""
:param img_model:
:type img_model: ImgModel
"""
self.img_model = img_model
self.points = []
self.points_index = []
self.spectrum_geometry = AzimuthalIntegrator()
self.cake_geometry = None
self.calibrant = Calibrant()
self.start_values = {'dist': 200e-3,
'wavelength': 0.3344e-10,
'pixel_width': 79e-6,
'pixel_height': 79e-6,
'polarization_factor': 0.99}
self.orig_pixel1 = 79e-6
self.orig_pixel2 = 79e-6
self.fit_wavelength = False
self.fit_distance = True
self.is_calibrated = False
self.use_mask = False
self.filename = ''
self.calibration_name = 'None'
self.polarization_factor = 0.99
self.supersampling_factor = 1
self._calibrants_working_dir = os.path.dirname(calibrants.__file__)
self.cake_img = np.zeros((2048, 2048))
self.tth = np.linspace(0, 25)
self.int = np.sin(self.tth)
self.num_points = len(self.int)
self.peak_search_algorithm = None
def find_peaks_automatic(self, x, y, peak_ind):
"""
Searches peaks by using the Massif algorithm
:param x:
x-coordinate in pixel - should be from original image (not supersampled x-coordinate)
:param y:
y-coordinate in pixel - should be from original image (not supersampled y-coordinate)
:param peak_ind:
peak/ring index to which the found points will be added
:return:
array of points found
"""
massif = Massif(self.img_model._img_data)
cur_peak_points = massif.find_peaks([x, y], stdout=DummyStdOut())
if len(cur_peak_points):
self.points.append(np.array(cur_peak_points))
self.points_index.append(peak_ind)
return np.array(cur_peak_points)
def find_peak(self, x, y, search_size, peak_ind):
"""
Searches a peak around the x,y position. It just searches for the maximum value in a specific search size.
:param x:
x-coordinate in pixel - should be from original image (not supersampled x-coordinate)
:param y:
y-coordinate in pixel - should be form original image (not supersampled y-coordinate)
:param search_size:
the length of the search rectangle in pixels in all direction in which the algorithm searches for
the maximum peak
:param peak_ind:
peak/ring index to which the found points will be added
:return:
point found (as array)
"""
left_ind = np.round(x - search_size * 0.5)
if left_ind < 0:
left_ind = 0
top_ind = np.round(y - search_size * 0.5)
if top_ind < 0:
top_ind = 0
search_array = self.img_model.img_data[left_ind:(left_ind + search_size),
top_ind:(top_ind + search_size)]
x_ind, y_ind = np.where(search_array == search_array.max())
x_ind = x_ind[0] + left_ind
y_ind = y_ind[0] + top_ind
self.points.append(np.array([x_ind, y_ind]))
self.points_index.append(peak_ind)
return np.array([np.array((x_ind, y_ind))])
def clear_peaks(self):
self.points = []
self.points_index = []
def create_cake_geometry(self):
self.cake_geometry = AzimuthalIntegrator()
pyFAI_parameter = self.spectrum_geometry.getPyFAI()
pyFAI_parameter['polarization_factor'] = self.polarization_factor
pyFAI_parameter['wavelength'] = self.spectrum_geometry.wavelength
self.cake_geometry.setPyFAI(dist=pyFAI_parameter['dist'],
poni1=pyFAI_parameter['poni1'],
poni2=pyFAI_parameter['poni2'],
rot1=pyFAI_parameter['rot1'],
#.........这里部分代码省略.........
示例4: run_mask_builder
# 需要导入模块: from pyFAI.azimuthalIntegrator import AzimuthalIntegrator [as 别名]
# 或者: from pyFAI.azimuthalIntegrator.AzimuthalIntegrator import setPyFAI [as 别名]
def run_mask_builder(exposure=300, dark_sub_bool=True,
polarization_factor=0.99,
sample_name=None, calib_dict=None,
mask_dict=None, save_name=None):
""" function to generate mask
this function will execute a count scan and generate a mask based on
image collected from this scan.
Parameters
----------
exposure : float, optional
exposure time of this scan. default is 300s.
dark_sub_bool : bool, optional
turn on/off of dark subtraction. default is True.
polarization_factor: float, optional.
polarization correction factor, ranged from -1(vertical) to +1
(horizontal). default is 0.99. set to None for no correction.
sample_name : str, optional
name of sample that new mask is going to be generated from.
default is 'mask_target'
calib_dict : dict, optional
dictionary with parameters for geometry correction
software. default is read out from glbl attribute (parameters
from the most recent calibration)
mask_dict : dict, optional
dictionary for arguments in masking function. for more details,
please check docstring from ``xpdan.tools.mask_img``
save_name : str, optional
full path for this mask going to be saved. if it is None,
default name 'xpdacq_mask.npy' will be saved inside
xpdUser/config_base/
Note
----
current software dealing with geometry correction is ``pyFAI``
See also
--------
xpdan.tools.mask_img
"""
_check_obj(_REQUIRED_OBJ_LIST)
ips = get_ipython()
bto = ips.ns_table['user_global']['bt']
xrun = ips.ns_table['user_global']['xrun']
# default behavior
if sample_name is None:
sample_name = 'mask_target'
if mask_dict is None:
mask_dict = glbl.mask_dict
print("INFO: use mask options: {}".format(mask_dict))
if calib_dict is None:
calib_dict = getattr(glbl, 'calib_config_dict', None)
if calib_dict is None:
print("INFO: there is no glbl calibration dictionary linked\n"
"Please do ``run_calibration()`` or provide your own"
"calibration parameter set")
return
# setting up geometry parameters
ai = AzimuthalIntegrator()
ai.setPyFAI(**calib_dict)
# scan
mask_collection_uid = str(uuid.uuid4())
mask_builder_dict = {'sample_name':sample_name,
'sample_composition':{sample_name :1},
'is_mask': True,
'mask_collection_uid': mask_collection_uid}
sample = Sample(bto, mask_builder_dict)
xrun_uid = xrun(sample, ScanPlan(bto, ct, exposure))
light_header = glbl.db[-1]
if dark_sub_bool:
dark_uid = light_header.start['sc_dk_field_uid']
dark_header = glbl.db[dark_uid]
dark_img = np.asarray(glbl.db.get_images(dark_header,
glbl.det_image_field)).squeeze()
for ev in glbl.db.get_events(light_header, fill=True):
img = ev['data'][glbl.det_image_field]
if dark_sub_bool:
img -= dark_img
img /= ai.polarization(img.shape, polarization_factor)
mask = mask_img(img, ai, **mask_dict)
print("INFO: add mask to global state")
glbl.mask = mask
if save_name is None:
save_name = os.path.join(glbl.config_base, glbl.mask_md_name)
# still save the most recent mask, as we are in file-based
np.save(save_name, mask)
return mask
示例5: CalibrationData
# 需要导入模块: from pyFAI.azimuthalIntegrator import AzimuthalIntegrator [as 别名]
# 或者: from pyFAI.azimuthalIntegrator.AzimuthalIntegrator import setPyFAI [as 别名]
class CalibrationData(object):
def __init__(self, img_data=None):
self.img_data = img_data
self.points = []
self.points_index = []
self.spectrum_geometry = AzimuthalIntegrator()
self.calibrant = Calibrant()
self.start_values = {'dist': 200e-3,
'wavelength': 0.3344e-10,
'pixel_width': 79e-6,
'pixel_height': 79e-6,
'polarization_factor': 0.99}
self.orig_pixel1 = 79e-6
self.orig_pixel2 = 79e-6
self.fit_wavelength = False
self.fit_distance = True
self.is_calibrated = False
self.use_mask = False
self.filename = ''
self.calibration_name = 'None'
self.polarization_factor = 0.99
self.supersampling_factor = 1
self._calibrants_working_dir = os.path.dirname(Calibrants.__file__)
self.cake_img = np.zeros((2048, 2048))
self.tth = np.linspace(0, 25)
self.int = np.sin(self.tth)
def find_peaks_automatic(self, x, y, peak_ind):
"""
Searches peaks by using the Massif algorithm
:param x:
x-coordinate in pixel - should be from original image (not supersampled x-coordinate)
:param y:
y-coordinate in pixel - should be from original image (not supersampled y-coordinate)
:param peak_ind:
peak/ring index to which the found points will be added
:return:
array of points found
"""
massif = Massif(self.img_data._img_data)
cur_peak_points = massif.find_peaks([x, y])
if len(cur_peak_points):
self.points.append(np.array(cur_peak_points))
self.points_index.append(peak_ind)
return np.array(cur_peak_points)
def find_peak(self, x, y, search_size, peak_ind):
"""
Searches a peak around the x,y position. It just searches for the maximum value in a specific search size.
:param x:
x-coordinate in pixel - should be from original image (not supersampled x-coordinate)
:param y:
y-coordinate in pixel - should be form original image (not supersampled y-coordinate)
:param search_size:
the amount of pixels in all direction in which the algorithm searches for the maximum peak
:param peak_ind:
peak/ring index to which the found points will be added
:return:
point found (as array)
"""
left_ind = np.round(x - search_size * 0.5)
top_ind = np.round(y - search_size * 0.5)
x_ind, y_ind = np.where(self.img_data._img_data[left_ind:(left_ind + search_size),
top_ind:(top_ind + search_size)] == \
self.img_data._img_data[left_ind:(left_ind + search_size),
top_ind:(top_ind + search_size)].max())
x_ind = x_ind[0] + left_ind
y_ind = y_ind[0] + top_ind
self.points.append(np.array([x_ind, y_ind]))
self.points_index.append(peak_ind)
return np.array([np.array((x_ind, y_ind))])
def clear_peaks(self):
self.points = []
self.points_index = []
def create_cake_geometry(self):
self.cake_geometry = AzimuthalIntegrator()
pyFAI_parameter = self.spectrum_geometry.getPyFAI()
pyFAI_parameter['polarization_factor'] = self.polarization_factor
pyFAI_parameter['wavelength'] = self.spectrum_geometry.wavelength
self.cake_geometry.setPyFAI(dist=pyFAI_parameter['dist'],
poni1=pyFAI_parameter['poni1'],
poni2=pyFAI_parameter['poni2'],
rot1=pyFAI_parameter['rot1'],
rot2=pyFAI_parameter['rot2'],
rot3=pyFAI_parameter['rot3'],
pixel1=pyFAI_parameter['pixel1'],
pixel2=pyFAI_parameter['pixel2'])
self.cake_geometry.wavelength = pyFAI_parameter['wavelength']
def setup_peak_search_algorithm(self, algorithm, mask=None):
"""
Initializes the peak search algorithm on the current image
:param algorithm:
peak search algorithm used. Possible algorithms are 'Massif' and 'Blob'
#.........这里部分代码省略.........
示例6: CalibrateDialog
# 需要导入模块: from pyFAI.azimuthalIntegrator import AzimuthalIntegrator [as 别名]
# 或者: from pyFAI.azimuthalIntegrator.AzimuthalIntegrator import setPyFAI [as 别名]
#.........这里部分代码省略.........
self.prepare_parameters()
self.orig_pixel1 = self.pixel_size
self.orig_pixel2 = self.pixel_size
self.pattern_geometry = GeometryRefinement(self.point_array,
dist=self.distance,
wavelength=self.wavelength,
pixel1=self.pixel_size,
pixel2=self.pixel_size,
calibrant=self.calibrant)
self.refine()
self.create_cake_geometry()
self.pattern_geometry.reset()
def refine(self):
self.pattern_geometry.data = self.point_array
if self.parameters['wavelength'].vary:
self.pattern_geometry.refine2()
fix = []
else:
fix = ['wavelength']
if not self.parameters['distance'].vary:
fix.append('dist')
self.pattern_geometry.refine2_wavelength(fix=fix)
self.read_parameters()
self.is_calibrated = True
self.create_cake_geometry()
self.pattern_geometry.reset()
def create_cake_geometry(self):
self.cake_geometry = AzimuthalIntegrator()
pyFAI_parameter = self.pattern_geometry.getPyFAI()
pyFAI_parameter['wavelength'] = self.pattern_geometry.wavelength
self.cake_geometry.setPyFAI(dist=pyFAI_parameter['dist'],
poni1=pyFAI_parameter['poni1'],
poni2=pyFAI_parameter['poni2'],
rot1=pyFAI_parameter['rot1'],
rot2=pyFAI_parameter['rot2'],
rot3=pyFAI_parameter['rot3'],
pixel1=pyFAI_parameter['pixel1'],
pixel2=pyFAI_parameter['pixel2'])
self.cake_geometry.wavelength = pyFAI_parameter['wavelength']
def plot_cake(self):
if 'Cake Plot' in plotviews:
plotview = plotviews['Cake Plot']
else:
plotview = NXPlotView('Cake Plot')
if not self.is_calibrated:
raise NeXusError('No refinement performed')
res = self.cake_geometry.integrate2d(self.counts,
1024, 1024,
method='csr',
unit='2th_deg',
correctSolidAngle=True)
self.cake_data = NXdata(res[0], (NXfield(res[2], name='azimumthal_angle'),
NXfield(res[1], name='polar_angle')))
self.cake_data['title'] = self.entry['instrument/calibration/title']
plotview.plot(self.cake_data, log=True)
wavelength = self.parameters['wavelength'].value
polar_angles = [2 * np.degrees(np.arcsin(wavelength/(2*d)))
for d in self.calibrant.dSpacing]
plotview.vlines([polar_angle for polar_angle in polar_angles
if polar_angle < plotview.xaxis.max],
linestyle=':', color='r')