def __init__(self, spectrum, T_eff, logg, z): ''' Object to generate realistic limb darkening parameters Parameters ---------- spectrum : TransitCurveGen.Spectrum Spectrum we want the LD coeffs for T_eff : tuple The effective temperature of the host star, given as (value, uncertainty) pair logg : tuple The log_10 of the surface gravity of the host star, with gravity measured in cm/s2. Should be given as a (value, uncertainty) pair. z : tuple The metalicity of the host, given as a (value, uncertainty) pair. ''' # Make the filters log_wl = np.log10(spectrum.wavelengths) delta = log_wl[1] - log_wl[0] edges = [log_wl[0] - delta] + [wl + delta for wl in log_wl] edges = np.array(edges) self.filters = [ BoxcarFilter('{}'.format(i), edges[i], edges[i + 1]) for i in range(len(edges) - 1) ] print(len(self.filters), len(spectrum.wavelengths)) sc = LDPSetCreator(teff=T_eff, logg=logg, z=z, filters=self.filters) self.ld_profiles = sc.create_profiles()
def setupInitialConditions(self): self.initial = {} self.initial['planet'] = Planet(J=0.0, \ k=0.107509268533, \ rs_over_a =0.136854018274, \ b =0.143228040337, \ q=0.0, \ period=3.95023867775, \ t0=2456416.39659, \ dt = -0.000109927092499, \ esinw=0.0, \ ecosw=0.0) self.initial['star'] = Star(u1=0.47, u2=0.33, temperature=6170.0, logg=4.27, metallicity=0.26) self.initial['instrument'] = Instrument(self.bins[0].tlc, order=2) self.speak('using LDTk to estimate limb-darkening coefficients') self.ldtk_filename = os.path.join(self.binningdirectory, 'ldtk_coefs.npy') try: self.ldtk_coefs, self.ldtk_coefuncertainties = np.load( self.ldtk_filename) self.speak('loaded LD coefficients from {}'.format( self.ldtk_filename)) except IOError: # create some filters for the limb-darkening self.ldtk_filters = [ BoxcarFilter(b.identifier, b.left / 10, b.right / 10) for b in self.bins ] # set up the profile creator self.ldtk_sc = LDPSetCreator( teff=(6170, 80), # Define your star, and the code logg=(4.27, 0.07), # downloads the uncached stellar z=(0.26, 0.15), # spectra from the Husser et al. filters=self.ldtk_filters) # FTP server automatically. self.ldtk_profiles = self.ldtk_sc.create_profiles() self.ldtk_coefs, self.ldtk_coefuncertainties = self.ldtk_profiles.coeffs_qd( do_mc=False) np.save(self.ldtk_filename, (self.ldtk_coefs, self.ldtk_coefuncertainties)) self.speak('saved new LD coefficients to {}'.format( self.ldtk_filename))
def ldtk_ldc(lambda_min, lambda_max, Teff, Teff_unc, logg, logg_unc, z, z_unc): """ Function to estimate quadratic limb darkening coefficients for a given star Parameters: ---------- lambda_min: Start wavelength of the bandpass filter. lambda_max: End wavelength of the bandpass filter. Teff: Effective temperature of the star. Teff_unc: Uncertainty in Teff. logg: Surface gravity of the star. logg_unc: Uncertainty in logg. z: Metallicity of the star. z_unc: Uncertainty in z. Returns ------- cq, eq : Each an array giving the 2 quadractic limb darkening parameters and the errors associated with them """ from ldtk import LDPSetCreator, BoxcarFilter # Define your passbands. Boxcar filters useful in transmission spectroscopy filters = [BoxcarFilter('a', lambda_min, lambda_max)] sc = LDPSetCreator( teff=(Teff, Teff_unc), # Define your star, and the code logg=(logg, logg_unc), # downloads the uncached stellar z=(z, z_unc), # spectra from the Husser et al. filters=filters) # FTP server automatically. ps = sc.create_profiles() # Create the limb darkening profiles cq, eq = ps.coeffs_qd(do_mc=True) # Estimate quadratic law coefficients #lnlike = ps.lnlike_qd([[0.45,0.15], # Calculate the quadratic law log # [0.35,0.10], # likelihood for a set of coefficients # [0.25,0.05]]) # (returns the joint likelihood) #lnlike = ps.lnlike_qd([0.25,0.05],flt=0) # Quad. law log L for the first filter return cq, eq
def __init__(self, host_T, host_logg, host_z, filters, ld_model='quadratic', n_samples=20000, do_mc=False, cache_path=None): # Sanity checks if not ld_model in _implemented_ld_models: raise ValueError('Unrecognised ld_model {}'.format(ld_model)) self.default_model = ld_model # Set up the filters #print('Setting up filters') ldtk_filters = [] for i, f in enumerate(filters): if isinstance(f[0], Iterable): # We have been passed a full filter profile, set up # TabulatedFilter # Work out if the profile is in percent or fraction - is # anything bigget than 1? if np.any(f[1] > 1): tmf = 1e-2 else: tmf = 1 ldtk_filters.append(TabulatedFilter(i, f[0], f[1], tmf)) else: ldtk_filters.append(BoxcarFilter(i, f[0], f[1])) # Make the set creator, downloading data files if required if cache_path is not None: os.makedirs(cache_path, exist_ok=True) #print('Making LD parameter set creator.') #print('This may take some time as we may need to download files...') set_creator = LDPSetCreator(teff=host_T, logg=host_logg, z=host_z, filters=ldtk_filters, cache=cache_path, dataset='visir-lowres') # Get the LD profiles from the set creator #print('Obtaining LD profiles') self.profile_set = set_creator.create_profiles(nsamples=n_samples) # Find the 'best values' for each filter and then find the ratios # compared to the first. #print('Finding coefficients and ratios') self.coeffs = {} self.ratios = {} self._power2_available = True for model in _implemented_ld_models: try: self.coeffs[model] = self._extract_best_coeffs(model) self.ratios[ model] = self.coeffs[model][0] / self.coeffs[model][0][0] except Exception as e: print(e) print(f'Unable to initialise {model} model') self._power2_available = False
def createldgrid(minmu, maxmu, orbp, ldmodel='nonlinear', phoenixmin=1e-1, segmentation=int(10), verbose=False): ''' G. ROUDIER: Wrapper around LDTK downloading tools LDTK: Parviainen et al. https://github.com/hpparvi/ldtk ''' tstar = orbp['T*'] terr = np.sqrt(abs(orbp['T*_uperr'] * orbp['T*_lowerr'])) fehstar = orbp['FEH*'] feherr = np.sqrt(abs(orbp['FEH*_uperr'] * orbp['FEH*_lowerr'])) loggstar = orbp['LOGG*'] loggerr = np.sqrt(abs(orbp['LOGG*_uperr'] * orbp['LOGG*_lowerr'])) log.warning('>-- Temperature: %s +/- %s', str(tstar), str(terr)) log.warning('>-- Metallicity: %s +/- %s', str(fehstar), str(feherr)) log.warning('>-- Surface Gravity: %s +/- %s', str(loggstar), str(loggerr)) niter = int(len(minmu) / segmentation) + 1 allcl = None allel = None out = {} avmu = [np.mean([mm, xm]) for mm, xm in zip(minmu, maxmu)] for i in np.arange(niter): loweri = i * segmentation upperi = (i + 1) * segmentation if i == (niter - 1): upperi = len(avmu) munm = 1e3 * np.array(avmu[loweri:upperi]) munmmin = 1e3 * np.array(minmu[loweri:upperi]) munmmax = 1e3 * np.array(maxmu[loweri:upperi]) filters = [ BoxcarFilter(str(mue), mun, mux) for mue, mun, mux in zip(munm, munmmin, munmmax) ] sc = LDPSetCreator(teff=(tstar, terr), logg=(loggstar, loggerr), z=(fehstar, feherr), filters=filters) ps = sc.create_profiles(nsamples=int(1e4)) itpfail = False for testprof in ps.profile_averages: if np.all(~np.isfinite(testprof)): itpfail = True pass nfail = 1e0 while itpfail: nfail *= 2 sc = LDPSetCreator(teff=(tstar, nfail * terr), logg=(loggstar, loggerr), z=(fehstar, feherr), filters=filters) ps = sc.create_profiles(nsamples=int(1e4)) itpfail = False for testprof in ps.profile_averages: if np.all(~np.isfinite(testprof)): itpfail = True pass pass cl, el = ldx(ps.profile_mu, ps.profile_averages, ps.profile_uncertainties, mumin=phoenixmin, debug=verbose, model=ldmodel) if allcl is None: allcl = cl else: allcl = np.concatenate((allcl, cl), axis=0) if allel is None: allel = el else: allel = np.concatenate((allel, el), axis=0) pass allel[allel > 1.] = 0. allel[~np.isfinite(allel)] = 0. out['MU'] = avmu out['LD'] = allcl.T out['ERR'] = allel.T for i in range(0, len(allcl.T)): log.warning('>-- LD%s: %s +/- %s', str(int(i)), str(float(allcl.T[i])), str(float(allel.T[i]))) pass return out