Integration added
This commit is contained in:
parent
17d7a12434
commit
24f9f8aebe
@ -7,6 +7,7 @@ import logging
|
||||
from astropy.io import ascii
|
||||
import re
|
||||
import os
|
||||
from scipy.integrate import trapz
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
@ -342,3 +343,14 @@ class SpectralQty:
|
||||
else:
|
||||
f = interp1d(self.wl, self.qty.value)
|
||||
return SpectralQty(wl, f(wl.to(self.wl.unit)) * self.qty.unit)
|
||||
|
||||
def integrate(self) -> u.Quantity:
|
||||
"""
|
||||
Integrate the spectral quantity over the given spectrum using
|
||||
|
||||
Returns
|
||||
-------
|
||||
int : Quantity
|
||||
The integrated quantity
|
||||
"""
|
||||
return u.Quantity(trapz(self.qty, self.wl))
|
||||
|
@ -145,3 +145,8 @@ class TestSpectralQty(TestCase):
|
||||
|
||||
sqty = SpectralQty.fromFile("data/target/target_demo_2.csv", u.nm, u.W / (u.m ** 2 * u.nm))
|
||||
self.assertEqual(sqty, res)
|
||||
|
||||
def test_integrate(self):
|
||||
integral = self.sqty.integrate()
|
||||
self.assertAlmostEqual(integral.value, 3.75)
|
||||
self.assertTrue(integral.unit.is_equivalent(u.W / u.m ** 2))
|
||||
|
Loading…
x
Reference in New Issue
Block a user