def test_gauss(): n = 64 sigma = 2 mean = n // 2 x = np.arange(n) gt = np.exp(-((x - float(mean))**2) / (2 * sigma**2)) g = get_gauss(x, mean, sigma, normalized=False) g_norm = get_gauss(n, mean, sigma, normalized=True) np.testing.assert_almost_equal(gt, g) assert np.abs(np.sum(g_norm) - 1) < 1e-7 # Extremely broad peak, sum must be 1 anyway g = get_gauss(x, mean, n, normalized=True) assert np.abs(np.sum(g_norm) - 1) < 1e-7
def __init__(self, energies, center, sigma, peak_transmission=1): """Create a Gussian beam filter for *energies* [keV], center it at *center* [keV] and use std *sigma* [keV]. *peak_transmission* specifies the transmitted intensity for energy *center*, i.e. this is the highest transmitted intensity. """ if len(energies) < 4: raise ValueError('Number of energy points too low for interpolation') energies = energies.rescale(q.keV).magnitude center = center.rescale(q.keV).magnitude sigma = sigma.rescale(q.keV).magnitude profile = get_gauss(energies, center, sigma) * peak_transmission * q.keV self._tck = interp.splrep(energies, profile)
def __init__(self, energies, center, sigma, peak_transmission=1): """Create a Gussian beam filter for *energies* [keV], center it at *center* [keV] and use std *sigma* [keV]. *peak_transmission* specifies the transmitted intensity for energy *center*, i.e. this is the highest transmitted intensity. """ if len(energies) < 4: raise ValueError("Number of energy points too low for interpolation") energies = energies.rescale(q.keV).magnitude center = center.rescale(q.keV).magnitude sigma = sigma.rescale(q.keV).magnitude profile = get_gauss(energies, center, sigma) * peak_transmission * q.keV self._tck = interp.splrep(energies, profile)
def main(): args = parse_args() syris.init() n = 1024 shape = (n, n) ps = 1 * q.um tr = Trajectory([(n / 2, n / 2, 0)] * ps, pixel_size=ps) energy_center = args.energy_center * q.keV fwhm = args.energy_resolution * energy_center sigma = smath.fwnm_to_sigma(fwhm, n=2) # Make sure we resolve the curve nicely energies = np.arange(max(1 * q.keV, energy_center - 2 * fwhm), energy_center + 2 * fwhm, fwhm / 25) * q.keV dE = energies[1] - energies[0] print 'Energy from, to, step, number:', energies[0], energies[-1], dE, len( energies) bm = make_topotomo(dE=dE, pixel_size=ps, trajectory=tr) spectrum_energies = np.arange(1, 50, 1) * q.keV native_spectrum = get_spectrum(bm, spectrum_energies, ps) fltr = GaussianFilter(energies, energy_center, sigma) gauss = get_gauss(energies.magnitude, energy_center.magnitude, sigma.magnitude) filtered_spectrum = get_spectrum(bm, energies, ps) * gauss intensity = propagate([bm, fltr], shape, energies, 0 * q.m, ps).get() show(intensity, title='Intensity for energy range {} - {}'.format( energies[0], energies[-1])) plt.figure() plt.plot(spectrum_energies.magnitude, native_spectrum) plt.title('Source Spectrum') plt.xlabel('Energy [keV]') plt.ylabel('Intensity') plt.figure() plt.plot(energies.magnitude, gauss) plt.title('Gaussian Filter') plt.xlabel('Energy [keV]') plt.ylabel('Transmitted intensity') plt.figure() plt.plot(energies.magnitude, filtered_spectrum) plt.title('Filtered Spectrum') plt.xlabel('Energy [keV]') plt.ylabel('Intensity') plt.show()
def main(): args = parse_args() syris.init() n = 1024 shape = (n, n) ps = 1 * q.um tr = Trajectory([(n / 2, n / 2, 0)] * ps, pixel_size=ps) energy_center = args.energy_center * q.keV fwhm = args.energy_resolution * energy_center sigma = smath.fwnm_to_sigma(fwhm, n=2) # Make sure we resolve the curve nicely energies = np.arange(max(1 * q.keV, energy_center - 2 * fwhm), energy_center + 2 * fwhm, fwhm / 25) * q.keV dE = energies[1] - energies[0] print 'Energy from, to, step, number:', energies[0], energies[-1], dE, len(energies) bm = make_topotomo(dE=dE, pixel_size=ps, trajectory=tr) spectrum_energies = np.arange(1, 50, 1) * q.keV native_spectrum = get_spectrum(bm, spectrum_energies, ps) fltr = GaussianFilter(energies, energy_center, sigma) gauss = get_gauss(energies.magnitude, energy_center.magnitude, sigma.magnitude) filtered_spectrum = get_spectrum(bm, energies, ps) * gauss intensity = propagate([bm, fltr], shape, energies, 0 * q.m, ps).get() show(intensity, title='Intensity for energy range {} - {}'.format(energies[0], energies[-1])) plt.figure() plt.plot(spectrum_energies.magnitude, native_spectrum) plt.title('Source Spectrum') plt.xlabel('Energy [keV]') plt.ylabel('Intensity') plt.figure() plt.plot(energies.magnitude, gauss) plt.title('Gaussian Filter') plt.xlabel('Energy [keV]') plt.ylabel('Transmitted intensity') plt.figure() plt.plot(energies.magnitude, filtered_spectrum) plt.title('Filtered Spectrum') plt.xlabel('Energy [keV]') plt.ylabel('Intensity') plt.show()