cositools / cosipy

The COSI high-level data analysis tools
Apache License 2.0
3 stars 16 forks source link

Add 3ML Band function with same parameters as megalib #71

Closed eneights closed 9 months ago

eneights commented 11 months ago

Added custom Band function (Band_Eflux) that takes same parameters as those in megalib source files

israelmcmc commented 10 months ago

Thanks @eneights . It looks good to me, except that I think it should be "particle flux" or just "flux" instead of "energy flux". If you agree, it's jut a matter of fixing the documentation.

I run this quick test:

from cosipy import Band_Eflux
from scipy.integrate import quad

a = 1e2
b = 1e4
K = 1

spec = Band_Eflux(alpha=-1,
                  beta=-2,
                  E0=500,
                  K=K,
                  a=a,
                  b=b)

print(quad(lambda e: spec.evaluate_at(e) * e, a, b)) # Energy flux

print(quad(lambda e: spec.evaluate_at(e), a, b)) # Flux

Which results in

(573.9853040642165, 2.498720039464673e-06)
(1.0, 3.697667766561933e-09)

Beside that, I think this should be moved to 3ML. Also, at some point we should clean up the spectral fitting NB, they are getting hard to follows because they have multiple version of the same code within the same notebook. We can merge this now though and I'll open issues to remember us to do this. I'll just wait for the fix in the function docstring.