Ejemplo n.º 1
0
 def func(spacing, angle):
     origin = shape_grid * np.array(spacing) * np.sqrt(2) / 2
     grid = LayoutGridSquares(shape_grid, spacing, origin=origin, angle=angle, filling_factor=filling_factor)
     shape_plane = np.ceil(shape_grid * np.array(spacing) * np.sqrt(2))
     scene = SceneGrid(shape_plane)
     proj = scene.get_integration_operator(grid.vertex)
     assert not proj.outside
     assert_same(np.sum(proj.matrix.data.value), len(grid) * spacing ** 2 * filling_factor, rtol=100)
Ejemplo n.º 2
0
 def func(spacing, angle):
     origin = shape_grid * np.array(spacing) * np.sqrt(2) / 2
     grid = LayoutGridSquares(shape_grid,
                              spacing,
                              origin=origin,
                              angle=angle,
                              filling_factor=filling_factor)
     shape_plane = np.ceil(shape_grid * np.array(spacing) * np.sqrt(2))
     scene = SceneGrid(shape_plane)
     proj = scene.get_integration_operator(grid.vertex)
     assert not proj.outside
     assert_same(np.sum(proj.matrix.data.value),
                 len(grid) * spacing**2 * filling_factor,
                 rtol=100)
Ejemplo n.º 3
0
def test_spatial_integration():
    #  -------------
    #  |12|13|14|15|
    #  |--+--+--+--+
    #  | 8| 9|10|11|
    #  |--+--+--+--+
    #  | 4| 5| 6| 7|
    #  |--+--+--+--+
    #  | 0| 1| 2| 3|
    #  -------------
    #  The plane center has world coordinates (0, 0)

    plane_shape = (4, 4)
    pixsize = 1  # um
    header = create_fitsheader(plane_shape,
                               ctype=['X---CAR', 'Y---CAR'],
                               cdelt=[pixsize, pixsize],
                               crval=(0, 0),
                               cunit=['um', 'um'])
    plane = SceneGrid.fromfits(header)

    def func(center, ncolmax, itype, ftype, expected):
        detectors = create_grid_squares((2, 2),
                                        Quantity(pixsize, 'um'),
                                        center=center)
        proj = plane.get_integration_operator(plane.topixel(detectors),
                                              ncolmax=ncolmax,
                                              dtype=ftype,
                                              dtype_index=itype)
        x = np.arange(len(plane)).reshape(plane_shape)
        y = proj(x)

        assert_equal(proj.matrix.dtype, ftype)
        assert_equal(proj.matrix.data.index.dtype, itype)
        assert_equal(proj.shapein, plane.shape)
        assert_equal(proj.shapeout, detectors.shape[:-2])
        assert_equal(proj.matrix.shape, (4, len(plane)))
        expected_min_ncolmax = 1 if center == (0, 0) else 4
        assert_equal(proj.matrix.data.shape,
                     (4, max(expected_min_ncolmax, ncolmax)))
        assert_equal(proj.min_ncolmax, expected_min_ncolmax)
        assert_same(y, expected)

    centers = [(0, 0), (-0.5, 0.5)]
    ncolmaxs = (0, 1, 4, 5)
    expecteds = [[[9, 10], [5, 6]],
                 [[0.25 * (8 + 9 + 12 + 13), 0.25 * (9 + 10 + 13 + 14)],
                  [0.25 * (4 + 5 + 8 + 9), 0.25 * (5 + 6 + 9 + 10)]]]
    for center, expected in zip(centers, expecteds):
        for ncolmax in ncolmaxs:
            for itype in itypes:
                for ftype in ftypes:
                    yield func, center, ncolmax, itype, ftype, expected
