Document how to use a component reading to create a new source#131
Document how to use a component reading to create a new source#131nvaytet wants to merge 3 commits intoinelastic-samplefrom
Conversation
…ore efficient source
|
Interesting! Could give a big speedup in some cases. However, I'd like to suggest a modification. Currently the probability of sampling neutrons from point If we have a source distribution such that the probability density of Intuitively, with the new source we only increase the probability of sampling in the region where we actually need to sample, but in that region, the ratio of the probabilities of sampling two points does not change. After applying the gaussian kernel to I'm imagining it would look something like this: def source_from_reading(\n",
reading,
original_source,
neutrons: int,
time_smooth_kernel: sc.Variable | None = None,
wavelength_smooth_kernel: sc.Variable | None = None,
):
from scipp.scipy.ndimage import gaussian_filter
p = reading.data.hist(wavelength=original_source.coords['wavelength'], birth_time=original_source.coords['birth_time'])
if time_smooth_kernel is None:
time_smooth_kernel = 2 * time_binning
if wavelength_smooth_kernel is None:
wavelength_smooth_kernel = 2 * wavelength_binning
p = gaussian_filter(
p,
sigma={
'birth_time': time_smooth_kernel,
'wavelength': wavelength_smooth_kernel,
},
)
q = original_source * (p > 1e-8) / (original_source * (p > 1e-8)).sum()
return tof.Source.from_distribution(neutrons=neutrons, p=q)" |
We add section to the docs where we show how to use a component reading to create a more efficient source.
We histogram the neutrons at the detector in wavelength and birth_time, smooth the histogram, and use it as a new distribution to sample from.
Can speed up calculations.
We should consider making the final function into a
classmethodof theSource:Source.from_reading(...).