def log_likelihood(theta, x, y, yerr, fixed): _, model = transit_spectra_model(x, theta, fixed) # print('model.size', model.size) # print('y.size', y.size) sigma = yerr**2 return -0.5 * np.sum((y - model)**2 / sigma + np.log(sigma))
def log_likelihood(theta): # retrieve the global variables global pixel_bins global transit_data global photon_noise global fixed_parameters # only 'y' changes on the fly fixed = fixed_parameters x = pixel_bins y = transit_data yerr = photon_noise _, model = transit_spectra_model(x, theta, fixed) sigma = yerr**2 return -0.5 * np.sum((y - model)**2 / sigma + np.log(sigma))
# test the model generation function # this produces the 'true' transit spectrum fixed_parameters = (fine_wavelengths, water_cross_sections, co_cross_sections, hcn_cross_sections, h2_cross_sections, g_planet, rad_star, R) theta = (rad_planet, T, log_f_h2o, log_fco, log_fhcn) pixel_wavelengths, pixel_transit_depth = transit_spectra_model(pixel_bins, theta, fixed_parameters) # generate photon noise from a signal value # signal = 1.22e9 # noise = (np.random.poisson(lam=signal, size=pixel_transit_depth.size) - signal)/signal # generate noise instances num_noise_inst = 10 photon_noise = 75 * 1e-6 # set noise to 75ppm noise_inst = [] while len(noise_inst) < num_noise_inst: noise_inst.append( np.random.normal(scale=photon_noise, size=pixel_transit_depth.size) ) # add noise to the transit spectrum noisey_transit_depth = pixel_transit_depth + noise_inst
# Choose the Nyquest sampling rate at the blue end samplerate_per_pixel = resolution / 2 number_pixels = int((flipped_wl[-1] - flipped_wl[0]) / samplerate_per_pixel) # make pixel bins pixel_bins = np.linspace(flipped_wl[0], flipped_wl[-1], num=number_pixels + 1) # pixel_wavelengths = np.linspace(flipped_wl[0], flipped_wl[-1], num=number_pixels) # pixel_bins = pixel_wavelengths # test the model generation function # this produces the 'true' transit spectrum fixed_parameters = (fine_wavelengths, water_cross_sections, co_cross_sections, hcn_cross_sections, h2_cross_sections, g_planet, rad_star, R) variables = (rad_planet, T, log_f_h2o, log_fco, log_fhcn) pixel_wavelengths, pixel_transit_depth = transit_spectra_model( pixel_bins, variables, fixed_parameters) # generate photon noise from a signal value # signal = 1.22e9 # noise = (np.random.poisson(lam=signal, size=pixel_transit_depth.size) - signal)/signal photon_noise = 75 * 1e-6 # set noise to 75ppm noise = np.random.normal(scale=photon_noise, size=pixel_transit_depth.size) # add noise to the transit spectrum noisey_transit_depth = pixel_transit_depth + noise # mean spectral resolution # spec_res = resolution plt.figure('transit depth R%.2f' % R, figsize=(8, 8))