-
Notifications
You must be signed in to change notification settings - Fork 3
Use normalisation in detector/q space to account for pixel differences #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the explanations are understandable.
Co-authored-by: Jan-Lukas Wynen <jan-lukas.wynen@ess.eu>
"metadata": {}, | ||
"source": [ | ||
"And we then convert to $Q$ as well" | ||
"However, if we want to obtain the normalisation between the sample data and the reference (accounting for detector pixel discontinuities), we want to work with the data with dimensions of `'detector_id'` and `'Q'` (the `*_q_binned` objects). " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is making reading the notebook read a bit more confusing (talking about the *q_binned
quantities).
I would re-work the notebook so that this is what you want to do from the beginning.
You don't define any *_q_summed
quantities, you just stick with the *_q_binned
(and possibly give them a better name), just say that you're making a quick preview in Q by plotting the sum over detector_id
, just as a sanity check.
And just move on to making the normalization as you want it.
There is no need to keep in the notebook the fact that we started by doing this, and then we improved it. The reader doesn't need to know about the developement history of the workflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point. I am planning to add the footprint correction soon so I suggest that when I add that we rework the whole thing (I suggest I get a first draft soon and you can go through it). This approach might also help to understand why mean
instead of sum
before (cause at the moment I am not 100 % sure why mean
gives the correct result and sum
doesn't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's too much work to change what I suggested, probably just a small number of cells that need changing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(cause at the moment I am not 100 % sure why mean gives the correct result and sum doesn't)
maybe we should dig down a little bit more and understand 100% before we move forward, as we may forget at some point that we were not 100% sure, and after a while everyone just assumes it's all correct?
The order of the operations is a little different now, maybe if we write them all down we can see where the mean comes from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very much agree, and in the process of second drafting this I think I am grepping it a bit better
…the notebook has had a large rewrite
I have added some new features (specifically the footprint correction and the supermirror calibration which were present in the original iteration of this code. Additionally, there has been a lot of new writing in the notebook. Feedback pls. I will add tests in the coming days. |
Fix the Note box formatting overflow
Have just spoken with the Amor instrument scientist and he recommends a slightly different footprint correction that I will look at tomorrow morning. |
Use <div> instead of <a> tag for citation links to work in sphinx
Rebased to main now that there is a |
Not sure what happened in the rebase, but I am seeing in the diff the changes from the release that are unrelated to this PR... |
Bugger, suggestions to resolve (squash?) |
How did you do your |
Merge main? |
Honestly can't remember now... |
"reference_wav = reference.transform_coords([\"wavelength\"], graph=graph)\n", | ||
"reference_wav = sc.bin(reference_wav, edges=[wavelength_edges])\n", | ||
"reference_wav.bins.concatenate('detector_id').plot()" | ||
"fwhm_to_std = sc.scalar(2.) * sc.sqrt(sc.scalar(2.) * sc.log(sc.scalar(2.)))\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to remember these were in a helper function before. Maybe we should do this again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it as a constant in the amor.tools
directory for now. Let me know if you think a function is more valuable.
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ess.amor.tools import FWHM_TO_STD\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also consider making a function that takes in the sample_size / beam_on_sample
and then converts to std by multiplying by fwhm_to_std
.
e.g.
def fwhm_to_std(x):
return x * sc.scalar(2.) * sc.sqrt(sc.scalar(2.) * sc.log(sc.scalar(2.)))
?
Note that you also need to replace fwhm_to_std = sc.scalar(2.) * sc.sqrt(sc.scalar(2.) * sc.log(sc.scalar(2.)))
further down below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rational for the current implementation was that this allows for the inverse to give the equivalent of STD_TO_FWHM
without another function.
"source": [ | ||
"normalized = sample_norm / reference_norm\n", | ||
"normalized.coords['footprint_ratio'] = ratio\n", | ||
"sc.plot(normalized)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remove the plot altogether?
"id": "64a82569-5c12-480e-a120-85b0215f1e31", | ||
"metadata": {}, | ||
"source": [ | ||
"Finally, we perfrom a mean along the `'detector_id'` to obtain the normalised reflectometry profile.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And are you sure about the mean
here? because the values at low q in the final normalized plot went from ~0.1 to ~10
If you had 3 detector pixels, before we were doing
(counts_1 + counts_2 + counts_3) / (reference_1 + reference_2 + reference_3)
and now we are doing
(counts_1/reference_1 + counts_2/reference_2 + counts_3/reference_3) / 3
?
We should check the final values against Jochen's code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have masked pixels on reference I think that the second is the one we want...There is also the fact that using sum
gives a result at looks wrong (i.e. the critical edge should be flat). Jochen's code doesn't do the normalisation, I need to go a level up to eos.py
which can do the normalisation but will take quite a while to get to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, a mean doesn't really make sense, but maybe that's just me. We need to be careful about what we mean by zero counts. Is it just zero because we didn't run the experiment long enough, and statistically we would have had some counts if we recorded longer? Or does it mean zero in the sense that there simply cannot be counts there, just like if you did not have a detector pixel there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think just saying the shape looks better is enough justification, especially since the values have changed by so much. We need to understand what is correct.
The fact that there are nan values would mess up both a sum and and mean operation so that should not be a reason to use one or the other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much agreed looks right isn't good scientific justification and we still need to understand it (but it indicates it is correct). Changed by so much compared to?
The sum
counts all the pixels and does no division, the mean
counts the pixels that are un-masked and divides by the number of un-masked pixels. The number of unmasked pixels changes as a function of q, which is why there is a difference between our sum and our mean. And I think it makes sense to consider that weighting (with sum doesn't do).
Co-authored-by: Neil Vaytet <39047984+nvaytet@users.noreply.github.com>
…verting to and from fwhm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had another look and changes look ok to me.
Same here. Happy for you to merge whenever. |
A first draft (please comment on the text cause I imagine the explanation isn't great) going through performing the normalisation on dimensions of
'detector_id'
and'Q'
instead of just'Q'
.