def calibrated_pixels_to_q(detector_size, pyfai_kwargs): """ For a given detector and pyfai calibrated geometry give back the q value for each pixel in the detector. Parameters ----------- detector_size : tuple 2 element tuple defining the number of pixels in the detector. Order is (num_columns, num_rows) pyfai_kwargs: dict The dictionary of pyfai geometry kwargs, given by pyFAI's calibration Ex: dist, poni1, poni2, rot1, rot2, rot3, splineFile, wavelength, detector, pixel1, pixel2 Returns ------- q_val : ndarray Reciprocal values for each pixel shape is [num_rows * num_columns] """ if geo is None: raise RuntimeError("You must have pyFAI installed to use this " "function.") a = geo.Geometry(**pyfai_kwargs) return a.qArray(detector_size)
def testGeometryFunctions(self): func, statargs, varargs, kwds, expectedFail = self.param kwds["pixel1"] = 1 kwds["pixel2"] = 1 g = geometry.Geometry(**kwds) g.wavelength = 1e-10 t0 = time.time() oldret = getattr(g, func)(*statargs, path=varargs[0]) t1 = time.time() newret = getattr(g, func)(*statargs, path=varargs[1]) t2 = time.time() logger.debug("TIMINGS\t meth: %s t=%.3fs\t meth: %s t=%.3fs" % (varargs[0], t1 - t0, varargs[1], t2 - t1)) maxDelta = abs(oldret - newret).max() msg = "geo=%s%s max delta=%.3f" % (g, os.linesep, maxDelta) if expectedFail: self.assertNotAlmostEquals(maxDelta, 0, 3, msg) else: self.assertAlmostEquals(maxDelta, 0, 3, msg) logger.info(msg)
def __display3dDialog(self): from ..dialog.Detector3dDialog import Detector3dDialog dialog = Detector3dDialog(self) settings = self.model().experimentSettingsModel() detector = settings.detectorModel().detector() image = settings.image().value() mask = settings.mask().value() colormap = CalibrationContext.instance().getRawColormap() geometry = None fittedGeometry = self.model().fittedGeometry() if fittedGeometry.isValid(): from pyFAI import geometry geometry = geometry.Geometry() model_transform.geometryModelToGeometry(fittedGeometry, geometry) dialog.setData(detector=detector, image=image, mask=mask, colormap=colormap, geometry=geometry) dialog.exec_()
qsize = map_x.size qshape = map_x.shape qimg = np.fromiter((image[(i, j)] for i, j in np.nditer([map_y.astype(int), map_x.astype(int)])), dtype=np.float, count=qsize).reshape(qshape) qimg[mask] = 0.0 return ( np.rot90(qimg, 3), qpar, qvrt) return if __name__ == '__main__': import fabio, pylab as plt, time filename = 'Burst/calibration/AGB_5S_USE_2_2m.edf' image = fabio.open(filename).data sdd = 0.283351 cen_y = 0.005363 cen_x = 0.040123 pixel = 0.000172 geo = geometry.Geometry(sdd, cen_y, cen_x, 0, 0, 0) geo.set_wavelength(1.23984e-10) geo.set_pixel1(0.000172) geo.set_pixel2(0.000172) t0 = time.clock() qimg = remesh(image, filename, geo) t1 = time.clock() - t0 print 'remesh clock time = %f' % t1 plt.imshow(np.log(qimg + 5)) plt.show() # okay decompiling remesh.pyc
def test_remesh(): filename = 'GIWAXS_sfloat_2m.gb' center = [632., 69.5] pixel = [172E-06, 172E-06] poni = np.multiply(center, pixel) dist = 300. det = detectors.Pilatus2M g = geometry.Geometry(dist=0.3, poni1=poni[1], poni2=poni[0], pixel1=pixel[0], pixel2=pixel[1], wavelength=0.123984E-09) data = np.fromfile(filename, dtype=np.float32).reshape(1679, 1475) data = np.flipud(data) ai = np.deg2rad(0.14) lims = [[0, 20], [0, 20]] res = [512, 512] # default qp-qz, same size as detector img, x, y = camsaxs.remesh(data, g, ai) box = [x.min(), x.max(), y.min(), y.max()] plt.imshow(np.log(img + 4), origin='lower', extent=box) plt.title('qp_qz_full.png') plt.show() plt.figure() img, x, y = camsaxs.remesh(data, g, ai, res=res, coord_sys='qp_qz', out_range=lims) box = [x.min(), x.max(), y.min(), y.max()] plt.imshow(np.log(img + 4), origin='lower', extent=box) plt.title('qp_qz_roi.png') plt.show() plt.figure() img, x, y = camsaxs.remesh(data, g, ai, coord_sys='qy_qz') box = [x.min(), x.max(), y.min(), y.max()] plt.imshow(np.log(img + 4), origin='lower', extent=box) plt.title('qy_qz_full.png') plt.show() plt.figure() img, x, y = camsaxs.remesh(data, g, ai, res=res, coord_sys='qy_qz') box = [x.min(), x.max(), y.min(), y.max()] plt.imshow(np.log(img + 4), origin='lower', extent=box) plt.title('qy_qz_roi.png') plt.show() plt.figure() img, x, y = camsaxs.remesh(data, g, ai, coord_sys='theta_alpha') box = [x.min(), x.max(), y.min(), y.max()] plt.imshow(np.log(img + 4), origin='lower', extent=box) plt.title('th_al_full.png') plt.show() plt.figure() lims = [[-0.1, 0.1], [0, 0.2]] res = [2000, 2000] img, x, y = camsaxs.remesh(data, g, ai, res=res, coord_sys='theta_alpha', out_range=lims) box = [x.min(), x.max(), y.min(), y.max()] plt.imshow(np.log(img + 4), origin='lower', extent=box) plt.title('th_al_roi.png') plt.show()