def Sim_spec(self, metal, age, tau): import pysynphot as S if self.delayed_tau == True: model = '../../../fsps_models_for_fit/fsps_spec/m%s_a%s_dt%s_spec.npy' % (metal, age, tau) else: model = '../../../fsps_models_for_fit/fsps_spec/m%s_a%s_t%s_spec.npy' % (metal, age, tau) wave, fl = np.load(model) spec = S.ArraySpectrum(wave, fl, fluxunits='flam') spec = spec.redshift(self.redshift).renorm(1., 'flam', S.ObsBandpass('wfc3,ir,f105w')) spec.convert('flam') ## Compute the models self.beam.compute_model(spectrum_1d=[spec.wave, spec.flux]) ## Extractions the model (error array here is meaningless) w, f, e = self.beam.beam.optimal_extract(self.beam.model, bin=0) ifl = interp1d(w, f)(self.gal_wv) ## Get sensitivity function fwv, ffl = [self.beam.beam.lam, self.beam.beam.sensitivity / np.max(self.beam.beam.sensitivity)] filt = interp1d(fwv, ffl)(self.gal_wv) adj_ifl = self.atten * ifl /filt C = Scale_model(self.gal_fl, self.gal_er, adj_ifl) self.fl = C * adj_ifl
def Full_fit(spec, Gmfl, Pmfl): Gchi = 0 for i in range(len(wvs2)): scale = Scale_model(flxs2[i], errs2[i], Gmfl[i]) Gchi = Gchi + np.sum(((((flxs2[i] / scale) - Gmfl[i]) / (errs2[i] / scale))**2)) Pchi = np.sum((((spec.SPflx - Pmfl) / spec.SPerr)**2)) return Gchi, Pchi
ew=np.zeros(len(age)) ewgr=np.zeros(len(age)) for i in range(len(age)): wv, fl = np.array(Readfile('../../../fsps_models_for_fit/fsps_spec/m0.015_a%s_t8.72_spec.dat' % age[i], 1)) ew[i]= D4000(wv,fl) wvgr,flgr,ergr= np.array(Readfile('../../../fsps_models_for_fit/models/m0.015_a%s_t8.72_z1.5_model.dat' % age[i], 1)) wvgr/=2.5 ewgr[i]=D4000(wvgr,flgr) M=D4000(swv,sfl) print M print wvgr[0],wvgr[-1] print swv[0],swv[-1] C1=Scale_model(sfl,serr,interp1d(wv,fl)(swv)) # C2=Scale_model(sfl,serr,interp1d(wvgr,flgr)(swv)) plt.plot(swv,sfl) plt.plot(wv,fl*C1) # plt.plot(wvgr,flgr*C2) plt.xlim(3000,5500) plt.show() # plt.plot(age,ew,label='Normal resolution') # plt.plot(age,ewgr,label='Grism resolution') # plt.hlines(M,min(age),max(age)) # plt.ylabel("D4000",size=20) # plt.xlabel('Age (Gyrs)',size=20) # plt.tick_params(axis='both', which='major', labelsize=17) # plt.gcf().subplots_adjust(bottom=0.16) # plt.legend(loc=2,fontsize=12)
def Full_scale(spec, Pmfl): return Scale_model(spec.SPflx, spec.SPerr, Pmfl)
def Best_fit_scale(wv, fl, er, mfl, p1): cal = Calibrate_grism([wv, fl, er], mfl, p1) scale = Scale_model(fl / cal, er / cal, mfl) FL = fl / cal / scale ER = er / cal / scale return FL, ER
zpsh]).astype(float) # print speclist[0][18:24] ### set index and file path to models IDS = 45 fp = '/Users/Vince.ec/fsps_models_for_fit/fsps_spec/' print speclist[IDS][18:24] ### read data and models mwv, mfl = np.array(Readfile(fp + 'm0.015_a1.5_t8.0_spec.dat')) wv, fl, er = np.array(Readfile(speclist[IDS])) """plotting""" ### zps w = wv / (1 + zsmax[IDS]) Mfl = interp1d(mwv, mfl)(w) C = Scale_model(fl, er, Mfl) plt.plot(w, fl, label='%s' % zsmax[IDS]) plt.plot(w, C * Mfl) plt.axvspan(3910, 3979, alpha=.2) plt.axvspan(3981, 4030, alpha=.2) plt.axvspan(4082, 4122, alpha=.2) plt.axvspan(4250, 4400, alpha=.2) plt.axvspan(4830, 4930, alpha=.2) plt.axvspan(4990, 5030, alpha=.2) plt.axvspan(5109, 5250, alpha=.2) plt.title('%s' % speclist[IDS][18:24]) plt.xlim(3600, 5500) plt.legend() # plt.show() plt.savefig('../research_plots/zsmax.png')