def setup_detector(theta, calib_csv=calib_csv): det_param_df = pd.read_csv(calib_csv) det_kwargs = dict(zip(det_param_df['param'], det_param_df['val'])) # Detector only holds pixel size for whatever reason detector = pyFAI.detectors.Detector(det_kwargs['det_pix'], det_kwargs['det_pix']) # Transform holds everything else pg = pygix.Transform( incident_angle=theta, detector=detector, **{k: v for k, v in det_kwargs.items() if k != 'det_pix'}) return pg
def create_ai_from_dict(poni_dict, gi=False): """Create Azimuthal Integrator object from Dictionary""" ai = AzimuthalIntegrator() for k, v in poni_dict.items(): ai.__setattr__(k, v) if not gi: ai._rot3 -= np.deg2rad(90) else: calib_pars = dict(dist=ai._dist, poni1=ai._poni1, poni2=ai._poni2, rot1=ai._rot1, rot2=ai._rot2, rot3=ai._rot3, wavelength=ai._wavelength, detector=ai.detector) ai = pygix.Transform(**calib_pars) ai.sample_orientation = 3 # 1 is horizontal, 2 is vertical return ai
directory = '/Users/rbelisle/Desktop/5050onoff/' file_interest = 'D7a_MAPbIBr2_PTAA_L60On_30s_01231947_0001.tif' dataFile = directory + file_interest data = fabio.open(dataFile).data # Use fabio to open file as a np.array # plot the imported file (this will not be calibrated) fig1, ax1 = plt.subplots() ax1.set_xlabel("x-pixel (#)") ax1.set_ylabel("y-pixel (#)") ax1.yaxis.set_ticks_position('both') ax1.xaxis.set_ticks_position('both') ax1.imshow(data, vmin=3, vmax=100, origin='lower') #use imshow to rasterize np.array # %% Load calibration file and set sample geomtetry pg = pygix.Transform() # set up the transformation file pg.load('/Users/rbelisle/Desktop/lab6_calib_315_0122.poni' ) # load the callibration file pg.sample_orientation = 3 # set sample orientation: 1 is horizontal, 2 is vertical, 3 is horizontal rotated by 180 deg, 4 is vertical rotated by 180 deg (for more details see: https://github.com/tgdane/pygix/blob/master/pygix/transform.py) pg.incident_angle = 3 # set indicent x-ray angle in deg pg.tilt_angle = 0 # tilt angle of sample in deg (misalignment in "chi") pg # optionally print geometry #%% Run calibration accounting for solid angle correction ii_2d, qxy_2d, qz_2d = pg.transform_reciprocal(data, correctSolidAngle=True, method='bbox', npt=3000) #plot the corrected file in the correct units fig2, ax2 = plt.subplots()
r[1:, 0] = q * .1 r[0, i + 1] = os.path.basename(tif) r[1:, i + 1] = intensity df = pd.DataFrame(r[1:], columns=r[0]) df['q'] = df['q'].apply(lambda x: x * 10) df.set_index(df['q'], inplace=True) df.drop(['q'], axis=1, inplace=True) plt.imshow(np.log(img)) plt.savefig(os.path.join( parentdir, 'results', 'png', os.path.basename(tif).replace('.tif', '') + '.png'), bbox_inches='tight') plt.close() pg = pygix.Transform() pg.load(ponifile) pg.incident_angle = incident_angle pg.sample_orientation = sample_orientation # qxyxz plot: intensity, qxy, qz = pg.transform_reciprocal(img, npt=(qbins, qbins), polarization_factor=-.95, method='nearest') with open('{}/png_qxyqz/{}_imageData.dat'.format(resultdir, filename), 'w') as f: np.savetxt(f, intensity) # default method is "splitpix", which for some reason fills the wedge with interpolated pixels. Function is defined in C:/Anaconda2/Lib/site-packages/pyFAI/ext/splitpixelFull.pyd, which is already compiled, so cannot be fixed. # Methods 'np' and 'cython' don't fill wedge, but returned array is much too big and mostly black, so valuable data fills only a few pixels. ip_range and op_range are defined to customize the range, but don't work