Esempio n. 1
0
    def test__save_trap_states_matrix(self):

        roe = ac.ROE()
        (
            express_matrix,
            monitor_traps_matrix,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=1)
        save_trap_states_matrix = roe.save_trap_states_matrix_from_express_matrix(
            express_matrix=express_matrix)

        assert save_trap_states_matrix == pytest.approx(
            (express_matrix * 0).astype(bool))

        roe = ac.ROE(empty_traps_for_first_transfers=False)
        (
            express_matrix,
            monitor_traps_matrix,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=4)
        save_trap_states_matrix = roe.save_trap_states_matrix_from_express_matrix(
            express_matrix=express_matrix)

        # Save on the pixel before where the next express pass will begin, so
        # that the trap states are appropriate for continuing
        assert save_trap_states_matrix == pytest.approx(
            np.array(
                [
                    [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                ],
                dtype=bool,
            ))
Esempio n. 2
0
    def test__express_matrix__dtype(self):

        # Unchanged for empty_traps_for_first_transfers = False
        roe = ac.ROE(empty_traps_for_first_transfers=False,
                     express_matrix_dtype=float)
        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=1)

        assert express_matrix == pytest.approx(np.array([np.arange(1, 13)]))

        roe = ac.ROE(empty_traps_for_first_transfers=True,
                     express_matrix_dtype=float)

        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=4)

        assert express_matrix == pytest.approx(
            np.array([
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 1, 0.75, 1.75, 2.75],
                [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 1, 0.5, 1.5, 2.5, 2.75, 2.75, 2.75],
                [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                [
                    0, 0, 1, 0.25, 1.25, 2.25, 2.75, 2.75, 2.75, 2.75, 2.75,
                    2.75
                ],
                [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [
                    1, 1, 2, 2.75, 2.75, 2.75, 2.75, 2.75, 2.75, 2.75, 2.75,
                    2.75
                ],
            ]))

        # Unchanged for no express
        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=12)

        assert express_matrix == pytest.approx(np.triu(np.ones((12, 12))))
Esempio n. 3
0
    def test__release_fractions_sum_to_unity(self):

        for n_phases in [1, 2, 3, 5, 8]:
            roe = ac.ROE([1] * n_phases)
            for step in roe.clock_sequence:
                for phase in step:
                    assert sum(phase.release_fraction_to_pixel) == 1
Esempio n. 4
0
    def test__express_matrix_from_pixels(self):

        roe = ac.ROE(empty_traps_for_first_transfers=False,
                     express_matrix_dtype=int)
        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=1)

        assert express_matrix == pytest.approx(np.array([np.arange(1, 13)]))

        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=4)

        assert express_matrix == pytest.approx(
            np.array([
                [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
                [0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3],
                [0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3],
            ]))

        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=12)

        assert express_matrix == pytest.approx(np.triu(np.ones((12, 12))))
Esempio n. 5
0
    def test__express_matrix__offset(self):

        roe = ac.ROE(empty_traps_for_first_transfers=False,
                     express_matrix_dtype=int)
        pixels = 12

        # Compare with offset added directly
        for offset in [1, 5, 11]:
            for express in [1, 3, 12, 0]:
                (
                    express_matrix,
                    _,
                ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
                    pixels=pixels,
                    express=express,
                    offset=offset,
                )

                (
                    express_matrix_manual_offset,
                    _,
                ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
                    pixels=pixels + offset,
                    express=express,
                )

                assert express_matrix[:] == pytest.approx(
                    express_matrix_manual_offset[:, offset:])
Esempio n. 6
0
    def test__readout_sequence_three_phase_single_phase_high(self):

        n_phases = 3

        roe = ac.ROE([1] * n_phases, force_release_away_from_readout=False)
        assert roe.pixels_accessed_during_clocking == pytest.approx([-1, 0, 1])
        assert roe.n_phases == n_phases
        assert roe.n_steps == n_phases

        for step in range(n_phases):
            phase = step
            assert roe.clock_sequence[step][phase].is_high
            assert (roe.clock_sequence[step][phase].capture_from_which_pixel ==
                    0), "Step {}, phase {}, capture".format(step, phase)
            assert (roe.clock_sequence[step][phase].release_to_which_pixels ==
                    0), "Step {}, phase {}, release".format(step, phase)

        # Check other phases
        assert roe.clock_sequence[0][1].release_to_which_pixels == 0
        assert roe.clock_sequence[0][2].release_to_which_pixels == -1
        assert roe.clock_sequence[1][0].release_to_which_pixels == 0
        assert roe.clock_sequence[1][2].release_to_which_pixels == 0
        assert roe.clock_sequence[2][0].release_to_which_pixels == 1
        assert roe.clock_sequence[2][1].release_to_which_pixels == 0

        # Never move electrons ahead of the trap
        roe = ac.ROE([1] * n_phases, force_release_away_from_readout=True)
        assert roe.pixels_accessed_during_clocking == pytest.approx([0, 1])
        assert roe.n_phases == n_phases
        assert roe.n_steps == n_phases

        # Check all high phases
        for step in range(n_phases):
            phase = step
            assert roe.clock_sequence[step][phase].is_high
            assert (roe.clock_sequence[step][phase].capture_from_which_pixel ==
                    0), "Step {}, phase {}, capture".format(step, phase)
            assert (roe.clock_sequence[step][phase].release_to_which_pixels ==
                    0), "Step {}, phase {}, release".format(step, phase)

        # Check other phases
        assert roe.clock_sequence[0][1].release_to_which_pixels == 1
        assert roe.clock_sequence[0][2].release_to_which_pixels == 0
        assert roe.clock_sequence[1][0].release_to_which_pixels == 0
        assert roe.clock_sequence[1][2].release_to_which_pixels == 1
        assert roe.clock_sequence[2][0].release_to_which_pixels == 1
        assert roe.clock_sequence[2][1].release_to_which_pixels == 0
Esempio n. 7
0
    def test__readout_sequence_two_phase_single_phase_high(self):

        n_phases = 2

        roe = ac.ROE([1] * n_phases, force_release_away_from_readout=False)
        assert roe.pixels_accessed_during_clocking == pytest.approx([-1, 0, 1])
        assert roe.n_phases == n_phases
        assert roe.n_steps == n_phases

        for step in range(n_phases):
            phase = step
            assert roe.clock_sequence[step][phase].is_high
            assert (roe.clock_sequence[step][phase].capture_from_which_pixel ==
                    0), "Step {}, phase {}, capture".format(step, phase)
            assert (roe.clock_sequence[step][phase].release_to_which_pixels ==
                    0), "Step {}, phase {}, release".format(step, phase)

        # Check other phases
        assert all(roe.clock_sequence[0][1].release_to_which_pixels ==
                   np.array([-1, 0]))
        assert all(roe.clock_sequence[1][0].release_to_which_pixels ==
                   np.array([0, 1]))

        roe = ac.ROE([1] * n_phases, force_release_away_from_readout=True)
        assert roe.pixels_accessed_during_clocking == pytest.approx([0, 1])
        assert roe.n_phases == n_phases
        assert roe.n_steps == n_phases

        for step in range(n_phases):
            phase = step
            assert roe.clock_sequence[step][phase].is_high
            assert (roe.clock_sequence[step][phase].capture_from_which_pixel ==
                    0), "Step {}, phase {}, capture".format(step, phase)
            assert (roe.clock_sequence[step][phase].release_to_which_pixels ==
                    0), "Step {}, phase {}, release".format(step, phase)

        # Check other phases
        assert all(roe.clock_sequence[0][1].release_to_which_pixels ==
                   np.array([0, 1]))
        assert all(roe.clock_sequence[1][0].release_to_which_pixels ==
                   np.array([0, 1]))
Esempio n. 8
0
    def test__readout_sequence_single_phase_single_phase_high(self):

        for force_release_away_from_readout in [True, False]:
            roe = ac.ROE(
                [1],
                force_release_away_from_readout=force_release_away_from_readout
            )
            assert roe.pixels_accessed_during_clocking == pytest.approx([0])
            assert roe.n_phases == 1
            assert roe.n_steps == 1
            assert roe.clock_sequence[0][0].is_high
            assert roe.clock_sequence[0][0].capture_from_which_pixel == 0
            assert roe.clock_sequence[0][0].release_to_which_pixels == 0
Esempio n. 9
0
    def test__express_matrix_monitor_and_traps_matrix__time_window(self):
        roe = ac.ROE(express_matrix_dtype=int)
        express = 2
        offset = 2
        pixels = 8
        total_pixels = pixels + offset

        (
            express_matrix_a,
            monitor_traps_matrix_a,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels, express, offset=offset, time_window_range=range(0, 6))
        (
            express_matrix_b,
            monitor_traps_matrix_b,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels, express, offset=offset, time_window_range=range(6, 9))
        (
            express_matrix_c,
            monitor_traps_matrix_c,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels,
            express,
            offset=offset,
            time_window_range=range(9, total_pixels),
        )
        (
            express_matrix_d,
            monitor_traps_matrix_d,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels, express, offset=offset)
        total_transfers = (np.sum(express_matrix_a, axis=0) +
                           np.sum(express_matrix_b, axis=0) +
                           np.sum(express_matrix_c, axis=0))

        # All monitor all the transfers
        assert monitor_traps_matrix_a == pytest.approx(monitor_traps_matrix_b)
        assert monitor_traps_matrix_a == pytest.approx(monitor_traps_matrix_c)
        assert monitor_traps_matrix_a == pytest.approx(monitor_traps_matrix_d)

        # Separate time windows add to the full image
        assert total_transfers == pytest.approx(
            np.arange(1, pixels + 1) + offset)
        assert express_matrix_a + express_matrix_b + express_matrix_c == pytest.approx(
            express_matrix_d)
Esempio n. 10
0
def run_benchmark():
    # Download the test image
    filename = os.path.join(os.path.join(path, ".."), "hst_acs_10_col.txt")
    if not os.path.isfile(filename):
        url_path = "http://astro.dur.ac.uk/~cklv53/files/hst_acs_10_col.txt"
        urlretrieve(url_path, filename)

    # Load the image
    image_pre_cti = np.loadtxt(filename, skiprows=1)

    # CTI model parameters
    roe = ac.ROE(
        dwell_times=[1.0],
        empty_traps_between_columns=True,
        empty_traps_for_first_transfers=False,
        force_release_away_from_readout=True,
        use_integer_express_matrix=False,
    )
    ccd = ac.CCD(
        phases=[
            ac.CCDPhase(full_well_depth=1e4,
                        well_notch_depth=0.0,
                        well_fill_power=1.0)
        ],
        fraction_of_traps_per_phase=[1.0],
    )
    traps = [
        ac.TrapInstantCapture(density=10.0,
                              release_timescale=-1.0 / np.log(0.5))
    ]
    express = 5
    offset = 0
    start = 0
    stop = -1

    image_post_cti = ac.add_cti(
        image=image_pre_cti,
        parallel_roe=roe,
        parallel_ccd=ccd,
        parallel_traps=traps,
        parallel_express=express,
        parallel_offset=offset,
        parallel_window_start=start,
        parallel_window_stop=stop,
    )
Esempio n. 11
0
    def test__express_matrix__empty_traps_for_first_transfers(self):

        roe = ac.ROE(empty_traps_for_first_transfers=True,
                     express_matrix_dtype=int)
        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=1)

        express_matrix_check = np.rot90(np.diag(np.ones(12)))
        express_matrix_check[-1] += np.arange(12)

        assert express_matrix == pytest.approx(express_matrix_check)

        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=4)

        assert express_matrix == pytest.approx(
            np.array([
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2],
                [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 3],
                [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 1, 1, 2, 3, 3, 3, 3, 3, 3],
                [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            ]))

        (
            express_matrix,
            _,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=12)

        assert express_matrix == pytest.approx(np.triu(np.ones((12, 12))))
Esempio n. 12
0
 def test__express_matrix_always_sums_to_n_transfers(self):
     for pixels in [5, 7, 17]:
         for express in [0, 1, 2, 7]:
             for offset in [0, 1, 13]:
                 for dtype in [int, float]:
                     for empty_traps_for_first_transfers in [True, False]:
                         roe = ac.ROE(
                             empty_traps_for_first_transfers=
                             empty_traps_for_first_transfers,
                             express_matrix_dtype=dtype,
                         )
                         (
                             express_matrix,
                             _,
                         ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
                             pixels=pixels, express=express, offset=offset)
                         assert np.sum(
                             express_matrix, axis=0) == pytest.approx(
                                 np.arange(1, pixels + 1) + offset)
Esempio n. 13
0
    def test__monitor_traps_matrix(self):

        roe = ac.ROE(empty_traps_for_first_transfers=False)
        (
            _,
            monitor_traps_matrix,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=1)

        assert monitor_traps_matrix == pytest.approx(
            np.array([np.ones(12).astype(bool)]))

        (
            _,
            monitor_traps_matrix,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=4)

        assert monitor_traps_matrix == pytest.approx(
            np.array(
                [
                    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                    [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                    [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
                ],
                dtype=bool,
            ))

        (
            _,
            monitor_traps_matrix,
        ) = roe.express_matrix_and_monitor_traps_matrix_from_pixels_and_express(
            pixels=12, express=12)

        assert monitor_traps_matrix == pytest.approx(
            np.triu(np.ones((12, 12)).astype(bool)))
Esempio n. 14
0
def run_demo():
    # Add CTI to a test image, then remove it
    image_pre_cti = np.array([
        [0.0, 0.0, 0.0, 0.0],
        [200.0, 0.0, 0.0, 0.0],
        [0.0, 200.0, 0.0, 0.0],
        [0.0, 0.0, 200.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
    ])

    roe = ac.ROE(
        dwell_times=[1.0],
        empty_traps_between_columns=True,
        empty_traps_for_first_transfers=False,
        force_release_away_from_readout=True,
        use_integer_express_matrix=False,
    )
    ccd = ac.CCD(
        phases=[
            ac.CCDPhase(full_well_depth=1e3,
                        well_notch_depth=0.0,
                        well_fill_power=1.0)
        ],
        fraction_of_traps_per_phase=[1.0],
    )
    traps = [
        ac.TrapInstantCapture(density=10.0,
                              release_timescale=-1.0 / np.log(0.5))
    ]
    express = 0
    offset = 0
    start = 0
    stop = -1

    print("\n# Test image:")
    ac.print_array_2D(image_pre_cti)

    print("\n# Add CTI")
    image_post_cti = ac.add_cti(
        image=image_pre_cti,
        parallel_roe=roe,
        parallel_ccd=ccd,
        parallel_traps=traps,
        parallel_express=express,
        parallel_offset=offset,
        parallel_window_start=start,
        parallel_window_stop=stop,
        serial_roe=roe,
        serial_ccd=ccd,
        serial_traps=traps,
        serial_express=express,
        serial_offset=offset,
        serial_window_start=start,
        serial_window_stop=stop,
        verbosity=1,
    )

    print("\n# Image with CTI added:")
    ac.print_array_2D(image_post_cti)

    print("\n# Remove CTI")
    image_removed_cti = ac.remove_cti(
        image=image_post_cti,
        n_iterations=4,
        parallel_roe=roe,
        parallel_ccd=ccd,
        parallel_traps=traps,
        parallel_express=express,
        parallel_offset=offset,
        parallel_window_start=start,
        parallel_window_stop=stop,
        serial_roe=roe,
        serial_ccd=ccd,
        serial_traps=traps,
        serial_express=express,
        serial_offset=offset,
        serial_window_start=start,
        serial_window_stop=stop,
        verbosity=1,
    )

    print("\n# Image with CTI removed:")
    ac.print_array_2D(image_removed_cti)
Esempio n. 15
0
    def test__remove_cti__better_removal_with_more_iterations(self):
        # Add CTI to a test image, then remove it
        image_pre_cti = np.array([
            [0.0, 0.0, 0.0, 0.0],
            [200.0, 0.0, 0.0, 0.0],
            [0.0, 200.0, 0.0, 0.0],
            [0.0, 0.0, 200.0, 0.0],
            [0.0, 0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0, 0.0],
        ])

        roe = ac.ROE(
            dwell_times=[1.0],
            empty_traps_between_columns=True,
            empty_traps_for_first_transfers=False,
            force_release_away_from_readout=True,
            use_integer_express_matrix=False,
        )
        ccd = ac.CCD(
            phases=[
                ac.CCDPhase(full_well_depth=1e3,
                            well_notch_depth=0.0,
                            well_fill_power=1.0)
            ],
            fraction_of_traps_per_phase=[1.0],
        )
        traps = [
            ac.TrapInstantCapture(density=10.0,
                                  release_timescale=-1.0 / np.log(0.5))
        ]
        express = 0
        offset = 0
        start = 0
        stop = -1

        # Add CTI
        image_add_cti = ac.add_cti(
            image=image_pre_cti,
            parallel_roe=roe,
            parallel_ccd=ccd,
            parallel_traps=traps,
            parallel_express=express,
            parallel_offset=offset,
            parallel_window_start=start,
            parallel_window_stop=stop,
            serial_roe=roe,
            serial_ccd=ccd,
            serial_traps=traps,
            serial_express=express,
            serial_offset=offset,
            serial_window_start=start,
            serial_window_stop=stop,
            verbosity=0,
        )

        # Remove CTI
        for n_iterations in range(2, 7):
            image_remove_cti = ac.remove_cti(
                image=image_add_cti,
                n_iterations=n_iterations,
                parallel_roe=roe,
                parallel_ccd=ccd,
                parallel_traps=traps,
                parallel_express=express,
                parallel_offset=offset,
                parallel_window_start=start,
                parallel_window_stop=stop,
                serial_roe=roe,
                serial_ccd=ccd,
                serial_traps=traps,
                serial_express=express,
                serial_offset=offset,
                serial_window_start=start,
                serial_window_stop=stop,
                verbosity=0,
            )

            # Expect better results with more iterations
            tolerance = 10**(1 - n_iterations)
            assert image_remove_cti == pytest.approx(image_pre_cti,
                                                     abs=tolerance)
Esempio n. 16
0
    def test__add_cti__all_trap_types_broadly_similar_results(self):

        # Manually set True to make the plot
        do_plot = False
        # do_plot = True

        image_pre_cti = np.zeros((20, 1))
        image_pre_cti[2, 0] = 800

        trap_ic = ac.TrapInstantCapture(density=10,
                                        release_timescale=-1 / np.log(0.5))
        trap_sc = ac.TrapSlowCapture(density=10,
                                     release_timescale=-1 / np.log(0.5),
                                     capture_timescale=0.1)
        trap_ic_co = ac.TrapInstantCaptureContinuum(
            density=10,
            release_timescale=-1 / np.log(0.5),
            release_timescale_sigma=0.05)
        trap_sc_co = ac.TrapSlowCaptureContinuum(
            density=10,
            release_timescale=-1 / np.log(0.5),
            release_timescale_sigma=0.05,
            capture_timescale=0.1,
        )

        ccd = ac.CCD(phases=[
            ac.CCDPhase(
                well_fill_power=1, full_well_depth=1000, well_notch_depth=0)
        ])
        roe = ac.ROE(
            empty_traps_between_columns=True,
            empty_traps_for_first_transfers=False,
            use_integer_express_matrix=True,
        )
        express = 5

        # Standard instant-capture traps
        image_post_cti_ic = ac.add_cti(
            image=image_pre_cti,
            parallel_roe=roe,
            parallel_ccd=ccd,
            parallel_traps=[trap_ic],
            parallel_express=express,
            verbosity=0,
        ).T[0]

        if do_plot:
            pixels = np.arange(len(image_pre_cti))
            colours = ["#1199ff", "#ee4400", "#7711dd", "#44dd44"]
            plt.figure(figsize=(10, 6))
            ax1 = plt.gca()
            ax2 = ax1.twinx()

            ax1.plot(
                pixels,
                image_post_cti_ic,
                alpha=0.8,
                c=colours[0],
                label="Instant Capture",
            )

        # Other trap types
        for i, (trap, label) in enumerate(
                zip(
                    [trap_sc, trap_ic_co, trap_sc_co],
                    [
                        "Slow Capture", "Instant Capture Continuum",
                        "Slow Capture Continuum"
                    ],
                )):
            image_post_cti = ac.add_cti(
                image=image_pre_cti,
                parallel_roe=roe,
                parallel_ccd=ccd,
                parallel_traps=[trap],
                parallel_express=express,
                verbosity=0,
            ).T[0]

            if do_plot:
                c = colours[i + 1]

                ax1.plot(pixels, image_post_cti, alpha=0.8, c=c, label=label)
                ax2.plot(
                    pixels,
                    (image_post_cti - image_post_cti_ic) / image_post_cti_ic,
                    alpha=0.8,
                    ls=":",
                    c=c,
                )

            assert image_post_cti == pytest.approx(image_post_cti_ic, rel=0.1)

        if do_plot:
            ax1.legend(loc="lower left")
            ax1.set_yscale("log")
            ax1.set_xlabel("Pixel")
            ax1.set_ylabel("Counts")
            ax2.set_ylabel("Fractional Difference (dotted)")
            plt.tight_layout()
            plt.show()
Esempio n. 17
0
    def test__add_cti__single_pixel__vary_express_3__compare_old_arctic(self):

        # Manually set True to make the plot
        do_plot = False
        # do_plot = True

        image_pre_cti = np.zeros((40, 1))
        image_pre_cti[2, 0] = 800

        traps = [ac.TrapInstantCapture(density=10, release_timescale=5)]
        ccd = ac.CCD(phases=[
            ac.CCDPhase(
                well_fill_power=0.5, full_well_depth=1000, well_notch_depth=0)
        ])
        roe = ac.ROE(
            empty_traps_between_columns=True,
            empty_traps_for_first_transfers=False,
            use_integer_express_matrix=True,
        )

        if do_plot:
            pixels = np.arange(len(image_pre_cti))
            colours = ["#1199ff", "#ee4400", "#7711dd", "#44dd44", "#775533"]
            plt.figure(figsize=(10, 6))
            ax1 = plt.gca()
            ax2 = ax1.twinx()

        for i, (express, image_idl) in enumerate(
                zip(
                    # [2, 40],
                    [40],
                    [
                        # [ # express=2 but different save/restore trap approach
                        #     0.0000000,
                        #     0.0000000,
                        #     773.16687,
                        #     6.1919436,
                        #     6.3684354,
                        #     6.2979879,
                        #     6.0507884,
                        #     5.7028670,
                        #     5.2915287,
                        #     4.8539200,
                        #     4.4115725,
                        #     3.9793868,
                        #     3.5681694,
                        #     3.1855009,
                        #     2.8297379,
                        #     2.5070403,
                        #     2.2149866,
                        #     1.9524645,
                        #     1.7182100,
                        #     1.5103321,
                        #     1.3410047,
                        #     1.1967528,
                        #     1.0735434,
                        #     0.96801299,
                        #     0.87580109,
                        #     0.79527515,
                        #     0.72667038,
                        #     0.66463155,
                        #     0.61054391,
                        #     0.56260395,
                        #     0.51870286,
                        #     0.47962612,
                        #     0.44496229,
                        #     0.41361856,
                        #     0.38440439,
                        #     0.35855818,
                        #     0.33410615,
                        #     0.31309450,
                        #     0.29213923,
                        #     0.27346680,
                        # ],
                        [
                            0.00000,
                            0.00000,
                            773.317,
                            5.98876,
                            6.13135,
                            6.05125,
                            5.81397,
                            5.49105,
                            5.11484,
                            4.71890,
                            4.32139,
                            3.93756,
                            3.57154,
                            3.23464,
                            2.91884,
                            2.63640,
                            2.37872,
                            2.14545,
                            1.93805,
                            1.75299,
                            1.58590,
                            1.43964,
                            1.30883,
                            1.19327,
                            1.09000,
                            0.996036,
                            0.915593,
                            0.841285,
                            0.775049,
                            0.718157,
                            0.664892,
                            0.617069,
                            0.574792,
                            0.537046,
                            0.502112,
                            0.471202,
                            0.442614,
                            0.417600,
                            0.394439,
                            0.373072,
                        ]
                    ],
                )):
            image_post_cti = ac.add_cti(
                image=image_pre_cti,
                parallel_traps=traps,
                parallel_ccd=ccd,
                parallel_roe=roe,
                parallel_express=express,
                verbosity=0,
            ).T[0]

            image_idl = np.array(image_idl)

            if do_plot:
                c = colours[i]

                if i == 0:
                    ax1.plot(
                        pixels,
                        image_post_cti,
                        alpha=0.8,
                        c=c,
                        label="%d (py)" % express,
                    )
                    ax1.plot(
                        pixels,
                        image_idl,
                        ls="--",
                        alpha=0.8,
                        c=c,
                        label="%d (idl)" % express,
                    )
                    ax2.plot(
                        pixels,
                        (image_post_cti - image_idl) / image_idl,
                        alpha=0.8,
                        ls=":",
                        c=c,
                    )
                else:
                    ax1.plot(pixels,
                             image_post_cti,
                             alpha=0.8,
                             c=c,
                             label="%d" % express)
                    ax1.plot(pixels, image_idl, alpha=0.8, c=c, ls="--")
                    ax2.plot(
                        pixels,
                        (image_post_cti - image_idl) / image_idl,
                        alpha=0.8,
                        ls=":",
                        c=c,
                    )

            assert image_post_cti == pytest.approx(image_idl, rel=0.03)

        if do_plot:
            ax1.legend(title="express", loc="lower left")
            ax1.set_yscale("log")
            ax1.set_xlabel("Pixel")
            ax1.set_ylabel("Counts")
            ax2.set_ylabel("Fractional Difference (dotted)")
            plt.tight_layout()
            plt.show()
Esempio n. 18
0
    def test__add_cti__single_pixel__vary_express_2__compare_old_arctic(self):

        # Manually set True to make the plot
        do_plot = False
        # do_plot = True

        image_pre_cti = np.zeros((120, 1))
        image_pre_cti[102, 0] = 800

        traps = [
            ac.TrapInstantCapture(density=10,
                                  release_timescale=-1 / np.log(0.5))
        ]
        ccd = ac.CCD(phases=[
            ac.CCDPhase(
                well_fill_power=0.5, full_well_depth=1000, well_notch_depth=0)
        ])
        roe = ac.ROE(
            empty_traps_between_columns=True,
            empty_traps_for_first_transfers=False,
            use_integer_express_matrix=True,
        )

        if do_plot:
            pixels = np.arange(len(image_pre_cti))
            colours = ["#1199ff", "#ee4400", "#7711dd", "#44dd44", "#775533"]
            plt.figure(figsize=(10, 6))
            ax1 = plt.gca()
            ax2 = ax1.twinx()

        for i, (express, image_idl) in enumerate(
                zip(
                    [2, 20],
                    [
                        [
                            0.00000,
                            0.00000,
                            42.6722,
                            250.952,
                            161.782,
                            107.450,
                            73.0897,
                            50.6914,
                            35.6441,
                            25.3839,
                            18.2665,
                            13.2970,
                            9.79078,
                            7.30555,
                            5.52511,
                            4.24364,
                            3.30829,
                            2.61813,
                            2.09710,
                            1.70752,
                        ],
                        [
                            0.00000,
                            0.00000,
                            134.103,
                            163.783,
                            117.887,
                            85.8632,
                            63.6406,
                            47.9437,
                            36.6625,
                            28.4648,
                            22.4259,
                            17.9131,
                            14.4976,
                            11.8789,
                            9.84568,
                            8.25520,
                            6.98939,
                            5.97310,
                            5.14856,
                            4.47386,
                        ],
                    ],
                )):
            image_post_cti = ac.add_cti(
                image=image_pre_cti,
                parallel_traps=traps,
                parallel_ccd=ccd,
                parallel_roe=roe,
                parallel_express=express,
                verbosity=0,
            ).T[0]

            image_idl = np.append(np.zeros(100), image_idl)

            if do_plot:
                c = colours[i]

                if i == 0:
                    ax1.plot(
                        pixels,
                        image_post_cti,
                        alpha=0.8,
                        c=c,
                        label="%d (py)" % express,
                    )
                    ax1.plot(
                        pixels,
                        image_idl,
                        ls="--",
                        alpha=0.8,
                        c=c,
                        label="%d (idl)" % express,
                    )
                    ax2.plot(
                        pixels,
                        (image_post_cti - image_idl) / image_idl,
                        alpha=0.8,
                        ls=":",
                        c=c,
                    )
                else:
                    ax1.plot(pixels,
                             image_post_cti,
                             alpha=0.8,
                             c=c,
                             label="%d" % express)
                    ax1.plot(pixels, image_idl, alpha=0.8, c=c, ls="--")
                    ax2.plot(
                        pixels,
                        (image_post_cti - image_idl) / image_idl,
                        alpha=0.8,
                        ls=":",
                        c=c,
                    )

            assert image_post_cti == pytest.approx(image_idl, rel=0.02)

        if do_plot:
            ax1.legend(title="express", loc="lower left")
            ax1.set_yscale("log")
            ax1.set_xlabel("Pixel")
            ax1.set_xlim(100, 121)
            ax1.set_ylabel("Counts")
            ax2.set_ylabel("Fractional Difference (dotted)")
            plt.tight_layout()
            plt.show()
Esempio n. 19
0
    def test__add_cti__single_pixel__vary_express__compare_old_arctic(self):

        # Manually set True to make the plot
        do_plot = False
        # do_plot = True

        image_pre_cti = np.zeros((20, 1))
        image_pre_cti[2, 0] = 800

        # Nice numbers for easy manual checking
        traps = [
            ac.TrapInstantCapture(density=10,
                                  release_timescale=-1 / np.log(0.5))
        ]
        ccd = ac.CCD(phases=[
            ac.CCDPhase(
                well_fill_power=1, full_well_depth=1000, well_notch_depth=0)
        ])
        roe = ac.ROE(
            empty_traps_between_columns=True,
            empty_traps_for_first_transfers=False,
            use_integer_express_matrix=True,
        )

        if do_plot:
            pixels = np.arange(len(image_pre_cti))
            colours = ["#1199ff", "#ee4400", "#7711dd", "#44dd44", "#775533"]
            plt.figure(figsize=(10, 6))
            ax1 = plt.gca()
            ax2 = ax1.twinx()

        for i, (express, image_idl) in enumerate(
                zip(
                    [1, 2, 5, 10, 20],
                    [
                        [
                            0.00000,
                            0.00000,
                            776.000,
                            15.3718,
                            9.65316,
                            5.81950,
                            3.41087,
                            1.95889,
                            1.10817,
                            0.619169,
                            0.342489,
                            0.187879,
                            0.102351,
                            0.0554257,
                            0.0298603,
                            0.0160170,
                            0.00855758,
                            0.00455620,
                            0.00241824,
                            0.00128579,
                        ],
                        [
                            0.00000,
                            0.00000,
                            776.000,
                            15.3718,
                            9.65316,
                            5.81950,
                            3.41087,
                            1.95889,
                            1.10817,
                            0.619169,
                            0.348832,
                            0.196128,
                            0.109984,
                            0.0614910,
                            0.0340331,
                            0.0187090,
                            0.0102421,
                            0.00558406,
                            0.00303254,
                            0.00164384,
                        ],
                        [
                            0.00000,
                            0.00000,
                            776.000,
                            15.3718,
                            9.59381,
                            5.80216,
                            3.43231,
                            1.99611,
                            1.15104,
                            0.658983,
                            0.374685,
                            0.211807,
                            0.119441,
                            0.0670274,
                            0.0373170,
                            0.0205845,
                            0.0113179,
                            0.00621127,
                            0.00341018,
                            0.00187955,
                        ],
                        [
                            0.00000,
                            0.00000,
                            776.160,
                            15.1432,
                            9.51562,
                            5.78087,
                            3.43630,
                            2.01144,
                            1.16452,
                            0.668743,
                            0.381432,
                            0.216600,
                            0.122556,
                            0.0689036,
                            0.0383241,
                            0.0211914,
                            0.0116758,
                            0.00641045,
                            0.00352960,
                            0.00195050,
                        ],
                        [
                            0.00000,
                            0.00000,
                            776.239,
                            15.0315,
                            9.47714,
                            5.77145,
                            3.43952,
                            2.01754,
                            1.17049,
                            0.673351,
                            0.384773,
                            0.218860,
                            0.124046,
                            0.0697859,
                            0.0388253,
                            0.0214799,
                            0.0118373,
                            0.00650488,
                            0.00358827,
                            0.00198517,
                        ],
                    ],
                )):
            image_post_cti = ac.add_cti(
                image=image_pre_cti,
                parallel_roe=roe,
                parallel_ccd=ccd,
                parallel_traps=traps,
                parallel_express=express,
                verbosity=0,
            ).T[0]

            image_idl = np.array(image_idl)

            if do_plot:
                c = colours[i]

                if i == 0:
                    ax1.plot(
                        pixels,
                        image_post_cti,
                        alpha=0.8,
                        c=c,
                        label="%d (py)" % express,
                    )
                    ax1.plot(
                        pixels,
                        image_idl,
                        ls="--",
                        alpha=0.8,
                        c=c,
                        label="%d (idl)" % express,
                    )
                    ax2.plot(
                        pixels,
                        (image_post_cti - image_idl) / image_idl,
                        alpha=0.8,
                        ls=":",
                        c=c,
                    )
                else:
                    ax1.plot(pixels,
                             image_post_cti,
                             alpha=0.8,
                             c=c,
                             label="%d" % express)
                    ax1.plot(pixels, image_idl, alpha=0.8, c=c, ls="--")
                    ax2.plot(
                        pixels,
                        (image_post_cti - image_idl) / image_idl,
                        alpha=0.8,
                        ls=":",
                        c=c,
                    )

            assert image_post_cti == pytest.approx(image_idl, rel=0.05)

        if do_plot:
            ax1.legend(title="express", loc="lower left")
            ax1.set_yscale("log")
            ax1.set_xlabel("Pixel")
            ax1.set_ylabel("Counts")
            ax2.set_ylabel("Fractional Difference (dotted)")
            plt.tight_layout()
            plt.show()
Esempio n. 20
0
#image_model[1000:1005,:]+=700
#image_model[1500:1505,:]+=700

parallel_traps = [
    arcticpy.TrapInstantCapture(density=10.0,
                                release_timescale=(-1 / np.log(0.5))),
    #arcticpy.TrapInstantCapture(density=10.0, release_timescale=100),
    #arcticpy.TrapSlowCapture(density=10.0, release_timescale=(-1/np.log(0.5)), capture_timescale=0.001),
    #arcticpy.TrapSlowCapture(density=10.0, release_timescale=(4), capture_timescale=0.001),
    #arcticpy.TrapInstantCaptureContinuum(density=10.0, release_timescale=(1.), release_timescale_sigma=0.1),
    #arcticpy.TrapSlowCaptureContinuum(density=10.0, release_timescale=(1.), capture_timescale=1, release_timescale_sigma=0.1),
]

parallel_ccd = arcticpy.CCD(full_well_depth=1000, well_fill_power=1.0)
parallel_roe = arcticpy.ROE(empty_traps_between_columns=True,
                            empty_traps_for_first_transfers=False,
                            overscan_start=1990,
                            prescan_offset=10)

#
# Noisy image
#
image_pre_cti = image_model + np.random.normal(0, 0.01, image_model.shape)
#image_pre_cti = np.maximum(image_pre_cti,np.zeros(image_pre_cti.shape));
#print(image_pre_cti[0:10,0])

start = time.time_ns()

image_post_cti = arcticpy.add_cti(
    image=image_pre_cti,
    parallel_traps=parallel_traps,
    parallel_ccd=parallel_ccd,
Esempio n. 21
0
    def test__add_cti__multiple_trap_types_together_or_consecutively(self):

        # Manually set True to make the plot
        do_plot = False
        # do_plot = True

        image_pre_cti = np.zeros((20, 1))
        image_pre_cti[2, 0] = 800

        trap_ic = cti.TrapInstantCapture(density=10,
                                         release_timescale=-1 / np.log(0.5))
        trap_sc = cti.TrapSlowCapture(density=10,
                                      release_timescale=-1 / np.log(0.5),
                                      capture_timescale=0.1)
        trap_ic_co = cti.TrapInstantCaptureContinuum(
            density=10,
            release_timescale=-1 / np.log(0.5),
            release_timescale_sigma=0.05)
        trap_sc_co = cti.TrapSlowCaptureContinuum(
            density=10,
            release_timescale=-1 / np.log(0.5),
            release_timescale_sigma=0.05,
            capture_timescale=0.1,
        )

        ccd = cti.CCD(phases=[
            cti.CCDPhase(
                well_fill_power=1, full_well_depth=1000, well_notch_depth=0)
        ])
        roe = cti.ROE(
            empty_traps_between_columns=True,
            empty_traps_for_first_transfers=False,
            use_integer_express_matrix=True,
        )
        express = 5

        # Implement all types of traps simultaneously
        image_post_cti_simultaneously = cti.add_cti(
            image=image_pre_cti,
            parallel_roe=roe,
            parallel_ccd=ccd,
            parallel_traps=[trap_ic, trap_sc, trap_ic_co, trap_sc_co],
            parallel_express=express,
            verbosity=0,
        ).T[0]

        if do_plot:
            pixels = np.arange(len(image_pre_cti))
            colours = ["#1199ff", "#ee4400", "#7711dd", "#44dd44", "#666666"]
            plt.figure(figsize=(10, 6))
            ax1 = plt.gca()
            ax2 = ax1.twinx()

            ax1.plot(
                pixels,
                image_post_cti_simultaneously,
                alpha=0.8,
                c=colours[0],
                label="All types simultaneously",
            )

        # Implement trap types one after another
        image_post_cti_separately = image_pre_cti
        for i, (trap, label) in enumerate(
                zip(
                    [trap_ic, trap_sc, trap_ic_co, trap_sc_co],
                    [
                        "After Instant Capture", "After Slow Capture",
                        "After Instant Capture Continuum",
                        "After Slow Capture Continuum"
                    ],
                )):
            image_pre_cti = image_post_cti_separately
            image_post_cti_separately = cti.add_cti(
                image=image_pre_cti,
                parallel_roe=roe,
                parallel_ccd=ccd,
                parallel_traps=[trap],
                parallel_express=express,
                verbosity=0,
            )

            if do_plot:
                c = colours[i + 1]

                ax1.plot(pixels,
                         image_post_cti_separately.T[0],
                         alpha=0.8,
                         c=c,
                         label=label)
                ax2.plot(
                    pixels,
                    (image_post_cti_separately.T[0] -
                     image_post_cti_simultaneously) /
                    image_post_cti_simultaneously,
                    alpha=0.8,
                    ls=":",
                    c=c,
                )

            assert 1 == pytest.approx(1.0001, rel=0.1)
        assert image_post_cti_separately.T[0] == pytest.approx(
            image_post_cti_simultaneously, rel=0.1)

        if do_plot:
            ax1.legend(loc="lower left")
            ax1.set_yscale("log")
            ax1.set_xlabel("Pixel")
            ax1.set_ylabel("Counts")
            ax2.set_ylabel("Fractional Difference (dotted)")
            plt.tight_layout()
            plt.show()
Esempio n. 22
0
import numpy as np
import sys
import os
import matplotlib as mpl
import matplotlib.pyplot as plt

path = os.path.dirname(os.path.realpath(__file__))

import arcticpy as cti
import autofit as af
import autocti as ac

# CTI model
roe_in = cti.ROE()
ccd_in = cti.CCD(full_well_depth=1e4,
                 well_notch_depth=0.0,
                 well_fill_power=1.0)
traps_in = [
    cti.TrapInstantCapture(density=10.0, release_timescale=-1.0 / np.log(0.5))
]
express = 0

# Test input
length = 9
warm_index = 4
pre_cti = np.zeros((length, 1))
pre_cti[warm_index, 0] = 1000

# Add CTI
post_cti = cti.add_cti(
    image=pre_cti,