def do_process(teffs, loggs, ebvs, zs, rvs, index, arr): output = np.zeros((len(responses) + 1, len(teffs))) c0 = time.time() N = len(teffs) for i, (teff, logg, ebv, z, rv, ind) in enumerate(zip(teffs, loggs, ebvs, zs, rvs, index)): if i % 100 == 0: dt = time.time() - c0 print("ETA", index[0], (N - i) / 100. * dt / 3600., 'hr') c0 = time.time() #-- get model SED and absolute luminosity model.set_defaults(z=z) wave, flux = model.get_table(teff, logg) Labs = model.luminosity(wave, flux) flux_ = reddening.redden(flux, wave=wave, ebv=ebv, rtype='flux', law=law, Rv=rv) #-- calculate synthetic fluxes output[0, i] = ind output[1:, i] = model.synthetic_flux(wave, flux_, responses, units=units) arr.append(output)
def do_ebv_process(ebvs,arr,responses): logger.debug('EBV: %s-->%s (%d)'%(ebvs[0],ebvs[-1],len(ebvs))) for ebv in ebvs: flux_ = reddening.redden(flux,wave=wave,ebv=ebv,rtype='flux',law=law,Rv=Rv) #-- calculate synthetic fluxes synflux = model.synthetic_flux(wave,flux_,responses,units=units) arr.append([np.concatenate(([ebv],synflux))]) logger.debug("Finished EBV process (len(arr)=%d)"%(len(arr)))
def do_process(teffs,loggs,ebvs,zs,rvs,index,arr): output = np.zeros((len(responses)+1,len(teffs))) c0 = time.time() N = len(teffs) for i,(teff,logg,ebv,z,rv,ind) in enumerate(zip(teffs,loggs,ebvs,zs,rvs,index)): if i%100==0: dt = time.time()-c0 print "ETA",index[0],(N-i)/100.*dt/3600.,'hr' c0 = time.time() #-- get model SED and absolute luminosity model.set_defaults(z=z) wave,flux = model.get_table(teff,logg) Labs = model.luminosity(wave,flux) flux_ = reddening.redden(flux,wave=wave,ebv=ebv,rtype='flux',law=law,Rv=rv) #-- calculate synthetic fluxes output[0,i] = ind output[1:,i] = model.synthetic_flux(wave,flux_,responses,units=units) arr.append(output)
def get_table(teff=None, logg=None, ebv=None, vrad=None, star=None, wave_units='AA', flux_units='erg/cm2/s/AA/sr', **kwargs): """ Retrieve the specific intensity of a model atmosphere. ebv is reddening vrad is radial velocity: positive is redshift, negative is blueshift (km/s!) extra kwargs are for reddening You get limb angles, wavelength and a table. The shape of the table is (N_wave,N_mu). WARNING: wave and flux units cannot be specificed for the moment. >>> mu,wave,table = get_table(10000,4.0) >>> p = pl.figure() >>> ax1 = pl.subplot(221) >>> p = pl.title('E(B-V)=0, vrad=0') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10000,4.0,ebv=0.5) >>> p = pl.subplot(222,sharex=ax1,sharey=ax1) >>> p = pl.title('E(B-V)=0.5, vrad=0') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10000,4.0,vrad=-1000.) >>> p = pl.subplot(223,sharex=ax1,sharey=ax1) >>> p = pl.title('E(B-V)=0., vrad=-10000.') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10000,4.0,vrad=-1000.,ebv=0.5) >>> p = pl.subplot(224,sharex=ax1,sharey=ax1) >>> p = pl.title('E(B-V)=0.5, vrad=-10000.') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10050,4.12) >>> p = pl.figure() >>> pl.gca().set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) @param teff: effective temperature (K) @type teff: float @param logg: log surface gravity (cgs, dex) @type logg: float @param ebv: reddening (mag) @type ebv: float @param vrad: radial velocity (for doppler shifting) (km/s) @type vrad: float @return: mu angles, wavelengths, table (Nwave x Nmu) @rtype: array, array, array """ #-- get the FITS-file containing the tables gridfile = get_file(**kwargs) #-- read the file: ff = pyfits.open(gridfile) teff = float(teff) logg = float(logg) #-- if we have a grid model, no need for interpolation try: #-- extenstion name as in fits files prepared by Steven mod_name = "T%05d_logg%01.02f" % (teff, logg) mod = ff[mod_name] mu = np.array(mod.columns.names[1:], float) table = np.array(mod.data.tolist())[:, 1:] wave = mod.data.field('wavelength') logger.debug('Model LD taken directly from file (%s)' % (os.path.basename(gridfile))) except KeyError: mu, wave, teffs, loggs, flux, flux_grid = get_grid_mesh(**kwargs) logger.debug('Model LD interpolated from grid %s (%s)' % (os.path.basename(gridfile), kwargs)) wave = wave + 0. table = flux_grid(np.log10(teff), logg) + 0. ff.close() #-- velocity shift if necessary if vrad is not None and vrad != 0: cc = constants.cc / 1000. #speed of light in km/s for i in range(len(mu)): flux_shift = tools.doppler_shift(wave, vrad, flux=table[:, i]) table[:, i] = flux_shift - 5. * vrad / cc * table[:, i] #-- redden if necessary if ebv is not None and ebv > 0: for i in range(len(mu)): table[:, i] = reddening.redden(table[:, i], wave=wave, ebv=ebv, rtype='flux', **kwargs) #-- that's it! return mu, wave, table
def get_table( teff=None, logg=None, ebv=None, vrad=None, star=None, wave_units="AA", flux_units="erg/cm2/s/AA/sr", **kwargs ): """ Retrieve the specific intensity of a model atmosphere. ebv is reddening vrad is radial velocity: positive is redshift, negative is blueshift (km/s!) extra kwargs are for reddening You get limb angles, wavelength and a table. The shape of the table is (N_wave,N_mu). WARNING: wave and flux units cannot be specificed for the moment. >>> mu,wave,table = get_table(10000,4.0) >>> p = pl.figure() >>> ax1 = pl.subplot(221) >>> p = pl.title('E(B-V)=0, vrad=0') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10000,4.0,ebv=0.5) >>> p = pl.subplot(222,sharex=ax1,sharey=ax1) >>> p = pl.title('E(B-V)=0.5, vrad=0') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10000,4.0,vrad=-1000.) >>> p = pl.subplot(223,sharex=ax1,sharey=ax1) >>> p = pl.title('E(B-V)=0., vrad=-10000.') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10000,4.0,vrad=-1000.,ebv=0.5) >>> p = pl.subplot(224,sharex=ax1,sharey=ax1) >>> p = pl.title('E(B-V)=0.5, vrad=-10000.') >>> ax = pl.gca() >>> ax.set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) >>> p = pl.xlim(700,15000) >>> p = pl.ylim(1e3,1e8) >>> mu,wave,table = get_table(10050,4.12) >>> p = pl.figure() >>> pl.gca().set_color_cycle([pl.cm.spectral(i) for i in np.linspace(0,1,len(mu))]) >>> p = pl.loglog(wave,table) @param teff: effective temperature (K) @type teff: float @param logg: log surface gravity (cgs, dex) @type logg: float @param ebv: reddening (mag) @type ebv: float @param vrad: radial velocity (for doppler shifting) (km/s) @type vrad: float @return: mu angles, wavelengths, table (Nwave x Nmu) @rtype: array, array, array """ # -- get the FITS-file containing the tables gridfile = get_file(**kwargs) # -- read the file: ff = pyfits.open(gridfile) teff = float(teff) logg = float(logg) # -- if we have a grid model, no need for interpolation try: # -- extenstion name as in fits files prepared by Steven mod_name = "T%05d_logg%01.02f" % (teff, logg) mod = ff[mod_name] mu = np.array(mod.columns.names[1:], float) table = np.array(mod.data.tolist())[:, 1:] wave = mod.data.field("wavelength") logger.debug("Model LD taken directly from file (%s)" % (os.path.basename(gridfile))) except KeyError: mu, wave, teffs, loggs, flux, flux_grid = get_grid_mesh(**kwargs) logger.debug("Model LD interpolated from grid %s (%s)" % (os.path.basename(gridfile), kwargs)) wave = wave + 0.0 table = flux_grid(np.log10(teff), logg) + 0.0 ff.close() # -- velocity shift if necessary if vrad is not None and vrad != 0: cc = constants.cc / 1000.0 # speed of light in km/s for i in range(len(mu)): flux_shift = tools.doppler_shift(wave, vrad, flux=table[:, i]) table[:, i] = flux_shift - 5.0 * vrad / cc * table[:, i] # -- redden if necessary if ebv is not None and ebv > 0: for i in range(len(mu)): table[:, i] = reddening.redden(table[:, i], wave=wave, ebv=ebv, rtype="flux", **kwargs) # -- that's it! return mu, wave, table