EXPERIMENT, obs_type, truth_dir=TRUTH_DIR) for jc, cval in enumerate(CVALS): # Build the submissions g1sub, g2sub = g3metrics.make_multiple_submissions_const_shear( cval, 0., evaluate.MFID, evaluate.MFID, g1true, g2true, NGALS_PER_IMAGE, NOISE_SIGMA[obs_type], rotate_cs=rotations, nsubmissions=NTEST, rho=RHO) # Loop over submissions evaluating metric for itest in xrange(NTEST): fdsub, subfile = tempfile.mkstemp(suffix=".dat") with os.fdopen(fdsub, "wb") as fsub: np.savetxt( fsub, np.array((subfield_index, g1sub[:, itest], g2sub[:, itest])).T, fmt="%d %e %e") qc[obs_type][itest, jc] = evaluate.q_constant( subfile, EXPERIMENT, obs_type, just_q=True, truth_dir=TRUTH_DIR) os.remove(subfile) print "mean(Q_c), std(Q_c) = "+str(qc[obs_type][:, jc].mean())+", "+\ str(qc[obs_type][:, jc].std())+" for "+str(NTEST)+" sims (with c+ = "+\ str(cval)+", obs_type = "+str(obs_type)+")" print print "Saving pickled Q_c versus c dict to "+coutfile with open(coutfile, "wb") as fout: cPickle.dump(qc, fout) print else: with open(coutfile, "rb") as fin: qc = cPickle.load(fin) if not os.path.isfile(moutfile): for obs_type in ("ground", "space",):
import momentsml import momentsml.tools import astropy import config import numpy as np import os import sys import logging logging.basicConfig(format=config.loggerformat, level=logging.DEBUG) logger = logging.getLogger(__name__) outcatpath = config.great3.path("submission_{}.txt".format(config.predcode)) metricsdirpath = os.path.join(config.great3.g3publicdir, "metrics") sys.path.append(metricsdirpath) import evaluate results = evaluate.q_constant( outcatpath, config.great3.experiment, config.great3.obstype, storage_dir=config.great3.path("eva_storage_dir_{}".format( config.predcode)), truth_dir=config.great3.truthdir, plot=config.great3.path("eva_plot_{}".format(config.predcode)), logger=logger, pretty_print=True)
rotate_cs=rotations, nsubmissions=NTEST, rho=RHO) # Loop over submissions evaluating metric for itest in xrange(NTEST): fdsub, subfile = tempfile.mkstemp(suffix=".dat") with os.fdopen(fdsub, "wb") as fsub: np.savetxt(fsub, np.array((subfield_index, g1sub[:, itest], g2sub[:, itest])).T, fmt="%d %e %e") qc[obs_type][itest, jc] = evaluate.q_constant( subfile, EXPERIMENT, obs_type, just_q=True, truth_dir=TRUTH_DIR) os.remove(subfile) print "mean(Q_c), std(Q_c) = "+str(qc[obs_type][:, jc].mean())+", "+\ str(qc[obs_type][:, jc].std())+" for "+str(NTEST)+" sims (with c+ = "+\ str(cval)+", obs_type = "+str(obs_type)+")" print print "Saving pickled Q_c versus c dict to " + coutfile with open(coutfile, "wb") as fout: cPickle.dump(qc, fout) print else: with open(coutfile, "rb") as fin:
"great3_ec-regauss-example-example_1-2013-12-27T15:24:57.472170+00:00.g3") TRUTH_DIR = "/Users/browe/great3/beta/truth" # Modify to wherever truth is unpacked if __name__ == "__main__": # Load up relevant data i3data = np.loadtxt(I3FILE) rgdata = np.loadtxt(RGFILE) subfield_index, g1true, g2true = evaluate.get_generate_const_truth( EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) rotations = evaluate.get_generate_const_rotations(EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) # Calculate m and c factors qi3, cpi3, mpi3, cxi3, mxi3, sigcpi3, sigmpi3, sigmxi3, sigcxi3 = evaluate.q_constant( I3FILE, EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) qrg, cprg, mprg, cxrg, mxrg, sigcprg, sigmprg, sigmxrg, sigcxrg = evaluate.q_constant( RGFILE, EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) # Rotate these c and m c1i3 = cpi3 * np.cos(2. * rotations) - cxi3 * np.sin(2. * rotations) c2i3 = cpi3 * np.sin(2. * rotations) + cxi3 * np.cos(2. * rotations) m1i3 = mpi3 * np.cos(2. * rotations) - mxi3 * np.sin(2. * rotations) m2i3 = mpi3 * np.sin(2. * rotations) + mxi3 * np.sin(2. * rotations) c1rg = cprg * np.cos(2. * rotations) - cxrg * np.sin(2. * rotations) c2rg = cprg * np.sin(2. * rotations) + cxrg * np.cos(2. * rotations) m1rg = mprg * np.cos(2. * rotations) - mxrg * np.sin(2. * rotations) m2rg = mprg * np.sin(2. * rotations) + mxrg * np.sin(2. * rotations) # Calculate bias model using these m and c values g1i3model = (1. + m1i3) * g1true + c1i3 g2i3model = (1. + m2i3) * g2true + c2i3 g1rgmodel = (1. + m1rg) * g1true + c1rg
RGFILE = os.path.join( "results", "great3_ec-regauss-example-example_1-2013-12-27T15:24:57.472170+00:00.g3") TRUTH_DIR = "/Users/browe/great3/beta/truth" # Modify to wherever truth is unpacked if __name__ == "__main__": # Load up relevant data i3data = np.loadtxt(I3FILE) rgdata = np.loadtxt(RGFILE) subfield_index, g1true, g2true = evaluate.get_generate_const_truth( EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) rotations = evaluate.get_generate_const_rotations(EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) # Calculate m and c factors qi3, cpi3, mpi3, cxi3, mxi3, sigcpi3, sigmpi3, sigmxi3, sigcxi3 = evaluate.q_constant( I3FILE, EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) qrg, cprg, mprg, cxrg, mxrg, sigcprg, sigmprg, sigmxrg, sigcxrg = evaluate.q_constant( RGFILE, EXPERIMENT, OBS_TYPE, truth_dir=TRUTH_DIR) # Rotate these c and m c1i3 = cpi3 * np.cos(2. * rotations) - cxi3 * np.sin(2. * rotations) c2i3 = cpi3 * np.sin(2. * rotations) + cxi3 * np.cos(2. * rotations) m1i3 = mpi3 * np.cos(2. * rotations) - mxi3 * np.sin(2. * rotations) m2i3 = mpi3 * np.sin(2. * rotations) + mxi3 * np.sin(2. * rotations) c1rg = cprg * np.cos(2. * rotations) - cxrg * np.sin(2. * rotations) c2rg = cprg * np.sin(2. * rotations) + cxrg * np.cos(2. * rotations) m1rg = mprg * np.cos(2. * rotations) - mxrg * np.sin(2. * rotations) m2rg = mprg * np.sin(2. * rotations) + mxrg * np.sin(2. * rotations) # Calculate bias model using these m and c values g1i3model = (1. + m1i3) * g1true + c1i3 g2i3model = (1. + m2i3) * g2true + c2i3 g1rgmodel = (1. + m1rg) * g1true + c1rg