def main(): colnames = ("ID", "Name", "M_sun Vega", "M_sun AB", "lambda_eff (Å)", "Description") filters = [fsps.get_filter(name) for name in fsps.list_filters()] filter_list = make_filter_list(filters) txt = make_table(filter_list, colnames) print(txt)
def main(): colnames = ("ID", "Name", "M_sun Vega", "M_sun AB", "lambda_eff (Å)", "Description") filters = [fsps.get_filter(name) for name in fsps.list_filters()] filter_list = make_filter_list(filters) txt = make_table(filter_list, colnames) print(txt)
def _set_filter(self, filt): #fetch filter transmission curve from FSPS #this sets the wavelength grid, so no rebinning needed #lookup for filter number given name fsps_filts = fsps.list_filters() filt_lookup = dict(zip(fsps_filts, range(1, len(fsps_filts) + 1))) #reference in case given a spitzer or mips filter...probably not an issue right now. mips_dict = {90: 23.68 * 1e4, 91: 71.42 * 1e4, 92: 155.9 * 1e4} spitzer_dict = { 53: 3.550 * 1e4, 54: 4.493 * 1e4, 55: 5.731 * 1e4, 56: 7.872 * 1e4 } #pull information for this filter fobj = fsps.get_filter(filt) filter_num = filt_lookup[filt] fwl, ftrans = fobj.transmission ftrans = np.maximum(ftrans, 0.) trans_interp = np.asarray(np.interp(self.inst_wavelength, fwl / 1e4, ftrans, left=0., right=0.), dtype=np.float) #normalize transmission ttrans = np.trapz( np.copy(trans_interp) / self.inst_wavelength, self.inst_wavelength) if ttrans < self.small_num: ttrans = 1. ntrans = np.maximum(trans_interp / ttrans, 0.0) if filter_num in mips_dict: td = np.trapz( ((self.inst_wavelength / mips_dict[filter_num])**(-2.)) * ntrans / self.inst_wavelength, self.inst_wavelength) ntrans = ntrans / max(1e-70, td) if filter_num in spitzer_dict: td = np.trapz( ((self.inst_wavelength / spitzer_dict[filter_num])**(-1.0)) * ntrans / self.inst_wavelength, self.inst_wavelength) ntrans = ntrans / max(1e-70, td) #stupid, but re-normalize to peak of 1 (since all other throughput terms #are included in the instrument throughput self.trans_norm = np.copy(ntrans) / ntrans.max() self.transmission = ntrans self.pivot = fobj.lambda_eff return
def fsps_filter_indices(bands): # Find the filter indices import fsps flist = fsps.list_filters() findex = [flist.index(filt) for b in bands for filt in fsps.find_filter(b)] if len(findex) != len(bands): raise ValueError("Your band names {} do not give " "a one-to-one mapping to FSPS filter " "names {}".format(bands, [flist[i] for i in findex])) return [flist[i] for i in findex], findex
def set_bands(self, filter_names): for name in filter_names: if not name in fsps.list_filters(): raise SPError( f"{name} not available in current version of FSPS. Please choose one of {fsps.list_filters()}" ) else: continue self.filter_names = filter_names return None
def _set_filter(self, filt): #fetch filter transmission curves from FSPS #normalize and interpolate onto template grid #lookup for filter number given name fsps_filts = fsps.list_filters() filt_lookup = dict(zip(fsps_filts, range(1,len(fsps_filts)+1))) #reference in case given a spitzer or mips filter...probably not an issue right now. mips_dict = {90:23.68*1e4, 91:71.42*1e4, 92:155.9*1e4} spitzer_dict = {53:3.550*1e4, 54:4.493*1e4, 55:5.731*1e4, 56:7.872*1e4} #pull information for this filter fobj = fsps.get_filter(filt) filter_num = filt_lookup[filt] fwl, ftrans = fobj.transmission ftrans = np.maximum(ftrans, 0.) trans_interp = np.asarray(np.interp(self.red_wavelength, fwl/1e4, ftrans, left=0., right=0.), dtype=np.float) #normalize transmission ttrans = np.trapz(np.copy(trans_interp)/self.red_wavelength, self.red_wavelength) if ttrans < self.small_num: ttrans = 1. ntrans = np.maximum(trans_interp / ttrans, 0.0) if filter_num in mips_dict: td = np.trapz(((self.red_wavelength/mips_dict[filter_num])**(-2.))*ntrans/self.red_wavelength, self.red_wavelength) ntrans = ntrans/max(1e-70,td) if filter_num in spitzer_dict: td = np.trapz(((self.red_wavelength/spitzer_dict[filter_num])**(-1.0))*ntrans/self.red_wavelength, self.red_wavelength) ntrans = ntrans/max(1e-70,td) self.transmission = ntrans return
def init_bands(self): """Initialization bands to compute.""" import fsps if isinstance(self.band_names, str): self.band_names = [self.band_names] if self.band_names[0] == 'all': self.band_names = fsps.list_filters() elif self.band_names[0] == 'uvoir': self.band_names = [] for ib, b in enumerate(fsps.list_filters()): band = fsps.filters.get_filter( b) # look up characteristics of desired band band_wave = band.transmission[0] # filter wavelengths band_trans = band.transmission[1] # filter response function meanwave = np.sum( band.transmission[0] * band.transmission[1]) / np.sum( band.transmission[1]) if meanwave < 50000: self.band_names.append(b) else: # collect all filters containing the input string(s) allfilters = fsps.list_filters() mybands = [] for b in self.band_names: # check that requested bands are actually available for b_all in allfilters: if b in b_all: if b == b_all: mybands.append(b_all) # if exact match, add elif len(b) > 3: mybands.append( b_all ) # avoid adding matching short band names (e.g. 'u') if len(mybands) == 0: assert b in allfilters, 'Band %s not found among available FSPS filters! Call fsps.list_filters() to list filters.' % self.band_names self.band_names = mybands # V band is always computed, so that one has A_V (= V_dust - V_nodust) if 'v' not in self.band_names: self.band_names.append('v') # Madau IGM attenuation is applied directly to rest-frame bandpasses only when computing apparent magnitudes; compute this curve here for specific redshift redshift = self.obj.simulation.redshift if self.use_cosmic_ext: from synphot import etau_madau # see synphot.readthedocs.io/en/latest/synphot/tutorials.html extcurve = etau_madau(self.ssp_wavelengths * (1. + redshift), redshift) cosmic_ext = extcurve(self.ssp_wavelengths) else: cosmic_ext = np.ones(len(self.ssp_wavelengths)) # set up band information nbands = len(self.band_names) self.band_meanwave = np.zeros(nbands, dtype=MY_DTYPE) self.band_indexes = np.zeros(nbands + 1, dtype=np.int32) self.band_ftrans = np.empty(0, dtype=MY_DTYPE) self.band_iwave0 = np.zeros(nbands, dtype=np.int32) self.band_iwave1 = np.zeros(nbands, dtype=np.int32) self.band_indz = np.zeros(nbands + 1, dtype=np.int32) self.band_ztrans = np.empty(0, dtype=MY_DTYPE) self.band_iwz0 = np.zeros(nbands, dtype=np.int32) self.band_iwz1 = np.zeros(nbands, dtype=np.int32) for ib, b in enumerate(self.band_names): band = fsps.filters.get_filter( b) # look up characteristics of desired band band_wave = band.transmission[0] # filter wavelengths band_trans = band.transmission[1] # filter response function self.band_meanwave[ib] = np.sum( band.transmission[0] * band.transmission[1]) / np.sum( band.transmission[1]) # Set up transmission curve in region probed by rest-frame band ind = np.where((self.ssp_wavelengths > band_wave[0]) & (self.ssp_wavelengths < band_wave[-1]))[ 0] # indices of wavelengths in the band self.band_iwave0[ib] = ind[0] self.band_iwave1[ib] = ind[-1] + 1 ftrans = np.interp(self.ssp_wavelengths[ind], band_wave, band_trans) # transmission at those wavelengths dnu = CLIGHT_AA / self.ssp_wavelengths[ ind[0]:ind[-1] + 1] - CLIGHT_AA / self.ssp_wavelengths[ ind[0] + 1:ind[-1] + 2] # convert to delta-nu #dnu = self.ssp_wavelengths[ind[0]+1:ind[-1]+2] - self.ssp_wavelengths[ind[0]:ind[-1]+1] # delta-lambda self.band_ftrans = np.append(self.band_ftrans, ftrans * dnu) self.band_indexes[ib + 1] = len(self.band_ftrans) # Now set up band for apparent mag computation # We will blueshift the band, corresponding to redshifting the intrinsic spectrum ind = np.where( (self.ssp_wavelengths > band_wave[0] * self.obj.simulation.scale_factor) & (self.ssp_wavelengths < band_wave[-1] * self.obj.simulation.scale_factor) )[0] # indices of wavelengths for redshifted rest-frame spectrum (i.e. blueshifted band) self.band_iwz0[ib] = ind[0] self.band_iwz1[ib] = ind[-1] + 1 ftrans = np.interp(self.ssp_wavelengths[ind], band_wave * self.obj.simulation.scale_factor, band_trans) # transmission at those wavelengths dnu = CLIGHT_AA / self.ssp_wavelengths[ ind[0]:ind[-1] + 1] - CLIGHT_AA / self.ssp_wavelengths[ ind[0] + 1:ind[-1] + 2] # convert to delta-nu #dnu = self.ssp_wavelengths[ind[0]+1:ind[-1]+2] - self.ssp_wavelengths[ind[0]:ind[-1]+1] # delta-lambda self.band_ztrans = np.append( self.band_ztrans, np.array(ftrans * dnu * cosmic_ext[ind])) self.band_indz[ib + 1] = len(self.band_ztrans) memlog('Computing %d bands: %s' % (len(self.band_names), self.band_names))