def test_flux(compressed_catalog, sim12_r_reference, flux_column,
              reference_flux_column, compressed_frame_cross, sim12_r_cross):
    """
    Cross-validate the magnitude columns. The measured magnitudes should be at least as close
    to the truth as the ref catalog (within a tolerance).
    We use only the hits, and ignore the detections that are a miss.
    """
    catalog_intersect, ref_intersect = intersect(compressed_frame_cross,
                                                 sim12_r_cross)
    catalog_hits = compressed_catalog[
        compressed_frame_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_reference[sim12_r_cross.all_catalog[ref_intersect]]

    assert len(catalog_hits) == len(ref_hits)

    catalog_flux = get_column(catalog_hits, flux_column[0])
    catalog_flux_err = get_column(catalog_hits, flux_column[1])
    ref_flux = get_column(ref_hits, reference_flux_column[0])
    ref_flux_err = get_column(ref_hits, reference_flux_column[1])
    real_flux = sim12_r_cross.all_fluxes[ref_intersect]

    catalog_dist = np.sqrt((catalog_flux - real_flux)**2 / catalog_flux_err**2)
    ref_dist = np.sqrt((ref_flux - real_flux)**2 / ref_flux_err**2)

    assert np.median(catalog_dist - ref_dist) <= 1e-1
예제 #2
0
def test_flux(single_frame_catalog, single_frame_cross, sim12_r_01_reference,
              sim12_r_01_cross, flux_column, reference_flux_column):
    """
    Cross-validate the flux columns.
    We use only the hits, and ignore the detections that are a miss.
    """
    catalog_intersect, ref_intersect = intersect(single_frame_cross,
                                                 sim12_r_01_cross)
    catalog_hits = single_frame_catalog[
        single_frame_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_01_reference[
        sim12_r_01_cross.all_catalog[ref_intersect]]

    assert len(catalog_hits) == len(ref_hits)

    catalog_flux = get_column(catalog_hits, flux_column[0])
    catalog_flux_err = get_column(catalog_hits, flux_column[1])
    ref_flux = get_column(ref_hits, reference_flux_column[0])
    ref_flux_err = get_column(ref_hits, reference_flux_column[1])
    real_flux = sim12_r_01_cross.all_fluxes[ref_intersect]

    catalog_dist = np.sqrt((catalog_flux - real_flux)**2 / catalog_flux_err**2)
    ref_dist = np.sqrt((ref_flux - real_flux)**2 / ref_flux_err**2)

    assert np.median(catalog_dist - ref_dist) <= 0.
예제 #3
0
def test_iso_flux(multi_compressed_catalog, sim12_r_reference,
                  multi_compressed_cross, sim12_r_cross):
    """
    Cross-validate the magnitude columns. The measured magnitudes should be at least as close
    to the truth as the ref catalog (within a tolerance).
    ISO is measured on the detection frame
    """
    catalog_intersect, ref_intersect = intersect(multi_compressed_cross,
                                                 sim12_r_cross)
    catalog_hits = multi_compressed_catalog[
        multi_compressed_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_reference[sim12_r_cross.all_catalog[ref_intersect]]

    assert len(catalog_hits) == len(ref_hits)

    catalog_flux = catalog_hits['isophotal_flux']
    catalog_flux_err = catalog_hits['isophotal_flux_err']
    ref_flux = ref_hits['FLUX_ISO']
    ref_flux_err = ref_hits['FLUXERR_ISO']
    real_flux = sim12_r_cross.all_fluxes[ref_intersect]

    catalog_dist = np.sqrt((catalog_flux - real_flux)**2 / catalog_flux_err**2)
    ref_dist = np.sqrt((ref_flux - real_flux)**2 / ref_flux_err**2)

    assert np.median(catalog_dist - ref_dist) <= 1e-1
예제 #4
0
def test_aper_flux(frame, aper_idx, multi_compressed_catalog,
                   sim12_r_reference, multi_compressed_cross, sim12_r_cross):
    """
    APERTURE is measured on the measurement frames, so it is trickier. Need to run the test for each
    frame, and filter out sources that are on the boundary or outside.
    """
    catalog_intersect, ref_intersect = intersect(multi_compressed_cross,
                                                 sim12_r_cross)
    catalog_hits = multi_compressed_catalog[
        multi_compressed_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_reference[sim12_r_cross.all_catalog[ref_intersect]]

    inframe_filter = (catalog_hits['aperture_flags'][:, frame, aper_idx] == 0)

    catalog_flux = catalog_hits['aperture_flux'][:, frame,
                                                 aper_idx][inframe_filter]
    catalog_flux_err = catalog_hits['aperture_flux_err'][:, frame, aper_idx][
        inframe_filter]
    ref_flux = ref_hits['FLUX_APER'][inframe_filter][:, aper_idx]
    ref_flux_err = ref_hits['FLUXERR_APER'][inframe_filter][:, aper_idx]
    real_flux = sim12_r_cross.all_fluxes[ref_intersect[inframe_filter]]

    catalog_dist = np.sqrt((catalog_flux - real_flux)**2 / catalog_flux_err**2)
    ref_dist = np.sqrt((ref_flux - real_flux)**2 / ref_flux_err**2)

    assert (catalog_dist > 0).all()
    assert np.median(catalog_dist - ref_dist) <= 1e-6
예제 #5
0
def test_growth_curve(single_frame_catalog, single_frame_cross,
                      sim12_r_01_reference, sim12_r_01_cross):
    """
    Cross-validate the growth curve
    """
    catalog_intersect, ref_intersect = intersect(single_frame_cross,
                                                 sim12_r_01_cross)
    catalog_hits = single_frame_catalog[
        single_frame_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_01_reference[
        sim12_r_01_cross.all_catalog[ref_intersect]]

    not_flagged = np.logical_and(catalog_hits['source_flags'] == 0,
                                 ref_hits['FLAGS'] == 0)
    assert not_flagged.sum() > 0

    step_diff = np.average(catalog_hits['flux_growth_step'][not_flagged] -
                           ref_hits['FLUX_GROWTHSTEP'][not_flagged])
    assert np.isclose(step_diff, 0., atol=1e-3)

    # Note that SExtractor2 does not apply FLXSCALE, so normalize both curves
    catalog_normed = catalog_hits['flux_growth'][:, 0, :] / catalog_hits[
        'flux_growth'][:, 0, -1:]
    ref_normed = ref_hits['FLUX_GROWTH'][:, :] / ref_hits['FLUX_GROWTH'][:,
                                                                         -1:]

    curve_diff = catalog_normed - ref_normed

    assert np.isclose(np.average(curve_diff), 0., atol=1e-2)
예제 #6
0
def test_elongation(coadded_catalog, coadded_frame_cross, sim12_r_reference, sim12_r_cross):
    """
    Cross-validate the elongation column.
    """
    catalog_intersect, ref_intersect = intersect(coadded_frame_cross, sim12_r_cross)
    catalog_hits = coadded_catalog[coadded_frame_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_reference[sim12_r_cross.all_catalog[ref_intersect]]

    not_flagged = np.logical_and(catalog_hits['source_flags'] == 0, ref_hits['FLAGS'] == 0)
    assert not_flagged.sum() > 0

    avg_ratio = np.average(
        catalog_hits['elongation'][not_flagged] / ref_hits['ELONGATION'][not_flagged],
        weights=ref_hits['SNR_WIN'][not_flagged]
    )

    assert np.isclose(avg_ratio, 1., atol=1e-3)
예제 #7
0
def test_auto_flux(frame, mef_catalog, sim12_r_reference, mef_frame_cross,
                   sim12_r_cross):
    """
    AUTO is measured on the measurement frames, so it is trickier. Need to run the test for each
    frame, and filter out sources that are on the boundary or outside.
    """
    catalog_intersect, ref_intersect = intersect(mef_frame_cross,
                                                 sim12_r_cross)
    catalog_hits = mef_catalog[mef_frame_cross.all_catalog[catalog_intersect]]
    ref_hits = sim12_r_reference[sim12_r_cross.all_catalog[ref_intersect]]

    inframe_filter = (catalog_hits['auto_flags'][:, frame] == 0)

    catalog_flux = catalog_hits['auto_flux'][:, frame][inframe_filter]
    catalog_flux_err = catalog_hits['auto_flux_err'][:, frame][inframe_filter]
    ref_flux = ref_hits['FLUX_AUTO'][inframe_filter]
    ref_flux_err = ref_hits['FLUXERR_AUTO'][inframe_filter]
    real_flux = sim12_r_cross.all_fluxes[ref_intersect[inframe_filter]]

    catalog_dist = np.sqrt((catalog_flux - real_flux)**2 / catalog_flux_err**2)
    ref_dist = np.sqrt((ref_flux - real_flux)**2 / ref_flux_err**2)

    assert np.median(catalog_dist - ref_dist) <= 1e-6