scipp / tof

A simple tool to create time-of-flight chopper cascade diagrams
https://tof.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

Add notebooks describing pulses and beamline components #26

Closed nvaytet closed 1 year ago

nvaytet commented 1 year ago
nvaytet commented 1 year ago

@SimonHeybrock this is ready for another review, thanks.

nvaytet commented 1 year ago

@SimonHeybrock another review would be good at this point. Going the read-only way for the results, I tried to make more use of dataclasses and less use of custom classes. We can do an in-person walkthrough at some point if you are getting lost in all the changes

nvaytet commented 1 year ago

@SimonHeybrock I think I am now more or less happy with this. I think I addressed your final comments.

In addition, I think I fixed something that had been bugging me for some time. Sampling the neutrons from the time and wavelength distributions were being done with np.random.choice, which only selects from the available values you pass to it, meaning that if you give 10,000 possible wavelengths, it will only have those in the pulse and nothing in between those values.

This meant that if you use a fine binning to inspect your result, you will see spikes separated by empty bins (Premek actually saw this in notebook) unless you really crank up the sampling number for the interpolation.

I tried out the Scipy methods for sampling from a continuous distribution (you just provide a callable function that defines the probability distribution instead of a discrete numpy array), but they are too slow for our use case (many minutes to create 10M neutrons).

Finally, I came up with a small trick where after sampling using random.choice, I add some noise to the values (+/- a small delta of the scale of the bin width) to spread them between the bins. This seems to work well, but maybe you want to check there isn't something fundamentally bad with the approach?