def calc_thermal_structure(temp_params): # calculate thermal structure pressures = np.logspace(-6, temp_params['P0'], 100) temperatures = nc.guillot_global(pressures, 1e1**temp_params['log_kappa_IR'], 1e1**temp_params['log_gamma'], 1e1**temp_params['log_gravity'], temp_params['t_int'], temp_params['t_equ']) return pressures, temperatures
def calc_spectrum(self, metal_params, temps_params, clouds_params, external_metal_profile=None, converting_units=True): external_profile = None if self.external_pt_profile is not None: pressures, temperatures = self.external_pt_profile external_profile = [ pressures, temperatures, external_metal_profile ] else: pressures = np.logspace(-6, temps_params['P0'], 100) temperatures = nc.guillot_global(pressures, 1e1**temps_params['log_kappa_IR'], 1e1**temps_params['log_gamma'], 1e1**temps_params['log_gravity'], temps_params['t_int'], temps_params['t_equ']) self.rt_obj.setup_opa_structure(pressures) wlen, flux = retrieval_model_initial(self.rt_obj, temps_params, metal_params, clouds_params, mode=self.mode, external_profile=external_profile) if converting_units: wlen_temp, flux_temp = convert_units(wlen, flux, temps_params['log_R'], distance=DISTANCE) else: wlen_temp = 1e4 * wlen flux_temp = flux return wlen_temp, flux_temp
atmosphere.setup_opa_structure(pressures) import petitRADTRANS.nat_cst as nc R_pl = 1.838*nc.r_jup_mean gravity = 1.e5 P0 = 0.01 kappa_IR = 0.01 gamma = 0.4 T_int = 200. T_equ = 1500. temperature = nc.guillot_global(pressures, kappa_IR, gamma, gravity, T_int, T_equ) print(len(temperature)) data = open('../co_exojax/Gl229/MMR/eq.dat', 'r') a = 0 MMW_k = np.ones_like(temperature) MMR = [[0] * len(pressures) for j in range(160)] for line in data: if line[0]=='#': continue lines = line.rstrip('\n').split() MMW_k[a] = lines[2] for i in range(0,160): MMR[i][a] = lines[i+3] a = a + 1
def calculate_model(loc): ''' Description: main wrapper function to run petitRADTRANS to calculate atmosphere model ''' WLEN = [loc['WL0'] / 1000., loc['WLF'] / 1000.] loc["WLEN_MICRONS"] = WLEN loc["RP_CGS"] = loc[ 'RP'] * nc.r_jup_mean #nominal hot Jupiter radius should be 1.25*nc.r_jup_mean loc["MP_CGS"] = loc[ 'MP'] * nc.m_jup #nominal hot Jupiter mass should be 1.81*nc.r_jup_mean loc["GRAVITY_CGS"] = (nc.G * loc["MP_CGS"]) / (loc["RP_CGS"]**2) loc["OPACITY_FILES"] = opacity_files(loc['SPECIES'], mode=loc['MODE']) # Create the Ratrans object here atmosphere = Radtrans(line_species=loc["OPACITY_FILES"], \ rayleigh_species=loc['RAYLEIGH_SPECIES'], \ continuum_opacities=loc['CONTINUUM_OPACITIES'], \ mode=loc['MODE'], \ wlen_bords_micron = loc["WLEN_MICRONS"]) # Create pressure and temperature distribution: Guillot loc["P_SCALE"] = 'log_10' pressures = np.logspace(loc["P_START"], loc["P_STOP"], loc["P_NSAMPLES"]) loc["P-T_Model"] = 'nc.guillot_global()' temperature = nc.guillot_global(pressures, loc['KAPPA'], loc['GAMMA'], loc['GRAVITY_CGS'], loc['TINT'], loc['TEQ']) atmosphere.setup_opa_structure(pressures) loc_abundances = {} # Define abundances of line species and mean molecular weight of atmosphere for i in range(len(loc["OPACITY_FILES"])): ab_percent = 10**(loc['ABUNDANCES'][i] + np.log10(loc['AB_H2'])) loc_abundances[loc["OPACITY_FILES"] [i]] = ab_percent * np.ones_like(temperature) # Define abundances of H2 and He and mean molecular weight of atmosphere loc_abundances["He"] = loc['AB_He'] * np.ones_like(temperature) loc_abundances["H2"] = loc['AB_H2'] * np.ones_like(temperature) loc["loc_abundances"] = loc_abundances MMW = 2.3 * np.ones_like(temperature) # calculation of transmission spectrum atmosphere.calc_transm(temperature, loc_abundances, loc["GRAVITY_CGS"], MMW, R_pl=loc["RP_CGS"], P0_bar=loc['P0']) # calculation of emission spectrum atmosphere.calc_flux(temperature, loc_abundances, loc["GRAVITY_CGS"], MMW) # create transmission data vector loc['transmission'] = atmosphere.transm_rad / nc.r_jup_mean # create emission data vector loc['emission'] = atmosphere.flux / 1e-6 # create wavelength array loc['wl'] = nc.c / atmosphere.freq / 1e-4 return loc
def calc_spectrum(self, ab_metals, temp_params, clouds_params, external_pt_profile=None, return_profiles=False, contribution=False, set_mol_abund=None): # temperature-pressure profile if external_pt_profile is not None: pressures, temperatures = external_pt_profile else: pressures = np.logspace(-6, temp_params['P0'], 100) temperatures = nc.guillot_global(pressures, 1e1**temp_params['log_kappa_IR'], 1e1**temp_params['log_gamma'], 1e1**temp_params['log_gravity'], temp_params['t_int'], temp_params['t_equ']) # setup up opacity structure if not yet done so if not (self.opa_struct_set): self.rt_obj.setup_opa_structure(pressures) self.opa_struct_set = True # translate ab_metals dictionary if we're using c-k mode if self.mode == 'c-k': # example: if mol = 'H2O_main_iso', then name_ck(mol) = 'H2O' # so it changes ab_metals = {'H2O_main_iso':obj} to ab_metals = {'H2O':obj} ab_metals_ck = { name_ck(mol): ab_metals[mol] for mol in ab_metals.keys() } ab_metals = ab_metals_ck # calculate forward model depending on case: free or chemical equilibrium if self.model == 'free': wlen, flux, abundances = retrieval_model_initial( self.rt_obj, pressures, temperatures, temp_params, ab_metals, clouds_params, mode=self.mode, contribution=contribution) elif self.model == 'chem_equ': # 'chem_equ' wlen, flux, abundances = retrieval_model_chem_disequ( self.rt_obj, temp_params, ab_metals, clouds_params, mode=self.mode, contribution=contribution, only_include=self.only_include, set_mol_abund=set_mol_abund) else: wlen, flux, abundances = calc_flux_from_model( self.rt_obj, temp_params, chem_model=self.model, chem_params=ab_metals, clouds_params=clouds_params, mode=self.mode, contribution=contribution) if self.only_include != 'all': assert (len(abundances.keys()) == len(self.only_include) + 2) if return_profiles: return wlen, flux, pressures, temperatures, abundances else: return wlen, flux
def Simulator(params): NaN_spectra = 0 atmosphere = Radtrans(line_species = ['H2O', 'CO_all_iso', \ 'CO2', 'CH4', \ 'Na', 'K'], \ rayleigh_species = ['H2', 'He'], \ continuum_opacities = ['H2-H2', 'H2-He'], \ wlen_bords_micron = WLENGTH)#, mode='c-k') pressures = np.logspace(-6, 2, 100) atmosphere.setup_opa_structure(pressures) temperature = 1200. * np.ones_like(pressures) t_int = params[0].numpy() #200. log_kappa_IR = params[1].numpy() #-2 log_gravity = params[2].numpy() #params[5].numpy() 1e1**2.45 gravity = np.exp(log_gravity) kappa_IR = np.exp(log_kappa_IR) temperature = nc.guillot_global(pressures, kappa_IR, gamma, gravity, t_int, t_equ) abundances = {} abundances['H2'] = 0.75 * np.ones_like(temperature) #0.74 * np.ones_like(temperature) (params[3].numpy()) abundances['He'] = 0.25 * np.ones_like(temperature) #0.24 * np.ones_like(temperature) (params[4].numpy()) abundances['H2O'] = 0.001 * np.ones_like(temperature) abundances['CO_all_iso'] = 0.01 * np.ones_like(temperature) abundances['CO2'] = 0.00001 * np.ones_like(temperature) abundances['CH4'] = 0.000001 * np.ones_like(temperature) abundances['Na'] = 0.00001 * np.ones_like(temperature) abundances['K'] = 0.000001 * np.ones_like(temperature) MMW = rm.calc_MMW(abundances) * np.ones_like(temperature) #print(MMW, abundances) atmosphere.calc_flux(temperature, abundances, gravity, MMW) wlen, flux_nu = nc.c/atmosphere.freq, atmosphere.flux/1e-6 # Just to make sure that a long chain does not die # unexpectedly: # Return -inf if forward model returns NaN values if np.sum(np.isnan(flux_nu)) > 0: print("NaN spectrum encountered") NaN_spectra += 1 return torch.ones([1,371])* -np.inf # Convert to observation for emission case flux_star = fstar(wlen) flux_sq = flux_nu/flux_star*(R_pl/R_star)**2 flux_rebinned = rgw.rebin_give_width(wlen, flux_sq, \ data_wlen['MIRI LRS'], data_wlen_bins['MIRI LRS']) #flux_rebinned = np.reshape(flux_rebinned, (371,1)) FR= torch.Tensor(flux_rebinned) return FR
P0_bar=P0_bar) petit_trans = atmosphere.transm_rad / pc.rjup pyrat = pb.run('petit_spectrum_H2O-CO.cfg') pyrat_wl = 1 / (pyrat.spec.wn * pc.um) pyrat_trans = np.sqrt(pyrat.spec.spectrum) * pyrat.phy.rstar / pc.rjup # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Emission models: # This one requires a non-isothermal profile: kappa_IR = 0.01 gamma = 0.4 T_int = 200.0 T_equ = 1500.0 temp2 = nc.guillot_global(pressure / pc.bar, kappa_IR, gamma, gravity, T_int, T_equ) atmosphere.calc_flux(temp2, abundances, gravity, mu) petit_emission = atmosphere.flux * pc.c pyrat.od.rt_path = 'emission' pyrat.run(temp=temp2, radius=atmosphere.radius) pyrat_emission = np.copy(pyrat.spec.spectrum) # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Additional calculation with methane opacity: atmosphere = Radtrans(line_species=['CH4', 'Na_lor_cut', 'K_lor_cut'], rayleigh_species=['H2'], continuum_opacities=['H2-H2'], wlen_bords_micron=[0.3, 10.0]) atmosphere.setup_opa_structure(pressure / pc.bar)