Ejemplo n.º 4
0
def test_spatial_integration():
    #  -------------
    #  |12|13|14|15|
    #  |--+--+--+--+
    #  | 8| 9|10|11|
    #  |--+--+--+--+
    #  | 4| 5| 6| 7|
    #  |--+--+--+--+
    #  | 0| 1| 2| 3|
    #  -------------
    #  The plane center has world coordinates (0, 0)

    plane_shape = (4, 4)
    pixsize = 1  # um
    header = create_fitsheader(
        plane_shape, ctype=["X---CAR", "Y---CAR"], cdelt=[pixsize, pixsize], crval=(0, 0), cunit=["um", "um"]
    )
    plane = SceneGrid.fromfits(header)

    def func(center, ncolmax, itype, ftype, expected):
        detectors = create_grid_squares((2, 2), Quantity(pixsize, "um"), center=center)
        proj = plane.get_integration_operator(plane.topixel(detectors), ncolmax=ncolmax, dtype=ftype, dtype_index=itype)
        x = np.arange(len(plane)).reshape(plane_shape)
        y = proj(x)

        assert_equal(proj.matrix.dtype, ftype)
        assert_equal(proj.matrix.data.index.dtype, itype)
        assert_equal(proj.shapein, plane.shape)
        assert_equal(proj.shapeout, detectors.shape[:-2])
        assert_equal(proj.matrix.shape, (4, len(plane)))
        expected_min_ncolmax = 1 if center == (0, 0) else 4
        assert_equal(proj.matrix.data.shape, (4, max(expected_min_ncolmax, ncolmax)))
        assert_equal(proj.min_ncolmax, expected_min_ncolmax)
        assert_same(y, expected)

    centers = [(0, 0), (-0.5, 0.5)]
    ncolmaxs = (0, 1, 4, 5)
    expecteds = [
        [[9, 10], [5, 6]],
        [[0.25 * (8 + 9 + 12 + 13), 0.25 * (9 + 10 + 13 + 14)], [0.25 * (4 + 5 + 8 + 9), 0.25 * (5 + 6 + 9 + 10)]],
    ]
    for center, expected in zip(centers, expecteds):
        for ncolmax in ncolmaxs:
            for itype in itypes:
                for ftype in ftypes:
                    yield func, center, ncolmax, itype, ftype, expected
Ejemplo n.º 5
0
#################
nfp_x = int(np.sqrt(NPOINT_FOCAL_PLANE))
a = np.r_[FOCAL_PLANE_LIMITS[0]:FOCAL_PLANE_LIMITS[1]:nfp_x * 1j]
fp_x, fp_y = np.meshgrid(a, a)
fp = np.dstack([fp_x, fp_y, np.full_like(fp_x, -qubic.optics.focal_length)])
fp_spacing = (FOCAL_PLANE_LIMITS[1] - FOCAL_PLANE_LIMITS[0]) / nfp_x

############
# DETECTORS
############
header = create_fitsheader((nfp_x, nfp_x),
                           cdelt=fp_spacing,
                           crval=(0, 0),
                           ctype=['X---CAR', 'Y---CAR'],
                           cunit=['m', 'm'])
focal_plane = SceneGrid.fromfits(header)
integ = MaskOperator(qubic.detector.all.removed) * \
        focal_plane.get_integration_operator(
            focal_plane.topixel(qubic.detector.all.vertex[..., :2]))

###############
# COMPUTATIONS
###############
E = qubic._get_response(SOURCE_THETA, SOURCE_PHI, SOURCE_POWER, fp,
                        fp_spacing**2, qubic.filter.nu, qubic.horn,
                        qubic.primary_beam, qubic.secondary_beam)
I = np.abs(E)**2
D = integ(I)

##########
# DISPLAY
Ejemplo n.º 6
0
#################
# FOCAL PLANE
#################
nfp_x = int(np.sqrt(NPOINT_FOCAL_PLANE))
a = np.r_[FOCAL_PLANE_LIMITS[0]:FOCAL_PLANE_LIMITS[1]:nfp_x*1j]
fp_x, fp_y = np.meshgrid(a, a)
fp = np.dstack([fp_x, fp_y, np.full_like(fp_x, -qubic.optics.focal_length)])
fp_spacing = (FOCAL_PLANE_LIMITS[1] - FOCAL_PLANE_LIMITS[0]) / nfp_x


############
# DETECTORS
############
header = create_fitsheader((nfp_x, nfp_x), cdelt=fp_spacing, crval=(0, 0),
                           ctype=['X---CAR', 'Y---CAR'], cunit=['m', 'm'])
focal_plane = SceneGrid.fromfits(header)
integ = MaskOperator(qubic.detector.all.removed) * \
        focal_plane.get_integration_operator(
            focal_plane.topixel(qubic.detector.all.vertex[..., :2]))


###############
# COMPUTATIONS
###############

# we make sure that exacty 1 W goes through the open horns
SOURCE_POWER = 1 / (np.sum(qubic.horn.open) * np.pi * qubic.horn.radius**2)
E = qubic._get_response(SOURCE_THETA, SOURCE_PHI, SOURCE_POWER,
                        fp, fp_spacing**2, qubic.filter.nu, qubic.horn,
                        qubic.primary_beam, qubic.secondary_beam)
I = np.abs(E)**2