Exemple #1
0
def master_ci_from(ci_list: List[Array2D]) -> Array2D:
    """
    Determine the master charge injection frame from a list of observations of charge injection images, which all use
    the same charge injection parameters and therefore should all be identical except for read noise.

    The master frame is computed by summing all images in the list and dividing by the number of images, e.g. it is
    the mean value across the images in every pixel.

    There are many effects this function does not account for (bias, NL, cosmics, CTI, etc.) that will most likely
    need to be accounted for before a more realistic implementation is possible.

    Parameters
    ----------
    ci_list
        A list of charge injection images all of which are taken using the same charge injection
        parameters / electronics.

    Returns
    -------
    The estimated master charge injection image.
    """

    master_ci = sum(ci_list) / len(ci_list)

    return Array2D.manual_native(array=master_ci.native,
                                 pixel_scales=ci_list[0].pixel_scales)
    def __init__(
        self,
        image: array_2d.Array2D,
        noise_map: array_2d.Array2D,
        psf: kernel_2d.Kernel2D = None,
        settings=SettingsImaging(),
        name: str = None,
        setup_convolver=False,
    ):
        """
        A class containing the data, noise-map and point spread function of a 2D imaging dataset.

        Parameters
        ----------
        image : aa.Array2D
            The array of the image data, in units of electrons per second.
        noise_map : Array2D
            An array describing the RMS standard deviation error in each pixel in units of electrons per second.
        psf : aa.Array2D
            An array describing the Point Spread Function kernel of the image.
        mask: msk.Mask2D
            The 2D mask that is applied to the image.
        """

        self.unmasked = None

        self.setup_convolver = setup_convolver

        if setup_convolver and psf is not None:

            try:
                image.mask.blurring_mask_from_kernel_shape(
                    kernel_shape_native=psf.shape_native
                )
            except exc.MaskException:
                image = image.padded_before_convolution_from(
                    kernel_shape=psf.shape_native, mask_pad_value=1
                )
                noise_map = noise_map.padded_before_convolution_from(
                    kernel_shape=psf.shape_native, mask_pad_value=1
                )
                print(
                    f"The image and noise map of the `Imaging` objected had been padded to the dimensions"
                    f"{image.shape}. This is because the blurring region around its mask, which defines where"
                    f"PSF flux may be convolved into the masked region, extended beyond the edge of the image."
                    f""
                    f"This can be prevented by using a smaller mask, smaller PSF kernel size or manually padding"
                    f"the image and noise-map yourself."
                )

        super().__init__(data=image, noise_map=noise_map, settings=settings, name=name)

        self.psf_unormalized = psf

        if psf is not None:

            self.psf_normalized = kernel_2d.Kernel2D.manual_native(
                array=psf.native, pixel_scales=psf.pixel_scales, normalize=True
            )

        if setup_convolver and psf is not None:

            self.convolver = convolver.Convolver(mask=self.mask, kernel=self.psf)
            self.blurring_grid = self.grid.blurring_grid_from_kernel_shape(
                kernel_shape_native=self.psf.shape_native
            )

        else:

            self.convolver = None
            self.blurring_grid = None
Exemple #3
0
    def plot_array(
        self,
        array: array_2d.Array2D,
        visuals_2d: vis.Visuals2D,
        auto_labels: AutoLabels,
        bypass: bool = False,
    ):
        """
        Plot an `Array2D` data structure as a figure using the matplotlib wrapper objects and tools.

        This `Array2D` is plotted using `plt.imshow`.

        Parameters
        -----------
        array : array_2d.Array2D
            The 2D array of data_type which is plotted.
        visuals_2d : vis.Visuals2D
            Contains all the visuals that are plotted over the `Array2D` (e.g. the origin, mask, grids, etc.).
        bypass : bool
            If `True`, `plt.close` is omitted and the matplotlib figure remains open. This is used when making subplots.
        """

        if array is None or np.all(array == 0):
            return

        if array.pixel_scales is None and self.units.use_scaled:
            raise exc.ArrayException(
                "You cannot plot an array using its scaled unit_label if the input array does not have "
                "a pixel scales attribute.")

        array = array.binned

        if array.mask.is_all_false:
            buffer = 0
        else:
            buffer = 1

        if array.zoom_for_plot:

            extent_imshow = array.extent_of_zoomed_array(buffer=buffer)
            array = array.zoomed_around_mask(buffer=buffer)

        else:

            extent_imshow = array.extent

        if not self.is_for_subplot:
            self.figure.open()
        else:
            if not bypass:
                self.setup_subplot()

        aspect = self.figure.aspect_from_shape_native(
            shape_native=array.shape_native)
        norm_scale = self.cmap.norm_from_array(array=array)

        plt.imshow(
            X=array.native,
            aspect=aspect,
            cmap=self.cmap.config_dict["cmap"],
            norm=norm_scale,
            extent=extent_imshow,
        )

        if visuals_2d.array_overlay is not None:
            self.array_overlay.overlay_array(array=visuals_2d.array_overlay,
                                             figure=self.figure)

        extent_axis = self.axis.config_dict.get("extent")
        extent_axis = extent_axis if extent_axis is not None else extent_imshow

        self.axis.set(extent=extent_axis)

        self.tickparams.set()

        self.yticks.set(
            array=array,
            min_value=extent_axis[2],
            max_value=extent_axis[3],
            units=self.units,
        )
        self.xticks.set(
            array=array,
            min_value=extent_axis[0],
            max_value=extent_axis[1],
            units=self.units,
        )

        self.title.set(auto_title=auto_labels.title)
        self.ylabel.set(units=self.units, include_brackets=True)
        self.xlabel.set(units=self.units, include_brackets=True)

        if self.colorbar is not None:
            cb = self.colorbar.set()
            self.colorbar_tickparams.set(cb=cb)

        visuals_2d.plot_via_plotter(plotter=self,
                                    grid_indexes=array.mask.masked_grid)

        if not self.is_for_subplot and not bypass:
            self.output.to_figure(structure=array,
                                  auto_filename=auto_labels.filename)
            self.figure.close()
Exemple #4
0
def make_noise_map_7x7_native():
    return Array2D.full(
        fill_value=2.0, shape_native=(7, 7), pixel_scales=(1.0, 1.0)
    ).native
Exemple #5
0
def make_image_7x7_native():
    return Array2D.full(
        fill_value=1.0, shape_native=(7, 7), pixel_scales=(1.0, 1.0)
    ).native
Exemple #6
0
def make_ci_noise_scaling_map_list_7x7():

    return [
        Array2D.ones(shape_native=(7, 7), pixel_scales=(1.0, 1.0)),
        Array2D.full(shape_native=(7, 7), fill_value=2.0, pixel_scales=(1.0, 1.0)),
    ]
Exemple #7
0
def make_ci_cosmic_ray_map_7x7():
    cosmic_ray_map = np.zeros(shape=(7, 7))

    return Array2D.manual(array=cosmic_ray_map, pixel_scales=(1.0, 1.0))
Exemple #8
0
def make_pre_cti_data_7x7():
    return Array2D.full(shape_native=(7, 7), fill_value=10.0, pixel_scales=(1.0, 1.0))