def execute(self, processes): summary_outname = self.params["outdir"] + "theory_fit.dat" print "opening: ", self.params["summary_file"] print "to summary: ", summary_outname cross_summary = h5py.File(self.params["summary_file"], "r") # this has: kvec, power_1d, power_1d_cov print "using col:%d of %s" % (self.params["pk_column"], self.params["theory_curve"]) theory_curve = np.genfromtxt(self.params["theory_curve"]) theory_curve = theory_curve[:, self.params["pk_column"]] #print theory_curve bin_center = cross_summary["kvec"]["k_1d_center"].value (kmin, kmax) = tuple(self.params["krange"]) restrict = np.where(np.logical_and(bin_center > kmin, bin_center < kmax)) res_slice = slice(min(restrict[0]), max(restrict[0]) + 1) #restrict_alt = np.where(restrict)[0][np.newaxis, :] #restricted_cov = covmock[restrict_alt][0] summary_outfile = open(summary_outname, "w") for treatment in cross_summary["power_1d"]: pwr = cross_summary["power_1d"][treatment].value cov = cross_summary["power_1d_cov"][treatment].value amplitude = utils.ampfit(pwr[res_slice], cov[res_slice, res_slice], theory_curve[res_slice]) nmodes = float(treatment.split("modes")[0]) snr = amplitude['amp'] / amplitude['error'] outstr = "%d " % nmodes outstr += "%(amp)10.5f %(error)10.5f " % amplitude outstr += "%(chi2)10.5f %(dof)10.5f %(pte)10.5f " % amplitude outstr += "%10.5f" % snr print outstr summary_outfile.write(outstr + "\n")
def execute(self, processes): summary_outname = self.params["outdir"] + "theory_fit.dat" print "opening: ", self.params["summary_file"] print "to summary: ", summary_outname cross_summary = h5py.File(self.params["summary_file"], "r") # this has: kvec, power_1d, power_1d_cov print "using col:%d of %s" % (self.params["pk_column"], self.params["theory_curve"]) theory_curve = np.genfromtxt(self.params["theory_curve"]) theory_curve = theory_curve[:, self.params["pk_column"]] #print theory_curve bin_center = cross_summary["kvec"]["k_1d_center"].value (kmin, kmax) = tuple(self.params["krange"]) restrict = np.where( np.logical_and(bin_center > kmin, bin_center < kmax)) res_slice = slice(min(restrict[0]), max(restrict[0]) + 1) #restrict_alt = np.where(restrict)[0][np.newaxis, :] #restricted_cov = covmock[restrict_alt][0] summary_outfile = open(summary_outname, "w") for treatment in cross_summary["power_1d"]: pwr = cross_summary["power_1d"][treatment].value cov = cross_summary["power_1d_cov"][treatment].value amplitude = utils.ampfit(pwr[res_slice], cov[res_slice, res_slice], theory_curve[res_slice]) nmodes = float(treatment.split("modes")[0]) snr = amplitude['amp'] / amplitude['error'] outstr = "%d " % nmodes outstr += "%(amp)10.5f %(error)10.5f " % amplitude outstr += "%(chi2)10.5f %(dof)10.5f %(pte)10.5f " % amplitude outstr += "%10.5f" % snr print outstr summary_outfile.write(outstr + "\n")
def make_xcorr_plotdata(): # find the mean brightness used in simulations corrobj = corr21cm.Corr21cm() T_b_sim = corrobj.T_b(1420. / 800. - 1) print T_b_sim #splt.process_batch_correlations(xcorr_real_param, # multiplier=1., cross_power=True) ##splt.process_batch_correlations(xcorr_sim_param, cross_power=True, ## multiplier=1./(T_b_sim/1.e3)) #splt.process_batch_correlations(xcorr_sim_param, cross_power=True, # multiplier=1./(T_b_sim)) #splt.process_batch_correlations(xcorr_loss_sim_param, # multiplier=1./T_b_sim*1.e-3, cross_power=True) #splt.process_batch_correlations(xcorr_variants_param, # multiplier=1., cross_power=True) #splt.plot_batch_correlations(xcorr_real_param, # dir_prefix="plots/xcorr_real/", # color_range=[-0.04, 0.04], cross_power=True) #splt.plot_batch_correlations(xcorr_sim_param, # dir_prefix="plots/xcorr_sim/", # color_range=[-0.04, 0.04], cross_power=True) #splt.plot_batch_correlations(xcorr_loss_param, # dir_prefix="plots/xcorr_loss/", # color_range=[-0.04, 0.04], cross_power=True) #splt.plot_batch_correlations(xcorr_loss_sim_param, # dir_prefix="plots/xcorr_loss_sim/", # color_range=[-0.04, 0.04], cross_power=True) #splt.plot_batch_correlations(xcorr_variants_param, # dir_prefix="plots/xcorr_variants/", # color_range=[-0.04, 0.04], cross_power=True) # find the real xcorr signal with errors xcorr_data = splt.batch_correlations_statistics(xcorr_real_param, randtoken="rand", include_signal=True) # find the simulated xcorr signal with errors xcorr_sim_data = splt.batch_correlations_statistics(xcorr_sim_param, randtoken="rand", include_signal=False) # find the compensation function from simulations compmode = splt.batch_compensation_function(xcorr_loss_sim_param) lagl = xcorr_data[0] lagc = xcorr_data[1] lagr = xcorr_data[2] xcorr_null = xcorr_data[3] xcorr_signal = xcorr_data[6] xcorr_cov = xcorr_data[5] xcorr_err = xcorr_data[4] xcorr_sim = xcorr_sim_data[3] xcorr_sim_err = xcorr_sim_data[4] xcorr_sim_cov = xcorr_sim_data[5] # 0=0, 5=1, 10=2, 15=3, etc. compensation = compmode[3, :] (amp, amp_err) = utils.ampfit(xcorr_signal, xcorr_cov + xcorr_sim_cov, xcorr_sim) print amp, amp_err # now convert from the 1e-3 Omega_HI in simulations to 0.5e-3 #xcorr_sim /= 2. #xcorr_sim_err /= 2. xcorr_sim *= amp xcorr_sim_err *= amp for correntry in zip(lagl, lagc, lagr, xcorr_signal, xcorr_null, xcorr_err, xcorr_sim, xcorr_sim_err, compensation): print "%5.3g %5.3g %5.3g %5.3g %5.3g %5.3g %5.3g %5.3g %5.3g" % correntry