def getFlux(self, slamb, sflux, axis=-1):
"""getFlux
Integrate the flux within the filter and return the integrated energy
If you consider applying the filter to many spectra, you might want to
consider extractSEDs.
Parameters
----------
slamb: ndarray(dtype=float, ndim=1)
spectrum wavelength definition domain
sflux: ndarray(dtype=float, ndim=1)
associated flux
Returns
-------
flux: float
Energy of the spectrum within the filter
"""
_wavelength = self._get_filter_in_units_of(slamb)
_slamb = _drop_units(slamb)
#clean data for inf values by interpolation
if True in np.isinf(sflux):
indinf = np.where(np.isinf(sflux))
indfin = np.where(np.isfinite(sflux))
sflux[indinf] = np.interp(_slamb[indinf], _slamb[indfin], sflux[indfin])
# reinterpolate transmission onto the same wavelength def as the data
ifT = np.interp(_slamb, _wavelength, self.transmit, left=0., right=0.)
# if the filter is null on that wavelength range flux is then 0
ind = ifT > 0.
if True in ind:
try:
_sflux = sflux[:, ind]
except:
_sflux = sflux[ind]
# limit integrals to where necessary
ind = ifT > 0.
if 'photon' in self.dtype:
a = np.trapz(_slamb[ind] * ifT[ind] * _sflux, _slamb[ind], axis=axis)
b = np.trapz(_slamb[ind] * ifT[ind], _slamb[ind] )
elif 'energy' in self.dtype:
a = np.trapz( ifT[ind] * _sflux, _slamb[ind], axis=axis )
b = np.trapz( ifT[ind], _slamb[ind])
if (np.isinf(a).any() | np.isinf(b).any()):
print(self.name, "Warn for inf value")
return a / b
else:
return 0.
评论列表
文章目录