Example #1
0
def test__add_cti_serial_fast():

    arr = np.array(([
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    ]))

    arr = ac.Array2D.manual(array=arr, pixel_scales=1.0).native

    ccd = ac.CCDPhase(full_well_depth=1e3,
                      well_notch_depth=0.0,
                      well_fill_power=1.0)

    trap_list = [
        ac.TrapInstantCapture(density=10.0,
                              release_timescale=-1.0 / np.log(0.5))
    ]

    clocker = ac.Clocker2D()

    image_via_clocker = clocker.add_cti(data=arr,
                                        serial_trap_list=trap_list,
                                        serial_ccd=ccd)

    clocker = ac.Clocker2D(serial_fast_pixels=(1, 3))

    image_via_clocker_fast = clocker.add_cti(data=arr,
                                             serial_trap_list=trap_list,
                                             serial_ccd=ccd)

    assert image_via_clocker == pytest.approx(image_via_clocker_fast, 1.0e-6)
Example #2
0
    def test__density_checks_raise_exception(self):

        settings = ac.SettingsCTI1D(total_density_range=(1.0, 2.0))

        traps = [
            ac.TrapInstantCapture(density=0.75),
            ac.TrapInstantCapture(density=0.75),
        ]

        settings.check_total_density_within_range(traps=traps)

        traps = [
            ac.TrapInstantCapture(density=1.1),
            ac.TrapInstantCapture(density=1.1)
        ]

        with pytest.raises(exc.PriorException):
            settings.check_total_density_within_range(traps=traps)
Example #3
0
def test__array_with_offset_through_arctic():

    arr = ac.Array2D.manual(
        array=[[1.0, 2.0], [3.0, 4.0]],
        pixel_scales=1.0,
        header=ac.Header(header_sci_obj=None,
                         header_hdu_obj=None,
                         readout_offsets=(3, 5)),
    ).native

    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_phase = ac.CCDPhase(full_well_depth=1e3,
                            well_notch_depth=0.0,
                            well_fill_power=1.0)
    ccd = ac.CCD(phases=[ccd_phase], fraction_of_traps_per_phase=[1.0])
    traps = [ac.TrapInstantCapture(10.0, -1.0 / np.log(0.5))]

    image_via_arctic = cti.add_cti(
        image=arr,
        parallel_traps=traps,
        parallel_ccd=ccd,
        parallel_roe=roe,
        parallel_express=3,
        parallel_offset=3,
    )

    clocker = ac.Clocker2D(parallel_express=3, parallel_roe=roe)

    image_via_clocker = clocker.add_cti(data=arr,
                                        parallel_trap_list=traps,
                                        parallel_ccd=ccd_phase)

    assert image_via_arctic == pytest.approx(image_via_clocker, 1.0e-4)

    image_via_arctic = cti.add_cti(
        image=arr,
        serial_traps=traps,
        serial_ccd=ccd,
        serial_roe=roe,
        serial_express=2,
        serial_offset=5,
    )

    clocker = ac.Clocker2D(serial_express=2, serial_roe=roe)

    image_via_clocker = clocker.add_cti(data=arr,
                                        serial_trap_list=traps,
                                        serial_ccd=ccd_phase)

    assert image_via_arctic == pytest.approx(image_via_clocker, 1.0e-4)
Example #4
0
    def test__parallel_and_serial_checks_raise_exception(self, imaging_ci_7x7):

        model = af.CollectionPriorModel(cti=af.Model(
            ac.CTI2D,
            parallel_traps=[
                ac.TrapInstantCapture(density=1.1),
                ac.TrapInstantCapture(density=1.1),
            ],
            parallel_ccd=ac.CCDPhase(),
        ))

        analysis = ac.AnalysisImagingCI(
            dataset_ci=imaging_ci_7x7,
            clocker=None,
            settings_cti=ac.SettingsCTI2D(parallel_total_density_range=(1.0,
                                                                        2.0)),
        )

        instance = model.instance_from_prior_medians()

        with pytest.raises(exc.PriorException):
            analysis.log_likelihood_function(instance=instance)

        model = af.CollectionPriorModel(cti=af.Model(
            ac.CTI2D,
            serial_traps=[
                ac.TrapInstantCapture(density=1.1),
                ac.TrapInstantCapture(density=1.1),
            ],
            serial_ccd=ac.CCDPhase(),
        ))

        analysis = ac.AnalysisImagingCI(
            dataset_ci=[imaging_ci_7x7],
            clocker=None,
            settings_cti=ac.SettingsCTI2D(serial_total_density_range=(1.0,
                                                                      2.0)),
        )

        instance = model.instance_from_prior_medians()

        with pytest.raises(exc.PriorException):
            analysis.log_likelihood_function(instance=instance)
Example #5
0
def test__add_cti_with_poisson_trap_densities():

    arr = np.array(([
        [1.0, 1.0, 1.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0],
    ]))

    arr = ac.Array2D.manual(array=arr, pixel_scales=1.0).native

    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.CCDPhase(full_well_depth=1e3,
                      well_notch_depth=0.0,
                      well_fill_power=1.0)

    trap_list = [
        ac.TrapInstantCapture(density=10.0,
                              release_timescale=-1.0 / np.log(0.5))
    ]

    clocker = ac.Clocker2D(
        parallel_poisson_traps=True,
        poisson_seed=1,
        parallel_express=3,
        parallel_roe=roe,
        serial_express=3,
        serial_roe=roe,
    )

    image_via_clocker = clocker.add_cti(
        data=arr,
        parallel_trap_list=trap_list,
        parallel_ccd=ccd,
        serial_trap_list=trap_list,
        serial_ccd=ccd,
    )

    assert image_via_clocker[0, 0] == pytest.approx(0.980298, 1.0e-4)
    assert image_via_clocker[0, 1] == pytest.approx(0.9901042, 1.0e-4)
    assert image_via_clocker[0, 2] == pytest.approx(0.9901981, 1.0e-4)
    assert (image_via_clocker[:, 3] > 0.0).all()
Example #6
0
def test__add_cti_serial_fast__raises_exception_if_nonzero_outside_tuple():

    ccd = ac.CCDPhase(full_well_depth=1e3,
                      well_notch_depth=0.0,
                      well_fill_power=1.0)

    trap_list = [
        ac.TrapInstantCapture(density=10.0,
                              release_timescale=-1.0 / np.log(0.5))
    ]

    clocker = ac.Clocker2D(serial_fast_pixels=(1, 3))

    arr = np.array(([
        [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    ]))

    arr = ac.Array2D.manual(array=arr, pixel_scales=1.0).native

    with pytest.raises(exc.ClockerException):

        clocker.add_cti(data=arr, serial_trap_list=trap_list, serial_ccd=ccd)

    arr = np.array(([
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
    ]))

    arr = ac.Array2D.manual(array=arr, pixel_scales=1.0).native

    with pytest.raises(exc.ClockerException):

        clocker.add_cti(data=arr, serial_trap_list=trap_list, serial_ccd=ccd)

    arr = np.array(([
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    ]))

    arr = ac.Array2D.manual(array=arr, pixel_scales=1.0).native

    with pytest.raises(exc.ClockerException):

        clocker.add_cti(data=arr, serial_trap_list=trap_list, serial_ccd=ccd)
Example #7
0
    def test__parallel_and_serial_checks_raise_exception(self):

        settings = ac.SettingsCTI2D(parallel_total_density_range=(1.0, 2.0))

        parallel_traps = [
            ac.TrapInstantCapture(density=0.75),
            ac.TrapInstantCapture(density=0.75),
        ]
        serial_traps = []

        settings.check_total_density_within_range(
            parallel_traps=parallel_traps, serial_traps=serial_traps)

        parallel_traps = [
            ac.TrapInstantCapture(density=1.1),
            ac.TrapInstantCapture(density=1.1),
        ]

        with pytest.raises(exc.PriorException):
            settings.check_total_density_within_range(
                parallel_traps=parallel_traps, serial_traps=serial_traps)

        settings = ac.SettingsCTI2D(serial_total_density_range=(1.0, 2.0))

        parallel_traps = []
        serial_traps = [
            ac.TrapInstantCapture(density=0.75),
            ac.TrapInstantCapture(density=0.75),
        ]

        settings.check_total_density_within_range(
            parallel_traps=parallel_traps, serial_traps=serial_traps)

        serial_traps = [
            ac.TrapInstantCapture(density=1.1),
            ac.TrapInstantCapture(density=1.1),
        ]

        with pytest.raises(exc.PriorException):
            settings.check_total_density_within_range(
                parallel_traps=parallel_traps, serial_traps=serial_traps)
Example #8
0
        serial_overscan=serial_overscan,
    ) for normalization in normalization_list
]
"""
The `Clocker` models the CCD read-out, including CTI. 
"""
clocker = ac.Clocker2D(serial_express=2)
"""
__CTI Model__

The CTI model used by arCTIc to add CTI to the input image in the serial direction, which contains: 

 - 3 trap species in the parallel direction.
 - A simple CCD volume beta parametrization.
"""
serial_trap_0 = ac.TrapInstantCapture(density=0.0442, release_timescale=0.8)
serial_trap_1 = ac.TrapInstantCapture(density=0.1326, release_timescale=4.0)
serial_trap_2 = ac.TrapInstantCapture(density=3.9782, release_timescale=20.0)

serial_ccd = ac.CCDPhase(well_fill_power=0.8,
                         well_notch_depth=0.0,
                         full_well_depth=84700.0)
"""
__Simulate__

To simulate charge injection imaging, we pass the charge injection pattern to a `SimulatorImagingCI`, which adds CTI 
via arCTIc and read-noise to the data.

This creates instances of the `ImagingCI` class, which include the images, noise-maps and pre_cti_data images.
"""
simulator = ac.ci.SimulatorImagingCI(read_noise=0.001, pixel_scales=0.1)
Example #9
0
__Clocker__

The `Clocker` models the CCD read-out, including CTI. 

For parallel clocking, we use 'charge injection mode' which transfers the charge of every pixel over the full CCD.
"""
clocker = ac.Clocker2D(parallel_express=2, parallel_charge_injection_mode=True)
"""
__CTI Model__

The CTI model used by arCTIc to add CTI to the input image in the parallel direction, which contains: 

 - 1 `Trap` species in the parallel direction.
 - A simple CCD volume beta parametrization.
"""
parallel_trap = ac.TrapInstantCapture(density=0.5, release_timescale=4.0)
parallel_ccd = ac.CCDPhase(well_fill_power=0.8,
                           well_notch_depth=0.0,
                           full_well_depth=84700.0)
"""
__Simulate__

To simulate charge injection imaging, we pass the charge injection pattern to a `SimulatorImagingCI`, which adds CTI 
via arCTIc and read-noise to the data.

This creates instances of the `ImagingCI` class, which include the images, noise-maps and pre_cti_data images.
"""
simulator = ac.ci.SimulatorImagingCI(read_noise=0.001, pixel_scales=0.1)
"""
We use the LA Cosmic algorithm to simulate and add cosmic rays to our ci pre cti image. This routine randomly
generates cosmimc rays based on realistic cosmic ray rates expected. These cosmic rays will then be added to our
The `Clocker` models the CCD read-out, including CTI. 

For parallel clocking, we use 'charge injection mode' which transfers the charge of every pixel over the full CCD.
"""
clocker = ac.Clocker2D(parallel_express=2, parallel_charge_injection_mode=True)
"""
__CTI Model__

The CTI model used by arCTIc to add CTI to the input image in the parallel direction, which contains: 

 - 2 `TrapInstantCapture` species in the parallel direction, which captures electrons during clocking instantly and 
 release them according to an exponential probability distribution defined by a single release times.
 - A simple CCD volume beta parametrization.
"""
parallel_trap_0 = ac.TrapInstantCapture(density=1.0, release_timescale=5.0)
parallel_ccd = ac.CCDPhase(well_fill_power=0.8,
                           well_notch_depth=0.0,
                           full_well_depth=84700.0)
"""
__Simulate__

To simulate charge injection imaging, we pass the charge injection pattern to a `SimulatorImagingCI`, which adds CTI 
via arCTIc and read-noise to the data.

This creates instances of the `ImagingCI` class, which include the images, noise-maps and pre_cti_data images.
"""
simulator = ac.ci.SimulatorImagingCI(read_noise=0.001, pixel_scales=0.1)
"""
We now pass each charge injection pattern to the simulator. This generate the charge injection image of each exposure
and before passing each image to arCTIc does the following:
Example #11
0
The `Clocker` models the CCD read-out, including CTI. 

