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 get_limbdarkening(teff=None, logg=None, ebv=None, vrad=None, z=None, photbands=None, normalised=False, **kwargs): """ Retrieve a limb darkening law for a specific star and specific bandpass. Possibility to include reddening via EB-V parameter. If not given, reddening will not be performed... You choose your own reddening function. See e.g. Heyrovsky et al., 2007 If you specify one angle (mu in radians), it will take the closest match from the grid. Mu = cos(theta) where theta is the angle between the surface and the line of sight. mu=1 means theta=0 means center of the star. Example usage: >>> teff,logg = 5000,4.5 >>> mu,intensities = get_limbdarkening(teff=teff,logg=logg,photbands=['JOHNSON.V']) @keyword teff: effective temperature @type teff: float @keyword logg: logarithmic gravity (cgs) @type logg: float @keyword system: bandpass system @type system: string @keyword photbands: bandpass filters @type photbands: list of strings @keyword ebv: reddening coefficient @type ebv: float @keyword vrad: radial velocity (+ is redshift, - is blueshift) @type vrad: float @keyword mu: specificy specific angle @type mu: float """ if z is None: z = defaults["z"] # -- retrieve model atmosphere for a given teff and logg mus, wave, table = get_table(teff=teff, logg=logg, ebv=ebv, vrad=vrad, z=z, **kwargs) # -- compute intensity over the stellar disk, and normalise intensities = np.zeros((len(mus), len(photbands))) for i in range(len(mus)): intensities[i] = model.synthetic_flux(wave, table[:, i], photbands) if normalised: intensities /= intensities.max(axis=0) # -- or compute the intensity only for one angle: logger.info("Calculated LD") return mus, intensities
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_synthetic_photometry(calibrator): """ Integrate the spectrum belonging to this calibrator and return the synthetic magnitudes """ hdu = pyfits.open(basedir + calibrator[1]) wave, flux = hdu[1].data['wavelength'], hdu[1].data['flux'] hdu.close() #-- integrate the flux over the 5 pass bands. flam = model.synthetic_flux(wave, flux, photbands=photbands) #-- convert fluxes to magnitudes (assuming Zp=0) mag = -2.5 * np.log10(flam / Flam_0) #-- only return is all bands are valid if any(np.isnan(mag)): return [] return mag
def get_limbdarkening(teff=None, logg=None, ebv=None, vrad=None, z=None, photbands=None, normalised=False, **kwargs): """ Retrieve a limb darkening law for a specific star and specific bandpass. Possibility to include reddening via EB-V parameter. If not given, reddening will not be performed... You choose your own reddening function. See e.g. Heyrovsky et al., 2007 If you specify one angle (mu in radians), it will take the closest match from the grid. Mu = cos(theta) where theta is the angle between the surface and the line of sight. mu=1 means theta=0 means center of the star. Example usage: >>> teff,logg = 5000,4.5 >>> mu,intensities = get_limbdarkening(teff=teff,logg=logg,photbands=['JOHNSON.V']) @keyword teff: effective temperature @type teff: float @keyword logg: logarithmic gravity (cgs) @type logg: float @keyword system: bandpass system @type system: string @keyword photbands: bandpass filters @type photbands: list of strings @keyword ebv: reddening coefficient @type ebv: float @keyword vrad: radial velocity (+ is redshift, - is blueshift) @type vrad: float @keyword mu: specificy specific angle @type mu: float """ if z is None: z = defaults['z'] #-- retrieve model atmosphere for a given teff and logg mus, wave, table = get_table(teff=teff, logg=logg, ebv=ebv, vrad=vrad, z=z, **kwargs) #-- compute intensity over the stellar disk, and normalise intensities = np.zeros((len(mus), len(photbands))) for i in range(len(mus)): intensities[i] = model.synthetic_flux(wave, table[:, i], photbands) if normalised: intensities /= intensities.max(axis=0) #-- or compute the intensity only for one angle: logger.info('Calculated LD') return mus, intensities
# Get all necessary data #=================================================================================== #-- Get the reference flux if reference == 'VEGA': #-- calculate Flam based on the Vega spectrum hdu = pyfits.open('alpha_lyr_stis_008.fits') wave, flux = hdu[1].data['wavelength'], hdu[1].data['flux'] hdu.close() else: #-- calculate Flam for the AB system wave = np.arange(3000, 9000, step=0.5) flux = cv.convert(cc.cc_units, 'AA/s', cc.cc) / wave**2 * 3631e-23 Flam_0 = model.synthetic_flux(wave, flux, photbands=photbands) #-- load the calibrators calibrators = ascii.read2array(basedir + 'calspec.ident', splitchar=',', dtype=str) def get_synthetic_photometry(calibrator): """ Integrate the spectrum belonging to this calibrator and return the synthetic magnitudes """ hdu = pyfits.open(basedir + calibrator[1]) wave, flux = hdu[1].data['wavelength'], hdu[1].data['flux'] hdu.close()
def get_law(name, norm='E(B-V)', wave_units='AA', photbands=None, **kwargs): """ Retrieve an interstellar reddening law. Parameter C{name} must be the function name of one of the laws defined in this module. By default, the law will be interpolated on a grid from 100 angstrom to 10 micron in steps of 10 angstrom. This can be adjusted with the parameter C{wave} (array), which B{must} be in angstrom. You can change the units ouf the returned wavelength array via C{wave_units}. By default, the curve is normalised with respect to E(B-V) (you get A(l)/E(B-V)). You can set the C{norm} keyword to Av if you want A(l)/Av. Remember that A(V) = Rv * E(B-V) The parameter C{Rv} is by default 3.1, other reasonable values lie between 2.0 and 5.1 Extra accepted keywords depend on the type of reddening law used. Example usage: >>> wave = np.r_[1e3:1e5:10] >>> wave,mag = get_law('cardelli1989',wave=wave,Rv=3.1) @param name: name of the interstellar law @type name: str, one of the functions defined here @param norm: type of normalisation of the curve @type norm: str (one of E(B-V), Av) @param wave_units: wavelength units @type wave_units: str (interpretable for units.conversions.convert) @param photbands: list of photometric passbands @type photbands: list of strings @keyword wave: wavelength array to interpolate the law on @type wave: ndarray @return: wavelength, reddening magnitude @rtype: (ndarray,ndarray) """ #-- get the inputs wave_ = kwargs.pop('wave', None) Rv = kwargs.setdefault('Rv', 3.1) #-- get the curve wave, mag = globals()[name.lower()](**kwargs) wave_orig, mag_orig = wave.copy(), mag.copy() #-- interpolate on user defined grid if wave_ is not None: if wave_units != 'AA': wave_ = conversions.convert(wave_units, 'AA', wave_) mag = np.interp(wave_, wave, mag, right=0) wave = wave_ #-- pick right normalisation: convert to A(lambda)/Av if needed if norm.lower() == 'e(b-v)': mag *= Rv else: #-- we allow ak and av as shortcuts for normalisation in JOHNSON K and # V bands if norm.lower() == 'ak': norm = 'JOHNSON.K' elif norm.lower() == 'av': norm = 'JOHNSON.V' norm_reddening = model.synthetic_flux(wave_orig, mag_orig, [norm])[0] logger.info('Normalisation via %s: Av/%s = %.6g' % (norm, norm, 1. / norm_reddening)) mag /= norm_reddening #-- maybe we want the curve in photometric filters if photbands is not None: mag = model.synthetic_flux(wave, mag, photbands) wave = filters.get_info(photbands)['eff_wave'] #-- set the units of the wavelengths if wave_units != 'AA' and photbands is not None: wave = conversions.convert('AA', wave_units, wave) return wave, mag