Beispiel #1
0
def display_geo(geo,
                l_max,
                res_healpix=5,
                title='geo display',
                fig=None,
                cmap='Greys',
                display=True,
                do_round=False,
                cbar=True,
                notext=False):
    """plot the area enclosed by a geo on a pixelated map"""
    pixels = get_healpix_pixelation(res_healpix)
    alms = geo.get_alm_table(l_max)
    reconstruction = reconstruct_from_alm(l_max, pixels[:, 0], pixels[:, 1],
                                          alms)
    if fig is None:
        fig = plt.figure()
    if do_round:
        reconstruction = np.round(reconstruction)

    plot_reconstruction(reconstruction,
                        title,
                        fig,
                        cmap,
                        cbar=cbar,
                        notext=notext)
    if display:
        plt.show(fig)
    return fig
def test_alm_recontruct(alms, theta_phis):
    """test that reconstruct_from_alm matches with and without mpmath"""
    if theta_phis.key != 2:
        alm_dict = alms.alm_dict.copy()
        thetas = theta_phis.thetas.copy()
        phis = theta_phis.phis.copy()
        l_max = alms.l_max
        alm1 = ylmu.reconstruct_from_alm(l_max, thetas, phis, alm_dict)
        alm2 = ylmu_mp.reconstruct_from_alm(l_max, thetas, phis, alm_dict)
        assert np.allclose(alm1, alm2, atol=ATOL_USE, rtol=RTOL_USE)
Beispiel #3
0
def test_absolute_improvement2(geo_input):
    """ test fine reconstruction improves on PolygonPixelGeo
        also test PolygonPixelGeo error while we're at it"""
    MSE_TOL = 10**-1
    if geo_input.params['do_pp_geo2']:
        pp_geo2 = geo_input.pp_geo2
        totals_poly = reconstruct_from_alm(geo_input.params['l_max_poly'],
                                           pp_geo2.all_pixels[:, 0],
                                           pp_geo2.all_pixels[:, 1],
                                           geo_input.poly_geo.alm_table)
        totals_pp1 = reconstruct_from_alm(geo_input.params['l_max_poly'],
                                          pp_geo2.all_pixels[:, 0],
                                          pp_geo2.all_pixels[:, 1],
                                          geo_input.pp_geo1.alm_table)
        abs_error_poly = np.abs(totals_poly - pp_geo2.contained * 1.)
        mse_poly = np.sqrt(np.average(abs_error_poly**2))
        assert MSE_TOL > mse_poly

        abs_error_pp1 = np.abs(totals_pp1 - pp_geo2.contained * 1.)
        mse_pp1 = np.sqrt(np.average(abs_error_pp1**2))
        assert MSE_TOL > mse_pp1
        assert mse_pp1 > mse_poly
Beispiel #4
0
def test_absolute_reconstruction1(geo_input):
    """test coarse reconstruction agreement
        note tolerance should really depend on l max"""
    MSE_TOL = 10**-1
    if geo_input.params['do_pp_geo1']:
        pp_geo1 = geo_input.pp_geo1
        totals_poly = reconstruct_from_alm(geo_input.params['l_max_poly'],
                                           pp_geo1.all_pixels[:, 0],
                                           pp_geo1.all_pixels[:, 1],
                                           geo_input.poly_geo.alm_table)
        abs_error = np.abs(totals_poly - pp_geo1.contained * 1.)
        mse = np.sqrt(np.average(abs_error**2))
        assert MSE_TOL > mse
Beispiel #5
0
def reconstruct_and_plot(geo,
                         l_max,
                         pixels,
                         title,
                         fig,
                         cmap='Greys',
                         do_round=False,
                         cbar=True,
                         notext=False):
    """plot the area enclosed by a geo on a pixelated map"""
    alms = geo.get_alm_table(l_max)
    reconstruction = reconstruct_from_alm(l_max, pixels[:, 0], pixels[:, 1],
                                          alms)
    if do_round:
        reconstruction = np.round(reconstruction)
    plot_reconstruction(reconstruction,
                        title,
                        fig,
                        cmap,
                        cbar=cbar,
                        notext=notext)
Beispiel #6
0
        pp_geo = gts.pp_geo1
        pp_geo2 = gts.pp_geo2

        nt = poly_geo.n_v

        my_table = poly_geo.alm_table.copy()
        if do_rect:
            #get RectGeo to cache the values in the table
            for ll in range(0, l_max + 1):
                for mm in range(0, ll + 1):
                    gts.r_geo.a_lm(ll, mm)
                    if mm > 0:
                        gts.r_geo.a_lm(ll, -mm)
        #r_alm_table = r_geo.alm_table
        #reconstruct at higher resolution to mitigate resolution effects in determining accuracy
        totals_poly = reconstruct_from_alm(l_max, pp_geo2.all_pixels[:, 0],
                                           pp_geo2.all_pixels[:, 1], my_table)

        poly_error = np.sqrt(
            np.average(np.abs(totals_poly - pp_geo2.contained * 1.)**2))
        print("rms reconstruction error of exact geo: " + str(poly_error))
        if do_rect:
            totals_pp = reconstruct_from_alm(l_max, pp_geo2.all_pixels[:, 0],
                                             pp_geo2.all_pixels[:, 1],
                                             gts.r_geo.alm_table)
            avg_diff = np.average(np.abs(totals_pp - totals_poly))
            print(
                "mean absolute difference between pixel and exact geo reconstruction: "
                + str(avg_diff))
            pp_error = np.sqrt(
                np.average(np.abs(totals_pp - pp_geo2.contained * 1.)**2))
            print("rms reconstruction error of pixel geo at res " +
Beispiel #7
0
def test_wfirst_lsst_embed():
    """test embedding wfirst in lsst with geometries"""
    cosmo_fid = defaults.cosmology.copy()
    C = CosmoPie(cosmo_fid, 'jdem')
    l_max = 30
    zs = np.array([0.01, 1.])
    z_fine = np.arange(0.0001, 1.0001, 0.1)

    do_approximate_checks = True

    res_healpix_high = 8
    res_healpix_low = 7
    l_max_high = 30
    geo_wfirst = WFIRSTGeo(zs, C, z_fine, l_max, {'n_double': 80})
    geo_lsst = LSSTGeo(zs, C, z_fine, l_max, {'n_double': 80})
    geo_wfirst_pp1 = WFIRSTPixelGeo(zs, C, z_fine, l_max, res_healpix_low)
    geo_lsst_pp1 = LSSTPixelGeo(zs, C, z_fine, l_max, res_healpix_low)
    geo_wfirst_pp2 = WFIRSTPixelGeo(zs, C, z_fine, l_max, res_healpix_high)
    geo_lsst_pp2 = LSSTPixelGeo(zs, C, z_fine, l_max, res_healpix_high)
    geo4 = PolygonUnionGeo(geo_lsst.geos, np.append(geo_wfirst,
                                                    geo_lsst.masks))
    geo5 = PolygonPixelUnionGeo(geo_lsst_pp2.geos,
                                np.append(geo_wfirst_pp2, geo_lsst_pp2.masks))
    geo6 = PolygonPixelUnionGeo(geo_lsst_pp1.geos,
                                np.append(geo_wfirst_pp1, geo_lsst_pp1.masks))
    geo7 = AlmDifferenceGeo(geo_lsst, geo_wfirst, C, zs, z_fine)
    print(geo4.angular_area(), geo7.angular_area())
    assert np.isclose(geo4.angular_area(),
                      geo_lsst.angular_area() - geo_wfirst.angular_area())
    assert np.isclose(
        geo5.angular_area(),
        geo_lsst_pp2.angular_area() - geo_wfirst_pp2.angular_area())
    assert np.isclose(
        geo6.angular_area(),
        geo_lsst_pp1.angular_area() - geo_wfirst_pp1.angular_area())
    assert np.isclose(geo4.angular_area(), geo7.angular_area())
    #geo4 = #WFIRSTGeo(zs,C,z_fine,l_max,{'n_double':80})
    #geo5 = WFIRSTPixelGeo(zs,C,z_fine,l_max,res_healpix_high)
    #geo6 = WFIRSTPixelGeo(zs,C,z_fine,l_max,res_healpix_low)
    #assert geo4.union_mask.area()<=geo4.masks[0].angular_area()
    assert np.isclose(geo4.union_pos.area(), geo4.geos[0].angular_area())
    assert np.isclose(geo4.angular_area(),
                      geo4.union_pos.area() - geo4.union_mask.area())
    assert geo4.angular_area() <= geo4.geos[0].angular_area()
    assert geo5.angular_area() <= geo5.geos[0].angular_area()
    assert geo6.angular_area() <= geo6.geos[0].angular_area()
    assert np.isclose(geo5.angular_area(),
                      geo4.angular_area(),
                      rtol=1.e-3,
                      atol=1.e-3)
    assert np.isclose(geo6.angular_area(),
                      geo4.angular_area(),
                      rtol=1.e-3,
                      atol=1.e-3)
    assert np.isclose(geo6.angular_area(),
                      geo5.angular_area(),
                      rtol=1.e-3,
                      atol=1.e-3)
    alms7_0 = deepcopy(geo7.get_alm_table(8))
    alms6_0 = deepcopy(geo6.get_alm_table(8))
    alms5_0 = deepcopy(geo5.get_alm_table(8))
    alms4_0 = deepcopy(geo4.get_alm_table(8))
    alms7_array_0 = deepcopy(geo7.get_alm_array(8))
    alms6_array_0 = deepcopy(geo6.get_alm_array(8))
    alms5_array_0 = deepcopy(geo5.get_alm_array(8))
    alms4_array_0 = deepcopy(geo4.get_alm_array(8))
    alms7_1 = deepcopy(geo7.get_alm_table(10))
    alms6_1 = deepcopy(geo6.get_alm_table(10))
    alms5_1 = deepcopy(geo5.get_alm_table(10))
    alms4_1 = deepcopy(geo4.get_alm_table(10))
    alms7_array_1 = deepcopy(geo7.get_alm_array(10))
    alms6_array_1 = deepcopy(geo6.get_alm_array(10))
    alms5_array_1 = deepcopy(geo5.get_alm_array(10))
    alms4_array_1 = deepcopy(geo4.get_alm_array(10))
    alms7_array_2 = deepcopy(geo7.get_alm_array(l_max_high))
    alms6_array_2 = deepcopy(geo6.get_alm_array(l_max_high))
    alms5_array_2 = deepcopy(geo5.get_alm_array(l_max_high))
    alms4_array_2 = deepcopy(geo4.get_alm_array(l_max_high))
    alms_wfirst_array = deepcopy(geo_wfirst.get_alm_array(l_max_high))
    alms_lsst_array = deepcopy(geo_lsst.get_alm_array(l_max_high))
    alms_wfirst_pp1_array = deepcopy(geo_wfirst_pp1.get_alm_array(l_max_high))
    alms_lsst_pp1_array = deepcopy(geo_lsst_pp1.get_alm_array(l_max_high))
    alms_wfirst_pp2_array = deepcopy(geo_wfirst_pp2.get_alm_array(l_max_high))
    alms_lsst_pp2_array = deepcopy(geo_lsst_pp2.get_alm_array(l_max_high))
    alms7_2 = deepcopy(geo7.get_alm_table(l_max_high))
    alms6_2 = deepcopy(geo6.get_alm_table(l_max_high))
    alms5_2 = deepcopy(geo5.get_alm_table(l_max_high))
    alms4_2 = deepcopy(geo4.get_alm_table(l_max_high))
    alms7_3 = deepcopy(geo7.get_alm_table(10))
    alms6_3 = deepcopy(geo6.get_alm_table(10))
    alms5_3 = deepcopy(geo5.get_alm_table(10))
    alms4_3 = deepcopy(geo4.get_alm_table(10))
    alms7_array_3 = deepcopy(geo7.get_alm_array(10))
    alms6_array_3 = deepcopy(geo6.get_alm_array(10))
    alms5_array_3 = deepcopy(geo5.get_alm_array(10))
    alms4_array_3 = deepcopy(geo4.get_alm_array(10))
    #a few basic self consistency checks
    assert np.all(alms7_array_3[0] == alms7_array_1[0])
    assert np.all(alms6_array_3[0] == alms6_array_1[0])
    assert np.all(alms5_array_3[0] == alms5_array_1[0])
    assert np.all(alms4_array_3[0] == alms4_array_1[0])
    assert np.all(
        alms7_array_2[0][0:alms5_array_1[0].size] == alms7_array_1[0])
    assert np.all(
        alms6_array_2[0][0:alms5_array_1[0].size] == alms6_array_1[0])
    assert np.all(
        alms5_array_2[0][0:alms5_array_1[0].size] == alms5_array_1[0])
    assert np.all(
        alms4_array_2[0][0:alms4_array_1[0].size] == alms4_array_1[0])
    assert np.all(
        alms7_array_2[0][0:alms5_array_0[0].size] == alms7_array_0[0])
    assert np.all(
        alms6_array_2[0][0:alms5_array_0[0].size] == alms6_array_0[0])
    assert np.all(
        alms5_array_2[0][0:alms5_array_0[0].size] == alms5_array_0[0])
    assert np.all(
        alms4_array_2[0][0:alms4_array_0[0].size] == alms4_array_0[0])
    assert sorted(list(alms4_1)) == sorted(list(alms7_1))
    assert sorted(list(alms4_1)) == sorted(list(alms5_1))
    assert sorted(list(alms4_1)) == sorted(list(alms6_1))
    assert sorted(list(alms4_2)) == sorted(list(alms5_2))
    assert sorted(list(alms4_2)) == sorted(list(alms6_2))
    assert sorted(list(alms4_2)) == sorted(list(alms7_2))
    assert sorted(list(alms4_0)) == sorted(list(alms5_0))
    assert sorted(list(alms4_0)) == sorted(list(alms6_0))
    assert sorted(list(alms7_0)) == sorted(list(alms7_0))
    assert sorted(list(alms4_3)) == sorted(list(alms5_3))
    assert sorted(list(alms4_3)) == sorted(list(alms6_3))
    assert sorted(list(alms4_3)) == sorted(list(alms7_3))
    assert sorted(list(alms4_1)) == sorted(list(alms4_3))
    assert sorted(list(alms5_1)) == sorted(list(alms5_3))
    assert sorted(list(alms6_1)) == sorted(list(alms6_3))
    assert sorted(list(alms6_1)) == sorted(list(alms7_3))
    assert alms7_array_0[0].size == len(list(alms7_0))
    assert alms6_array_0[0].size == len(list(alms6_0))
    assert alms5_array_0[0].size == len(list(alms5_0))
    assert alms4_array_0[0].size == len(list(alms4_0))
    assert alms7_array_1[0].size == len(list(alms7_1))
    assert alms6_array_1[0].size == len(list(alms6_1))
    assert alms6_array_1[0].size == len(list(alms6_1))
    assert alms5_array_1[0].size == len(list(alms5_1))
    assert alms4_array_2[0].size == len(list(alms4_2))
    assert alms5_array_2[0].size == len(list(alms5_2))
    assert alms4_array_2[0].size == len(list(alms4_2))
    assert alms7_array_3[0].size == len(list(alms7_3))
    assert alms6_array_3[0].size == len(list(alms6_3))
    assert alms5_array_3[0].size == len(list(alms5_3))
    assert alms4_array_3[0].size == len(list(alms4_3))
    #assert np.all(alms5_array_3[0]==alms5_array_1[0])
    #assert np.all(alms4_array_3[0]==alms4_array_1[0])
    for key in list(alms7_0):
        assert alms7_2[key] == alms7_0[key]
    for key in list(alms6_0):
        assert alms6_2[key] == alms6_0[key]
    for key in list(alms5_0):
        assert alms5_2[key] == alms5_0[key]
    for key in list(alms4_0):
        assert alms4_2[key] == alms4_0[key]
    for key in list(alms7_1):
        assert alms7_2[key] == alms7_1[key]
        assert alms7_3[key] == alms7_1[key]
    for key in list(alms6_1):
        assert alms6_2[key] == alms6_1[key]
        assert alms6_3[key] == alms6_1[key]
    for key in list(alms5_1):
        assert alms5_2[key] == alms5_1[key]
        assert alms5_3[key] == alms5_1[key]
    for key in list(alms4_1):
        assert alms4_2[key] == alms4_1[key]
    for itr in range(0, alms7_array_2[0].size):
        assert alms7_2[(alms7_array_2[1][itr],
                        alms7_array_2[2][itr])] == alms7_array_2[0][itr]
    for itr in range(0, alms6_array_2[0].size):
        assert alms6_2[(alms6_array_2[1][itr],
                        alms6_array_2[2][itr])] == alms6_array_2[0][itr]
    for itr in range(0, alms5_array_2[0].size):
        assert alms5_2[(alms5_array_2[1][itr],
                        alms5_array_2[2][itr])] == alms5_array_2[0][itr]
    for itr in range(0, alms4_array_2[0].size):
        assert alms4_2[(alms4_array_2[1][itr],
                        alms4_array_2[2][itr])] == alms4_array_2[0][itr]
    #check inter geo consistency
    if do_approximate_checks:
        assert np.allclose(alms5_array_2,
                           alms4_array_2,
                           atol=1.e-3,
                           rtol=1.e-3)
        assert np.allclose(alms5_array_2,
                           alms6_array_2,
                           atol=5.e-3,
                           rtol=5.e-3)
        assert np.allclose(alms4_array_2,
                           alms6_array_2,
                           atol=5.e-3,
                           rtol=5.e-3)
        assert np.allclose(alms6_array_2,
                           alms7_array_2,
                           atol=5.e-3,
                           rtol=5.e-3)
        assert np.allclose(alms5_array_2,
                           alms7_array_2,
                           atol=5.e-3,
                           rtol=5.e-3)
    assert np.allclose(alms4_array_2, alms7_array_2)

    #use complete intersection
    assert np.allclose(alms4_array_2[0],
                       alms_lsst_array[0] - alms_wfirst_array[0])
    assert np.allclose(alms5_array_2[0],
                       alms_lsst_pp2_array[0] - alms_wfirst_pp2_array[0])
    assert np.allclose(alms6_array_2[0],
                       alms_lsst_pp1_array[0] - alms_wfirst_pp1_array[0])
    assert np.allclose(alms7_array_2[0],
                       alms_lsst_array[0] - alms_wfirst_array[0])

    pixels = get_healpix_pixelation(res_healpix_low)
    reconstruct4 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1],
                                        alms4_2)
    reconstruct5 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1],
                                        alms5_2)
    reconstruct6 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1],
                                        alms6_2)
    reconstruct7 = reconstruct_from_alm(l_max_high, pixels[:, 0], pixels[:, 1],
                                        alms7_2)
    assert np.allclose(reconstruct4, reconstruct7)
    if do_approximate_checks:
        assert np.allclose(reconstruct4, reconstruct5, atol=4.e-2, rtol=1.e-4)
        assert np.allclose(reconstruct4, reconstruct6, atol=4.e-1, rtol=1.e-4)
        assert np.allclose(reconstruct5, reconstruct6, atol=4.e-1, rtol=1.e-4)
        assert np.allclose(reconstruct5, reconstruct7, atol=4.e-1, rtol=1.e-4)
        assert np.allclose(reconstruct6, reconstruct7, atol=4.e-1, rtol=1.e-4)