def window_map(scene, az, el, dk, cf, pperd=0.5, fov=np.pi):
    w = int(np.sqrt(pperd * conv))  # Pixels over the whole sphere
    winsamps = 10
    wr = cf["winrad"]
    R = cf["aptoffr"]
    k1 = k2 = np.arange(-wr * 1.5, wr * 1.5, wr / winsamps)
    K1, K2 = np.meshgrid(k1, k2)
    K1 = np.reshape(K1, (np.size(K1), 1))
    K2 = np.reshape(K2, (np.size(K2), 1))
    r = np.sqrt(K1**2 + (R - K2)**2)
    th = np.arctan2(K1, R - K2)
    gsfrac = np.zeros((len(r), 1))
    for i in range(0, len(K1)):
        if np.sqrt(K1[i]**2 + K2[i]**2) <= wr:
            cf2 = cf.copy()
            cf2["drumangle"] = cf2["drumangle"] + th[i]
            cf2["aptoffr"] = r[i]
            fbpos, fbdir, fbort = mountxform(ORG, Z, X, az, el, dk, cf2)
            O, D, xp, yp = camera(fbpos,
                                  fbdir,
                                  fbort,
                                  w,
                                  w,
                                  proj="sphere2",
                                  fov=fov)
            color = rt.raytrace(O, D, scene, O, trace="hit")

            gsfrac[i] = get_hit_frac(color, clrs["fbm"], pperd)

    gsfrac[np.sqrt(K1**2 + K2**2) > wr] = np.nan
    gsfrac = np.ma.masked_where(np.isnan(gsfrac), gsfrac)

    c = np.reshape(gsfrac, (len(k1), len(k2)))
    # fig = plt.figure(figsize=(4, 4))
    fig = plt.figure()
    plt.subplot()
    plt.pcolormesh(k1, k2, c)  # , vmin=0)#, vmax=0.0025)
    plt.xlim([-1 * wr * 1.1, wr * 1.1])
    plt.ylim([-1 * wr * 1.1, wr * 1.1])
    plt.xlabel("Window X (m)")
    plt.ylabel("Window Y (m)")
    cbar = plt.colorbar()
    cbar.ax.set_ylabel('GS subtend fraction', rotation=270)
    plt.show()
def do_test(cf):
    # This is a test of the raytracer. The scene is only made up of our spherical camera and
    # a single unit sphere. Because it is easy to predict the solid angle of a sphere at a known
    # distance, we can verify that our camera can effectively return the solid angle to an arbitrary
    # accuracy and precision, independent of where the sphere is on the sky.

    spr = 1.  # Sphere radius
    scene = [0]

    plt.figure(1)
    # Check for systematics due to pixel aliasing
    # Should do this at a distance that is larger than the things you care about.
    # in our case, a ground shield that is ~10 meters away
    if True:
        sppos, spdir, sport = mountxform(rt.vec3(0, 0, 20.), Z, X, 0.,
                                         np.pi / 2., 0., cf)
        scene[0] = rt.Sphere(sppos, spr, rgb(5, 0., 0.), mirror=0.02)

        ang = 2 * np.arcsin(
            spr / sppos.dist())  # angular diameter of the sphere.
        sphcov = (1 - np.cos(
            ang / 2)) / 2  # Fractional area: solid angle divided by 4pi

        res = np.logspace(0, 2)
        r = np.zeros([
            len(res),
        ])
        for i in range(0, len(res)):
            pperd = res[i]  # pipxels per sq-deg
            w = int(np.sqrt(pperd * conv))  # Pixels over the whole sphere
            O, D, xp, yp = camera(rt.vec3(0, 0, 0),
                                  spdir,
                                  sport,
                                  w,
                                  w,
                                  proj="sphere2")
            color = rt.raytrace(O, D, scene, hitmap=True)
            cd = color.dist()
            ind = (cd == 5.)
            r[i] = (np.size(np.where(ind)) / (w**2)) / sphcov - 1

        plt.subplot(211)
        plt.semilogx(res, r, '.')
        plt.title("Sphere at distance of 30m")
        plt.xlabel("Pixels per sq-deg")
        plt.ylabel("Fractional residuals")
        plt.ylim([-0.01, 0.01])
        plt.grid()

    # Look at accuracy over distance when you've optimized the resolution.
    if True:
        pperd = 7  # pipxels per sq-deg
        w = int(np.sqrt(pperd * conv))  # Pixels over the whole sphere
        dist = np.logspace(0, 1.5)
        r = np.zeros([
            len(dist),
        ])
        for i in range(0, len(dist)):
            sppos, spdir, sport = mountxform(rt.vec3(0, 0, dist[i]), Z, X, 0.,
                                             np.pi / 2., 0., cf)
            scene[0] = rt.Sphere(sppos, spr, rgb(5, 0., 0.), mirror=0.02)

            ang = 2 * np.arcsin(
                spr / sppos.dist())  # angular diameter of the sphere.
            sphcov = (1 - np.cos(
                ang / 2)) / 2  # Fractional area: solid angle divided by 4pi

            O, D, xp, yp = camera(rt.vec3(0, 0, 0),
                                  spdir,
                                  sport,
                                  w,
                                  w,
                                  proj="sphere2")
            color = rt.raytrace(O, D, scene, hitmap=True)
            cd = color.dist()
            ind = (cd == 5.)
            r[i] = (np.size(np.where(ind)) / (w**2)) / sphcov - 1

        plt.subplot(212)
        plt.semilogx(dist, r)
        plt.title("Camera at {0} px/sq-deg resolution".format(pperd))
        plt.xlabel("Distance to sphere (m)")
        plt.ylabel("Fractional residuals")
        plt.ylim([-0.01, 0.01])
        plt.grid()

    plt.subplots_adjust(hspace=1.2)
    #plt.show()
    # Check for spatial systematics
    if True:
        az = np.arange(0, 2 * np.pi, np.pi / 2)
        el = np.arange(0, np.pi / 2, np.pi / 20)
        dk = np.arange(0, 1)  # range(0,2*np.pi,np.pi/2)
        rat = np.zeros([len(az), len(el)])

        pperd = 7  # pipxels per sq-deg
        w = int(np.sqrt(pperd * conv))  # Pixels over the whole sphere
        ext = [min(az), max(az), min(el), max(el)]
        ext = [i * 180 / np.pi for i in ext]
        cf["eloffz"] = 1.0
        for i in range(0, len(az)):

            for j in range(0, len(el)):
                for k in range(0, len(dk)):
                    sppos, spdir, sport = mountxform(rt.vec3(0, 0, 0.0), Z, X,
                                                     az[i], el[j], dk[k], cf)
                    scene[0] = rt.Sphere(sppos,
                                         spr,
                                         rgb(5, 0., 0.),
                                         mirror=0.02)

                    ang = 2 * np.arcsin(
                        spr / sppos.dist())  # angular diameter of the sphere.
                    sphcov = (
                        1 - np.cos(ang / 2)
                    ) / 2  # Fractional area: solid angle divided by 4pi
                    O, D, xp, yp = camera(rt.vec3(0, 0, 0),
                                          spdir,
                                          sport,
                                          w,
                                          w,
                                          proj="sphere2")
                    color = rt.raytrace(O, D, scene, hitmap=True)
                    cd = color.dist()
                    ind = (cd == 5.)
                    rat[i,
                        j] = ((np.size(np.where(ind)) / (w**2)) / sphcov) - 1

        plt.figure(2)
        plt.subplot(111)
        plt.imshow(rat, extent=ext)
        cbar = plt.colorbar()
        cbar.ax.set_ylabel('Fractional Residuals', rotation=270)
        plt.title("Camera at {0} px/sq-deg resolution, sphere ".format(pperd))
        plt.ylabel("Elevation (o)")
        plt.xlabel("Azimuth (o)")
        plt.show()
        cf2 = cf.copy()
        fbpos, fbdir, fbort = mountxform(ORG, Z, X, az, el, dk, cf2)
        fov = np.pi

        O, D, xp, yp = camera(fbpos,
                              fbdir,
                              fbort,
                              w,
                              w,
                              proj="sphere2",
                              fov=fov,
                              PLOT=False)
        if args.showtemp == False:
            color = rt.raytrace(O,
                                D,
                                scene,
                                O,
                                trace="hit",
                                clrstop=clrs["gnd"])
            show_hit_map(xp, yp, color.sum(), filename, pperd)
        else:
            color = rt.raytrace(O, D, scene, O, trace="temp")
            if np.size(clrs["gnd"]) > 1:
                scene[0].diffuse.x = scene[0].diffuse.x * 0 + clrs["gnd"][1]
                if dowall:
                    scene[1].diffuse.x = scene[0].diffuse.x * 0 + clrs["gnd"][
                        1] / mgs / 2
                color = color - rt.raytrace(O, D, scene, O, trace="temp")
                show_temp_map(xp, yp, color.sum(), filename, log=True)
            else:
                show_temp_map(xp, yp, color.sum(), filename)
Example #4
0
                    wr = cf["winrad"]  # window radius
                    R = cf["aptoffr"]  # window center distance
                    k1 = k2 = np.arange(-wr, wr,
                                        2 * wr / winsamps) + wr / winsamps
                    K1, K2 = np.meshgrid(k1, k2)
                    K1 = np.reshape(K1, (np.size(K1), 1))
                    K2 = np.reshape(K2, (np.size(K2), 1))
                    winhit = np.zeros((len(K1), 1))
                    V3 = rt.make_array(fbpos, np.ones(np.shape(K1)))
                    V1 = rt.make_array(fbort, K1)
                    V2 = rt.make_array(fbort2, K2)
                    Oray = V3 + V1 + V2
                    Dray = rt.make_array(D, np.ones(np.shape(K1)))

                    # Do a raytrace, return the color ID of the first this we hit.
                    color = rt.raytrace(Oray, Dray, scene, Oray, trace="hit")
                    ind = color.sum() == mirrcf["color"] * np.ones(
                        np.shape(color.sum()))
                    winhit[ind] = 1
                    ind = (np.sqrt(K1**2 + K2**2) < wr)
                    hitfrac[j] = np.nansum(winhit[ind]) / np.size(winhit[ind])

                # Plot the fractional coupling with the mirror.
                if False:
                    c = np.reshape(hitfrac, (len(x), len(y)))
                    pixconv = 150
                    plt.figure(1, figsize=(1000 / pixconv, 834 / pixconv))
                    plt.subplot()
                    plt.pcolormesh(-1 * y * 180 / np.pi,
                                   -1 * x * 180 / np.pi,
                                   c,