def test_integrate():
subslice = slice(100,200)
wvln = np.linspace(1000., 4000., 1024)
flux = np.zeros_like(wvln)
flux[subslice] = 1./np.ptp(wvln[subslice]) # so the integral is 1
s = Spectrum(wvln*u.angstrom, flux*u.erg/u.cm**2/u.angstrom)
# the integration grid is a sub-section of the full wavelength array
wvln_grid = s.wavelength[subslice]
i_flux = s.integrate(wvln_grid)
assert np.allclose(i_flux.value, 1.) # "close" because this is float comparison
评论列表
文章目录