Skip to content
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

Error returned when extrapolating cross section values #204

Closed
keeble opened this issue Jul 4, 2022 · 5 comments
Closed

Error returned when extrapolating cross section values #204

keeble opened this issue Jul 4, 2022 · 5 comments

Comments

@keeble
Copy link

keeble commented Jul 4, 2022

Hi Tom, hope you're well.

I'm updating some dependencies and found an issue with calculating cross section data for low energies. The error resembles #187 in that it's related to extrapolation of the source data. I have seen this affecting CS_Photo, CS_Compt, CS_Rayl, and their various children CS_Total, *_CP etc.

Using the python bindings, version 3.3.0 gave:

>>> import xraylib
>>> xraylib.__version__
'3.3.0'
>>> xraylib.CS_Photo(10, 0.01)
119431.70730436413

and with the up-to-date version:

>>> import xraylib
>>> xraylib.__version__
'4.1.2'
>>> xraylib.CS_Photo(10, 0.01)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/scratch/xraylib/env/lib/python3.10/site-packages/xraylib.py", line 2252, in CS_Photo
    return _xraylib.CS_Photo(*args)
ValueError: Spline extrapolation is not allowed

For #187 the fix appears to be linear ln-ln extrapolation from the lowest 2 energies. I'm happy to put in a PR to apply a similar fix to these 3 functions, but I'm not 100% sure whether this is physically meaningful in this case; or whether it's preferable to just return the lowest value in the source data. What do you think?

@tschoonj
Copy link
Owner

tschoonj commented Jul 5, 2022

Hi Dean,

I am well and hope that the same goes for you.

What you have run into is not a bug and is in fact intended behaviour. Before 4.0.0 I allowed users querying lower and higher energies than were available in the energy range of the dataset. There wouldn't be any real extrapolation happening though, just the cross section for the lowest/highest available energy would be returned, which didn't feel right.

The CS_Photo function only has data starting at 100 eV, which is why you are now getting that error. Basically xraylib doesn't have any data available for the soft X-ray energy range, mainly because it's not available, and would have large uncertainties if it did.

Hope this helps!

@keeble
Copy link
Author

keeble commented Jul 5, 2022

Ah - I see. I suppose that sounds like a more reasonable approach than returning knowingly wrong answers!

Is the raw data exposed anywhere through the python bindings, so I when I catch a ValueError I can implement the behaviour I want? Or are all of cross section data over the same range (I'm afraid our library does not give me access to the paper where I may well find this information - sorry!)

@tschoonj
Copy link
Owner

tschoonj commented Jul 5, 2022

The raw data is not exposed, not even in the core C library.

I am not sure that the cross section data has the same range across types and atomic numbers.

Let me know If you'd like a copy of the xraylib manuscript (even though it's outdated).

@keeble
Copy link
Author

keeble commented Jul 5, 2022

I am not sure that the cross section data has the same range across types and atomic numbers

Ok, thanks - this is what I was thinking. At the moment CP_Photo(10,0.00001) raises the same exception as CP_Photo(10,100000) but since I can assume that they all work at 1 keV I can catch the ValueError and sort out the logic at my end.

@keeble keeble closed this as completed Jul 5, 2022
@daveabiy
Copy link

daveabiy commented Jun 2, 2023

Thanks for the answer. This was also my question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants