def __init__(self, array, mask, sub_grid_size=<NUM_LIT:1>):

<EOL>super(SubGrid, self).__init__()<EOL>self.mask = mask<EOL>self.sub_grid_size = sub_grid_size<EOL>self.sub_grid_length = int(sub_grid_size ** <NUM_LIT>)<EOL>self.sub_grid_fraction = <NUM_LIT:1.0> / self.sub_grid_length<EOL>

A sub-grid of coordinates, where each entry corresponds to the (y,x) coordinates at the centre of each \
        sub-pixel of an unmasked pixel (e.g. the pixels of a regular-grid). The positive y-axis is upwards and poitive \
        x-axis to the right, and this convention is followed for the sub-pixels in each unmasked pixel.

        A *SubGrid* is ordered such that pixels begin from the first (top-left) sub-pixel in the first unmasked pixel. \
        Indexes then go over the sub-pixels in each unmasked pixel, for every unmasked pixel. Therefore, \
        the sub-grid is an ndarray of shape [total_unmasked_pixels*(sub_grid_shape)**2, 2]. For example:

        - sub_grid[9, 1] - using a 2x2 sub-grid, gives the 3rd unmasked pixel's 2nd sub-pixel x-coordinate.
        - sub_grid[9, 1] - using a 3x3 sub-grid, gives the 2nd unmasked pixel's 1st sub-pixel x-coordinate.
        - sub_grid[27, 0] - using a 3x3 sub-grid, gives the 4th unmasked pixel's 1st sub-pixel y-coordinate.

        Below is a visual illustration of a sub grid. Like the regular grid, the indexing of each sub-pixel goes from \
        the top-left corner. In contrast to the regular grid above, our illustration below restricts the mask to just \
        2 pixels, to keep the illustration brief.

        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|     This is an example mask.Mask, where:
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|     x = True (Pixel is masked and excluded from lens)
        |x|x|x|x|o|o|x|x|x|x|     o = False (Pixel is not masked and included in lens)
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|

        Our regular-grid looks like it did before:

        pixel_scale = 1.0"

        <--- -ve  x  +ve -->

        |x|x|x|x|x|x|x|x|x|x|  ^
        |x|x|x|x|x|x|x|x|x|x|  |
        |x|x|x|x|x|x|x|x|x|x|  |                        y     x
        |x|x|x|x|x|x|x|x|x|x| +ve  regular_grid[0] = [0.5,  -1.5]
        |x|x|x|0|1|x|x|x|x|x|  y   regular_grid[1] = [0.5,  -0.5]
        |x|x|x|x|x|x|x|x|x|x| -ve
        |x|x|x|x|x|x|x|x|x|x|  |
        |x|x|x|x|x|x|x|x|x|x|  |
        |x|x|x|x|x|x|x|x|x|x| \/
        |x|x|x|x|x|x|x|x|x|x|

        However, we now go to each unmasked pixel and derive a sub-pixel grid for it. For example, for pixel 0,
        if *sub_grid_size=2*, we use a 2x2 sub-grid:

        Pixel 0 - (2x2):
                                y      x
               sub_grid[0] = [0.66, -1.66]
        |0|1|  sub_grid[1] = [0.66, -1.33]
        |2|3|  sub_grid[2] = [0.33, -1.66]
               sub_grid[3] = [0.33, -1.33]

        Now, we'd normally sub-grid all pixels using the same *sub_grid_size*, but for this illustration lets
        pretend we used a sub_grid_size of 3x3 for pixel 1:

                                  y      x
                 sub_grid[0] = [0.75, -0.75]
                 sub_grid[1] = [0.75, -0.5]
                 sub_grid[2] = [0.75, -0.25]
        |0|1|2|  sub_grid[3] = [0.5,  -0.75]
        |3|4|5|  sub_grid[4] = [0.5,  -0.5]
        |6|7|8|  sub_grid[5] = [0.5,  -0.25]
                 sub_grid[6] = [0.25, -0.75]
                 sub_grid[7] = [0.25, -0.5]
                 sub_grid[8] = [0.25, -0.25]


border = arr.view(cls)<EOL>return border<EOL>

