def integrate( self, age ):
# calculate range to integrate over
lower_bound = age - self.maxage
upper_bound = age - self.minage
# if upper_bound is negative then this is a later region and we are working on early ages
# If so, return zeros
if upper_bound < 0: return ( np.zeros( self.ls.size ), 0 )
# find things in the age range (include a little extra to account for rounding errors)
inds = np.where( (self.ages >= lower_bound-age*1e-5) & (self.ages <= upper_bound+age*1e-5) )[0]
# simpsons rule is based on intervals, so include the SED one age lower if it exists
# otherwise one interval will be missed at every boundary
if inds[0] > 0 and np.abs( self.ages[inds[0]] - lower_bound ) > 1e-5*age:
inds = np.append( inds[0]-1, inds )
weights = self.sfh_func( age-self.ages[inds] )
# if weights are all zero then there is no star formation in this region and therefore no need to integrate
if max( weights ) <= 0:
return ( np.zeros( self.ls.size ), 0 )
if self.has_dust:
# integrate weights*sed*dust
seds = integrate.simps( weights*self.seds[:,inds]*self.dust_func( self.ages[inds], self.ls ), x=self.ages[inds], even='avg' )
else:
# integrate weights*sed
seds = integrate.simps( weights*self.seds[:,inds], x=self.ages[inds], even='avg' )
# integrate weights*mass
mass = integrate.simps( weights*self.masses[inds], x=self.ages[inds], even='avg' ) if self.has_masses else 0
return ( seds, mass )
评论列表
文章目录