def test_generate_signal(): data = np.ones((1, 10)) * np.arange(1, 5).reshape(4, 1) data = data.reshape(2, 2, 10) pdf = PairDistributionFunction1D(data) assert isinstance(pdf, PairDistributionFunction1D) pdf.normalise_signal() assert np.equal(pdf, np.ones((2, 2, 10)))
def get_pdf(self, s_min, s_max=None, r_min=0, r_max=20, r_increment=0.01 ): """ Calculates the pdf from the reduced intensity signal. Parameters ---------- s_min : float Minimum scattering vector s for the pdf calculation. Note that s is defined here as s = 2 sin(theta)/lambda = 1/d. s_max : float Maximum scattering vector s for the pdf calculation. Note that s is defined here as s = 2 sin(theta)/lambda = 1/d. r_cutoff : list of float A list with the format [<r_min>, <r_max>], which sets the limits of the real space axis in the calculated PDF. r_increment : float Step size in r in the extracted PDF. Returns ------- pdf : PDF1D A signal of pair distribution functions. """ s_scale = self.signal.axes_manager.signal_axes[0].scale if s_max is None: s_max = self.signal.axes_manager.signal_axes[0].size * s_scale print('s_max set to maximum of signal.') r_values = np.arange(r_min, r_max, r_increment) r_values = r_values.reshape(1, r_values.size) s_limits = [int(s_min / s_scale), int(s_max / s_scale)] #check that these aren't out of bounds if s_limits[1] > self.signal.axes_manager.signal_axes[0].size: raise ValueError('User specified s_max is larger than the maximum ' 'scattering vector magnitude in the data. Please reduce ' 's_max or use s_max=None to use the full scattering range.') s_values = np.arange(s_limits[0], s_limits[1], 1) * s_scale s_values = s_values.reshape(s_values.size, 1) # column vector limited_red_int = self.signal.isig[s_limits[0]:s_limits[1]].data pdf_sine = np.sin(2 * np.pi * np.matmul(s_values,r_values)) # creates a vector of the pdf rpdf = PairDistributionFunction1D(8 * np.pi * s_scale * np.matmul(limited_red_int,pdf_sine)) signal_axis = rpdf.axes_manager.signal_axes[0] pdf_scaling = r_increment signal_axis.scale = pdf_scaling signal_axis.name = 'Radius r' signal_axis.units = '$Å$' rpdf = transfer_navigation_axes(rpdf,self.signal) return rpdf