The borders of a regular grid, containing the pixel-index's of all masked pixels that are on the \
        mask's border (e.g. they are next to a *True* value in at least one of the surrounding 8 pixels and at one of \
        the exterior edge's of the mask).

        This is used to relocate demagnified pixel's in a grid to its border, so that they do not disrupt an \
        adaptive pixelization's inversion.

        Parameters
        -----------
        arr : ndarray
            A 1D array of the integer indexes of an *RegularGrid*'s borders pixels.


@wraps(func)<EOL>def wrapper(grid, galaxies, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>result = func(grid, galaxies, *args, *kwargs)<EOL>if isinstance(grid, SubGrid):<EOL><INDENT>return grid.regular_data_1d_from_sub_data_1d(result)<EOL><DEDENT>else:<EOL><INDENT>return result<EOL><DEDENT><DEDENT>return wrapper<EOL>

Wrap the function in a function that, if the grid is a sub-grid (grids.SubGrid), rebins the computed \
values to the sub-grids corresponding regular-grid by taking the mean of each set of sub-gridded values.

Parameters
----------
func : (profiles, *args, **kwargs) -> Object
    A function that requires the sub-grid and galaxies.


@wraps(func)<EOL>def wrapper(profile, grid, grid_radial_minimum=None, *args, **kwargs):<EOL><INDENT>if hasattr(grid, "<STR_LIT>"):<EOL><INDENT>interpolator = grid.interpolator<EOL>if grid.interpolator is not None:<EOL><INDENT>values = func(profile, interpolator.interp_grid, grid_radial_minimum, *args, **kwargs)<EOL>if values.ndim == <NUM_LIT:1>:<EOL><INDENT>return interpolator.interpolated_values_from_values(values=values)<EOL><DEDENT>elif values.ndim == <NUM_LIT:2>:<EOL><INDENT>y_values = interpolator.interpolated_values_from_values(values=values[:, <NUM_LIT:0>])<EOL>x_values = interpolator.interpolated_values_from_values(values=values[:, <NUM_LIT:1>])<EOL>return np.asarray([y_values, x_values]).T<EOL><DEDENT><DEDENT><DEDENT>return func(profile, grid, grid_radial_minimum, *args, **kwargs)<EOL><DEDENT>return wrapper<EOL>

Decorate a profile method that accepts a coordinate grid and returns a data grid.

If an interpolator attribute is associated with the input grid then that interpolator is used to down sample the
coordinate grid prior to calling the function and up sample the result of the function.

If no interpolator attribute is associated with the input grid then the function is called as normal.

Parameters
----------
func
    Some method that accepts a grid

Returns
-------
decorated_function
    The function with optional interpolation


@classmethod<EOL><INDENT>def from_shape_pixel_scale_and_sub_grid_size(cls, shape, pixel_scale, sub_grid_size=<NUM_LIT:2>):<DEDENT>

regular_grid = RegularGrid.from_shape_and_pixel_scale(shape=shape, pixel_scale=pixel_scale)<EOL>sub_grid = SubGrid.from_shape_pixel_scale_and_sub_grid_size(shape=shape, pixel_scale=pixel_scale,<EOL>sub_grid_size=sub_grid_size)<EOL>blurring_grid = np.array([[<NUM_LIT:0.0>, <NUM_LIT:0.0>]])<EOL>return GridStack(regular_grid, sub_grid, blurring_grid)<EOL>

Setup a grid-stack of grid_stack from a 2D array shape, a pixel scale and a sub-grid size.

        This grid corresponds to a fully unmasked 2D array.

        Parameters
        -----------
        shape : (int, int)
            The 2D shape of the array, where all pixels are used to generate the grid-stack's grid_stack.
        pixel_scale : float
            The size of each pixel in arc seconds.
        sub_grid_size : int
            The size of a sub-pixel's sub-grid (sub_grid_size x sub_grid_size).


def __new__(cls, arr, mask, *args, **kwargs):

obj = arr.view(cls)<EOL>obj.mask = mask<EOL>obj.interpolator = None<EOL>return obj<EOL>

A regular grid of coordinates, where each entry corresponds to the (y,x) coordinates at the centre of an \
        unmasked pixel. The positive y-axis is upwards and poitive x-axis to the right.

        A *RegularGrid* is ordered such pixels begin from the top-row of the mask and go rightwards and then \
        downwards. Therefore, it is a ndarray of shape [total_unmasked_pixels, 2]. The first element of the ndarray \
        thus corresponds to the regular pixel index and second element the y or x arc -econd coordinates. For example:

        - regular_grid[3,0] = the 4th unmasked pixel's y-coordinate.
        - regular_grid[6,1] = the 7th unmasked pixel's x-coordinate.

        Below is a visual illustration of a regular-grid, where a total of 10 pixels are unmasked and are included in \
        the grid.

        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|     This is an example mask.Mask, where:
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|o|o|x|x|x|x|     x = True (Pixel is masked and excluded from the regular grid)
        |x|x|x|o|o|o|o|x|x|x|     o = False (Pixel is not masked and included in the regular grid)
        |x|x|x|o|o|o|o|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|
        |x|x|x|x|x|x|x|x|x|x|

        The mask pixel index's will come out like this (and the direction of arc-second coordinates is highlighted
        around the mask.

        pixel_scale = 1.0"

        <--- -ve  x  +ve -->
                                                        y      x
        |x|x|x|x|x|x|x|x|x|x|  ^   regular_grid[0] = [ 1.5, -0.5]
        |x|x|x|x|x|x|x|x|x|x|  |   regular_grid[1] = [ 1.5,  0.5]
        |x|x|x|x|x|x|x|x|x|x|  |   regular_grid[2] = [ 0.5, -1.5]
        |x|x|x|x|0|1|x|x|x|x| +ve  regular_grid[3] = [ 0.5, -0.5]
        |x|x|x|2|3|4|5|x|x|x|  y   regular_grid[4] = [ 0.5,  0.5]
        |x|x|x|6|7|8|9|x|x|x| -ve  regular_grid[5] = [ 0.5,  1.5]
        |x|x|x|x|x|x|x|x|x|x|  |   regular_grid[6] = [-0.5, -1.5]
        |x|x|x|x|x|x|x|x|x|x|  |   regular_grid[7] = [-0.5, -0.5]
        |x|x|x|x|x|x|x|x|x|x| \/   regular_grid[8] = [-0.5,  0.5]
        |x|x|x|x|x|x|x|x|x|x|      regular_grid[9] = [-0.5,  1.5]


def map_function(self, func, *arg_lists):

return GridStack(*[func(*args) for args in zip(self, *arg_lists)])<EOL>

Map a function to all grid_stack in a grid-stack


def new_grid_stack_with_pix_grid_added(self, pix_grid, regular_to_nearest_pix):

pix = PixGrid(arr=pix_grid, regular_to_nearest_pix=regular_to_nearest_pix)<EOL>return GridStack(regular=self.regular, sub=self.sub, blurring=self.blurring, pix=pix)<EOL>

Setup a grid-stack of grid_stack using an existing grid-stack.

        The new grid-stack has the same grid_stack (regular, sub, blurring, etc.) as before, but adds a pix-grid as a \
        new attribute.

        Parameters
        -----------
        pix_grid : ndarray
            The grid of (y,x) arc-second coordinates of every image-plane pixelization grid used for adaptive \
             pixelizations.
        regular_to_nearest_pix : ndarray
            A 1D array that maps every regular-grid pixel to its nearest pix-grid pixel.


return np.linspace(np.min(self[:, <NUM_LIT:0>]), np.max(self[:, <NUM_LIT:0>]), <NUM_LIT:4>)<EOL>

Compute the yticks labels of this grid, used for plotting the y-axis ticks when visualizing a regular


Map a 1D sub-array the same dimension as the sub-grid to its original masked 2D sub-array and return it as
        a scaled array.

        Parameters
        -----------
        sub_array_1d : ndarray
            The 1D sub-array of which is mapped to a 2D scaled sub-array the dimensions.


return mapping_util.map_masked_1d_array_to_2d_array_from_array_1d_shape_and_one_to_two(<EOL>array_1d=array_1d, shape=self.mask.shape, one_to_two=self.mask.masked_grid_index_to_pixel)<EOL>

Map a 1D array the same dimension as the grid to its original masked 2D array.

        Parameters
        -----------
        array_1d : ndarray
            The 1D array which is mapped to its masked 2D array.


return mapping_util.sub_to_regular_from_mask(self.mask, self.sub_grid_size).astype('<STR_LIT:int>')<EOL>

The mapping between every sub-pixel and its host regular-pixel.

        For example:

        - sub_to_pixel[8] = 2 -  The ninth sub-pixel is within the 3rd regular pixel.
        - sub_to_pixel[20] = 4 -  The twenty first sub-pixel is within the 5th regular pixel.


@classmethod<EOL><INDENT>def from_shape_and_pixel_scale(cls, shape, pixel_scale):<DEDENT>

mask = msk.Mask.unmasked_for_shape_and_pixel_scale(shape=shape, pixel_scale=pixel_scale)<EOL>array = grid_util.regular_grid_1d_masked_from_mask_pixel_scales_and_origin(mask=mask,<EOL>pixel_scales=mask.pixel_scales)<EOL>return cls(array, mask)<EOL>

Setup a regular-grid from a 2D array shape and pixel scale. Here, the center of every pixel on the 2D \
        array gives the grid's (y,x) arc-second coordinates.

        This is equivalent to using a 2D mask consisting entirely of unmasked pixels.

        Parameters
        -----------
        shape : (int, int)
            The 2D shape of the array, where all pixels are used to generate the grid-stack's grid_stack.
        pixel_scale : float
            The size of each pixel in arc seconds.


sub_shape = (self.mask.shape[<NUM_LIT:0>] * self.sub_grid_size, self.mask.shape[<NUM_LIT:1>] * self.sub_grid_size)<EOL>sub_one_to_two = self.mask.masked_sub_grid_index_to_sub_pixel(sub_grid_size=self.sub_grid_size)<EOL>return mapping_util.map_masked_1d_array_to_2d_array_from_array_1d_shape_and_one_to_two(<EOL>array_1d=sub_array_1d, shape=sub_shape, one_to_two=sub_one_to_two)<EOL>

Map a 1D sub-array the same dimension as the sub-grid (e.g. including sub-pixels) to its original masked
        2D sub array.

        Parameters
        -----------
        sub_array_1d : ndarray
            The 1D sub_array which is mapped to its masked 2D sub-array.


@classmethod<EOL><INDENT>def padded_grid_stack_from_mask_sub_grid_size_and_psf_shape(cls, mask, sub_grid_size, psf_shape):<DEDENT>

regular_padded_grid = PaddedRegularGrid.padded_grid_from_shape_psf_shape_and_pixel_scale(<EOL>shape=mask.shape,<EOL>psf_shape=psf_shape,<EOL>pixel_scale=mask.pixel_scale)<EOL>sub_padded_grid = PaddedSubGrid.padded_grid_from_mask_sub_grid_size_and_psf_shape(mask=mask,<EOL>sub_grid_size=sub_grid_size,<EOL>psf_shape=psf_shape)<EOL>return GridStack(regular=regular_padded_grid, sub=sub_padded_grid, blurring=np.array([[<NUM_LIT:0.0>, <NUM_LIT:0.0>]]))<EOL>

Setup a grid-stack of masked grid_stack from a mask,  sub-grid size and psf-shape.

        Parameters
        -----------
        mask : Mask
            The mask whose masked pixels the grid-stack are setup using.
        sub_grid_size : int
            The size of a sub-pixels sub-grid (sub_grid_size x sub_grid_size).
        psf_shape : (int, int)
            The shape of the PSF used in the analysis, which defines the mask's blurring-region.


return mapping_util.map_unmasked_1d_array_to_2d_array_from_array_1d_and_shape(array_1d=padded_array_1d,<EOL>shape=self.mask.shape)<EOL>

Map a padded 1D array of values to its padded 2D array.

        Parameters
        -----------
        padded_array_1d : ndarray
            A 1D array of values which were computed using the *PaddedRegularGrid*.


def __init__(self, array, pixel_scale, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

<EOL>super(Mask, self).__init__(array=array, pixel_scale=pixel_scale, origin=origin)<EOL>

A mask, which is applied to a 2D array of hyper to extract a set of unmasked image pixels (i.e. mask entry \
        is *False* or 0) which are then fitted in an analysis.

        The mask retains the pixel scale of the array and has a centre and origin.

        Parameters
        ----------
        array: ndarray
            An array of bools representing the mask.
        pixel_scale: float
            The arc-second to pixel conversion factor of each pixel.
        origin : (float, float)
            The (y,x) arc-second origin of the mask's coordinate system.
        centre : (float, float)
            The (y,x) arc-second centre of the mask provided it is a standard geometric shape (e.g. a circle).


return mask_util.masked_grid_1d_index_to_2d_pixel_index_from_mask(self).astype('<STR_LIT:int>')<EOL>

A 1D array of mappings between every unmasked pixel and its 2D pixel coordinates.


if array_2d is None or isinstance(array_2d, float):<EOL><INDENT>return array_2d<EOL><DEDENT>return mapping_util.map_2d_array_to_masked_1d_array_from_array_2d_and_mask(self, array_2d)<EOL>

For a 2D array (e.g. an image, noise_map, etc.) map it to a masked 1D array of valuees using this mask.

        Parameters
        ----------
        array_2d : ndarray | None | float
            The 2D array to be mapped to a masked 1D array.


@classmethod<EOL><INDENT>def circular(cls, shape, pixel_scale, radius_arcsec, centre=(<NUM_LIT:0.>, <NUM_LIT:0.>), invert=False):<DEDENT>

mask = mask_util.mask_circular_from_shape_pixel_scale_and_radius(shape, pixel_scale, radius_arcsec,<EOL>centre)<EOL>if invert: mask = np.invert(mask)<EOL>return cls(array=mask.astype('<STR_LIT:bool>'), pixel_scale=pixel_scale)<EOL>

Setup a mask where unmasked pixels are within a circle of an input arc second radius and centre.

        Parameters
        ----------
        shape: (int, int)
            The (y,x) shape of the mask in units of pixels.
        pixel_scale: float
            The arc-second to pixel conversion factor of each pixel.
        radius_arcsec : float
            The radius (in arc seconds) of the circle within which pixels unmasked.
        centre: (float, float)
            The centre of the circle used to mask pixels.


return mask_util.border_pixels_from_mask(self).astype('<STR_LIT:int>')<EOL>

The indicies of the mask's border pixels, where a border pixel is any unmasked pixel on an
        exterior edge (e.g. next to at least one pixel with a *True* value but not central pixels like those within \
        an annulus mask).


@classmethod<EOL><INDENT>def circular_annular(cls, shape, pixel_scale, inner_radius_arcsec, outer_radius_arcsec, centre=(<NUM_LIT:0.>, <NUM_LIT:0.>),<EOL>invert=False):<DEDENT>

mask = mask_util.mask_circular_annular_from_shape_pixel_scale_and_radii(shape, pixel_scale, inner_radius_arcsec,<EOL>outer_radius_arcsec, centre)<EOL>if invert: mask = np.invert(mask)<EOL>return cls(array=mask.astype('<STR_LIT:bool>'), pixel_scale=pixel_scale)<EOL>

Setup a mask where unmasked pixels are within an annulus of input inner and outer arc second radii and \
         centre.

        Parameters
        ----------
        shape : (int, int)
            The (y,x) shape of the mask in units of pixels.
        pixel_scale: float
            The arc-second to pixel conversion factor of each pixel.
        inner_radius_arcsec : float
            The radius (in arc seconds) of the inner circle outside of which pixels are unmasked.
        outer_radius_arcsec : float
            The radius (in arc seconds) of the outer circle within which pixels are unmasked.
        centre: (float, float)
            The centre of the annulus used to mask pixels.


<EOL>where = np.array(np.where(np.invert(self.astype('<STR_LIT:bool>'))))<EOL>y0, x0 = np.amin(where, axis=<NUM_LIT:1>)<EOL>y1, x1 = np.amax(where, axis=<NUM_LIT:1>)<EOL>return [y0, y1+<NUM_LIT:1>, x0, x1+<NUM_LIT:1>]<EOL>

The zoomed rectangular region corresponding to the square encompassing all unmasked values.

        This is used to zoom in on the region of an image that is used in an analysis for visualization.


if psf_shape[<NUM_LIT:0>] % <NUM_LIT:2> == <NUM_LIT:0> or psf_shape[<NUM_LIT:1>] % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>raise exc.MaskException("<STR_LIT>")<EOL><DEDENT>blurring_mask = mask_util.mask_blurring_from_mask_and_psf_shape(self, psf_shape)<EOL>return Mask(blurring_mask, self.pixel_scale)<EOL>

Compute a blurring mask, which represents all masked pixels whose light will be blurred into unmasked \
        pixels via PSF convolution (see grid_stack.RegularGrid.blurring_grid_from_mask_and_psf_shape).

        Parameters
        ----------
        psf_shape : (int, int)
           The shape of the psf which defines the blurring region (e.g. the shape of the PSF)


return mask_util.edge_pixels_from_mask(self).astype('<STR_LIT:int>')<EOL>

The indicies of the mask's edge pixels, where an edge pixel is any unmasked pixel on its edge \
        (next to at least one pixel with a *True* value).


@classmethod<EOL><INDENT>def circular_anti_annular(cls, shape, pixel_scale, inner_radius_arcsec, outer_radius_arcsec, outer_radius_2_arcsec,<EOL>centre=(<NUM_LIT:0.>, <NUM_LIT:0.>), invert=False):<DEDENT>

mask = mask_util.mask_circular_anti_annular_from_shape_pixel_scale_and_radii(shape, pixel_scale, inner_radius_arcsec,<EOL>outer_radius_arcsec,<EOL>outer_radius_2_arcsec, centre)<EOL>if invert: mask = np.invert(mask)<EOL>return cls(array=mask.astype('<STR_LIT:bool>'), pixel_scale=pixel_scale)<EOL>

Setup a mask where unmasked pixels are outside an annulus of input inner and outer arc second radii, but \
        within a second outer radius, and at a given centre.

        This mask there has two distinct unmasked regions (an inner circle and outer annulus), with an inner annulus \
        of masked pixels.

        Parameters
        ----------
        shape : (int, int)
            The (y,x) shape of the mask in units of pixels.
        pixel_scale: float
            The arc-second to pixel conversion factor of each pixel.
        inner_radius_arcsec : float
            The radius (in arc seconds) of the inner circle inside of which pixels are unmasked.
        outer_radius_arcsec : float
            The radius (in arc seconds) of the outer circle within which pixels are masked and outside of which they \
            are unmasked.
        outer_radius_2_arcsec : float
            The radius (in arc seconds) of the second outer circle within which pixels are unmasked and outside of \
            which they masked.
        centre: (float, float)
            The centre of the anti-annulus used to mask pixels.


@decorator_util.jit()<EOL>def centres_from_shape_pixel_scales_and_origin(shape, pixel_scales, origin):

y_centre_arcsec = float(shape[<NUM_LIT:0>] - <NUM_LIT:1>) / <NUM_LIT:2> + (origin[<NUM_LIT:0>] / pixel_scales[<NUM_LIT:0>])<EOL>x_centre_arcsec = float(shape[<NUM_LIT:1>] - <NUM_LIT:1>) / <NUM_LIT:2> - (origin[<NUM_LIT:1>] / pixel_scales[<NUM_LIT:1>])<EOL>return (y_centre_arcsec, x_centre_arcsec)<EOL>

Determine the (y,x) arc-second central coordinates of an array from its shape, pixel-scales and origin.

     The coordinate system is defined such that the positive y axis is up and positive x axis is right.

    Parameters
     ----------
    shape : (int, int)
        The (y,x) shape of the 2D array the arc-second centre is computed for.
    pixel_scales : (float, float)
        The (y,x) arc-second to pixel scales of the 2D array.
    origin : (float, flloat)
        The (y,x) origin of the 2D array, which the centre is shifted to.

    Returns
    --------
    tuple (float, float)
        The (y,x) arc-second central coordinates of the input array.

    Examples
    --------
    centres_arcsec = centres_from_shape_pixel_scales_and_origin(shape=(5,5), pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))


@decorator_util.jit()<EOL>def grid_arcsec_1d_to_grid_pixel_centres_1d(grid_arcsec_1d, shape, pixel_scales, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

grid_pixels_1d = np.zeros((grid_arcsec_1d.shape[<NUM_LIT:0>], <NUM_LIT:2>))<EOL>centres_arcsec = centres_from_shape_pixel_scales_and_origin(shape=shape, pixel_scales=pixel_scales, origin=origin)<EOL>for i in range(grid_arcsec_1d.shape[<NUM_LIT:0>]):<EOL><INDENT>grid_pixels_1d[i, <NUM_LIT:0>] = int((-grid_arcsec_1d[i, <NUM_LIT:0>] / pixel_scales[<NUM_LIT:0>]) + centres_arcsec[<NUM_LIT:0>] + <NUM_LIT:0.5>)<EOL>grid_pixels_1d[i, <NUM_LIT:1>] = int((grid_arcsec_1d[i, <NUM_LIT:1>] / pixel_scales[<NUM_LIT:1>]) + centres_arcsec[<NUM_LIT:1>] + <NUM_LIT:0.5>)<EOL><DEDENT>return grid_pixels_1d<EOL>

Convert a grid of (y,x) arc second coordinates to a grid of (y,x) pixel values. Pixel coordinates are \
    returned as integers such that they map directly to the pixel they are contained within.

    The pixel coordinate origin is at the top left corner of the grid, such that the pixel [0,0] corresponds to \
    higher y arc-second coordinate value and lowest x arc-second coordinate.

    The arc-second coordinate grid is defined by the class attribute origin, and coordinates are shifted to this \
    origin before computing their 1D grid pixel indexes.

    The input and output grids are both of shape (total_pixels, 2).

    Parameters
    ----------
    grid_arcsec_1d: ndarray
        The grid of (y,x) coordinates in arc seconds which is converted to pixel indexes.
    shape : (int, int)
        The (y,x) shape of the original 2D array the arc-second coordinates were computed on.
    pixel_scales : (float, float)
        The (y,x) arc-second to pixel scales of the original 2D array.
    origin : (float, flloat)
        The (y,x) origin of the grid, which the arc-second grid is shifted

    Returns
    --------
    ndarray
        A grid of (y,x) pixel indexes with dimensions (total_pixels, 2).

    Examples
    --------
    grid_arcsec_1d = np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0]])
    grid_pixels_1d = grid_arcsec_1d_to_grid_pixel_centres_1d(grid_arcsec_1d=grid_arcsec_1d, shape=(2,2),
                                                           pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))


@decorator_util.jit()<EOL>def grid_arcsec_1d_to_grid_pixel_indexes_1d(grid_arcsec_1d, shape, pixel_scales, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

grid_pixels_1d = grid_arcsec_1d_to_grid_pixel_centres_1d(grid_arcsec_1d=grid_arcsec_1d, shape=shape,<EOL>pixel_scales=pixel_scales, origin=origin)<EOL>grid_pixel_indexes_1d = np.zeros(grid_pixels_1d.shape[<NUM_LIT:0>])<EOL>for i in range(grid_pixels_1d.shape[<NUM_LIT:0>]):<EOL><INDENT>grid_pixel_indexes_1d[i] = int(grid_pixels_1d[i,<NUM_LIT:0>] * shape[<NUM_LIT:1>] + grid_pixels_1d[i,<NUM_LIT:1>])<EOL><DEDENT>return grid_pixel_indexes_1d<EOL>

Convert a grid of (y,x) arc second coordinates to a grid of (y,x) pixel 1D indexes. Pixel coordinates are \
    returned as integers such that they are the pixel from the top-left of the 2D grid going rights and then \
    downwards.

    For example:

    The pixel at the top-left, whose 2D index is [0,0], corresponds to 1D index 0.
    The fifth pixel on the top row, whose 2D index is [0,5], corresponds to 1D index 4.
    The first pixel on the second row, whose 2D index is [0,1], has 1D index 10 if a row has 10 pixels.

    The arc-second coordinate grid is defined by the class attribute origin, and coordinates are shifted to this \
    origin before computing their 1D grid pixel indexes.

    The input and output grids are both of shape (total_pixels, 2).

    Parameters
    ----------
    grid_arcsec_1d: ndarray
        The grid of (y,x) coordinates in arc seconds which is converted to 1D pixel indexes.
    shape : (int, int)
        The (y,x) shape of the original 2D array the arc-second coordinates were computed on.
    pixel_scales : (float, float)
        The (y,x) arc-second to pixel scales of the original 2D array.
    origin : (float, flloat)
        The (y,x) origin of the grid, which the arc-second grid is shifted.

    Returns
    --------
    ndarray
        A grid of 1d pixel indexes with dimensions (total_pixels, 2).

    Examples
    --------
    grid_arcsec_1d = np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0]])
    grid_pixels_1d = grid_arcsec_1d_to_grid_pixel_indexes_1d(grid_arcsec_1d=grid_arcsec_1d, shape=(2,2),
                                                           pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))


@decorator_util.jit()<EOL>def regular_grid_1d_masked_from_mask_pixel_scales_and_origin(mask, pixel_scales, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

grid_2d = regular_grid_2d_from_shape_pixel_scales_and_origin(mask.shape, pixel_scales, origin)<EOL>total_regular_pixels = mask_util.total_regular_pixels_from_mask(mask)<EOL>regular_grid_1d = np.zeros(shape=(total_regular_pixels, <NUM_LIT:2>))<EOL>pixel_count = <NUM_LIT:0><EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[y, x]:<EOL><INDENT>regular_grid_1d[pixel_count, :] = grid_2d[y, x]<EOL>pixel_count += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return regular_grid_1d<EOL>

Compute the (y,x) arc second coordinates at the centre of every pixel of a 2D mask array of shape (rows, columns).

    Coordinates are defined from the top-left corner, where the first unmasked pixel corresponds to index 0. The pixel \
    at the top-left of the array has negative x and y values in arc seconds.

    The regular grid is returned on an array of shape (total_unmasked_pixels, 2). y coordinates are stored in the 0 \
    index of the second dimension, x coordinates in the 1 index.

    Parameters
     ----------
    mask : ndarray
        A 2D array of bools, where *False* values mean unmasked and are therefore included as part of the calculated \
        regular grid.
    pixel_scales : (float, float)
        The (y,x) arc-second to pixel scales of the 2D mask array.
    origin : (float, flloat)
        The (y,x) origin of the 2D array, which the regular grid is shifted around.

    Returns
    --------
    ndarray
        A regular grid of (y,x) arc-second coordinates at the centre of every pixel unmasked pixel on the 2D mask \
        array. The regular grid array has dimensions (total_unmasked_pixels, 2).

    Examples
    --------
    mask = np.array([[True, False, True],
                     [False, False, False]
                     [True, False, True]])
    regular_grid_1d = regular_grid_1d_masked_from_mask_pixel_scales_and_origin(mask=mask, pixel_scales=(0.5, 0.5),
                                                                            origin=(0.0, 0.0))


@decorator_util.jit()<EOL>def grid_arcsec_2d_to_grid_pixel_centres_2d(grid_arcsec_2d, shape, pixel_scales, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

grid_pixels_2d = np.zeros((grid_arcsec_2d.shape[<NUM_LIT:0>], grid_arcsec_2d.shape[<NUM_LIT:1>], <NUM_LIT:2>))<EOL>centres_arcsec = centres_from_shape_pixel_scales_and_origin(shape=shape, pixel_scales=pixel_scales, origin=origin)<EOL>for y in range(grid_arcsec_2d.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(grid_arcsec_2d.shape[<NUM_LIT:1>]):<EOL><INDENT>grid_pixels_2d[y, x, <NUM_LIT:0>] = int((-grid_arcsec_2d[y, x, <NUM_LIT:0>] / pixel_scales[<NUM_LIT:0>]) + centres_arcsec[<NUM_LIT:0>] + <NUM_LIT:0.5>)<EOL>grid_pixels_2d[y, x, <NUM_LIT:1>] = int((grid_arcsec_2d[y, x, <NUM_LIT:1>] / pixel_scales[<NUM_LIT:1>]) + centres_arcsec[<NUM_LIT:1>] + <NUM_LIT:0.5>)<EOL><DEDENT><DEDENT>return grid_pixels_2d<EOL>


@decorator_util.jit()<EOL>def grid_arcsec_1d_to_grid_pixels_1d(grid_arcsec_1d, shape, pixel_scales, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

grid_pixels_1d = np.zeros((grid_arcsec_1d.shape[<NUM_LIT:0>], <NUM_LIT:2>))<EOL>centres_arcsec = centres_from_shape_pixel_scales_and_origin(shape=shape, pixel_scales=pixel_scales, origin=origin)<EOL>for i in range(grid_arcsec_1d.shape[<NUM_LIT:0>]):<EOL><INDENT>grid_pixels_1d[i, <NUM_LIT:0>] = (-grid_arcsec_1d[i, <NUM_LIT:0>] / pixel_scales[<NUM_LIT:0>]) + centres_arcsec[<NUM_LIT:0>] + <NUM_LIT:0.5><EOL>grid_pixels_1d[i, <NUM_LIT:1>] = (grid_arcsec_1d[i, <NUM_LIT:1>] / pixel_scales[<NUM_LIT:1>]) + centres_arcsec[<NUM_LIT:1>] + <NUM_LIT:0.5><EOL><DEDENT>return grid_pixels_1d<EOL>

Convert a grid of (y,x) arc second coordinates to a grid of (y,x) pixel coordinate values. Pixel coordinates \
    are returned as floats such that they include the decimal offset from each pixel's top-left corner relative to \
    the input arc-second coordinate.

    The pixel coordinate origin is at the top left corner of the grid, such that the pixel [0,0] corresponds to \
    the highest y arc-second coordinate and lowest x arc-second coordinate on the gird.

    The arc-second grid is defined by an origin and coordinates are shifted to this origin before computing their \
    1D grid pixel coordinate values.

    The input and output grids are both of shape (total_pixels, 2).

    Parameters
    ----------
    grid_arcsec_1d: ndarray
        The grid of (y,x) coordinates in arc seconds which is converted to pixel value coordinates.
    shape : (int, int)
        The (y,x) shape of the original 2D array the arc-second coordinates were computed on.
    pixel_scales : (float, float)
        The (y,x) arc-second to pixel scales of the original 2D array.
    origin : (float, flloat)
        The (y,x) origin of the grid, which the arc-second grid is shifted to.

    Returns
    --------
    ndarray
        A grid of (y,x) pixel-value coordinates with dimensions (total_pixels, 2).

    Examples
    --------
    grid_arcsec_1d = np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0]])
    grid_pixels_1d = grid_arcsec_1d_to_grid_pixels_1d(grid_arcsec_1d=grid_arcsec_1d, shape=(2,2),
                                                           pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))


@decorator_util.jit()<EOL>def extracted_array_2d_from_array_2d_and_coordinates(array_2d, y0, y1, x0, x1):

new_shape = (y1-y0, x1-x0)<EOL>resized_array = np.zeros(shape=new_shape)<EOL>for y_resized, y in enumerate(range(y0, y1)):<EOL><INDENT>for x_resized, x in enumerate(range(x0, x1)):<EOL><INDENT>resized_array[y_resized, x_resized] = array_2d[y, x]<EOL><DEDENT><DEDENT>return resized_array<EOL>

Resize an array to a new size by extracting a sub-set of the array.

    The extracted input coordinates use NumPy convention, such that the upper values should be specified as +1 the \
    dimensions of the extracted array.

    In the example below, an array of size (5,5) is extracted using the coordinates y0=1, y1=4, x0=1, x1=4. This
    extracts an array of dimensions (2,2) and is equivalent to array_2d[1:4, 1:4]

    Parameters
    ----------
    array_2d : ndarray
        The 2D array that is an array is extracted from.
    y0 : int
        The lower row number (e.g. the higher y-coodinate) of the array that is extracted for the resize.
    y1 : int
        The upper row number (e.g. the lower y-coodinate) of the array that is extracted for the resize.
    x0 : int
        The lower column number (e.g. the lower x-coodinate) of the array that is extracted for the resize.
    x1 : int
        The upper column number (e.g. the higher x-coodinate) of the array that is extracted for the resize.

    Returns
    -------
    ndarray
        The extracted 2D array from the input 2D array.

    Examples
    --------
    array_2d = np.ones((5,5))
    extracted_array = extract_array_2d(array_2d=array_2d, y0=1, y1=4, x0=1, x1=4)


