xraypy / xraylarch

Larch: Applications and Python Library for Data Analysis of X-ray Absorption Spectroscopy (XAS, XANES, XAFS, EXAFS), X-ray Fluorescence (XRF) Spectroscopy and Imaging, and more.
https://xraypy.github.io/xraylarch
Other
127 stars 62 forks source link

Computing the forward f'->f" Kramers Kronig transform using kkmclf_sca in DIFFKK.py #516

Open Ayrtonb1 opened 4 weeks ago

Ayrtonb1 commented 4 weeks ago

Hi there,

Hope you are well. I have a starting guess value for molecular f' that I am trying to convert to f" using diffkk. I know typically this takes a 'mu' input and scales the f", then calculates a f'. However, I want to scale this molecular f' to the atomic 'f1' instead and then calculate a f" based on this (scaled to 'f2'). It seems that using kkmclf_sca instead of kkmclr_sca is the solution, however the 'kk' function described in diffkk.py does not seemingly have an option for this. Are you aware of any way I might be able to get this to work? Happy to provide more information if required... let me know what you think.

Thank you

newville commented 3 weeks ago

@Ayrtonb1 I suppose one could "just" replace kkmclr_sca with kkmclf_sca in the code. Well, you might need to look into how to normalize the data too.

I guess the expectation is that "measuring mu with wiggles" is generally easier than "measuring isolated f1 with wiggles".

Ayrtonb1 commented 3 weeks ago

Hi Matthew. Thank you very much for your response. Yes, I agree that applying this to conventional XAS measurements is a much more common use. And I agree with your suggestion of replacing kkmclr with kkmclf...

however if I try and do this by copying the relevant parts of the diffkk.py into my code, and it also requires other elements of the larch.xafs package - mback.py (I believe for normalising the data?), which requires pre_edge.py, and so on, and I end up copying lots and lots of code into my program.

I am going to look at ways of modifying the source code on my device but I am trying to make this easy to use for others moving forward, too. Would you have any suggestions for an easier way to do this? Thanks again

Ayrtonb1 commented 2 weeks ago

Hey there, Sorry to bother you again. Still stuck on this - once it is figured out I think it would be very useful in the context of modelling DAFS, if you are interested.

newville commented 2 weeks ago

@Ayrtonb1 Following the example of diffkk for f2 to f1, note that the steps are a) scale/offset input mu to match the tabulated f2 to give "df=f2_with_wiggles - f2_tabulated" b) transform df2 = f2_with_wiggles - f2_tabulated to df1 = f1_with_wiggles - f1_tabulated (ie difference) b) add f1_tabulated to df1 to give f1_with_wiggles.

So, the first order of business (and probably "the hard part") is to get the input data to match the tabulated f1.
By "match", the point is that df2 and df1 must go to zero away from the edge.

That means that if you have experimental f1 (and, from where? To be clear: f1, not diffraction intensity dominated by f1. Or do you have refraction data?), then you have to work out how to match that to tabulated f1. For XAFS mu(E), we use the mback function -- that "match tabulated f2" is what mback does. You would have to do something different in place of that.