def __init__(self, fpath, unused_detector=23, phi=None): """ Extract useful data from raw .nxs file. Deletes data from unused detector. Allows definition of az_angle (phi) if the unused detector is not 23. Prepares the file for peak/profile analysis. Args: fpath (str): Path to NeXus file unused_detector (int): Unused detector (normally 23) phi (ndarray, list): Re-define phi if detector order is mixed """ self.fpath = fpath f = h5py.File(fpath, 'r') # Use scan command to find number of dimensions and the order in which # they were acquired. Important/useful for plotting! scan_command = f['entry1/scan_command'][()][0] dims = re.findall(b'ss2_\w+', scan_command) self.ndim = len(dims) all_dims = [b'ss2_x', b'ss2_y', b'ss2_z'] dims = dims + [dim for dim in all_dims if dim not in dims] co_ords = [] for dim in dims: co_ords.append(dimension_fill(f, dim.decode("utf-8"))) self.d1, self.d2, self.d3 = co_ords # Remove unused detector - resulting detector array is almost certainly # arrayed in ascending order from from -np.pi to 0 (phi). Option exists # to specify the order if this isn't true. self.q = f['entry1/EDXD_elements/edxd_q'][()] self.q = np.delete(self.q, unused_detector, 0) self.I = f['entry1/EDXD_elements/data'][()] self.I = np.delete(self.I, unused_detector, -2) self.phi = np.linspace(-np.pi, 0, 23) if phi is None else phi self.analysis_state = 'integrated' self.detector = i12_energy()
def __init__(self, folder, fend='mca', fname=None, phi=[0, np.pi / 2]): """ Takes a folder containing .mca data files from ED detectors and merges the data while associating it with spatial information. The I data can then be analysed (peak_fit/strain calculations). Args: folder (str): Folder containing the files for analysis """ fname = '{}.h5'.format(os.path.split(folder)[1]) self.fpath = os.path.join(folder, fname) self.phi = np.array(phi) co_ords, self.I = mca_array(folder, fend) (self.d1, self.d2, self.d3), self.dims = dim_fill(co_ords) self.ndim = len(self.dims) # Not sure how data will be presented, but this can be remedied. E = np.linspace(0, 4095, 4096) q1 = e_to_q(0.07 + 0.07493 * E + 4.422e-8 * E, 5.10541851 * np.pi / 180) q2 = e_to_q(0.1453 + 0.07483 * E + 9.026e-8 * E, 4.9718601 * np.pi / 180) #E = np.vstack((q1, q2)) self.q = np.vstack((q1, q2)) # Create az_slice 'specific' q values - to work with edxd data #self.q = np.repeat(q[None, :], self.phi.size, axis=0) self.analysis_state = 'integrated' # Temporary - extract from ai! self.detector = i12_energy() #folder = os.path.expanduser(r'~/Dropbox/Python/nc_ni/') #test = EDID15(folder)
from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals from mock import patch import numpy as np import matplotlib.pyplot as plt from pyxpb.detectors import i12_energy i12 = i12_energy() i12.add_material('Fe') def test_intensity_profiles(): phi = np.pi / 3.2 profile_0 = i12.intensity(phi, background=0, x_axis='q', strain_tensor=(0.2, 0.2, 0.3)) profile_180 = i12.intensity(phi - np.pi, background=0, x_axis='q', strain_tensor=(0.2, 0.2, 0.3)) assert np.allclose(profile_0[1]['Fe'], profile_180[1]['Fe']) # Test a few combinations of parameters i12.intensity(0, background=0, x_axis='energy',
from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals from mock import patch import numpy as np from pyxpb.detectors import i12_energy i12 = i12_energy() i12.add_material('Fe') def test_intensity_profiles(): phi = np.pi / 3.2 profile_0 = i12.intensity(phi, background=0, x_axis='q', strain_tensor=(0.2, 0.2, 0.3)) profile_180 = i12.intensity(phi-np.pi, background=0, x_axis='q', strain_tensor=(0.2, 0.2, 0.3)) assert np.allclose(profile_0[1]['Fe'], profile_180[1]['Fe']) # Test a few combinations of parameters i12.intensity(0, background=0, x_axis='energy', strain_tensor=(0.2, 0.2, 0.3)) i12.intensity([0, np.pi/7], background=0, x_axis='energy', strain_tensor=(0., 0., 0.)) def test_all_intensity():