tschoonj / xraylib

A library for X-ray matter interaction cross sections for X-ray fluorescence applications
https://github.com/tschoonj/xraylib/wiki
Other
120 stars 54 forks source link

Compton differential crosssection angle range change #130

Closed gazzar closed 4 years ago

gazzar commented 4 years ago

Hi Tom, in version 4.0.0 the valid range of the polar angle argument in DCSP_Compt_CP seems to have changed.

It looks like the polar angle isn't making it to 0 any more so that DCSP_Compt_CP('Al', 30.0, 0.001, 0) returns a result but DCSP_Compt_CP('Al', 30.0, 0.0001, 0) raises an exception.

I tried it also with DCSP_Rayl_CP but that seems happy all the way to a polar angle of 0.

Python traceback:

In Python, if I call DCSP_Compt_CP('Al', 30.0, 0, 0) in xraylib 3.3.0 I get the result 0.005434526755569271 but in 4.0.0 I get an exception at the Python level

ValueError Traceback (most recent call last)

in ----> 1 xrl.DCSP_Compt_CP('Al', 30.0, 0, 0) ~\anaconda3\envs\vis\lib\site-packages\xraylib.py in DCSP_Compt_CP(compound, E, theta, phi) 3057 3058 """ -> 3059 return _xraylib.DCSP_Compt_CP(compound, E, theta, phi) 3060 3061 def DCSPb_Rayl_CP(compound, E, theta, phi): ValueError: q must be positive
tschoonj commented 4 years ago

Hi Gary, glad to read you are still using xraylib :+1:

I am a bit confused by your post: calling DCSP_Compt_CP or DCSP_Compt with theta = 0.0 has always returned zero, and an error message. In 3.3.0 you would have gotten:

$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xraylib as xrl
>>> xrl.__version__
'3.3.0'
>>> xrl.DCSP_Compt(13, 30.0, 0, 0)
q <=0 in function SF_Compt
0.0
>>> xrl.DCSP_Compt_CP('Al', 30.0, 0, 0)
q <=0 in function SF_Compt
0.0

In 4.0.0 this has been translated into an exception:

$ python
Python 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:38) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xraylib as xrl
>>> xrl.__version__
'4.0.0'
>>> xrl.DCSP_Compt_CP('Al', 30.0, 0, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/dls_sw/apps/python/anaconda/4.6.14/64/envs/python3.8/lib/python3.8/site-packages/xraylib.py", line 4646, in DCSP_Compt_CP
    return _xraylib.DCSP_Compt_CP(compound, E, theta, phi)
ValueError: q must be positive
>>> xrl.DCSP_Compt(13, 30.0, 0, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/dls_sw/apps/python/anaconda/4.6.14/64/envs/python3.8/lib/python3.8/site-packages/xraylib.py", line 4056, in DCSP_Compt
    return _xraylib.DCSP_Compt(Z, E, theta, phi)
ValueError: q must be positive

When talking about small (!= 0.0) theta angles there has indeed been a change. This release does not allow any of the databases to be extrapolated any more, and the exception you received is the consequence of requesting the incoherent scattering function SF_Compt, called internally by DCSP_Compt_CP that would have required extrapolation.

This is different for DCSP_Rayl_CP because this method actually allows theta = 0.0, so any value greater than 0.0 will also be accepted.

Hope this helps!

gazzar commented 4 years ago

Yes, we still use xraylib regularly. I appreciate your continued development of it; Thanks!

I think I was oblivious of that error with the older version because I must have only explored that angular region from inside Jupyter and the error only appeared in the (hidden) console window. Exposing it as a Python Exception means that now I have to pay attention to it and decide what to do about it :) That's good! Thanks for letting me know it is intentional; that does help. Please feel free to close this issue.

tschoonj commented 4 years ago

Ok Gary, let me know if you have any further questions!