def synphotSNR(filtname, mag, etime=1200, nexp=4, aperture=0.4, pixscale=0.128): import pysynphot as syn from numpy import pi, sqrt bandpass = syn.ObsBandpass('wfc3,ir,%s,aper#%.1f' % (filtname, aperture)) sn1a = syn.FileSpectrum('sn1a_flux_max.dat').redshift(1.5).renorm( mag, 'abmag', bandpass) sourcecps = syn.Observation(sn1a, bandpass).countrate() srccounts = sourcecps * etime skybandpass = syn.ObsBandpass('wfc3,ir,%s' % filtname) earthshine = syn.FileSpectrum('earthshine_average.dat') earthcps_arcsec2 = syn.Observation(earthshine, skybandpass, force='extrap').countrate() V = syn.ObsBandpass('landolt,V') zodiacal = syn.FileSpectrum('zodiacal_high.dat').renorm(22.7, 'vegamag', V) zodcps_arcsec2 = syn.Observation(zodiacal, skybandpass, force='extrap').countrate() aparea_arcsec2 = pi * aperture**2 aparea_pix = aparea_arcsec2 / pixscale**2 npix = (aparea_arcsec2 / pixscale**2) sharpness = 3.3 / npix skycounts = (earthcps_arcsec2 + zodcps_arcsec2) * aparea_arcsec2 * etime skycounts_pix = skycounts / npix # TODO : get thermal noise, dark current and readnoise from SYNPHOT darkcps_arcsec2 = 3.05 darkcounts = darkcps_arcsec2 * aparea_arcsec2 * etime darkcounts_pix = darkcounts / npix thermcps_arcsec2 = 8.15 thermcounts = thermcps_arcsec2 * aparea_arcsec2 * etime thermcounts_pix = thermcounts / npix rdnoise_pix = 12.5 # read noise per pixel (per exposure) rdnoiseTot = rdnoise_pix * aparea_pix # 161.61 bgcounts_pix = skycounts_pix + darkcounts_pix + thermcounts_pix noise = sqrt(srccounts + npix * bgcounts_pix + npix * nexp * rdnoise_pix**2) SNR = srccounts / noise onoise = sqrt(srccounts + (bgcounts_pix + rdnoise_pix**2) / sharpness) oSNR = srccounts / onoise return SNR, oSNR
def compute_zodi(ra, dec, jd, FILTER='F140W', verbose=False): """ Get the predicted Zodiacal surface brightness and then fold it through the Synphot WFC3 filters """ import pysynphot as S thermal = { 'F160W': 0.134, 'F140W': 0.069, 'F105W': 0.051, 'F110W': 0.05, 'F125W': 0.052, 'F128N': 0.051, 'F130N': 0.051, 'F132N': 0.051, 'F164N': 0.0651, 'G141': 0.1, 'G102': 0.04, 'F098M': 0.05 } lat, lng = helio_lat_lng(ra, dec, jd) SB = get_zodi_SB(lat, lng) if verbose: print 'Lat, Lng: %f, %f, SB=%.2f' % (lat, lng, SB + 2.5 * np.log10(0.128254**2)) zod = S.FileSpectrum('%s/zodiacal_model_001.fits' % (datapath())) nz = zod.renorm(SB, S.units.VegaMag, S.ObsBandpass("V")) bp = S.ObsBandpass('wfc3,ir,%s' % (FILTER.lower())) obs = S.Observation(nz, bp) return obs.countrate() + thermal[FILTER]
def __init__(self, template, refband=VJohnson, refmag=-21.0, ebmv=0., extlaw='xgal', filters=default_filters, cosmo=cosmo_def): self.template = template self.sp = S.FileSpectrum(template) if ebmv > 0: self.sp = self.sp * S.Extinction(ebmv, extlaw) if type(refband) == type(1500.): self.refband = S.Box(refband, 100.) else: self.refband = refband self.refmag = refmag self.filternames = [f.name for f in filters] self.kcorrs = {} for f in filters: self.kcorrs[f.name] = kcorr.KCorrect(self.sp, self.refband, f) if type(cosmo) == type([]): self.cosmo = cosmoclass.cosmoclass(H0=cosmo[0], omega_m=cosmo[1], omega_l=cosmo[2]) else: self.cosmo = cosmo
def get_pickles_spectrum(spt, verbose=False): ''' A function that retuns a pysynphot pickles spectrum for a given spectral type ''' #Read in the pickles master list. pickles_dir = os.environ['PYSYN_CDBS'] + "grid/pickles/dat_uvk/" pickles_filename = pickles_dir + "pickles_uk.fits" pickles_table = np.array(fits.open(pickles_filename)[1].data) pickles_filenames = [x[0].decode().replace(" ", "") for x in pickles_table] pickles_spts = [x[1].decode().replace(" ", "") for x in pickles_table] #The spectral types output by EXOSIMS are sometimes annoying spt = spt.replace(" ", "").split("/")[-1] #Sometimes there are fractional spectral types. Rounding to nearest integer spt_split = spt.split(".") if np.size(spt_split) > 1: spt = spt_split[0] + spt_split[1][1:] #Get the index of the relevant pickles spectrum filename try: ind = pickles_spts.index(spt) except: if verbose: print("Couldn't match spectral type {} to the pickles library". format(spt)) print("Assuming 'G0V'") ind = pickles_spts.index('G0V') sp = ps.FileSpectrum(pickles_dir + pickles_filenames[ind] + ".fits") sp.convert("Micron") sp.convert("photlam") return sp
def compute_photometry(catalog, photmode): """ Compute magnitudes for sources from catalog based on observations photmode Parameters ----------- catalog : object Astropy Table with 'source_sum' column for the measured flux for each source photmode : String Specification of the observation filter configuration used for the exposure as reported by the 'PHOTMODE' keyword from the PRIMARY header. Returns -------- phot_cat : object Astropy Table object of input source catalog with added column for VEGAMAG photometry (in magnitudes). """ # Determine VEGAMAG zero-point using pysynphot for this photmode photmode = photmode.replace(' ', ',') vega = S.FileSpectrum(VEGASPEC) bp = S.ObsBandpass(photmode) vegauvis = S.Observation(vega, bp) vegazpt = 2.5 * np.log10(vegauvis.countrate()) # Use zero-point to convert flux values from catalog into magnitudes source_phot = vegazpt - 2.5 * np.log10(catalog['source_sum']) source_phot.name = 'vegamag' # Now add this new column to the catalog table catalog.add_column(source_phot) return catalog
def testclip(self): self.sp = S.FileSpectrum(self.fname) self.obs = Observation(self.sp, self.bp) rate = self.obs.countrate() self.assertTrue(abs(rate - self.refrate) < 1.0, msg="tst %f ref %f" % (rate, self.refrate))
def test_johnson_v_tabular_spectra(): bp = pysyn.FileBandpass("data/test_bp_johnson_v.fits", thrucol="THROUGHPUT") sp = pysyn.FileSpectrum("data/test_sp_vega.fits") obs = pysyn.Observation(sp, bp) obs *= 1e20 result(obs, 411896149580, 0, 8893)
def setUp(self): testdata = os.path.join(locations.rootdir, 'calspec', 'feige66_002.fits') self.sp = S.FileSpectrum(testdata) self.bandpass = S.ObsBandpass('acs,hrc,f555w') self.refrate = 8.30680E+05 self.reflam = 5304.462
def test_hst_tabular_spectra(): bp = pysyn.FileBandpass("data/test_bp_acs_hrc_f555w.fits", thrucol="THROUGHPUT") sp = pysyn.FileSpectrum("data/test_sp_vega.fits") obs = pysyn.Observation(sp, bp) obs *= 1e20 result(obs, 112231834769, 0, 15866)
def __call__(self, z_range, obsband, outputfile): # Because m(z) = M + DM(z) + K_QR(z) := M + dm, # so dm = DM + K_QR. dm = np.zeros(len(z_range)) sp = S.FileSpectrum(self.sedfile) dust = S.Extinction(self.ebmv, self.extlaw) sp_ext = sp * dust K = kcorr.KCorrect(sp_ext, self.Q, obsband, mode='AB') for i in range(len(z_range)): z = z_range[i] ## Use my own (clumsy) way to compute dm # m = self.factory.redshift(z_range[i]).ABmag(obsband) # dm[i] = m - self.normmag # self.factory.reset() ## Use my implementation of Hogg et al. K-correction dm[i] = self.cosmo.distmod(z) + K(z) if i % 20 == 0: sys.stdout.write('z = %.3f \r' % z_range[i]) sys.stdout.flush() f = open(outputfile, 'wb') f.write('# 1 z \n') f.write('# 2 dm \n') for i in range(len(z_range)): f.write('%.4f %.6f \n' % (z_range[i], dm[i])) f.close() print "Done!"
def get_many_bc95(): ''' Get many Galaxy profiles ''' SEDfile_dir = os.path.join(top_pysynphot_data_dir, dir_nostar, dir_submodels[5], 'templates') filelist = os.listdir(SEDfile_dir) obj_headers = [] obj_files = [] index = 0 for filename in filelist: if re.search('fits', filename): #example of filename filter index += 1 fullfilename = os.path.join(SEDfile_dir, filename) hdr = fits.getheader(fullfilename) obj_headers.append(hdr) obj_files.append(filename) obj_names = [] index = 0 for hdr in obj_headers: obj_name = obj_headers[index]['TARGETID'] obj_names.append(obj_name) index += 1 objames_and_objfiles = zip(obj_names, obj_files) OBJDict = {} for obj, thefile in objames_and_objfiles: #print obj,': ' OBJDict[obj] = thefile #print OBJDict[obj] all_sed = [] all_z_rs = np.linspace(0, 2., 10) #for keyobj in OBJDict: for obj, thefile in objames_and_objfiles: #the_file=OBJDict[keyobj] #selected_file=the_file selected_file = thefile selected_fullfile = os.path.join(SEDfile_dir, selected_file) sed = S.FileSpectrum(selected_fullfile) sed.convert('flam') # to be sure every spectrum is in flam unit # loop on Redshifts for z_rs in all_z_rs: if (z_rs > 0): sed_z = sed.redshift(z_rs) all_sed.append(sed_z) else: all_sed.append(sed) return all_sed
def next(self): if self.pointer >= len(self.lines): raise StopIteration a = self.lines[self.pointer].split() s = S.FileSpectrum(a[0]) s.otherstuff = " ".join(a[1:]) self.pointer += 1 return s
def Vegamag(spec, band): # added by Kuang-Han Huang vega = S.FileSpectrum(pytool_path + '/sedtools/alpha_lyr_stis_003.fits') # make sure that this vega spectrum is in the same directory vegaflux = (vega * band).integrate() # vegaflux corresponds to vegamag 0 in any band flux = (spec * band).integrate() vegamag = -2.5 * log10(flux / vegaflux) return vegamag
def setUp(self): self.fname='blank.dat' fh=open(self.fname,'w') self.len=writedata(fh) for k in range(5): fh.write("\n") fh.close() self.sp=S.FileSpectrum(self.fname)
def setUp(self): self.fname='head2.dat' fh=open(self.fname,'w') fh.write("# 1 wave\n") fh.write("# 2 flux\n") self.len=writedata(fh) fh.close() self.sp=S.FileSpectrum(self.fname)
def test_hst_tabular_spectra_binset(): bp = pysyn.FileBandpass("data/test_bp_acs_hrc_f555w.fits", thrucol="THROUGHPUT") sp = pysyn.FileSpectrum("data/test_sp_vega.fits") binset = np.asarray([1000, 2000, 5000, 11000]) obs = pysyn.Observation(sp, bp, binset=binset) obs *= 1e20 result(obs, 112231834769, 0, 15866)
def get_many_bpgs(): all_sed = [] SEDfile_dir = os.path.join(top_pysynphot_data_dir, dir_nostar, dir_submodels[1]) fits_files = [f for f in os.listdir(SEDfile_dir) if f.endswith('.fits')] obj_headers = [] obj_files = [] for filename in fits_files: index = 0 if re.search('fits', filename): #example of filename filter index += 1 fullfilename = os.path.join(SEDfile_dir, filename) hdr = fits.getheader(fullfilename) obj_headers.append(hdr) obj_files.append(filename) obj_names = [] index = 0 for hdr in obj_headers: obj_name = obj_headers[index]['TARGETID'] obj_names.append(obj_name) index += 1 obj_names2 = [] index = 0 for thefile in fits_files: #thenames=re.findall('^bk_([a-z][0-9]+).fits$',thefile) thenames = re.findall('^bpgs_([0-9].*).fits$', thefile) if (len(thenames) > 0): obj_names2.append('bpgs_' + thenames[0]) else: print 'bad file ', thefile index += 1 obj_names = obj_names2 objames_and_objfiles = zip(obj_names, obj_files) OBJDict = {} for obj, thefile in objames_and_objfiles: OBJDict[obj] = thefile for keyobj in OBJDict: the_file = OBJDict[keyobj] selected_file = the_file selected_fullfile = os.path.join(SEDfile_dir, selected_file) sed = S.FileSpectrum(selected_fullfile) sed.convert('flam') # to be sure every spectrum is in flam unit all_sed.append(sed) return all_sed
def setUp(self): self.fname='midcomment.dat' fh=open(self.fname,'w') x1=writedata(fh,end=2000) fh.write("#middle of the file\n") fh.write("# yet more middle of the file\n") x2=writedata(fh,start=2000) fh.close() self.len=x1+x2 self.sp=S.FileSpectrum(self.fname)
def fit_beta_sed(sedfile, beta0, ebmv=0.): # a wrapper that takes an SED, read it with pysynphot, and find the best-fit beta sp = S.FileSpectrum(sedfile) if ebmv > 0.: sp = sp * S.Extinction(ebmv, 'xgal') wave = sp.wave[(sp.wave >= 1220.) & (sp.wave <= 3200.)] # the rest-frame wavelength range sedflux = sp.sample(wave) # the flux from sp x = fit_beta(wave, sedflux, beta0=beta0) return x[0][0]
def setUp(self): self.bb = S.BlackBody(5000) self.em = S.GaussianSource(3300, 1, 1) self.flat = S.FlatSpectrum(10) self.pl = S.PowerLaw(5000, -2) self.tspec = S.ArraySpectrum(self.bb.wave, self.bb.flux, fluxunits=self.bb.fluxunits) self.pl.writefits('ac_pl.fits') self.fspec = S.FileSpectrum('ac_pl.fits')
def zeropoint(self): ps.setref(**self.REFS) standard_star_file = GetStipsData( os.path.join("standards", "alpha_lyr_stis_008.fits")) sp = ps.FileSpectrum(standard_star_file) sp.convert('angstroms') bp = self.bandpass sp = sp.renorm(0.0, "VEGAMAG", bp) obs = ps.Observation(sp, bp, binset=sp.wave) zeropoint = obs.effstim("OBMAG") return zeropoint
def setUp(self): self.fname = os.path.join(locations.rootdir, 'calspec', 'feige66_002.fits') self.old_sp = S.FileSpectrum(self.fname) self.openfits = pyfits.open(self.fname) fdata = self.openfits[1].data self.new_sp = S.ArraySpectrum( wave=fdata.field('wavelength'), flux=fdata.field('flux'), waveunits=self.openfits[1].header['tunit1'], fluxunits=self.openfits[1].header['tunit2'], name='table from feige66')
def add_spectrum_to_library(): spec_dict = {} tab = ascii.read('CTTS_etc_d140pc_101116.txt', names=['wave','flux']) sp = S.ArraySpectrum(wave=tab['wave'], flux=tab['flux'], waveunits='Angstrom', fluxunits='flam') ctts = sp.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['Classical T Tauri'] = ctts tab = ascii.read('dM1_etc_d5pc_101116.txt', names=['wave','flux']) sp = S.ArraySpectrum(wave=tab['wave'], flux=tab['flux'], waveunits='Angstrom', fluxunits='flam') Mdwarf = sp.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['M1 Dwarf'] = Mdwarf tab = ascii.read('10Myr_Starburst_nodust.dat', names=['wave', 'flux']) sp = S.ArraySpectrum(wave=tab['wave'], flux=tab['flux'], waveunits='Angstrom', fluxunits='flam') s99 = sp.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['10 Myr Starburst'] = s99 filename_qso = os.path.join(os.environ['PYSYN_CDBS'], 'grid', 'agn', 'qso_template.fits') qso = S.FileSpectrum(filename_qso) q = qso.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['QSO'] = q filename_star = os.path.join(os.environ['PYSYN_CDBS'], 'grid', 'pickles', 'dat_uvk', 'pickles_uk_1.fits') star = S.FileSpectrum(filename_star) s = star.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['O5V Star'] = s filename_star = os.path.join(os.environ['PYSYN_CDBS'], 'grid', 'pickles', 'dat_uvk', 'pickles_uk_26.fits') star = S.FileSpectrum(filename_star) s = star.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['G2V Star'] = s filename_star = os.path.join(os.environ['PYSYN_CDBS'], 'grid', 'galactic', 'orion_template.fits') star = S.FileSpectrum(filename_star) s = star.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['Orion Nebula'] = s filename_star = os.path.join(os.environ['PYSYN_CDBS'], 'calspec', 'g191b2b_mod_010.fits') star = S.FileSpectrum(filename_star) s = star.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['G191B2B'] = s filename_star = os.path.join(os.environ['PYSYN_CDBS'], 'grid', 'kc96', 'starb1_template.fits') star = S.FileSpectrum(filename_star) s = star.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['Starburst, No Dust'] = s filename_star = os.path.join(os.environ['PYSYN_CDBS'], 'grid', 'kc96', 'starb6_template.fits') star = S.FileSpectrum(filename_star) s = star.renorm(21., 'abmag', S.ObsBandpass('galex,fuv')) spec_dict['Starburst, E(B-V) = 0.6'] = s return spec_dict
def add_models_and_beams(grp, source_id, beam_id, grism_filt, spectrum): """ Add models and create beam cutouts. Parameters ---------- grp : GroupFLT object The GroupFLT grizli object. A collection of files, models, extensions, etc. source_id : int The the seg id of the source that needs extracting. beam_id : str The fringe/beam_id to model. grism_filt : str The grism filter. spectrum : str Either 'skip' to not do a more complex model, or the path to a data file with a source spectra. Returns ------- beams : list of beam objects List of beam objects, which is like a GroupFLT but centered around these beam cutouts tracing the grism. """ # Start with general model grp.compute_full_model() # Build beam objects beams = grp.get_beams(source_id, size=24, beam_id=beam_id) if spectrum == 'skip': return beams else: mb = grizli.multifit.MultiBeam(beams, fcontam=0.2, psf=True) # Read in alternate data sp = S.FileSpectrum(spectrum) bp = S.ObsBandpass('wfc3,ir,' + grism_filt) rn = sp.renorm(1, 'flam', bp) # Cast to floats rn_wave = np.cast[float](rn.wave) rn_flux = np.cast[float](rn.flux) mb.compute_model(spectrum_1d=[rn_wave, rn_flux]) beams = mb.beams return beams
def testcrspec(self): iraf.thermback(obsmode=self.obsmode, form='counts', output=self.csname) spref = S.FileSpectrum(self.csname) self.savepysyn(spref.wave, self.sptest.sample(spref.wave), self.csname, units='counts') ridx = N.where(spref.wave >= 900.0) rflux = spref.flux[ridx] tflux = self.sptest.sample(spref.wave[ridx]) self.arraysigtest(tflux, rflux)
def do_calc(src_type, mag_src, obs_wave, exp_time, coadds, dither, dither_repeat, seeing, num_reads, redshift): global qso_sp, sy1_sp, sy2_sp qso = os.path.join(datadir, 'qso_template.fits') qso_sp = S.FileSpectrum(qso).redshift(redshift) sy1 = os.path.join(datadir, 'seyfert1_template.fits') sy1_sp = S.FileSpectrum(sy1).redshift(redshift) sy2 = os.path.join(datadir, 'seyfert2_template.fits') sy2_sp = S.FileSpectrum(sy2).redshift(redshift) ## fixed instrument parameters slit_width = 0.55 #arcsec slit_lenth = 18.0 #arcsec print(src_type) if src_type == "PointSource": s2n = calculate_nires_s2n_pointsource(mag_src, obs_wave, exp_time, coadds, dither, dither_repeat, seeing, num_reads) print("S/N = %f" % s2n) elif src_type == "qso": s2n = calculate_nires_s2n_qso(src_type, redshift, obs_wave, exp_time, coadds, dither, dither_repeat, seeing, num_reads) print("S/N = %f" % s2n) elif src_type == "sy1": s2n = calculate_nires_s2n_qso(src_type, redshift, obs_wave, exp_time, coadds, dither, dither_repeat, seeing, num_reads) print("S/N = %f" % s2n) elif src_type == "sy2": s2n = calculate_nires_s2n_qso(src_type, redshift, obs_wave, exp_time, coadds, dither, dither_repeat, seeing, num_reads) print("S/N = %f" % s2n) else: s2n = 'N/A' return s2n
def renorm_compare(sp, rnval, rnunits, bp, callable): """Sp and bp must have a special .syndescrip attribute that contains the string needed to make it with synphot""" # Renormalize the spectrum pysyn = callable(sp, bp, rnval, rnunits) #pysyn=sp.renorm(rnval,rnunits,bp) #pysyn = spectrum.StdRenorm(sp,bp,rnval,rnunits) userdir = tempfile.mkdtemp(suffix='pysynphot') old_cwd = os.getcwd() iraf.chdir(userdir) # Make a wavetable and a wavecat fname = "%s.fits" % rnunits pysyn.writefits(fname, clobber=True) wname = "%s.cat" % rnunits f = open(wname, 'w') f.write("box %s\n" % fname) f.close() oname = "syn_%s" % fname try: #Run countrate spstring = "rn(%s,%s,%s,%s) " % (sp.syndescrip, bp.syndescrip, rnval, rnunits) iraf.countrate(spectrum=spstring, magnitude="", instrument="box(15000,30000)", form=str(pysyn.fluxunits), wavecat=wname, output=oname) syn = S.FileSpectrum(oname) # Check that they have the same shape and fluxunits assert (syn.flux.shape == pysyn.flux.shape) assert (type(syn.fluxunits) == type(pysyn.fluxunits)) # Now a real test idx = np.where(syn.flux != 0) rat = (syn.flux[idx] / pysyn.flux[idx]) q = abs(1 - rat[2:-2]) qtrunc = (10**4*q).astype(np.int) assert np.alltrue(qtrunc < 110), \ "Min/max ratio = %f,%f" % (q.min(),q.max()) finally: iraf.chdir(old_cwd) shutil.rmtree(userdir)
def getSpectrum(self,Teff=5800,z=0.,logg=4.43,vega=False,): #default: Sun at 10pc Teff=5800, z=0, logg=4.4, johnson_v_abs=4.68 self.johnson_v = S.ObsBandpass('johnson,v') self.T=Teff self.z=z self.g=logg if vega: self.star= S.FileSpectrum(S.locations.VegaFile) print ' Using default Pysynphot Vega spectrum' else: print self.getFiltername(), self.getSpectrumInfo() self.star= S.Icat('ck04models',self.T,self.z,self.g) #FLAM surface flux units, i.e. ergs cm-2 s-1 A-1 #star = S.BlackBody(6000) #self.star= self.star.renorm(self.j_v_abs,'vegamag',self.johnson_v) #renorm spectrum to (abs_mag, units system, band) return self.star
def get_all_pickle(): all_sed = [] # common SED container SEDfile_dir = os.path.join(top_pysynphot_data_dir, dir_nostar, dir_submodels[9], 'dat_uvi') fits_files = [f for f in os.listdir(SEDfile_dir) if f.endswith('.fits')] fits_files.remove('pickles.fits') obj_headers = [] obj_files = [] for filename in fits_files: index = 0 if re.search('fits', filename): #example of filename filter index += 1 fullfilename = os.path.join(SEDfile_dir, filename) hdr = fits.getheader(fullfilename) obj_headers.append(hdr) obj_files.append(filename) obj_names2 = [] index = 0 for thefile in fits_files: #thenames=re.findall('^bk_([a-z][0-9]+).fits$',thefile) thenames = re.findall('^(.*).fits$', thefile) if (len(thenames) > 0): obj_names2.append(thenames[0]) else: print 'bad file ', thefile index += 1 obj_names = obj_names2 objames_and_objfiles = zip(obj_names, obj_files) OBJDict = {} for obj, thefile in objames_and_objfiles: #print obj,': ' OBJDict[obj] = thefile #print OBJDict[obj] for keyobj in OBJDict: the_file = OBJDict[keyobj] selected_file = the_file selected_fullfile = os.path.join(SEDfile_dir, selected_file) sed = S.FileSpectrum(selected_fullfile) sed.convert('flam') # to be sure every spectrum is in flam unit all_sed.append(sed) return all_sed
def setUp(self): self.oldcwd = os.getcwd() os.chdir(os.path.dirname(__file__)) self.oldref = S.refs.getref() S.setref(comptable='$PYSYN_CDBS/mtab/t260548pm_tmc.fits') self.spectrum = "data/qso_template.fits" self.obsmode = "cos,fuv,g140l,c1230,PSA" self.bp = S.ObsBandpass(self.obsmode) self.sp = S.FileSpectrum(self.spectrum) self.tst = self.sp.renorm(17.0, 'vegamag', self.bp) self.tda = dict(spectrum=self.spectrum, obsmode=self.obsmode, file=S.__file__)