@decorator_util.jit()<EOL>def resized_array_2d_from_array_2d_and_resized_shape(array_2d, resized_shape, origin=(-<NUM_LIT:1>, -<NUM_LIT:1>), pad_value=<NUM_LIT:0.0>):

y_is_even = int(array_2d.shape[<NUM_LIT:0>]) % <NUM_LIT:2> == <NUM_LIT:0><EOL>x_is_even = int(array_2d.shape[<NUM_LIT:1>]) % <NUM_LIT:2> == <NUM_LIT:0><EOL>if origin is (-<NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>if y_is_even:<EOL><INDENT>y_centre = int(array_2d.shape[<NUM_LIT:0>] / <NUM_LIT:2>)<EOL><DEDENT>elif not y_is_even:<EOL><INDENT>y_centre = int(array_2d.shape[<NUM_LIT:0>] / <NUM_LIT:2>)<EOL><DEDENT>if x_is_even:<EOL><INDENT>x_centre = int(array_2d.shape[<NUM_LIT:1>] / <NUM_LIT:2>)<EOL><DEDENT>elif not x_is_even:<EOL><INDENT>x_centre = int(array_2d.shape[<NUM_LIT:1>] / <NUM_LIT:2>)<EOL><DEDENT>origin = (y_centre, x_centre)<EOL><DEDENT>resized_array = np.zeros(shape=resized_shape)<EOL>if y_is_even:<EOL><INDENT>y_min = origin[<NUM_LIT:0>] - int(resized_shape[<NUM_LIT:0>] / <NUM_LIT:2>)<EOL>y_max = origin[<NUM_LIT:0>] + int((resized_shape[<NUM_LIT:0>] / <NUM_LIT:2>)) + <NUM_LIT:1><EOL><DEDENT>elif not y_is_even:<EOL><INDENT>y_min = origin[<NUM_LIT:0>] - int(resized_shape[<NUM_LIT:0>] / <NUM_LIT:2>)<EOL>y_max = origin[<NUM_LIT:0>] + int((resized_shape[<NUM_LIT:0>] / <NUM_LIT:2>)) + <NUM_LIT:1><EOL><DEDENT>if x_is_even:<EOL><INDENT>x_min = origin[<NUM_LIT:1>] - int(resized_shape[<NUM_LIT:1>] / <NUM_LIT:2>)<EOL>x_max = origin[<NUM_LIT:1>] + int((resized_shape[<NUM_LIT:1>] / <NUM_LIT:2>)) + <NUM_LIT:1><EOL><DEDENT>elif not x_is_even:<EOL><INDENT>x_min = origin[<NUM_LIT:1>] - int(resized_shape[<NUM_LIT:1>] / <NUM_LIT:2>)<EOL>x_max = origin[<NUM_LIT:1>] + int((resized_shape[<NUM_LIT:1>] / <NUM_LIT:2>)) + <NUM_LIT:1><EOL><DEDENT>for y_resized, y in enumerate(range(y_min, y_max)):<EOL><INDENT>for x_resized, x in enumerate(range(x_min, x_max)):<EOL><INDENT>if y >= <NUM_LIT:0> and y < array_2d.shape[<NUM_LIT:0>] and x >= <NUM_LIT:0> and x < array_2d.shape[<NUM_LIT:1>]:<EOL><INDENT>if y_resized >= <NUM_LIT:0> and y_resized < resized_shape[<NUM_LIT:0>] and x_resized >= <NUM_LIT:0> and x_resized < resized_shape[<NUM_LIT:1>]:<EOL><INDENT>resized_array[y_resized, x_resized] = array_2d[y, x]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if y_resized >= <NUM_LIT:0> and y_resized < resized_shape[<NUM_LIT:0>] and x_resized >= <NUM_LIT:0> and x_resized < resized_shape[<NUM_LIT:1>]:<EOL><INDENT>resized_array[y_resized, x_resized] = pad_value<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return resized_array<EOL>

Resize an array to a new size around a central pixel.

    If the origin (e.g. the central pixel) of the resized array is not specified, the central pixel of the array is \
    calculated automatically. For example, a (5,5) array's central pixel is (2,2). For even dimensions the central \
    pixel is assumed to be the lower indexed value, e.g. a (6,4) array's central pixel is calculated as (2,1).

    The default origin is (-1, -1) because numba requires that the function input is the same type throughout the \
    function, thus a default 'None' value cannot be used.

    Parameters
    ----------
    array_2d : ndarray
        The 2D array that is resized.
    resized_shape : (int, int)
        The (y,x) new pixel dimension of the trimmed array.
    origin : (int, int)
        The oigin of the resized array, e.g. the central pixel around which the array is extracted.

    Returns
    -------
    ndarray
        The resized 2D array from the input 2D array.

    Examples
    --------
    array_2d = np.ones((5,5))
    resize_array = resize_array_2d(array_2d=array_2d, new_shape=(2,2), origin=(2, 2))


padded_array_2d = pad_2d_array_for_binning_up_with_bin_up_factor(array_2d=array_2d, bin_up_factor=bin_up_factor)<EOL>binned_array_2d = np.zeros(shape=(padded_array_2d.shape[<NUM_LIT:0>] // bin_up_factor,<EOL>padded_array_2d.shape[<NUM_LIT:1>] // bin_up_factor))<EOL>for y in range(binned_array_2d.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(binned_array_2d.shape[<NUM_LIT:1>]):<EOL><INDENT>value = <NUM_LIT:0.0><EOL>for y1 in range(bin_up_factor):<EOL><INDENT>for x1 in range(bin_up_factor):<EOL><INDENT>padded_y = y*bin_up_factor + y1<EOL>padded_x = x*bin_up_factor + x1<EOL>value += padded_array_2d[padded_y, padded_x]<EOL><DEDENT><DEDENT>binned_array_2d[y,x] = value / (bin_up_factor ** <NUM_LIT>)<EOL><DEDENT><DEDENT>return binned_array_2d<EOL>

Bin up an array to coarser resolution, by binning up groups of pixels and using their mean value to determine \
     the value of the new pixel.

    If an array of shape (8,8) is input and the bin up size is 2, this would return a new array of size (4,4) where \
    every pixel was the mean of each collection of 2x2 pixels on the (8,8) array.

    If binning up the array leads to an edge being cut (e.g. a (9,9) array binned up by 2), an array is first \
    extracted around the centre of that array.

    Parameters
    ----------
    array_2d : ndarray
        The 2D array that is resized.
    new_shape : (int, int)
        The (y,x) new pixel dimension of the trimmed array.
    origin : (int, int)
        The oigin of the resized array, e.g. the central pixel around which the array is extracted.

    Returns
    -------
    ndarray
        The resized 2D array from the input 2D array.

    Examples
    --------
    array_2d = np.ones((5,5))
    resize_array = resize_array_2d(array_2d=array_2d, new_shape=(2,2), origin=(2, 2))


if self.arg_names is not None:<EOL><INDENT>raise AssertionError("<STR_LIT>")<EOL><DEDENT>self.arg_names = inspect.getfullargspec(func).args<EOL>@wraps(func)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>key = "<STR_LIT:U+002CU+0020>".join(<EOL>["<STR_LIT>".format(arg_name, arg) for arg_name, arg in<EOL>list(zip(self.arg_names, args)) + [(k, v) for k, v in kwargs.items()]])<EOL>if key not in self.results:<EOL><INDENT>self.calls += <NUM_LIT:1><EOL><DEDENT>self.results[key] = func(*args, **kwargs)<EOL>return self.results[key]<EOL><DEDENT>return wrapper<EOL>

Memoize decorator. Any time a function is called that a memoizer has been attached to its results are stored in
the results dictionary or retrieved from the dictionary if the function has already been called with those
arguments.

Note that the same memoizer persists over all instances of a class. Any state for a given instance that is not
given in the representation of that instance will be ignored. That is, it is possible that the memoizer will
give incorrect results if instance state does not affect __str__ but does affect the value returned by the
memoized method.

Parameters
----------
func: function
    A function for which results should be memoized

Returns
-------
decorated : function
    A function that memoizes results


self.results = {}<EOL>self.calls = <NUM_LIT:0><EOL>self.arg_names = None<EOL>

Class to store the results of a function given a set of inputs.


padded_array_2d = pad_2d_array_for_binning_up_with_bin_up_factor(array_2d=array_2d, bin_up_factor=bin_up_factor)<EOL>binned_array_2d = np.zeros(shape=(padded_array_2d.shape[<NUM_LIT:0>] // bin_up_factor,<EOL>padded_array_2d.shape[<NUM_LIT:1>] // bin_up_factor))<EOL>for y in range(binned_array_2d.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(binned_array_2d.shape[<NUM_LIT:1>]):<EOL><INDENT>value = <NUM_LIT:0.0><EOL>for y1 in range(bin_up_factor):<EOL><INDENT>for x1 in range(bin_up_factor):<EOL><INDENT>padded_y = y*bin_up_factor + y1<EOL>padded_x = x*bin_up_factor + x1<EOL>value += padded_array_2d[padded_y, padded_x] ** <NUM_LIT><EOL><DEDENT><DEDENT>binned_array_2d[y,x] = np.sqrt(value) / (bin_up_factor ** <NUM_LIT>)<EOL><DEDENT><DEDENT>return binned_array_2d<EOL>

Bin up an array to coarser resolution, by binning up groups of pixels and using their quadrature value to determine \
     the value of the new pixel.

    If an array of shape (8,8) is input and the bin up size is 2, this would return a new array of size (4,4) where \
    every pixel was the quadrature of each collection of 2x2 pixels on the (8,8) array.

    If binning up the array leads to an edge being cut (e.g. a (9,9) array binned up by 2), an array is first \
    extracted around the centre of that array.

    Parameters
    ----------
    array_2d : ndarray
        The 2D array that is resized.
    new_shape : (int, int)
        The (y,x) new pixel dimension of the trimmed array.
    origin : (int, int)
        The oigin of the resized array, e.g. the central pixel around which the array is extracted.

    Returns
    -------
    ndarray
        The resized 2D array from the input 2D array.

    Examples
    --------
    array_2d = np.ones((5,5))
    resize_array = resize_array_2d(array_2d=array_2d, new_shape=(2,2), origin=(2, 2))


total_sub_pixels = total_sub_pixels_from_mask_and_sub_grid_size(mask=mask, sub_grid_size=sub_grid_size)<EOL>sub_grid_to_sub_pixel = np.zeros(shape=(total_sub_pixels, <NUM_LIT:2>))<EOL>sub_pixel_count = <NUM_LIT:0><EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[y, x]:<EOL><INDENT>for y1 in range(sub_grid_size):<EOL><INDENT>for x1 in range(sub_grid_size):<EOL><INDENT>sub_grid_to_sub_pixel[sub_pixel_count, :] = (y*sub_grid_size)+y1, (x*sub_grid_size)+x1<EOL>sub_pixel_count += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return sub_grid_to_sub_pixel<EOL>

Compute a 1D array that maps every unmasked pixel to its corresponding 2d pixel using its (y,x) pixel indexes.

    For howtolens if pixel [2,5] corresponds to the second pixel on the 1D array, grid_to_pixel[1] = [2,5]


total_sparse_pixels = <NUM_LIT:0><EOL>for unmasked_sparse_pixel_index in range(unmasked_sparse_grid_pixel_centres.shape[<NUM_LIT:0>]):<EOL><INDENT>y = unmasked_sparse_grid_pixel_centres[unmasked_sparse_pixel_index, <NUM_LIT:0>]<EOL>x = unmasked_sparse_grid_pixel_centres[unmasked_sparse_pixel_index, <NUM_LIT:1>]<EOL>if not mask[y,x]:<EOL><INDENT>total_sparse_pixels += <NUM_LIT:1><EOL><DEDENT><DEDENT>return total_sparse_pixels<EOL>

Given the full (i.e. without removing pixels which are outside the regular-masks) pixelization grid's pixel centers
    and the regular-masks, compute the total number of pixels which are within the regular-masks and thus used by the
    pixelization grid.

    Parameters
    -----------
    mask : ccd.masks.Mask
        The regular-masks within which pixelization pixels must be inside
    unmasked_sparse_grid_pixel_centres : ndarray
        The centres of the unmasked pixelization grid pixels.


edge_pixels = edge_pixels_from_mask(mask)<EOL>masked_grid_index_to_pixel = masked_grid_1d_index_to_2d_pixel_index_from_mask(mask)<EOL>border_pixel_total = total_border_pixels_from_mask_and_edge_pixels(mask, edge_pixels, masked_grid_index_to_pixel)<EOL>border_pixels = np.zeros(border_pixel_total)<EOL>border_pixel_index = <NUM_LIT:0><EOL>for edge_pixel_index in range(edge_pixels.shape[<NUM_LIT:0>]):<EOL><INDENT>if check_if_border_pixel(mask, edge_pixels[edge_pixel_index], masked_grid_index_to_pixel):<EOL><INDENT>border_pixels[border_pixel_index] = edge_pixels[edge_pixel_index]<EOL>border_pixel_index += <NUM_LIT:1><EOL><DEDENT><DEDENT>return border_pixels<EOL>

Compute a 1D array listing all borders pixel indexes in the masks. A borders pixel is a pixel which:

     1) is not fully surrounding by False masks values.
     2) Can reach the edge of the array without hitting a masked pixel in one of four directions (upwards, downwards,
     left, right).

     The borders pixels are thus pixels which are on the exterior edge of the masks. For example, the inner ring of edge \
     pixels in an annular masks are edge pixels but not borders pixels.


@decorator_util.jit()<EOL>def mask_circular_annular_from_shape_pixel_scale_and_radii(shape, pixel_scale, inner_radius_arcsec, outer_radius_arcsec,<EOL>centre=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

mask = np.full(shape, True)<EOL>centres_arcsec = mask_centres_from_shape_pixel_scale_and_centre(shape=mask.shape, pixel_scale=pixel_scale, centre=centre)<EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>y_arcsec = (y - centres_arcsec[<NUM_LIT:0>]) * pixel_scale<EOL>x_arcsec = (x - centres_arcsec[<NUM_LIT:1>]) * pixel_scale<EOL>r_arcsec = np.sqrt(x_arcsec ** <NUM_LIT:2> + y_arcsec ** <NUM_LIT:2>)<EOL>if outer_radius_arcsec >= r_arcsec >= inner_radius_arcsec:<EOL><INDENT>mask[y, x] = False<EOL><DEDENT><DEDENT><DEDENT>return mask<EOL>

Compute an annular masks from an input inner and outer masks radius and regular shape.


@decorator_util.jit()<EOL>def mask_circular_from_shape_pixel_scale_and_radius(shape, pixel_scale, radius_arcsec, centre=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

mask = np.full(shape, True)<EOL>centres_arcsec = mask_centres_from_shape_pixel_scale_and_centre(shape=mask.shape, pixel_scale=pixel_scale, centre=centre)<EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>y_arcsec = (y - centres_arcsec[<NUM_LIT:0>]) * pixel_scale<EOL>x_arcsec = (x - centres_arcsec[<NUM_LIT:1>]) * pixel_scale<EOL>r_arcsec = np.sqrt(x_arcsec ** <NUM_LIT:2> + y_arcsec ** <NUM_LIT:2>)<EOL>if r_arcsec <= radius_arcsec:<EOL><INDENT>mask[y, x] = False<EOL><DEDENT><DEDENT><DEDENT>return mask<EOL>

Compute a circular masks from an input masks radius and regular shape.


border_pixel_total = <NUM_LIT:0><EOL>for i in range(edge_pixels.shape[<NUM_LIT:0>]):<EOL><INDENT>if check_if_border_pixel(mask, edge_pixels[i], masked_grid_index_to_pixel):<EOL><INDENT>border_pixel_total += <NUM_LIT:1><EOL><DEDENT><DEDENT>return border_pixel_total<EOL>

Compute the total number of borders-pixels in a masks.


total_regular_pixels = <NUM_LIT:0><EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[y, x]:<EOL><INDENT>total_regular_pixels += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return total_regular_pixels<EOL>

Compute the total number of unmasked regular pixels in a masks.


edge_pixel_total = total_edge_pixels_from_mask(mask)<EOL>edge_pixels = np.zeros(edge_pixel_total)<EOL>edge_index = <NUM_LIT:0><EOL>regular_index = <NUM_LIT:0><EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[y, x]:<EOL><INDENT>if mask[y + <NUM_LIT:1>, x] or mask[y - <NUM_LIT:1>, x] or mask[y, x + <NUM_LIT:1>] or mask[y, x - <NUM_LIT:1>] ormask[y + <NUM_LIT:1>, x + <NUM_LIT:1>] or mask[y + <NUM_LIT:1>, x - <NUM_LIT:1>] or mask[y - <NUM_LIT:1>, x + <NUM_LIT:1>] or mask[y - <NUM_LIT:1>, x - <NUM_LIT:1>]:<EOL><INDENT>edge_pixels[edge_index] = regular_index<EOL>edge_index += <NUM_LIT:1><EOL><DEDENT>regular_index += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return edge_pixels<EOL>

Compute a 1D array listing all edge pixel indexes in the masks. An edge pixel is a pixel which is not fully \
    surrounding by False masks values i.e. it is on an edge.


array_2d = np.zeros(shape)<EOL>index = <NUM_LIT:0><EOL>for y in range(shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(shape[<NUM_LIT:1>]):<EOL><INDENT>array_2d[y, x] = array_1d[index]<EOL>index += <NUM_LIT:1><EOL><DEDENT><DEDENT>return array_2d<EOL>

For a 1D array that was flattened from a 2D array of shape (rows, columns), map its values back to the \
    original 2D array.

    The pixel coordinate origin is at the top left corner of the 2D array and goes right-wards and downwards, such
    that for an array of shape (3,3):

    - pixel 0 of the 1D array will correspond to index [0,0] of the 2D array.
    - pixel 1 of the 1D array will correspond to index [0,1] of the 2D array.
    - pixel 4 of the 1D array will correspond to index [1,0] of the 2D array.

    Parameters
     ----------
    array_1d : ndarray
        The 1D array of values which are mapped to a 2D array.
    shape : (int, int)
        The shape of the 2D array which the pixels are defined on.

    Returns
    --------
    ndarray
        A 2D array of values mapped from the 1D array with dimensions (shape).

    Examples
    --------
    one_to_two = np.array([[0,1], [1,0], [1,1], [1,2], [2,1]])

    array_1d = np.array([[2.0, 4.0, 5.0, 6.0, 8.0])

    array_2d = map_masked_1d_array_to_2d_array_from_array_1d_shape_and_one_to_two(array_1d=array_1d, shape=(3,3),
                                                                                one_to_two=one_to_two)


total_pix_pixels = sparse_to_unmasked_sparse.shape[<NUM_LIT:0>]<EOL>pix_grid = np.zeros((total_pix_pixels, <NUM_LIT:2>))<EOL>for pixel_index in range(total_pix_pixels):<EOL><INDENT>pix_grid[pixel_index, <NUM_LIT:0>] = unmasked_sparse_grid[sparse_to_unmasked_sparse[pixel_index], <NUM_LIT:0>]<EOL>pix_grid[pixel_index, <NUM_LIT:1>] = unmasked_sparse_grid[sparse_to_unmasked_sparse[pixel_index], <NUM_LIT:1>]<EOL><DEDENT>return pix_grid<EOL>

Use the central arc-second coordinate of every unmasked pixelization grid's pixels and mapping between each
    pixelization pixel and unmasked pixelization pixel to compute the central arc-second coordinate of every masked
    pixelization grid pixel.

    Parameters
    -----------
    unmasked_sparse_grid : ndarray
        The (y,x) arc-second centre of every unmasked pixelization grid pixel.
    sparse_to_unmasked_sparse : ndarray
        The index mapping between every pixelization pixel and masked pixelization pixel.


indexes_1d = np.zeros(indexes_2d.shape[<NUM_LIT:0>])<EOL>for i in range(indexes_2d.shape[<NUM_LIT:0>]):<EOL><INDENT>indexes_1d[i] = int((indexes_2d[i, <NUM_LIT:0>]) * shape[<NUM_LIT:1>] + indexes_2d[i, <NUM_LIT:1>])<EOL><DEDENT>return indexes_1d<EOL>

For pixels on a 2D array of shape (rows, colums), map an array of 2D pixel indexes to 1D pixel indexes.

    Indexing is defined from the top-left corner rightwards and downwards, whereby the top-left pixel on the 2D array
    corresponds to index 0, the pixel to its right pixel 1, and so on.

    For a 2D array of shape (3,3), 2D pixel indexes are converted as follows:

    - 2D Pixel index [0,0] maps -> 1D pixel index 0.
    - 2D Pixel index [0,1] maps -> 2D pixel index 1.
    - 2D Pixel index [1,0] maps -> 2D pixel index 4.
    - 2D Pixel index [2,2] maps -> 2D pixel index 8.

    Parameters
     ----------
    indexes_2d : ndarray
        The 2D pixel indexes which are mapped to 1D indexes.
    shape : (int, int)
        The shape of the 2D array which the pixels are defined on.

    Returns
    --------
    ndarray
        An array of 1d pixel indexes with dimensions (total_indexes).

    Examples
    --------
    indexes_2d = np.array([[0,0], [1,0], [2,0], [2,2]])
    indexes_1d = map_1d_indexes_to_1d_indexes_for_shape(indexes_2d=indexes_2d, shape=(3,3))


total_image_pixels = mask_util.total_regular_pixels_from_mask(mask)<EOL>array_1d = np.zeros(shape=total_image_pixels)<EOL>index = <NUM_LIT:0><EOL>for y in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for x in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[y, x]:<EOL><INDENT>array_1d[index] = array_2d[y, x]<EOL>index += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return array_1d<EOL>

For a 2D array and mask, map the values of all unmasked pixels to a 1D array.

    The pixel coordinate origin is at the top left corner of the 2D array and goes right-wards and downwards, such
    that for an array of shape (3,3) where all pixels are unmasked:

    - pixel [0,0] of the 2D array will correspond to index 0 of the 1D array.
    - pixel [0,1] of the 2D array will correspond to index 1 of the 1D array.
    - pixel [1,0] of the 2D array will correspond to index 4 of the 1D array.

    Parameters
     ----------
    mask : ndarray
        A 2D array of bools, where *False* values mean unmasked and are included in the mapping.
    array_2d : ndarray
        The 2D array of values which are mapped to a 1D array.

    Returns
    --------
    ndarray
        A 1D array of values mapped from the 2D array with dimensions (total_unmasked_pixels).

    Examples
    --------
    mask = np.array([[True, False, True],
                     [False, False, False]
                     [True, False, True]])

    array_2d = np.array([[1.0, 2.0, 3.0],
                          [4.0, 5.0, 6.0],
                          [7.0, 8.0, 9.0]])

    array_1d = map_2d_array_to_masked_1d_array_from_array_2d_and_mask(mask=mask, array_2d=array_2d)


total_unmasked_sparse_pixels = unmasked_sparse_grid_pixel_centres.shape[<NUM_LIT:0>]<EOL>unmasked_sparse_to_sparse = np.zeros(total_unmasked_sparse_pixels)<EOL>pixel_index = <NUM_LIT:0><EOL>for unmasked_sparse_pixel_index in range(total_unmasked_sparse_pixels):<EOL><INDENT>y = unmasked_sparse_grid_pixel_centres[unmasked_sparse_pixel_index, <NUM_LIT:0>]<EOL>x = unmasked_sparse_grid_pixel_centres[unmasked_sparse_pixel_index, <NUM_LIT:1>]<EOL>unmasked_sparse_to_sparse[unmasked_sparse_pixel_index] = pixel_index<EOL>if not mask[y, x]:<EOL><INDENT>if pixel_index < total_sparse_pixels - <NUM_LIT:1>:<EOL><INDENT>pixel_index += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return unmasked_sparse_to_sparse<EOL>

Determine the mapping between every pixelization-grid pixel and masked pixelization-grid pixel. This is
    performed by checking whether each pixelization-grid pixel is within the regular-masks, and mapping the indexes.

    Pixelization pixels are paired with the next masked pixel index. This may mean that a pixel is not paired with a
    pixel near it, if the next pixel is on the next row of the grid. This is not a problem, as it is only
    unmasked pixels that are referened when computing image_to_pix, which is what this array is used for.

    Parameters
    -----------
    total_sparse_pixels : int
        The total number of pixels in the pixelization grid which fall within the regular-masks.
    mask : ccd.masks.Mask
        The regular-masks within which pixelization pixels must be inside
    unmasked_sparse_grid_pixel_centres : ndarray
        The centres of the unmasked pixelization grid pixels.


def resized_scaled_array_from_array(self, new_shape, new_centre_pixels=None, new_centre_arcsec=None):

if new_centre_pixels is None and new_centre_arcsec is None:<EOL><INDENT>new_centre = (-<NUM_LIT:1>, -<NUM_LIT:1>)  <EOL><DEDENT>elif new_centre_pixels is not None and new_centre_arcsec is None:<EOL><INDENT>new_centre = new_centre_pixels<EOL><DEDENT>elif new_centre_pixels is None and new_centre_arcsec is not None:<EOL><INDENT>new_centre = self.arc_second_coordinates_to_pixel_coordinates(arc_second_coordinates=new_centre_arcsec)<EOL><DEDENT>else:<EOL><INDENT>raise exc.DataException('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return self.new_with_array(array=array_util.resized_array_2d_from_array_2d_and_resized_shape(<EOL>array_2d=self, resized_shape=new_shape, origin=new_centre))<EOL>

resized the array to a new shape and at a new origin.

        Parameters
        -----------
        new_shape : (int, int)
            The new two-dimensional shape of the array.


return grid_util.regular_grid_2d_from_shape_pixel_scales_and_origin(shape=self.shape,<EOL>pixel_scales=self.pixel_scales,<EOL>origin=self.origin)<EOL>

The arc second-grid of (y,x) coordinates of every pixel.

        This is defined from the top-left corner, such that the first pixel at location [0, 0] will have a negative x \
        value y value in arc seconds.


return grid_util.grid_arcsec_1d_to_grid_pixel_indexes_1d(grid_arcsec_1d=grid_arcsec,<EOL>shape=self.shape,<EOL>pixel_scales=self.pixel_scales,<EOL>origin=self.origin).astype('<STR_LIT:int>')<EOL>

Convert a grid of (y,x) arc second coordinates to a grid of (y,x) pixel 1D indexes. Pixel coordinates are \
        returned as integers such that they are the pixel from the top-left of the 2D grid going rights and then \
        downwards.

        For example:

        The pixel at the top-left, whose 2D index is [0,0], corresponds to 1D index 0.
        The fifth pixel on the top row, whose 2D index is [0,5], corresponds to 1D index 4.
        The first pixel on the second row, whose 2D index is [0,1], has 1D index 10 if a row has 10 pixels.

        The arc-second coordinate origin is defined by the class attribute origin, and coordinates are shifted to this \
        origin before computing their 1D grid pixel indexes.

        Parameters
        ----------
        grid_arcsec: ndarray
            The grid of (y,x) coordinates in arc seconds.


arguments = vars(self)<EOL>arguments.update({"<STR_LIT>": array})<EOL>if '<STR_LIT>' in arguments:<EOL><INDENT>arguments.pop("<STR_LIT>")<EOL><DEDENT>return self.__class__(**arguments)<EOL>

Parameters
----------
array: ndarray
    An ndarray

Returns
-------
new_array: ScaledSquarePixelArray
    A new instance of this class that shares all of this instances attributes with a new ndarray.


def zoomed_scaled_array_around_mask(self, mask, buffer=<NUM_LIT:1>):

return self.new_with_array(array=array_util.extracted_array_2d_from_array_2d_and_coordinates(<EOL>array_2d=self,  y0=mask.zoom_region[<NUM_LIT:0>]-buffer, y1=mask.zoom_region[<NUM_LIT:1>]+buffer,<EOL>x0=mask.zoom_region[<NUM_LIT:2>]-buffer, x1=mask.zoom_region[<NUM_LIT:3>]+buffer))<EOL>

Extract the 2D region of an array corresponding to the rectangle encompassing all unmasked values.

        This is used to extract and visualize only the region of an image that is used in an analysis.

        Parameters
        ----------
        mask : mask.Mask
            The mask around which the scaled array is extracted.
        buffer : int
            The buffer of pixels around the extraction.


@classmethod<EOL><INDENT>def single_value(cls, value, shape, pixel_scale, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):<DEDENT>

array = np.ones(shape) * value<EOL>return cls(array, pixel_scale, origin)<EOL>

Creates an instance of Array and fills it with a single value

Parameters
----------
value: float
    The value with which the array should be filled
shape: (int, int)
    The shape of the array
pixel_scale: float
    The scale of a pixel in arc seconds

Returns
-------
array: ScaledSquarePixelArray
    An array filled with a single value


def __init__(self, array, pixel_scale, origin=(<NUM_LIT:0.0>, <NUM_LIT:0.0>)):

pixel_scale_sanity_checks(pixel_scales=(pixel_scale, pixel_scale))<EOL>self.pixel_scale = pixel_scale<EOL>self.origin = origin<EOL>super(ScaledSquarePixelArray, self).__init__(array=array)<EOL>

A scaled array with square-pixels.

        Parameters
        ----------
        array: ndarray
            An array representing image (e.g. an image, noise-map, etc.)
        pixel_scale: float
            The arc-second to pixel conversion factor of each pixel.
        origin : (float, float)
            The arc-second origin of the scaled array's coordinate system.


if psf.shape[<NUM_LIT:0>] % <NUM_LIT:2> == <NUM_LIT:0> or psf.shape[<NUM_LIT:1>] % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>raise exc.KernelException("<STR_LIT>")<EOL><DEDENT>self.mask_index_array = np.full(mask.shape, -<NUM_LIT:1>)<EOL>self.pixels_in_mask = int(np.size(mask) - np.sum(mask))<EOL>count = <NUM_LIT:0><EOL>for x in range(mask.shape[<NUM_LIT:0>]):<EOL><INDENT>for y in range(mask.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[x, y]:<EOL><INDENT>self.mask_index_array[x, y] = count<EOL>count += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>self.psf = psf<EOL>self.psf_shape = psf.shape<EOL>self.psf_max_size = self.psf_shape[<NUM_LIT:0>] * self.psf_shape[<NUM_LIT:1>]<EOL>image_index = <NUM_LIT:0><EOL>self.image_frame_indexes = np.zeros((self.pixels_in_mask, self.psf_max_size), dtype='<STR_LIT:int>')<EOL>self.image_frame_psfs = np.zeros((self.pixels_in_mask, self.psf_max_size))<EOL>self.image_frame_lengths = np.zeros((self.pixels_in_mask), dtype='<STR_LIT:int>')<EOL>for x in range(self.mask_index_array.shape[<NUM_LIT:0>]):<EOL><INDENT>for y in range(self.mask_index_array.shape[<NUM_LIT:1>]):<EOL><INDENT>if not mask[x][y]:<EOL><INDENT>image_frame_indexes, image_frame_psfs = self.frame_at_coordinates_jit((x, y), mask,<EOL>self.mask_index_array,<EOL>self.psf[:, :])<EOL>self.image_frame_indexes[image_index, :] = image_frame_indexes<EOL>self.image_frame_psfs[image_index, :] = image_frame_psfs<EOL>self.image_frame_lengths[image_index] = image_frame_indexes[image_frame_indexes >= <NUM_LIT:0>].shape[<NUM_LIT:0>]<EOL>image_index += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>

Class to create regular frames and blurring frames used to convolve a psf with a 1D regular of non-masked \
values.

Parameters
----------
mask : Mask
    A masks where True eliminates datas.
psf : regular.PSF or ndarray
    An array representing a PSF.


def convolve_image(self, image_array, blurring_array):

return self.convolve_jit(image_array, self.image_frame_indexes, self.image_frame_psfs, self.image_frame_lengths,<EOL>blurring_array, self.blurring_frame_indexes, self.blurring_frame_psfs,<EOL>self.blurring_frame_lengths)<EOL>

For a given 1D regular array and blurring array, convolve the two using this convolver.

        Parameters
        -----------
        image_array : ndarray
            1D array of the regular values which are to be blurred with the convolver's PSF.
        blurring_array : ndarray
            1D array of the blurring regular values which blur into the regular-array after PSF convolution.


def plot_image(<EOL>image, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False,<EOL>should_plot_border=False, positions=None, as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>mask_pointsize=<NUM_LIT:10>, position_pointsize=<NUM_LIT:30>, grid_pointsize=<NUM_LIT:1>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT:image>'):

origin = get_origin(array=image, plot_origin=plot_origin)<EOL>array_plotters.plot_array(<EOL>array=image, origin=origin, mask=mask, extract_array_from_mask=extract_array_from_mask,<EOL>zoom_around_mask=zoom_around_mask,<EOL>should_plot_border=should_plot_border, positions=positions, as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize, position_pointsize=position_pointsize, grid_pointsize=grid_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the observed image of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all input parameters not described below.

    Parameters
    -----------
    image : ScaledSquarePixelArray
        The image of the data.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.
    image_plane_pix_grid : ndarray or data.array.grid_stacks.PixGrid
        If an adaptive pixelization whose pixels are formed by tracing pixels from the data, this plots those pixels \
        over the immage.


def plot_potential_chi_squared_map(<EOL>potential_chi_squared_map, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False,<EOL>as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>mask_pointsize=<NUM_LIT:10>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

origin = get_origin(array=potential_chi_squared_map, plot_origin=plot_origin)<EOL>array_plotters.plot_array(<EOL>array=potential_chi_squared_map, origin=origin, mask=mask, extract_array_from_mask=extract_array_from_mask,<EOL>zoom_around_mask=zoom_around_mask,<EOL>as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the signal-to-noise_map of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all input parameters not described below.

    Parameters
    -----------
    potential_chi_squared_map : ScaledSquarePixelArray
        The signal-to-noise map of the data.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.


if plot_origin:<EOL><INDENT>return array.origin<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Get the (y,x) origin of the ccd data if it going to be plotted.

    Parameters
    -----------
    array : data.array.scaled_array.ScaledArray
        The array from which the origin is extracted.
    plot_origin : True
        If true, the origin of the data's coordinate system is returned.


def plot_absolute_signal_to_noise_map(<EOL>absolute_signal_to_noise_map, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False,<EOL>as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>mask_pointsize=<NUM_LIT:10>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

origin = get_origin(array=absolute_signal_to_noise_map, plot_origin=plot_origin)<EOL>array_plotters.plot_array(<EOL>array=absolute_signal_to_noise_map, origin=origin, mask=mask, extract_array_from_mask=extract_array_from_mask,<EOL>zoom_around_mask=zoom_around_mask,<EOL>as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the absolute signal-to-noise map of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all input parameters not described below.

    Parameters
    -----------
    absolute_signal_to_noise_map : ScaledSquarePixelArray
        The absolute signal-to-noise map of the data.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.


def plot_noise_map(<EOL>noise_map, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False, as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>mask_pointsize=<NUM_LIT:10>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

origin = get_origin(array=noise_map, plot_origin=plot_origin)<EOL>array_plotters.plot_array(<EOL>array=noise_map, origin=origin, mask=mask, extract_array_from_mask=extract_array_from_mask,<EOL>zoom_around_mask=zoom_around_mask, as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the noise_map of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all input parameters not described below.

    Parameters
    -----------
    noise_map : ScaledSquarePixelArray
        The noise map of the data.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.


def plot_image(<EOL>ccd_data, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False,<EOL>should_plot_border=False, positions=None,<EOL>as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>mask_pointsize=<NUM_LIT:10>, position_pointsize=<NUM_LIT:30>, grid_pointsize=<NUM_LIT:1>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

data_plotters.plot_image(<EOL>image=ccd_data.image, plot_origin=plot_origin, mask=mask, extract_array_from_mask=extract_array_from_mask,<EOL>zoom_around_mask=zoom_around_mask, should_plot_border=should_plot_border, positions=positions,<EOL>as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize, position_pointsize=position_pointsize, grid_pointsize=grid_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the observed data of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all innput parameters not described below.

    Parameters
    -----------
    image : data.CCDData
        The ccd data, which includes the observed data, noise_map-map, PSF, signal-to-noise_map-map, etc.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.
    image_plane_pix_grid : ndarray or data.array.grid_stacks.PixGrid
        If an adaptive pixelization whose pixels are formed by tracing pixels from the data, this plots those pixels \
        over the immage.


def plot_signal_to_noise_map(<EOL>ccd_data, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False, as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>mask_pointsize=<NUM_LIT:10>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

data_plotters.plot_signal_to_noise_map(<EOL>signal_to_noise_map=ccd_data.signal_to_noise_map, plot_origin=plot_origin, mask=mask,<EOL>extract_array_from_mask=extract_array_from_mask, zoom_around_mask=zoom_around_mask, as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the signal-to-noise_map-map of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all innput parameters not described below.

    Parameters
    -----------
    image : data.CCDData
        The ccd data, which includes the observed image, noise_map-map, PSF, signal-to-noise_map-map, etc.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.


def plot_psf(<EOL>ccd_data, plot_origin=True, as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

data_plotters.plot_psf(<EOL>psf=ccd_data.psf, plot_origin=plot_origin, as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the PSF of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all innput parameters not described below.

    Parameters
    -----------
    image : data.CCDData
        The ccd data, which includes the observed data, noise_map-map, PSF, signal-to-noise_map-map, etc.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.


def plot_noise_map(<EOL>ccd_data, plot_origin=True, mask=None, extract_array_from_mask=False, zoom_around_mask=False, as_subplot=False,<EOL>units='<STR_LIT>', kpc_per_arcsec=None, figsize=(<NUM_LIT:7>, <NUM_LIT:7>), aspect='<STR_LIT>',<EOL>cmap='<STR_LIT>', norm='<STR_LIT>', norm_min=None, norm_max=None, linthresh=<NUM_LIT>, linscale=<NUM_LIT>,<EOL>cb_ticksize=<NUM_LIT:10>, cb_fraction=<NUM_LIT>, cb_pad=<NUM_LIT>, cb_tick_values=None, cb_tick_labels=None,<EOL>title='<STR_LIT>', titlesize=<NUM_LIT:16>, xlabelsize=<NUM_LIT:16>, ylabelsize=<NUM_LIT:16>, xyticksize=<NUM_LIT:16>, mask_pointsize=<NUM_LIT:10>,<EOL>output_path=None, output_format='<STR_LIT>', output_filename='<STR_LIT>'):

data_plotters.plot_noise_map(<EOL>noise_map=ccd_data.noise_map, plot_origin=plot_origin, mask=mask, extract_array_from_mask=extract_array_from_mask,<EOL>zoom_around_mask=zoom_around_mask, as_subplot=as_subplot,<EOL>units=units, kpc_per_arcsec=kpc_per_arcsec, figsize=figsize, aspect=aspect,<EOL>cmap=cmap, norm=norm, norm_min=norm_min, norm_max=norm_max, linthresh=linthresh, linscale=linscale,<EOL>cb_ticksize=cb_ticksize, cb_fraction=cb_fraction, cb_pad=cb_pad, <EOL>cb_tick_values=cb_tick_values, cb_tick_labels=cb_tick_labels,<EOL>title=title, titlesize=titlesize, xlabelsize=xlabelsize, ylabelsize=ylabelsize, xyticksize=xyticksize,<EOL>mask_pointsize=mask_pointsize,<EOL>output_path=output_path, output_format=output_format, output_filename=output_filename)<EOL>

Plot the noise_map-map of the ccd data.

    Set *autolens.data.array.plotters.array_plotters* for a description of all innput parameters not described below.

    Parameters
    -----------
    image : data.CCDData
        The ccd data, which includes the observed data, noise_map-map, PSF, signal-to-noise_map-map, etc.
    plot_origin : True
        If true, the origin of the data's coordinate system is plotted as a 'x'.


if data_resolution == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif data_resolution == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:0.1><EOL><DEDENT>elif data_resolution == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif data_resolution == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif data_resolution == '<STR_LIT>':<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>', data_resolution)<EOL><DEDENT>

Determine the pixel scale from a data resolution type based on real observations.

    These options are representative of LSST, Euclid, HST, over-sampled HST and Adaptive Optics image.

    Parameters
    ----------
    data_resolution : str
        A string giving the resolution of the desired data type (LSST | Euclid | HST | HST_Up | AO).


data = json.dumps({<EOL>'<STR_LIT>': self.version,<EOL>'<STR_LIT>': self.service_name,<EOL>'<STR_LIT>': params,<EOL>'<STR_LIT:id>': text_type(uuid.uuid4())<EOL>})<EOL>data_binary = data.encode('<STR_LIT:utf-8>')<EOL>url_request = Request(self.service_url, data_binary, headers=self.headers)<EOL>return urlopen(url_request).read()<EOL>

Performs the actual sending action and returns the result


status_or_headers = headers = None<EOL>if isinstance(rv, tuple):<EOL><INDENT>rv, status_or_headers, headers = rv + (None,) * (<NUM_LIT:3> - len(rv))<EOL><DEDENT>if rv is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(status_or_headers, (dict, list)):<EOL><INDENT>headers, status_or_headers = status_or_headers, None<EOL><DEDENT>D = json.loads(extract_raw_data_request(request))<EOL>if type(D) is list:<EOL><INDENT>raise InvalidRequestError('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>response_obj = self.empty_response(version=D['<STR_LIT>'])<EOL>response_obj['<STR_LIT:id>'] = D['<STR_LIT:id>']<EOL>response_obj['<STR_LIT:result>'] = rv<EOL>response_obj.pop('<STR_LIT:error>', None)<EOL>rv = jsonify(response_obj)<EOL><DEDENT>if status_or_headers is not None:<EOL><INDENT>if isinstance(status_or_headers, string_types):<EOL><INDENT>rv.status = status_or_headers<EOL><DEDENT>else:<EOL><INDENT>rv.status_code = status_or_headers<EOL><DEDENT><DEDENT>if headers:<EOL><INDENT>rv.headers.extend(headers)<EOL><DEDENT>return rv<EOL>

Converts the return value from a view function to a real
        response object that is an instance of :attr:`response_class`.


if '<STR_LIT:(>' in sig:<EOL><INDENT>parts = sig.split('<STR_LIT:(>')<EOL>sig = '<STR_LIT>'.format(<EOL>parts[<NUM_LIT:0>], '<STR_LIT:U+002CU+0020>'.join(types),<EOL>('<STR_LIT:U+002CU+0020>' if parts[<NUM_LIT:1>].index('<STR_LIT:)>') > <NUM_LIT:0> else '<STR_LIT>'), parts[<NUM_LIT:1>]<EOL>)<EOL><DEDENT>else:<EOL><INDENT>sig = '<STR_LIT>'.format(sig, '<STR_LIT:U+002CU+0020>'.join(types))<EOL><DEDENT>return sig<EOL>

A function to inject arguments manually into a method signature before
    it's been parsed. If using keyword arguments use 'kw=type' instead in
    the types array.

        sig         the string signature
        types       a list of types to be inserted

    Returns the altered signature.


def jsonify_status_code(status_code, *args, **kw):

is_batch = kw.pop('<STR_LIT>', False)<EOL>if is_batch:<EOL><INDENT>response = flask_make_response(json.dumps(*args, **kw))<EOL>response.mimetype = '<STR_LIT:application/json>'<EOL>response.status_code = status_code<EOL>return response<EOL><DEDENT>response = jsonify(*args, **kw)<EOL>response.status_code = status_code<EOL>return response<EOL>

Returns a jsonified response with the specified HTTP status code.

    The positional and keyword arguments are passed directly to the
    :func:`flask.jsonify` function which creates the response.


def __init__(self, message=None, code=None, data=None):

super(Error, self).__init__()<EOL>if message is not None:<EOL><INDENT>self.message = message<EOL><DEDENT>if code is not None:<EOL><INDENT>self.code = code<EOL><DEDENT>if data is not None:<EOL><INDENT>self.data = data<EOL><DEDENT>

Setup the Exception and overwrite the default message


error = {<EOL>'<STR_LIT:name>': text_type(self.__class__.__name__),<EOL>'<STR_LIT:code>': self.code,<EOL>'<STR_LIT:message>': '<STR_LIT>'.format(text_type(self.message)),<EOL>'<STR_LIT:data>': self.data<EOL>}<EOL>if current_app.config['<STR_LIT>']:<EOL><INDENT>import sys, traceback<EOL>error['<STR_LIT>'] = traceback.format_exc()<EOL>error['<STR_LIT>'] = sys.executable<EOL><DEDENT>return error<EOL>

Return the Exception data in a format for JSON-RPC


def register(self, app, options, first_registration=False):

self.jsonrpc_site = options.get('<STR_LIT>')<EOL>self._got_registered_once = True<EOL>state = self.make_setup_state(app, options, first_registration)<EOL>if self.has_static_folder andnot self.name + '<STR_LIT>' in state.app.view_functions.keys():<EOL><INDENT>state.add_url_rule(self.static_url_path + '<STR_LIT>',<EOL>view_func=self.send_static_file,<EOL>endpoint='<STR_LIT>')<EOL><DEDENT>for deferred in self.deferred_functions:<EOL><INDENT>deferred(state)<EOL><DEDENT>

Called by :meth:`Flask.register_blueprint` to register a blueprint
        on the application. This can be overridden to customize the register
        behavior. Keyword arguments from
        :func:`~flask.Flask.register_blueprint` are directly forwarded to this
        method in the `options` dictionary.


Parses command line arguments.

    Args:
      prog: The path of the program (dsub.py) or an alternate program name to
      display in usage.
      argv: The list of program arguments to parse.

    Returns:
      A Namespace of parsed arguments.


if not task_descriptors:<EOL><INDENT>return<EOL><DEDENT>task_params = task_descriptors[<NUM_LIT:0>].task_params<EOL>from_jobs = {label.name for label in job_params['<STR_LIT>']}<EOL>from_tasks = {label.name for label in task_params['<STR_LIT>']}<EOL>intersect = from_jobs & from_tasks<EOL>if intersect:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format('<STR_LIT:U+002C>'.join(intersect)))<EOL><DEDENT>from_jobs = {<EOL>item.name<EOL>for item in job_params['<STR_LIT>'] | job_params['<STR_LIT>']<EOL>| job_params['<STR_LIT>']<EOL>}<EOL>from_tasks = {<EOL>item.name<EOL>for item in task_params['<STR_LIT>'] | task_params['<STR_LIT>']<EOL>| task_params['<STR_LIT>']<EOL>}<EOL>intersect = from_jobs & from_tasks<EOL>if intersect:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format('<STR_LIT:U+002C>'.join(intersect)))<EOL><DEDENT>

Validates that job and task argument names do not overlap.


def _retry_task(provider, job_descriptor, task_id, task_attempt):

td_orig = job_descriptor.find_task_descriptor(task_id)<EOL>new_task_descriptors = [<EOL>job_model.TaskDescriptor({<EOL>'<STR_LIT>': task_id,<EOL>'<STR_LIT>': task_attempt<EOL>}, td_orig.task_params, td_orig.task_resources)<EOL>]<EOL>_resolve_task_resources(job_descriptor.job_metadata,<EOL>job_descriptor.job_resources, new_task_descriptors)<EOL>provider.submit_job(<EOL>job_model.JobDescriptor(<EOL>job_descriptor.job_metadata, job_descriptor.job_params,<EOL>job_descriptor.job_resources, new_task_descriptors), False)<EOL>

Retry task_id (numeric id) assigning it task_attempt.


def _resolve_task_resources(job_metadata, job_resources, task_descriptors):

_resolve_task_logging(job_metadata, job_resources, task_descriptors)<EOL>

Resolve task properties (such as the logging path) from job properties.

    Args:
      job_metadata: Job metadata, such as job-id, job-name, and user-id.
      job_resources: Resources specified such as ram, cpu, and logging path.
      task_descriptors: Task metadata, parameters, and resources.

    This function exists to be called at the point that all job properties have
    been validated and resolved. It is also called prior to re-trying a task.

    The only property to be resolved right now is the logging path,
    which may have substitution parameters such as
    job-id, task-id, task-attempt, user-id, and job-name.


per_job = _group_tasks_by_jobid(tasks)<EOL>ret = []<EOL>for job_id in per_job.keys():<EOL><INDENT>tasks_in_salience_order = sorted(per_job[job_id], key=_importance_of_task)<EOL>ret.append(tasks_in_salience_order[<NUM_LIT:0>])<EOL><DEDENT>return ret<EOL>

A list with, for each job, its dominant task.

    The dominant task is the one that exemplifies its job's
    status. It is either:
    - the first (FAILURE or CANCELED) task, or if none
    - the first RUNNING task, or if none
    - the first SUCCESS task.

    Args:
      tasks: a list of tasks to consider

    Returns:
      A list with, for each job, its dominant task.


if args.machine_type:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if args.mount:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>


date_fields = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>int_fields = ['<STR_LIT>']<EOL>for col in date_fields:<EOL><INDENT>if col in row:<EOL><INDENT>row[col] = self.default_format_date(row[col])<EOL><DEDENT><DEDENT>for col in int_fields:<EOL><INDENT>if col in row and row[col] is not None:<EOL><INDENT>row[col] = int(row[col])<EOL><DEDENT><DEDENT>return row<EOL>


def string_presenter(self, dumper, data):

if '<STR_LIT:\n>' in data:<EOL><INDENT>return dumper.represent_scalar('<STR_LIT>', data, style='<STR_LIT:|>')<EOL><DEDENT>else:<EOL><INDENT>return dumper.represent_scalar('<STR_LIT>', data)<EOL><DEDENT>

Presenter to force yaml.dump to use multi-line string style.


return directory.rstrip('<STR_LIT:/>') + '<STR_LIT:/>'<EOL>

In ensure that directories end with '/'.

    Frequently we need to ensure that directory paths end with a forward slash.
    Pythons dirname and split functions in the path library treat this
    inconsistently creating this requirement. This function is simple but was
    written to centralize documentation of an often used (and often explained)
    requirement in this codebase.

    >>> os.path.dirname('gs://bucket/folder/file.txt')
    'gs://bucket/folder'
    >>> directory_fmt(os.path.dirname('gs://bucket/folder/file.txt'))
    'gs://bucket/folder/'
    >>> os.path.dirname('/newfile')
    '/'
    >>> directory_fmt(os.path.dirname('/newfile'))
    '/'

    Specifically we need this since copy commands must know whether the
    destination is a directory to function properly. See the following shell
    interaction for an example of the inconsistency. Notice that text files are
    copied as expected but the bam is copied over the directory name.

    Multiple files copy, works as intended in all cases:
        $ touch a.txt b.txt
        $ gsutil cp ./*.txt gs://mybucket/text_dest
        $ gsutil ls gs://mybucket/text_dest/
              0  2017-07-19T21:44:36Z  gs://mybucket/text_dest/a.txt
              0  2017-07-19T21:44:36Z  gs://mybucket/text_dest/b.txt
        TOTAL: 2 objects, 0 bytes (0 B)

    Single file copy fails to copy into a directory:
        $ touch 1.bam
        $ gsutil cp ./*.bam gs://mybucket/bad_dest
        $ gsutil ls gs://mybucket/bad_dest
                 0  2017-07-19T21:46:16Z  gs://mybucket/bad_dest
        TOTAL: 1 objects, 0 bytes (0 B)

    Adding a trailing forward slash fixes this:
        $ touch my.sam
        $ gsutil cp ./*.sam gs://mybucket/good_folder
        $ gsutil ls gs://mybucket/good_folder
                 0  2017-07-19T21:46:16Z  gs://mybucket/good_folder/my.sam
        TOTAL: 1 objects, 0 bytes (0 B)

    Args:
      directory (str): a uri without an blob or file basename.

    Returns:
      the directory with a trailing slash.


return _get_filtered_mounts(mounts, job_model.GCSMountParam)<EOL>


if not age:<EOL><INDENT>return None<EOL><DEDENT>if not from_time:<EOL><INDENT>from_time = dsub_util.replace_timezone(datetime.datetime.now(), tzlocal())<EOL><DEDENT>try:<EOL><INDENT>last_char = age[-<NUM_LIT:1>]<EOL>if last_char == '<STR_LIT:s>':<EOL><INDENT>return from_time - datetime.timedelta(seconds=int(age[:-<NUM_LIT:1>]))<EOL><DEDENT>elif last_char == '<STR_LIT:m>':<EOL><INDENT>return from_time - datetime.timedelta(minutes=int(age[:-<NUM_LIT:1>]))<EOL><DEDENT>elif last_char == '<STR_LIT:h>':<EOL><INDENT>return from_time - datetime.timedelta(hours=int(age[:-<NUM_LIT:1>]))<EOL><DEDENT>elif last_char == '<STR_LIT:d>':<EOL><INDENT>return from_time - datetime.timedelta(days=int(age[:-<NUM_LIT:1>]))<EOL><DEDENT>elif last_char == '<STR_LIT:w>':<EOL><INDENT>return from_time - datetime.timedelta(weeks=int(age[:-<NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>return dsub_util.replace_timezone(<EOL>datetime.datetime.utcfromtimestamp(int(age)), pytz.utc)<EOL><DEDENT><DEDENT>except (ValueError, OverflowError) as e:<EOL><INDENT>raise ValueError('<STR_LIT>' % (age, e))<EOL><DEDENT>

Compute the create time (UTC) for the list filter.

    If the age is an integer value it is treated as a UTC date.
    Otherwise the value must be of the form "<integer><unit>" where supported
    units are s, m, h, d, w (seconds, minutes, hours, days, weeks).

    Args:
      age: A "<integer><unit>" string or integer value.
      from_time:

    Returns:
      A timezone-aware datetime or None if age parameter is empty.


def args_to_job_params(envs, labels, inputs, inputs_recursive, outputs,<EOL>outputs_recursive, mounts, input_file_param_util,<EOL>output_file_param_util, mount_param_util):

<EOL>env_data = parse_pair_args(envs, job_model.EnvParam)<EOL>label_data = parse_pair_args(labels, job_model.LabelParam)<EOL>input_data = set()<EOL>for (recursive, args) in ((False, inputs), (True, inputs_recursive)):<EOL><INDENT>for arg in args:<EOL><INDENT>name, value = split_pair(arg, '<STR_LIT:=>', nullable_idx=<NUM_LIT:0>)<EOL>name = input_file_param_util.get_variable_name(name)<EOL>input_data.add(input_file_param_util.make_param(name, value, recursive))<EOL><DEDENT><DEDENT>output_data = set()<EOL>for (recursive, args) in ((False, outputs), (True, outputs_recursive)):<EOL><INDENT>for arg in args:<EOL><INDENT>name, value = split_pair(arg, '<STR_LIT:=>', <NUM_LIT:0>)<EOL>name = output_file_param_util.get_variable_name(name)<EOL>output_data.add(output_file_param_util.make_param(name, value, recursive))<EOL><DEDENT><DEDENT>mount_data = set()<EOL>for arg in mounts:<EOL><INDENT>if '<STR_LIT:U+0020>' in arg:<EOL><INDENT>key_value_pair, disk_size = arg.split('<STR_LIT:U+0020>')<EOL>name, value = split_pair(key_value_pair, '<STR_LIT:=>', <NUM_LIT:1>)<EOL>mount_data.add(mount_param_util.make_param(name, value, disk_size))<EOL><DEDENT>else:<EOL><INDENT>name, value = split_pair(arg, '<STR_LIT:=>', <NUM_LIT:1>)<EOL>mount_data.add(mount_param_util.make_param(name, value, disk_size=None))<EOL><DEDENT><DEDENT>return {<EOL>'<STR_LIT>': env_data,<EOL>'<STR_LIT>': input_data,<EOL>'<STR_LIT>': output_data,<EOL>'<STR_LIT>': label_data,<EOL>'<STR_LIT>': mount_data,<EOL>}<EOL>

Parse env, input, and output parameters into a job parameters and data.

    Passing arguments on the command-line allows for launching a single job.
    The env, input, and output arguments encode both the definition of the
    job as well as the single job's values.

    Env arguments are simple name=value pairs.
    Input and output file arguments can contain name=value pairs or just values.
    Either of the following is valid:

      uri
      myfile=uri

    Args:
      envs: list of environment variable job parameters
      labels: list of labels to attach to the tasks
      inputs: list of file input parameters
      inputs_recursive: list of recursive directory input parameters
      outputs: list of file output parameters
      outputs_recursive: list of recursive directory output parameters
      mounts: list of gcs buckets to mount
      input_file_param_util: Utility for producing InputFileParam objects.
      output_file_param_util: Utility for producing OutputFileParam objects.
      mount_param_util: Utility for producing MountParam objects.

    Returns:
      job_params: a dictionary of 'envs', 'inputs', and 'outputs' that defines the
      set of parameters and data for a job.


label_data = set()<EOL>for arg in labels:<EOL><INDENT>name, value = split_pair(arg, '<STR_LIT:=>', nullable_idx=<NUM_LIT:1>)<EOL>label_data.add(argclass(name, value))<EOL><DEDENT>return label_data<EOL>

Parse flags of key=value pairs and return a list of argclass.

    For pair variables, we need to:
       * split the input into name=value pairs (value optional)
       * Create the EnvParam object

    Args:
      labels: list of 'key' or 'key=value' strings.
      argclass: Container class for args, must instantiate with argclass(k, v).

    Returns:
      list of argclass objects.


return _get_filtered_mounts(mounts, job_model.LocalMountParam)<EOL>


raw_uri = directory_fmt(raw_uri)<EOL>_, docker_path = _local_uri_rewriter(raw_uri)<EOL>local_path = docker_path[len('<STR_LIT:file>'):]<EOL>docker_uri = os.path.join(self._relative_path, docker_path)<EOL>return local_path, docker_uri<EOL>

Return a valid docker_path for a local file path.


<EOL>docker_uri = os.path.join(self._relative_path,<EOL>raw_uri.replace('<STR_LIT>', '<STR_LIT>', <NUM_LIT:1>))<EOL>return docker_uri<EOL>

Return a valid docker_path from a Google Persistent Disk url.


providers = {'<STR_LIT>': job_model.P_GCS, '<STR_LIT:file>': job_model.P_LOCAL}<EOL>provider_found = re.match(r'<STR_LIT>', uri)<EOL>if provider_found:<EOL><INDENT>prefix = provider_found.group(<NUM_LIT:1>).lower()<EOL><DEDENT>else:<EOL><INDENT>prefix = '<STR_LIT:file>'<EOL><DEDENT>if prefix in providers:<EOL><INDENT>return providers[prefix]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % prefix)<EOL><DEDENT>


def split_pair(pair_string, separator, nullable_idx=<NUM_LIT:1>):

pair = pair_string.split(separator, <NUM_LIT:1>)<EOL>if len(pair) == <NUM_LIT:1>:<EOL><INDENT>if nullable_idx == <NUM_LIT:0>:<EOL><INDENT>return [None, pair[<NUM_LIT:0>]]<EOL><DEDENT>elif nullable_idx == <NUM_LIT:1>:<EOL><INDENT>return [pair[<NUM_LIT:0>], None]<EOL><DEDENT>else:<EOL><INDENT>raise IndexError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return pair<EOL><DEDENT>

Split a string into a pair, which can have one empty value.

    Args:
      pair_string: The string to be split.
      separator: The separator to be used for splitting.
      nullable_idx: The location to be set to null if the separator is not in the
                    input string. Should be either 0 or 1.

    Returns:
      A list containing the pair.

    Raises:
      IndexError: If nullable_idx is not 0 or 1.