def recip_ex(detector_size, pixel_size, calibrated_center, dist_sample, ub_mat, wavelength, motors, i_stack, H_range, K_range, L_range): # convert to Q space q_values = recip.process_to_q(motors, detector_size, pixel_size, calibrated_center, dist_sample, wavelength, ub_mat) # minimum and maximum values of the voxel q_min = np.array([H_range[0], K_range[0], L_range[0]]) q_max = np.array([H_range[1], K_range[1], L_range[1]]) # no. of bins dqn = np.array([40, 40, 1]) # process the grid values (grid_data, grid_occu, std_err, grid_out, bounds) = grid3d(q_values, i_stack, dqn[0], dqn[1], dqn[2]) grid = np.mgrid[0:dqn[0], 0:dqn[1], 0:dqn[2]] r = (q_max - q_min) / dqn X = grid[0] * r[0] + q_min[0] Y = grid[1] * r[1] + q_min[1] Z = grid[2] * r[2] + q_min[2] # creating a mask _mask = grid_occu <= 10 grid_mask_data = ma.masked_array(grid_data, _mask) grid_mask_std_err = ma.masked_array(std_err, _mask) grid_mask_occu = ma.masked_array(grid_occu, _mask) return X, Y, Z, grid_mask_data
def test_process_to_q(): detector_size = (256, 256) pixel_size = (0.0135 * 8, 0.0135 * 8) calibrated_center = (256 / 2.0, 256 / 2.0) dist_sample = 355.0 energy = 640 # ( in eV) # HC_OVER_E to convert from Energy to wavelength (Lambda) hc_over_e = 12398.4 wavelength = hc_over_e / energy # (Angstrom ) ub_mat = np.array([[-0.01231028454, 0.7405370482, 0.06323870032], [0.4450897473, 0.04166852402, -0.9509449389], [-0.7449130975, 0.01265920962, -0.5692399963]]) setting_angles = np.array([[40., 15., 30., 25., 10., 5.], [90., 60., 0., 30., 10., 5.]]) # delta=40, theta=15, chi = 90, phi = 30, mu = 10.0, gamma=5.0 pdict = {} pdict['setting_angles'] = setting_angles pdict['detector_size'] = detector_size pdict['pixel_size'] = pixel_size pdict['calibrated_center'] = calibrated_center pdict['dist_sample'] = dist_sample pdict['wavelength'] = wavelength pdict['ub'] = ub_mat # ensure invalid entries for frame_mode actually fail # todo test frame_modes 1, 2, and 3 # test that the values are coming back as expected for frame_mode=4 hkl = recip.process_to_q(**pdict) # Known HKL values for the given six angles) # each entry in list is (pixel_number, known hkl value) known_hkl = [(32896, np.array([-0.15471196, 0.19673939, -0.11440936])), (98432, np.array([0.10205953, 0.45624416, -0.27200778]))] for pixel, kn_hkl in known_hkl: npt.assert_array_almost_equal(hkl[pixel], kn_hkl, decimal=8) # smoketest the frame_mode variable pass_list = recip.process_to_q.frame_mode pass_list.append(None) for passes in pass_list: recip.process_to_q(frame_mode=passes, **pdict)
def test_process_to_q(): detector_size = (256, 256) pixel_size = (0.0135*8, 0.0135*8) calibrated_center = (256/2.0, 256/2.0) dist_sample = 355.0 energy = 640 # ( in eV) # HC_OVER_E to convert from Energy to wavelength (Lambda) hc_over_e = 12398.4 wavelength = hc_over_e / energy # (Angstrom ) ub_mat = np.array([[-0.01231028454, 0.7405370482, 0.06323870032], [0.4450897473, 0.04166852402, -0.9509449389], [-0.7449130975, 0.01265920962, -0.5692399963]]) setting_angles = np.array([[40., 15., 30., 25., 10., 5.], [90., 60., 0., 30., 10., 5.]]) # delta=40, theta=15, chi = 90, phi = 30, mu = 10.0, gamma=5.0 pdict = {} pdict['setting_angles'] = setting_angles pdict['detector_size'] = detector_size pdict['pixel_size'] = pixel_size pdict['calibrated_center'] = calibrated_center pdict['dist_sample'] = dist_sample pdict['wavelength'] = wavelength pdict['ub'] = ub_mat # ensure invalid entries for frame_mode actually fail # todo test frame_modes 1, 2, and 3 # test that the values are coming back as expected for frame_mode=4 hkl = recip.process_to_q(**pdict) # Known HKL values for the given six angles) # each entry in list is (pixel_number, known hkl value) known_hkl = [(32896, np.array([-0.15471196, 0.19673939, -0.11440936])), (98432, np.array([0.10205953, 0.45624416, -0.27200778]))] for pixel, kn_hkl in known_hkl: npt.assert_array_almost_equal(hkl[pixel], kn_hkl, decimal=8) # smoketest the frame_mode variable pass_list = recip.process_to_q.frame_mode pass_list.append(None) for passes in pass_list: recip.process_to_q(frame_mode=passes, **pdict)
def _process_to_q_exception(param_dict, frame_mode): with pytest.raises(KeyError): recip.process_to_q(frame_mode=frame_mode, **param_dict)
def _process_to_q_exception(param_dict, frame_mode): recip.process_to_q(frame_mode=frame_mode, **param_dict)