threeML / astromodels

Spatial and spectral models for astrophysics
BSD 3-Clause "New" or "Revised" License
43 stars 44 forks source link

Add integrate() method to Function class #199

Open israelmcmc opened 1 year ago

israelmcmc commented 1 year ago

In various applications --e.g. convolving a detector response with a spectrum-- it would be desirable for functions to return the analytical integral within a range when possible. Even when analytics integration is not possible, numerical integration is a common task and it would be nice to provide it instead of everyone writing their own code.

Some initial thoughts on how to implement this:

  1. Add an integrate() method to the Function class that, by default, passes args, kwargs, and the Function.evaluate to scipy.integrate
  2. For functions with an analytic integral, override this method with the exact calculation
  3. For functions using scipy.integrate might be problematic in the context of composite functions --e.g. discontinuous functions-- throw a warning. Maybe a flag is needed to specify this?