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)" |
Yes that's it. Because then the distribution in the detector will be unchanged, assuming we sampled a reasonable number of points to figure out what region of the source makes it to the detector.
I don't understand why we want the shape of the new source to be independent of the original source. If we want the new source to be finer than the original source, then we can first up-sample the original source (for example by using scipy.ndimage.zoom, or scipp.rebin) to the desired shape, and then do the same thing. Making the new source coarser than the original source does not seem useful, but I might be missing something. |
|
I meant that to do an operation such as In my current version, I had missed that in the code you proposed, you suggested to use for histogramming the bin edges from the original source, which ensures consistency. |

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(...).