For parallel clocking, we use 'charge injection mode' which transfers the charge of every pixel over the full CCD.
"""
clocker = ac.Clocker2D(parallel_express=2, parallel_charge_injection_mode=True)
"""
__CTI Model__

The CTI model used by arCTIc to add CTI to the input image in the parallel direction, which contains: 

 - 2 `TrapInstantCapture` species in the parallel direction, which captures electrons during clocking instantly and 
 release them according to an exponential probability distribution defined by a single release times.
 - A simple CCD volume beta parametrization.
"""
parallel_trap_0 = ac.TrapInstantCapture(density=0.13, release_timescale=1.25)
parallel_trap_1 = ac.TrapInstantCapture(density=0.25, release_timescale=4.4)
parallel_ccd = ac.CCDPhase(well_fill_power=0.8,
                           well_notch_depth=0.0,
                           full_well_depth=84700.0)
"""
__Simulate__

To simulate charge injection imaging, we pass the charge injection pattern to a `SimulatorImagingCI`, which adds CTI 
via arCTIc and read-noise to the data.

This creates instances of the `ImagingCI` class, which include the images, noise-maps and pre_cti_data images.
"""
simulator = ac.ci.SimulatorImagingCI(read_noise=0.001, pixel_scales=0.1)
"""
We now pass each charge injection pattern to the simulator. This generate the charge injection image of each exposure
Example #12
0
def test__raises_exception_if_no_traps_or_ccd_passed():

    arr = ac.Array2D.manual(
        array=[[1.0, 2.0], [3.0, 4.0]],
        pixel_scales=1.0,
        header=ac.Header(header_sci_obj=None,
                         header_hdu_obj=None,
                         readout_offsets=(3, 5)),
    ).native

    ccd_phase = ac.CCDPhase(full_well_depth=1e3,
                            well_notch_depth=0.0,
                            well_fill_power=1.0)

    traps = [ac.TrapInstantCapture(10.0, -1.0 / np.log(0.5))]

    clocker = ac.Clocker2D(parallel_express=3)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr, parallel_trap_list=traps)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr, serial_trap_list=traps)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr,
                        parallel_trap_list=traps,
                        serial_trap_list=traps)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr, parallel_ccd=ccd_phase)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr, serial_ccd=ccd_phase)

    with pytest.raises(exc.ClockerException):
        clocker.add_cti(data=arr, parallel_ccd=ccd_phase, serial_ccd=ccd_phase)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr, parallel_trap_list=traps)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr, serial_trap_list=traps)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr,
                           parallel_trap_list=traps,
                           serial_trap_list=traps)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr, parallel_ccd=ccd_phase)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr, serial_ccd=ccd_phase)

    with pytest.raises(exc.ClockerException):
        clocker.remove_cti(data=arr,
                           parallel_ccd=ccd_phase,
                           serial_ccd=ccd_phase)
Example #13
0
"""
To correct the ACS data, we need a CTI model describing:
 
 - The properties of the `Trap`'s on the CCD that are responsible for CTI by capturing and releasing electrons during 
   read-out.
 - The volume-filling behaviour of electrons in CCD pixels, as this effects whether `Trap`'s are able to captrue them
   or not!
   
**PyAutoCTI** again has in-built tools for automatically loading the CTI model appropriate for correcting ACS data, 
using the date of observation loaded in the `ACSFrame` object to choose a model based on the date of observation.
"""

# trap_list = ac.acs.trap_list.from_header(header=header)
# ccd = ac.acs.CCD()

trap_list = [ac.TrapInstantCapture(density=0.1, release_timescale=1.0)]
ccd = ac.CCD(full_well_depth=1000, well_fill_power=0.8, well_notch_depth=100.0)
"""
We next create a `Clocker`, which determines how we 'clock' the image to mimic the effects of CTI and in turn use this
clocked image to perform the CTI correction.

For simplicity, we'll use all default values except using 5 iterations, which means when correcting the image we clock 
it to reproduce CTI and use this image to correct the image, and repeat that process 5 times.
"""
clocker = ac.Clocker2D(iterations=5, serial_express=20)
"""
We can now pass the image and CTI model to the `Clocker` to remove CTI.
"""

frame_corrected = clocker.remove_cti(data=frame,
                                     serial_trap_list=trap_list,