James-Durant / fisher-information

A framework for determining the maximum information gain and optimising experimental design in neutron reflectometry using the Fisher information.
GNU General Public License v3.0
7 stars 0 forks source link

simulate.py #2

Open andyfaff opened 3 years ago

andyfaff commented 3 years ago

simulate.py doesn't introduce any Angular or wavelength resolution into the simulated datasets, and I don't think it's realistic for simulation of noise in an NR dataset. The noise from both the direct and reflected spectra isn't taken into account.

I think this tof_simulator would be viable for simulating ISIS datasets as well, so long as the correct incoming spectrum was used. Just set the dlambda wavelength resolution to 0 (no chopper dependence), the rebinning uncertainty is handled separately. You also have to change L251 to use ISIS spectra and not ANSTO data.

andyfaff commented 3 years ago

Whilst the noise from the reflected signal is taken into account, I think you have to add noise to the direct beam on L125. With something like:

noise_flux = np.sqrt(flux) * np.random.standard_normal()
flux_noisy = flux + noise_flux

r_noisy = noisy_count / flux_noisy
r_error = np.sqrt(r_noisy**2 * ((noise_flux / flux_noisy)**2 + (error_bar / noisy_count)**2))
James-Durant commented 3 years ago

Hi Andrew, Thank you for all the great comments! The simulation code is definitely not perfect in its current state and we are looking at fixing the issues with it. I'd be happy to incorporate your suggestions and changes into the code.

@jfkcooper is away for Christmas at the moment but I'll have a chat to him when he's back to see what he thinks. Thanks, James

lucas-wilkins commented 3 years ago

Hey guys,

1) I was talking to @jfkcooper about this a couple of weeks ago, the way the background noise is calculated is very strange (I think wrong). I would have done it very differently, but I understand that you wanted to empirically include the error bar size.

I'm not that familiar with the beam line setup, but the basic setup should be something like this (assuming the background noise is shot noise):

measured_reflected_count= np.random.poisson((reflectance * direct_flux_rate + background_rate) * reflect_measure_time)
measured_direct_count= np.random.poisson((direct_flux_rate + background_rate) * direct_measure_time)
measured_reflectance = (measured_reflected_count / measured_direct_count) / (reflect_measure_time / direct_measure_time)

So, far, we have been assuming that the direct_measure_time is sufficiently large for the associated error to be ignored.

2) Whatever you do to the noise model should be done to the Fisher information (don't know where you guys are with that, or how useful it turned out to be)

:L

jfkcooper commented 3 years ago

So we had intentionally not included any noise from the direct beam, the reasoning being that the error on the measured reflectivity point is almost always dictated by the counts on the reflected signal. This is due to the reflected signal being alot less for almost all points; where this isn't the case, is around the critical edge, where we have the highest reflectivity for the longest wavelength neutrons (which are those we have fewest of). The two reasons to still not include the direct beam counts are that it is almost always the case that we have measured the direct beam for longer than the reflected (i.e. more neutrons counted), and those points contain the least information about our structure (there being no information at q values less than the critical edge), thus they would not affect the Fisher information. In terms of the background, I agree that what we are currently doing is incorrect and we will change it to uses np.random.Poisson . Am happy to discuss if I have missed something in my reasoning about the direct beam noise.

andyfaff commented 3 years ago

So we had intentionally not included any noise from the direct beam, the reasoning being that the error on the measured reflectivity point is almost always dictated by the counts on the reflected signal. This is due to the reflected signal being alot less for almost all points; where this isn't the case, is around the critical edge, where we have the highest reflectivity for the longest wavelength neutrons (which are those we have fewest of)

I agree that the contribution to the overall uncertainty from the direct beam will be the largest below the critical edge (although it may also be a reasonable contribution for the first few points over the critical edge as well).

There is information below and around the critical edge: