def get_variable_gsuffix(experiment, obs_type, suffix="_intrinsic", file_prefix="galaxy_catalog",
                         logger=None, test_dir=TEST_DIR):
    """Get the full catalog of intrinsic "shears" and positions for all fields.

    Gets "g1"+suffix and "g2"+suffix from the subfield_catalog files.

    @return id, x, y, g1, g2
    """
    mapper = great3sims.mapper.Mapper(test_dir, experiment, obs_type, "variable")
    identifier = np.empty(
        (evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS), dtype=int)
    g1int = np.empty(
        (evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS))
    g2int = np.empty(
        (evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS))
    xx = np.empty(
        (evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS))
    yy = np.empty(
        (evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS))
    # Load the offsets
    subfield_indices, offset_deg_x, offset_deg_y = evaluate.get_generate_variable_offsets(
        experiment, obs_type, storage_dir=evaluate.STORAGE_DIR, truth_dir=evaluate.TRUTH_DIR,
        logger=logger)
    # Build basic x and y grids to use for coord positions
    xgrid_deg, ygrid_deg = np.meshgrid(
        np.arange(0., evaluate.XMAX_GRID_DEG, evaluate.DX_GRID_DEG),
        np.arange(0., evaluate.XMAX_GRID_DEG, evaluate.DX_GRID_DEG))
    xgrid_deg = xgrid_deg.flatten() # Flatten these - the default C ordering corresponds to the way
    ygrid_deg = ygrid_deg.flatten() # the shears are ordered too, which is handy
    if len(xgrid_deg) != evaluate.NGALS_PER_SUBFIELD:
        raise ValueError(
            "Dimensions of xgrid_deg and ygrid_deg do not match NGALS_PER_SUBFIELD.  Please check "+
            "the values of XMAX_GRID_DEG and DX_GRID_DEG in evaluate.py.")
    # Then loop over the fields and subfields getting the galaxy catalogues
    import pyfits
    for ifield in range(evaluate.NFIELDS):

        # Read in all the shears in this field and store
        for jsub in range(evaluate.NSUBFIELDS_PER_FIELD):

            # Build the x,y grid using the subfield offsets
            isubfield_index = jsub + ifield * evaluate.NSUBFIELDS_PER_FIELD
            xx[:, jsub, ifield] = xgrid_deg + offset_deg_x[isubfield_index]
            yy[:, jsub, ifield] = ygrid_deg + offset_deg_y[isubfield_index]
            galcatfile = os.path.join(
                mapper.full_dir, (file_prefix+"-%03d.fits" % isubfield_index))
            truedata = pyfits.getdata(galcatfile)
            if len(truedata) != evaluate.NGALS_PER_SUBFIELD:
                raise ValueError(
                    "Number of records in "+galcatfile+" (="+str(len(truedata))+") is not "+
                    "equal to NGALS_PER_SUBFIELD (="+str(evaluate.NGALS_PER_SUBFIELD)+")")
            g1int[:, jsub, ifield] = truedata["g1"+suffix]
            g2int[:, jsub, ifield] = truedata["g2"+suffix]
            identifier[:, jsub, ifield] = truedata["ID"]

    # Then return
    return identifier, xx, yy, g1int, g2int
def print_offsets_times_70(experiment, obs_type, truth_dir=TRUTH_DIR):
    """Prints the offsets multiplied by 70 for comparison with branch_id x_offset and y_offset
    values as per Melanie's suggestion on Issue #16.
    """
    subfield_index, x_offset_deg, y_offset_deg = evaluate.get_generate_variable_offsets(
        experiment, obs_type, truth_dir=truth_dir)
    print "70. * x_offset ="
    print x_offset_deg * 70.
    print "70. * y_offset ="
    print y_offset_deg * 70.
    return
Esempio n. 3
0
def print_offsets_times_70(experiment, obs_type, truth_dir=TRUTH_DIR):
    """Prints the offsets multiplied by 70 for comparison with branch_id x_offset and y_offset
    values as per Melanie's suggestion on Issue #16.
    """
    subfield_index, x_offset_deg, y_offset_deg = evaluate.get_generate_variable_offsets(
        experiment, obs_type, truth_dir=truth_dir)
    print "70. * x_offset ="
    print x_offset_deg * 70.
    print "70. * y_offset ="
    print y_offset_deg * 70.
    return
        experiment, obs_type, truth_dir=truth_dir)
    print "70. * x_offset ="
    print x_offset_deg * 70.
    print "70. * y_offset ="
    print y_offset_deg * 70.
    return

if __name__ == "__main__":

    experiment = "control"

    # First test the offsets in branch_id match those in the offset_truth files
    for obs_type in ("ground", "space"):

        subfield_index_truth, x_offset_truth, y_offset_truth = \
            evaluate.get_generate_variable_offsets(experiment, obs_type, truth_dir=TRUTH_DIR)
        x_offset_presub = branch_id.x_offset[experiment+"-"+obs_type+"-variable"]
        y_offset_presub = branch_id.y_offset[experiment+"-"+obs_type+"-variable"]
        # Assert that the truth * 70 = presub version
        np.testing.assert_array_equal(
            (70. * x_offset_truth).astype(int), np.asarray(x_offset_presub),
            err_msg="Truth x_offsets do not match those in public-scripts.branch_id")
        np.testing.assert_array_equal(
            (70. * y_offset_truth).astype(int), np.asarray(y_offset_presub),
            err_msg="Truth x_offsets do not match those in public-scripts.branch_id")

        # Then try testing the whole x-y using the (no longer) hacked presubmission
        pipelines.build_submission(
            "im3shape-1", experiment, obs_type, "variable",
            submission_dir=os.path.join("..", "submissions"),
            presubmission_exec=os.path.join("..", "..", "public-scripts", "presubmission.py"))
