import numpy as np
from numpy import ndarray
from scipy.special import erf
def _get_factors_by_beam_shape(scattering_angle: ndarray, beam_width: float, sample_length: float, beam_shape: str):
if beam_shape == 'gauss':
return gaussian_factors(scattering_angle, beam_width, sample_length)
elif beam_shape == 'box':
return box_factors(scattering_angle, beam_width, sample_length)
else:
raise ValueError('invalid beam shape')
[docs]def box_factors(scattering_angle, beam_width, sample_length):
max_angle = 2 * np.arcsin(beam_width / sample_length) / np.pi * 180
ratios = beam_footprint_ratio(scattering_angle, beam_width, sample_length)
ones = np.ones_like(scattering_angle)
return np.where(scattering_angle < max_angle, ones * ratios, ones)
[docs]def gaussian_factors(scattering_angle, beam_width, sample_length):
ratio = beam_footprint_ratio(scattering_angle, beam_width, sample_length)
return 1 / erf(np.sqrt(np.log(2)) / ratio)