Esempio n. 5
0
    print "70. * x_offset ="
    print x_offset_deg * 70.
    print "70. * y_offset ="
    print y_offset_deg * 70.
    return


if __name__ == "__main__":

    experiment = "control"

    # First test the offsets in branch_id match those in the offset_truth files
    for obs_type in ("ground", "space"):

        subfield_index_truth, x_offset_truth, y_offset_truth = \
            evaluate.get_generate_variable_offsets(experiment, obs_type, truth_dir=TRUTH_DIR)
        x_offset_presub = branch_id.x_offset[experiment + "-" + obs_type +
                                             "-variable"]
        y_offset_presub = branch_id.y_offset[experiment + "-" + obs_type +
                                             "-variable"]
        # Assert that the truth * 70 = presub version
        np.testing.assert_array_equal(
            (70. * x_offset_truth).astype(int),
            np.asarray(x_offset_presub),
            err_msg=
            "Truth x_offsets do not match those in public-scripts.branch_id")
        np.testing.assert_array_equal(
            (70. * y_offset_truth).astype(int),
            np.asarray(y_offset_presub),
            err_msg=
            "Truth x_offsets do not match those in public-scripts.branch_id")
Esempio n. 6
0
def get_variable_gtrue(experiment,
                       obs_type,
                       logger=None,
                       truth_dir=evaluate.TRUTH_DIR):
    """Get the full catalog of shears and positions for all fields.

    @return id, x, y, g1, g2
    """
    mapper = great3sims.mapper.Mapper(truth_dir, experiment, obs_type,
                                      "variable")
    identifier = np.empty((evaluate.NGALS_PER_SUBFIELD,
                           evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS),
                          dtype=int)
    g1true = np.empty((evaluate.NGALS_PER_SUBFIELD,
                       evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS))
    g2true = np.empty((evaluate.NGALS_PER_SUBFIELD,
                       evaluate.NSUBFIELDS_PER_FIELD, evaluate.NFIELDS))
    xx = np.empty((evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD,
                   evaluate.NFIELDS))
    yy = np.empty((evaluate.NGALS_PER_SUBFIELD, evaluate.NSUBFIELDS_PER_FIELD,
                   evaluate.NFIELDS))
    # Load the offsets
    subfield_indices, offset_deg_x, offset_deg_y = evaluate.get_generate_variable_offsets(
        experiment,
        obs_type,
        storage_dir=evaluate.STORAGE_DIR,
        truth_dir=truth_dir,
        logger=logger)
    # Build basic x and y grids to use for coord positions
    xgrid_deg, ygrid_deg = np.meshgrid(
        np.arange(0., evaluate.XMAX_GRID_DEG, evaluate.DX_GRID_DEG),
        np.arange(0., evaluate.XMAX_GRID_DEG, evaluate.DX_GRID_DEG))
    xgrid_deg = xgrid_deg.flatten(
    )  # Flatten these - the default C ordering corresponds to the way
    ygrid_deg = ygrid_deg.flatten(
    )  # the true shears are ordered too, which is handy
    if len(xgrid_deg) != evaluate.NGALS_PER_SUBFIELD:
        raise ValueError(
            "Dimensions of xgrid_deg and ygrid_deg do not match NGALS_PER_SUBFIELD.  Please check "
            + "the values of XMAX_GRID_DEG and DX_GRID_DEG in evaluate.py.")
    # Then loop over the fields and subfields getting the galaxy catalogues
    import pyfits
    for ifield in range(evaluate.NFIELDS):

        # Read in all the shears in this field and store
        for jsub in range(evaluate.NSUBFIELDS_PER_FIELD):

            # Build the x,y grid using the subfield offsets
            isubfield_index = jsub + ifield * evaluate.NSUBFIELDS_PER_FIELD
            xx[:, jsub, ifield] = xgrid_deg + offset_deg_x[isubfield_index]
            yy[:, jsub, ifield] = ygrid_deg + offset_deg_y[isubfield_index]
            galcatfile = os.path.join(
                mapper.full_dir,
                ("galaxy_catalog-%03d.fits" % isubfield_index))
            truedata = pyfits.getdata(galcatfile)
            if len(truedata) != evaluate.NGALS_PER_SUBFIELD:
                raise ValueError("Number of records in " + galcatfile + " (=" +
                                 str(len(truedata)) + ") is not " +
                                 "equal to NGALS_PER_SUBFIELD (=" +
                                 str(evaluate.NGALS_PER_SUBFIELD) + ")")
            g1true[:, jsub, ifield] = truedata["g1"]
            g2true[:, jsub, ifield] = truedata["g2"]
            identifier[:, jsub, ifield] = truedata["ID"]

    # Then return
    return identifier, xx, yy, g1true, g2true