signature:
def plot_array ( array , origin = None , mask = None , extract_array_from_mask = False , zoom_around_mask = False , should_plot_border = False , positions = None , centres = None , axis_ratios = None , phis = None , grid = None , as_subplot = False , units = 'arcsec' , kpc_per_arcsec = None , figsize = ( 7 , 7 ) , aspect = 'equal' , cmap = 'jet' , norm = 'linear' , norm_min = None , norm_max = None , linthresh = 0.05 , linscale = 0.01 , cb_ticksize = 10 , cb_fraction = 0.047 , cb_pad = 0.01 , cb_tick_values = None , cb_tick_labels = None , title = 'Array' , titlesize = 16 , xlabelsize = 16 , ylabelsize = 16 , xyticksize = 16 , mask_pointsize = 10 , border_pointsize = 2 , position_pointsize = 30 , grid_pointsize = 1 , xticks_manual = None , yticks_manual = None , output_path = None , output_format = 'show' , output_filename = 'array' ) :
    """Plot an array of data as a figure .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 origin : ( float , float ) .
 The origin of the coordinate system of the array , which is plotted as an ' x ' on the image if input .
 mask : data . array . mask . Mask
 The mask applied to the array , the edge of which is plotted as a set of points over the plotted array .
 extract _ array _ from _ mask : bool
 The plotter array is extracted using the mask , such that masked values are plotted as zeros . This ensures bright features outside the mask do not impact the color map of the plot .
 zoom _ around _ mask : bool
 If True , the 2D region of the array corresponding to the rectangle encompassing all unmasked values is plotted , thereby zooming into the region of interest .
 should _ plot _ border : bool
 If a mask is supplied , its borders pixels ( e . g . the exterior edge ) is plotted if this is * True * .
 positions : [ [ ] ]
 Lists of ( y , x ) coordinates on the image which are plotted as colored dots , to highlight specific pixels .
 grid : data . array . grids . RegularGrid
 A grid of ( y , x ) coordinates which may be plotted over the plotted array .
 as _ subplot : bool
 Whether the array is plotted as part of a subplot , in which case the grid figure is not opened / closed .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 figsize : ( int , int )
 The size of the figure in ( rows , columns ) .
 aspect : str
 The aspect ratio of the array , specifically whether it is forced to be square ( ' equal ' ) or adapts its size to the figure size ( ' auto ' ) .
 cmap : str
 The colormap the array is plotted using , which may be chosen from the standard matplotlib colormaps .
 norm : str
 The normalization of the colormap used to plot the image , specifically whether it is linear ( ' linear ' ) , log ( ' log ' ) or a symmetric log normalization ( ' symmetric _ log ' ) .
 norm _ min : float or None
 The minimum array value the colormap map spans ( all values below this value are plotted the same color ) .
 norm _ max : float or None
 The maximum array value the colormap map spans ( all values above this value are plotted the same color ) .
 linthresh : float
 For the ' symmetric _ log ' colormap normalization , this specifies the range of values within which the colormap is linear .
 linscale : float
 For the ' symmetric _ log ' colormap normalization , this allowws the linear range set by linthresh to be stretched relative to the logarithmic range .
 cb _ ticksize : int
 The size of the tick labels on the colorbar .
 cb _ fraction : float
 The fraction of the figure that the colorbar takes up , which resizes the colorbar relative to the figure .
 cb _ pad : float
 Pads the color bar in the figure , which resizes the colorbar relative to the figure .
 xlabelsize : int
 The fontsize of the x axes label .
 ylabelsize : int
 The fontsize of the y axes label .
 xyticksize : int
 The font size of the x and y ticks on the figure axes .
 mask _ pointsize : int
 The size of the points plotted to show the mask .
 border _ pointsize : int
 The size of the points plotted to show the borders .
 positions _ pointsize : int
 The size of the points plotted to show the input positions .
 grid _ pointsize : int
 The size of the points plotted to show the grid .
 xticks _ manual : [ ] or None
 If input , the xticks do not use the array ' s default xticks but instead overwrite them as these values .
 yticks _ manual : [ ] or None
 If input , the yticks do not use the array ' s default yticks but instead overwrite them as these values .
 output _ path : str
 The path on the hard - disk where the figure is output .
 output _ filename : str
 The filename of the figure that is output .
 output _ format : str
 The format the figue is output :
 ' show ' - display on computer screen .
 ' png ' - output to hard - disk as a png .
 ' fits ' - output to hard - disk as a fits file . '
 Returns
 None
 Examples
 array _ plotters . plot _ array (
 array = image , origin = ( 0.0 , 0.0 ) , mask = circular _ mask , extract _ array _ from _ mask = True , zoom _ around _ mask = True ,
 should _ plot _ border = False , positions = [ [ 1.0 , 1.0 ] , [ 2.0 , 2.0 ] ] , grid = None , as _ subplot = False ,
 units = ' arcsec ' , kpc _ per _ arcsec = None , figsize = ( 7,7 ) , aspect = ' auto ' ,
 cmap = ' jet ' , norm = ' linear , norm _ min = None , norm _ max = None , linthresh = None , linscale = None ,
 cb _ ticksize = 10 , cb _ fraction = 0.047 , cb _ pad = 0.01 , cb _ tick _ values = None , cb _ tick _ labels = None ,
 title = ' Image ' , titlesize = 16 , xlabelsize = 16 , ylabelsize = 16 , xyticksize = 16,
 mask _ pointsize = 10 , border _ pointsize = 2 , position _ pointsize = 10 , grid _ pointsize = 10,
 xticks _ manual = None , yticks _ manual = None ,
 output _ path = ' / path / to / output ' , output _ format = ' png ' , output _ filename = ' image ' )"""

implementation:
if array is None :
    return
if extract_array_from_mask and mask is not None :
    array = np . add ( array , 0.0 , out = np . zeros_like ( array ) , where = np . asarray ( mask ) == 0 )
if zoom_around_mask and mask is not None :
    array = array . zoomed_scaled_array_around_mask ( mask = mask , buffer = 2 )
    zoom_offset_pixels = np . asarray ( mask . zoom_offset_pixels )
    zoom_offset_arcsec = np . asarray ( mask . zoom_offset_arcsec )
else :
    zoom_offset_pixels = None
    zoom_offset_arcsec = None
if aspect is 'square' :
    aspect = float ( array . shape_arcsec [ 1 ] ) / float ( array . shape_arcsec [ 0 ] )
fig = plot_figure ( array = array , as_subplot = as_subplot , units = units , kpc_per_arcsec = kpc_per_arcsec , figsize = figsize , aspect = aspect , cmap = cmap , norm = norm , norm_min = norm_min , norm_max = norm_max , linthresh = linthresh , linscale = linscale , xticks_manual = xticks_manual , yticks_manual = yticks_manual )
plotter_util . set_title ( title = title , titlesize = titlesize )
set_xy_labels_and_ticksize ( units = units , kpc_per_arcsec = kpc_per_arcsec , xlabelsize = xlabelsize , ylabelsize = ylabelsize , xyticksize = xyticksize )
set_colorbar ( cb_ticksize = cb_ticksize , cb_fraction = cb_fraction , cb_pad = cb_pad , cb_tick_values = cb_tick_values , cb_tick_labels = cb_tick_labels )
plot_origin ( array = array , origin = origin , units = units , kpc_per_arcsec = kpc_per_arcsec , zoom_offset_arcsec = zoom_offset_arcsec )
plot_mask ( mask = mask , units = units , kpc_per_arcsec = kpc_per_arcsec , pointsize = mask_pointsize , zoom_offset_pixels = zoom_offset_pixels )
plot_border ( mask = mask , should_plot_border = should_plot_border , units = units , kpc_per_arcsec = kpc_per_arcsec , pointsize = border_pointsize , zoom_offset_pixels = zoom_offset_pixels )
plot_points ( points_arcsec = positions , array = array , units = units , kpc_per_arcsec = kpc_per_arcsec , pointsize = position_pointsize , zoom_offset_arcsec = zoom_offset_arcsec )
plot_grid ( grid_arcsec = grid , array = array , units = units , kpc_per_arcsec = kpc_per_arcsec , pointsize = grid_pointsize , zoom_offset_arcsec = zoom_offset_arcsec )
plot_centres ( array = array , centres = centres , units = units , kpc_per_arcsec = kpc_per_arcsec , zoom_offset_arcsec = zoom_offset_arcsec )
plot_ellipses ( fig = fig , array = array , centres = centres , axis_ratios = axis_ratios , phis = phis , units = units , kpc_per_arcsec = kpc_per_arcsec , zoom_offset_arcsec = zoom_offset_arcsec )
plotter_util . output_figure ( array , as_subplot = as_subplot , output_path = output_path , output_filename = output_filename , output_format = output_format )
plotter_util . close_figure ( as_subplot = as_subplot )


signature:
def plot_figure ( array , as_subplot , units , kpc_per_arcsec , figsize , aspect , cmap , norm , norm_min , norm_max , linthresh , linscale , xticks_manual , yticks_manual ) :
    """Open a matplotlib figure and plot the array of data on it .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 as _ subplot : bool
 Whether the array is plotted as part of a subplot , in which case the grid figure is not opened / closed .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 figsize : ( int , int )
 The size of the figure in ( rows , columns ) .
 aspect : str
 The aspect ratio of the array , specifically whether it is forced to be square ( ' equal ' ) or adapts its size to the figure size ( ' auto ' ) .
 cmap : str
 The colormap the array is plotted using , which may be chosen from the standard matplotlib colormaps .
 norm : str
 The normalization of the colormap used to plot the image , specifically whether it is linear ( ' linear ' ) , log ( ' log ' ) or a symmetric log normalization ( ' symmetric _ log ' ) .
 norm _ min : float or None
 The minimum array value the colormap map spans ( all values below this value are plotted the same color ) .
 norm _ max : float or None
 The maximum array value the colormap map spans ( all values above this value are plotted the same color ) .
 linthresh : float
 For the ' symmetric _ log ' colormap normalization , this specifies the range of values within which the colormap is linear .
 linscale : float
 For the ' symmetric _ log ' colormap normalization , this allowws the linear range set by linthresh to be stretched relative to the logarithmic range .
 xticks _ manual : [ ] or None
 If input , the xticks do not use the array ' s default xticks but instead overwrite them as these values .
 yticks _ manual : [ ] or None
 If input , the yticks do not use the array ' s default yticks but instead overwrite them as these values ."""

implementation:
fig = plotter_util . setup_figure ( figsize = figsize , as_subplot = as_subplot )
norm_min , norm_max = get_normalization_min_max ( array = array , norm_min = norm_min , norm_max = norm_max )
norm_scale = get_normalization_scale ( norm = norm , norm_min = norm_min , norm_max = norm_max , linthresh = linthresh , linscale = linscale )
extent = get_extent ( array = array , units = units , kpc_per_arcsec = kpc_per_arcsec , xticks_manual = xticks_manual , yticks_manual = yticks_manual )
plt . imshow ( array , aspect = aspect , cmap = cmap , norm = norm_scale , extent = extent )
return fig


signature:
def get_extent ( array , units , kpc_per_arcsec , xticks_manual , yticks_manual ) :
    """Get the extent of the dimensions of the array in the units of the figure ( e . g . arc - seconds or kpc ) .
 This is used to set the extent of the array and thus the y / x axis limits .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 xticks _ manual : [ ] or None
 If input , the xticks do not use the array ' s default xticks but instead overwrite them as these values .
 yticks _ manual : [ ] or None
 If input , the yticks do not use the array ' s default yticks but instead overwrite them as these values ."""

implementation:
if xticks_manual is not None and yticks_manual is not None :
    return np . asarray ( [ xticks_manual [ 0 ] , xticks_manual [ 3 ] , yticks_manual [ 0 ] , yticks_manual [ 3 ] ] )
if units in 'pixels' :
    return np . asarray ( [ 0 , array . shape [ 1 ] , 0 , array . shape [ 0 ] ] )
elif units in 'arcsec' or kpc_per_arcsec is None :
    return np . asarray ( [ array . arc_second_minima [ 1 ] , array . arc_second_maxima [ 1 ] , array . arc_second_minima [ 0 ] , array . arc_second_maxima [ 0 ] ] )
elif units in 'kpc' :
    return list ( map ( lambda tick : tick * kpc_per_arcsec , np . asarray ( [ array . arc_second_minima [ 1 ] , array . arc_second_maxima [ 1 ] , array . arc_second_minima [ 0 ] , array . arc_second_maxima [ 0 ] ] ) ) )
else :
    raise exc . PlottingException ( 'The units supplied to the plotted are not a valid string (must be pixels | ' 'arcsec | kpc)' )


signature:
def get_normalization_min_max ( array , norm_min , norm_max ) :
    """Get the minimum and maximum of the normalization of the array , which sets the lower and upper limits of the colormap .
 If norm _ min / norm _ max are not supplied , the minimum / maximum values of the array of data are used .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 norm _ min : float or None
 The minimum array value the colormap map spans ( all values below this value are plotted the same color ) .
 norm _ max : float or None
 The maximum array value the colormap map spans ( all values above this value are plotted the same color ) ."""

implementation:
if norm_min is None :
    norm_min = array . min ( )
if norm_max is None :
    norm_max = array . max ( )
return norm_min , norm_max


signature:
def get_normalization_scale ( norm , norm_min , norm_max , linthresh , linscale ) :
    """Get the normalization scale of the colormap . This will be scaled based on the input min / max normalization values .
 For a ' symmetric _ log ' colormap , linthesh and linscale also change the colormap .
 If norm _ min / norm _ max are not supplied , the minimum / maximum values of the array of data are used .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 norm _ min : float or None
 The minimum array value the colormap map spans ( all values below this value are plotted the same color ) .
 norm _ max : float or None
 The maximum array value the colormap map spans ( all values above this value are plotted the same color ) .
 linthresh : float
 For the ' symmetric _ log ' colormap normalization , this specifies the range of values within which the colormap is linear .
 linscale : float
 For the ' symmetric _ log ' colormap normalization , this allowws the linear range set by linthresh to be stretched relative to the logarithmic range ."""

implementation:
if norm is 'linear' :
    return colors . Normalize ( vmin = norm_min , vmax = norm_max )
elif norm is 'log' :
    if norm_min == 0.0 :
        norm_min = 1.e-4
    return colors . LogNorm ( vmin = norm_min , vmax = norm_max )
elif norm is 'symmetric_log' :
    return colors . SymLogNorm ( linthresh = linthresh , linscale = linscale , vmin = norm_min , vmax = norm_max )
else :
    raise exc . PlottingException ( 'The normalization (norm) supplied to the plotter is not a valid string (must be ' 'linear | log | symmetric_log' )


signature:
def set_colorbar ( cb_ticksize , cb_fraction , cb_pad , cb_tick_values , cb_tick_labels ) :
    """Setup the colorbar of the figure , specifically its ticksize and the size is appears relative to the figure .
 Parameters
 cb _ ticksize : int
 The size of the tick labels on the colorbar .
 cb _ fraction : float
 The fraction of the figure that the colorbar takes up , which resizes the colorbar relative to the figure .
 cb _ pad : float
 Pads the color bar in the figure , which resizes the colorbar relative to the figure .
 cb _ tick _ values : [ float ]
 Manually specified values of where the colorbar tick labels appear on the colorbar .
 cb _ tick _ labels : [ float ]
 Manually specified labels of the color bar tick labels , which appear where specified by cb _ tick _ values ."""

implementation:
if cb_tick_values is None and cb_tick_labels is None :
    cb = plt . colorbar ( fraction = cb_fraction , pad = cb_pad )
elif cb_tick_values is not None and cb_tick_labels is not None :
    cb = plt . colorbar ( fraction = cb_fraction , pad = cb_pad , ticks = cb_tick_values )
    cb . ax . set_yticklabels ( cb_tick_labels )
else :
    raise exc . PlottingException ( 'Only 1 entry of cb_tick_values or cb_tick_labels was input. You must either supply' 'both the values and labels, or neither.' )
cb . ax . tick_params ( labelsize = cb_ticksize )


signature:
def convert_grid_units ( array , grid_arcsec , units , kpc_per_arcsec ) :
    """Convert the grid from its input units ( arc - seconds ) to the input unit ( e . g . retain arc - seconds ) or convert to another set of units ( pixels or kilo parsecs ) .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted , the shape of which is used for converting the grid to units of pixels .
 grid _ arcsec : ndarray or data . array . grids . RegularGrid
 The ( y , x ) coordinates of the grid in arc - seconds , in an array of shape ( total _ coordinates , 2 ) .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc ."""

implementation:
if units in 'pixels' :
    return array . grid_arcsec_to_grid_pixels ( grid_arcsec = grid_arcsec )
elif units in 'arcsec' or kpc_per_arcsec is None :
    return grid_arcsec
elif units in 'kpc' :
    return grid_arcsec * kpc_per_arcsec
else :
    raise exc . PlottingException ( 'The units supplied to the plotter are not a valid string (must be pixels | ' 'arcsec | kpc)' )


signature:
def plot_origin ( array , origin , units , kpc_per_arcsec , zoom_offset_arcsec ) :
    """Plot the ( y , x ) origin ofo the array ' s coordinates as a ' x ' .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 origin : ( float , float ) .
 The origin of the coordinate system of the array , which is plotted as an ' x ' on the image if input .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc ."""

implementation:
if origin is not None :
    origin_grid = np . asarray ( origin )
    if zoom_offset_arcsec is not None :
        origin_grid -= zoom_offset_arcsec
    origin_units = convert_grid_units ( array = array , grid_arcsec = origin_grid , units = units , kpc_per_arcsec = kpc_per_arcsec )
    plt . scatter ( y = origin_units [ 0 ] , x = origin_units [ 1 ] , s = 80 , c = 'k' , marker = 'x' )


signature:
def plot_centres ( array , centres , units , kpc_per_arcsec , zoom_offset_arcsec ) :
    """Plot the ( y , x ) centres ( e . g . of a mass profile ) on the array as an ' x ' .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 centres : [ [ tuple ] ]
 The list of centres ; centres in the same list entry are colored the same .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc ."""

implementation:
if centres is not None :
    colors = itertools . cycle ( [ "m" , "y" , "r" , "w" , "c" , "b" , "g" , "k" ] )
    for centres_of_galaxy in centres :
        color = next ( colors )
        for centre in centres_of_galaxy :
            if zoom_offset_arcsec is not None :
                centre -= zoom_offset_arcsec
            centre_units = convert_grid_units ( array = array , grid_arcsec = centre , units = units , kpc_per_arcsec = kpc_per_arcsec )
            plt . scatter ( y = centre_units [ 0 ] , x = centre_units [ 1 ] , s = 300 , c = color , marker = 'x' )


signature:
def plot_ellipses ( fig , array , centres , axis_ratios , phis , units , kpc_per_arcsec , zoom_offset_arcsec ) :
    """Plot the ( y , x ) centres ( e . g . of a mass profile ) on the array as an ' x ' .
 Parameters
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 centres : [ [ tuple ] ]
 The list of centres ; centres in the same list entry are colored the same .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc ."""

implementation:
if centres is not None and axis_ratios is not None and phis is not None :
    colors = itertools . cycle ( [ "m" , "y" , "r" , "w" , "c" , "b" , "g" , "k" ] )
    for set_index in range ( len ( centres ) ) :
        color = next ( colors )
        for geometry_index in range ( len ( centres [ set_index ] ) ) :
            centre = centres [ set_index ] [ geometry_index ]
            axis_ratio = axis_ratios [ set_index ] [ geometry_index ]
            phi = phis [ set_index ] [ geometry_index ]
            if zoom_offset_arcsec is not None :
                centre -= zoom_offset_arcsec
            centre_units = convert_grid_units ( array = array , grid_arcsec = centre , units = units , kpc_per_arcsec = kpc_per_arcsec )
            y = 1.0
            x = 1.0 * axis_ratio
            t = np . linspace ( 0 , 2 * np . pi , 100 )
            plt . plot ( centre_units [ 0 ] + y * np . cos ( t ) , centre_units [ 1 ] + x * np . sin ( t ) , color = color )


signature:
def plot_mask ( mask , units , kpc_per_arcsec , pointsize , zoom_offset_pixels ) :
    """Plot the mask of the array on the figure .
 Parameters
 mask : ndarray of data . array . mask . Mask
 The mask applied to the array , the edge of which is plotted as a set of points over the plotted array .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 pointsize : int
 The size of the points plotted to show the mask ."""

implementation:
if mask is not None :
    plt . gca ( )
    edge_pixels = mask . masked_grid_index_to_pixel [ mask . edge_pixels ] + 0.5
    if zoom_offset_pixels is not None :
        edge_pixels -= zoom_offset_pixels
    edge_arcsec = mask . grid_pixels_to_grid_arcsec ( grid_pixels = edge_pixels )
    edge_units = convert_grid_units ( array = mask , grid_arcsec = edge_arcsec , units = units , kpc_per_arcsec = kpc_per_arcsec )
    plt . scatter ( y = edge_units [ : , 0 ] , x = edge_units [ : , 1 ] , s = pointsize , c = 'k' )


signature:
def plot_border ( mask , should_plot_border , units , kpc_per_arcsec , pointsize , zoom_offset_pixels ) :
    """Plot the borders of the mask or the array on the figure .
 Parameters
 mask : ndarray of data . array . mask . Mask
 The mask applied to the array , the edge of which is plotted as a set of points over the plotted array .
 should _ plot _ border : bool
 If a mask is supplied , its borders pixels ( e . g . the exterior edge ) is plotted if this is * True * .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 border _ pointsize : int
 The size of the points plotted to show the borders ."""

implementation:
if should_plot_border and mask is not None :
    plt . gca ( )
    border_pixels = mask . masked_grid_index_to_pixel [ mask . border_pixels ]
    if zoom_offset_pixels is not None :
        border_pixels -= zoom_offset_pixels
    border_arcsec = mask . grid_pixels_to_grid_arcsec ( grid_pixels = border_pixels )
    border_units = convert_grid_units ( array = mask , grid_arcsec = border_arcsec , units = units , kpc_per_arcsec = kpc_per_arcsec )
    plt . scatter ( y = border_units [ : , 0 ] , x = border_units [ : , 1 ] , s = pointsize , c = 'y' )


signature:
def plot_points ( points_arcsec , array , units , kpc_per_arcsec , pointsize , zoom_offset_arcsec ) :
    """Plot a set of points over the array of data on the figure .
 Parameters
 positions : [ [ ] ]
 Lists of ( y , x ) coordinates on the image which are plotted as colored dots , to highlight specific pixels .
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 pointsize : int
 The size of the points plotted to show the input positions ."""

implementation:
if points_arcsec is not None :
    points_arcsec = list ( map ( lambda position_set : np . asarray ( position_set ) , points_arcsec ) )
    point_colors = itertools . cycle ( [ "m" , "y" , "r" , "w" , "c" , "b" , "g" , "k" ] )
    for point_set_arcsec in points_arcsec :
        if zoom_offset_arcsec is not None :
            point_set_arcsec -= zoom_offset_arcsec
        point_set_units = convert_grid_units ( array = array , grid_arcsec = point_set_arcsec , units = units , kpc_per_arcsec = kpc_per_arcsec )
        plt . scatter ( y = point_set_units [ : , 0 ] , x = point_set_units [ : , 1 ] , color = next ( point_colors ) , s = pointsize )


signature:
def plot_grid ( grid_arcsec , array , units , kpc_per_arcsec , pointsize , zoom_offset_arcsec ) :
    """Plot a grid of points over the array of data on the figure .
 Parameters
 grid _ arcsec : ndarray or data . array . grids . RegularGrid
 A grid of ( y , x ) coordinates in arc - seconds which may be plotted over the array .
 array : data . array . scaled _ array . ScaledArray
 The 2D array of data which is plotted .
 units : str
 The units of the y / x axis of the plots , in arc - seconds ( ' arcsec ' ) or kiloparsecs ( ' kpc ' ) .
 kpc _ per _ arcsec : float or None
 The conversion factor between arc - seconds and kiloparsecs , required to plot the units in kpc .
 grid _ pointsize : int
 The size of the points plotted to show the grid ."""

implementation:
if grid_arcsec is not None :
    if zoom_offset_arcsec is not None :
        grid_arcsec -= zoom_offset_arcsec
    grid_units = convert_grid_units ( grid_arcsec = grid_arcsec , array = array , units = units , kpc_per_arcsec = kpc_per_arcsec )
    plt . scatter ( y = np . asarray ( grid_units [ : , 0 ] ) , x = np . asarray ( grid_units [ : , 1 ] ) , s = pointsize , c = 'k' )


signature:
def mapping_matrix ( self ) :
    """The mapping matrix is a matrix representing the mapping between every unmasked pixel of a grid and the pixels of a pixelization . Non - zero entries signify a mapping , whereas zeros signify no mapping .
 For example , if the regular grid has 5 pixels and the pixelization 3 pixels , with the following mappings :
 regular pixel 0 - > pixelization pixel 0
 regular pixel 1 - > pixelization pixel 0
 regular pixel 2 - > pixelization pixel 1
 regular pixel 3 - > pixelization pixel 1
 regular pixel 4 - > pixelization pixel 2
 The mapping matrix ( which is of dimensions regular _ pixels x pixelization _ pixels ) would appear as follows :
 [1 , 0 , 0 ] [ 0 - > 0]
 [1 , 0 , 0 ] [ 1 - > 0]
 [0 , 1 , 0 ] [ 2 - > 1]
 [0 , 1 , 0 ] [ 3 - > 1]
 [0 , 0 , 1 ] [ 4 - > 2]
 The mapping matrix is in fact built using the sub - grid of the grid - stack , whereby each regular - pixel is divided into a regular grid of sub - pixels which are all paired to pixels in the pixelization . The entires in the mapping matrix now become fractional values dependent on the sub - grid size . For example , for a 2x2 sub - grid in each pixel ( which means the fraction value is 1.0 / ( 2.0 ^ 2 ) = 0.25 , if we have the following mappings :
 regular pixel 0 - > sub pixel 0 - > pixelization pixel 0
 regular pixel 0 - > sub pixel 1 - > pixelization pixel 1
 regular pixel 0 - > sub pixel 2 - > pixelization pixel 1
 regular pixel 0 - > sub pixel 3 - > pixelization pixel 1
 regular pixel 1 - > sub pixel 0 - > pixelization pixel 1
 regular pixel 1 - > sub pixel 1 - > pixelization pixel 1
 regular pixel 1 - > sub pixel 2 - > pixelization pixel 1
 regular pixel 1 - > sub pixel 3 - > pixelization pixel 1
 regular pixel 2 - > sub pixel 0 - > pixelization pixel 2
 regular pixel 2 - > sub pixel 1 - > pixelization pixel 2
 regular pixel 2 - > sub pixel 2 - > pixelization pixel 3
 regular pixel 2 - > sub pixel 3 - > pixelization pixel 3
 The mapping matrix ( which is still of dimensions regular _ pixels x source _ pixels ) would appear as follows :
 [0.25 , 0.75 , 0.0 , 0.0 ] [ 1 sub - pixel maps to pixel 0 , 3 map to pixel 1]
 [ 0.0 , 1.0 , 0.0 , 0.0 ] [ All sub - pixels map to pixel 1]
 [ 0.0 , 0.0 , 0.5 , 0.5 ] [ 2 sub - pixels map to pixel 2 , 2 map to pixel 3]"""

implementation: return mapper_util . mapping_matrix_from_sub_to_pix ( sub_to_pix = self . sub_to_pix , pixels = self . pixels , regular_pixels = self . grid_stack . regular . shape [ 0 ] , sub_to_regular = self . grid_stack . sub . sub_to_regular , sub_grid_fraction = self . grid_stack . sub . sub_grid_fraction )


signature:
def pix_to_regular ( self ) :
    """Compute the mappings between a pixelization ' s pixels and the unmasked regular - grid pixels . These mappings are determined after the regular - grid is used to determine the pixelization .
 The pixelization ' s pixels map to different number of regular - grid pixels , thus a list of lists is used to represent these mappings"""

implementation:
pix_to_regular = [ [ ] for _ in range ( self . pixels ) ]
for regular_pixel , pix_pixel in enumerate ( self . regular_to_pix ) :
    pix_to_regular [ pix_pixel ] . append ( regular_pixel )
return pix_to_regular


signature:
def pix_to_sub ( self ) :
    """Compute the mappings between a pixelization ' s pixels and the unmasked sub - grid pixels . These mappings are determined after the regular - grid is used to determine the pixelization .
 The pixelization ' s pixels map to different number of sub - grid pixels , thus a list of lists is used to represent these mappings"""

implementation:
pix_to_sub = [ [ ] for _ in range ( self . pixels ) ]
for regular_pixel , pix_pixel in enumerate ( self . sub_to_pix ) :
    pix_to_sub [ pix_pixel ] . append ( regular_pixel )
return pix_to_sub


signature:
def reconstructed_pixelization_from_solution_vector ( self , solution_vector ) :
    """Given the solution vector of an inversion ( see * inversions . Inversion * ) , determine the reconstructed pixelization of the rectangular pixelization by using the mapper ."""

implementation:
recon = mapping_util . map_unmasked_1d_array_to_2d_array_from_array_1d_and_shape ( array_1d = solution_vector , shape = self . shape )
return scaled_array . ScaledRectangularPixelArray ( array = recon , pixel_scales = self . geometry . pixel_scales , origin = self . geometry . origin )


signature:
def regular_to_pix ( self ) :
    """The 1D index mappings between the regular pixels and Voronoi pixelization pixels ."""

implementation: return mapper_util . voronoi_regular_to_pix_from_grids_and_geometry ( regular_grid = self . grid_stack . regular , regular_to_nearest_pix = self . grid_stack . pix . regular_to_nearest_pix , pixel_centres = self . geometry . pixel_centres , pixel_neighbors = self . geometry . pixel_neighbors , pixel_neighbors_size = self . geometry . pixel_neighbors_size ) . astype ( 'int' )


signature:
def sub_to_pix ( self ) :
    """The 1D index mappings between the sub pixels and Voronoi pixelization pixels ."""

implementation: return mapper_util . voronoi_sub_to_pix_from_grids_and_geometry ( sub_grid = self . grid_stack . sub , regular_to_nearest_pix = self . grid_stack . pix . regular_to_nearest_pix , sub_to_regular = self . grid_stack . sub . sub_to_regular , pixel_centres = self . geometry . pixel_centres , pixel_neighbors = self . geometry . pixel_neighbors , pixel_neighbors_size = self . geometry . pixel_neighbors_size ) . astype ( 'int' )


signature:
def centres_from_shape_pixel_scales_and_origin ( shape , pixel_scales , origin ) :
    """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 ) )"""

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


signature:
def regular_grid_2d_from_shape_pixel_scales_and_origin ( shape , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """Compute the ( y , x ) arc second coordinates at the centre of every pixel of an array of shape ( rows , columns ) .
 Coordinates are defined from the top - left corner , such that the first pixel at location [ 0 , 0 ] has negative x and y values in arc seconds .
 The regular grid is returned on an array of shape ( total _ pixels , total _ pixels , 2 ) where coordinate indexes match those of the original 2D array . y coordinates are stored in the 0 index of the third dimension , x coordinates in the 1 index .
 Parameters
 shape : ( int , int )
 The ( y , x ) shape of the 2D array the regular grid of coordinates 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 regular grid is shifted around .
 Returns
 ndarray
 A regular grid of ( y , x ) arc - second coordinates at the centre of every pixel on a 2D array . The regular grid array has dimensions ( total _ pixels , total _ pixels , 2 ) .
 Examples
 regular _ grid _ 1d = regular _ grid _ 2d _ from _ shape _ pixel _ scales _ and _ origin ( shape = ( 5,5 ) , pixel _ scales = ( 0.5 , 0.5 ) , origin = ( 0.0 , 0.0 ) )"""

implementation:
regular_grid_2d = np . zeros ( ( shape [ 0 ] , shape [ 1 ] , 2 ) )
centres_arcsec = centres_from_shape_pixel_scales_and_origin ( shape = shape , pixel_scales = pixel_scales , origin = origin )
for y in range ( shape [ 0 ] ) :
    for x in range ( shape [ 1 ] ) :
        regular_grid_2d [ y , x , 0 ] = - ( y - centres_arcsec [ 0 ] ) * pixel_scales [ 0 ]
        regular_grid_2d [ y , x , 1 ] = ( x - centres_arcsec [ 1 ] ) * pixel_scales [ 1 ]
return regular_grid_2d


signature:
def regular_grid_1d_from_shape_pixel_scales_and_origin ( shape , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """Compute the ( y , x ) arc second coordinates at the centre of every pixel of an array of shape ( rows , columns ) .
 Coordinates are defined from the top - left corner , such that the first pixel at location [ 0 , 0 ] has negative x and y values in arc seconds .
 The regular grid is returned on an array of shape ( total _ pixels * * 2 , 2 ) where the 2D dimension of the original 2D array are reduced to one dimension . y coordinates are stored in the 0 index of the second dimension , x coordinates
 in the 1 index .
 Parameters
 shape : ( int , int )
 The ( y , x ) shape of the 2D array the regular grid of coordinates 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 regular grid is shifted around .
 Returns
 ndarray
 A regular grid of ( y , x ) arc - second coordinates at the centre of every pixel on a 2D array . The regular grid
 array has dimensions ( total _ pixels * * 2 , 2 ) .
 Examples
 regular _ grid _ 1d = regular _ grid _ 1d _ from _ shape _ pixel _ scales _ and _ origin ( shape = ( 5,5 ) , pixel _ scales = ( 0.5 , 0.5 ) , origin = ( 0.0 , 0.0 ) )"""

implementation:
regular_grid_1d = np . zeros ( ( shape [ 0 ] * shape [ 1 ] , 2 ) )
centres_arcsec = centres_from_shape_pixel_scales_and_origin ( shape = shape , pixel_scales = pixel_scales , origin = origin )
i = 0
for y in range ( shape [ 0 ] ) :
    for x in range ( shape [ 1 ] ) :
        regular_grid_1d [ i , 0 ] = - ( y - centres_arcsec [ 0 ] ) * pixel_scales [ 0 ]
        regular_grid_1d [ i , 1 ] = ( x - centres_arcsec [ 1 ] ) * pixel_scales [ 1 ]
        i += 1
return regular_grid_1d


signature:
def regular_grid_1d_masked_from_mask_pixel_scales_and_origin ( mask , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """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 ) )"""

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


signature:
def sub_grid_1d_masked_from_mask_pixel_scales_and_sub_grid_size ( mask , pixel_scales , sub_grid_size , origin = ( 0.0 , 0.0 ) ) :
    """For the sub - grid , every unmasked pixel of a 2D mask array of shape ( rows , columns ) is divided into a finer uniform grid of shape ( sub _ grid _ size , sub _ grid _ size ) . This routine computes the ( y , x ) arc second coordinates at the centre of every sub - pixel defined by this grid .
 Coordinates are defined from the top - left corner , where the first unmasked sub - pixel corresponds to index 0 . Sub - pixels that are part of the same mask array pixel are indexed next to one another , such that the second sub - pixel in the first pixel has index 1 , its next sub - pixel has index 2 , and so forth .
 The sub - grid is returned on an array of shape ( total _ unmasked _ pixels * sub _ grid _ size * * 2 , 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 .
 sub _ grid _ size : int
 The size of the sub - grid that each pixel of the 2D mask array is divided into .
 origin : ( float , flloat )
 The ( y , x ) origin of the 2D array , which the sub - grid is shifted around .
 Returns
 ndarray
 A sub grid of ( y , x ) arc - second coordinates at the centre of every pixel unmasked pixel on the 2D mask array . The sub grid array has dimensions ( total _ unmasked _ pixels * sub _ grid _ size * * 2 , 2 ) .
 Examples
 mask = np . array ( [ [ True , False , True ] ,
 [ False , False , False ]
 [ True , False , True ] ] )
 sub _ grid _ 1d = sub _ grid _ 1d _ from _ mask _ pixel _ scales _ and _ origin ( mask = mask , pixel _ scales = ( 0.5 , 0.5 ) , origin = ( 0.0 , 0.0 ) )"""

implementation:
total_sub_pixels = mask_util . total_sub_pixels_from_mask_and_sub_grid_size ( mask , sub_grid_size )
sub_grid_1d = np . zeros ( shape = ( total_sub_pixels , 2 ) )
centres_arcsec = centres_from_shape_pixel_scales_and_origin ( shape = mask . shape , pixel_scales = pixel_scales , origin = origin )
sub_index = 0
y_sub_half = pixel_scales [ 0 ] / 2
y_sub_step = pixel_scales [ 0 ] / ( sub_grid_size + 1 )
x_sub_half = pixel_scales [ 1 ] / 2
x_sub_step = pixel_scales [ 1 ] / ( sub_grid_size + 1 )
for y in range ( mask . shape [ 0 ] ) :
    for x in range ( mask . shape [ 1 ] ) :
        if not mask [ y , x ] :
            y_arcsec = ( y - centres_arcsec [ 0 ] ) * pixel_scales [ 0 ]
            x_arcsec = ( x - centres_arcsec [ 1 ] ) * pixel_scales [ 1 ]
            for y1 in range ( sub_grid_size ) :
                for x1 in range ( sub_grid_size ) :
                    sub_grid_1d [ sub_index , 0 ] = - ( y_arcsec - y_sub_half + ( y1 + 1 ) * y_sub_step )
                    sub_grid_1d [ sub_index , 1 ] = x_arcsec - x_sub_half + ( x1 + 1 ) * x_sub_step
                    sub_index += 1
return sub_grid_1d


signature:
def grid_arcsec_1d_to_grid_pixel_centres_1d ( grid_arcsec_1d , shape , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """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 ) )"""

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


signature:
def grid_arcsec_1d_to_grid_pixel_indexes_1d ( grid_arcsec_1d , shape , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """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 ) )"""

implementation:
grid_pixels_1d = grid_arcsec_1d_to_grid_pixel_centres_1d ( grid_arcsec_1d = grid_arcsec_1d , shape = shape , pixel_scales = pixel_scales , origin = origin )
grid_pixel_indexes_1d = np . zeros ( grid_pixels_1d . shape [ 0 ] )
for i in range ( grid_pixels_1d . shape [ 0 ] ) :
    grid_pixel_indexes_1d [ i ] = int ( grid_pixels_1d [ i , 0 ] * shape [ 1 ] + grid_pixels_1d [ i , 1 ] )
return grid_pixel_indexes_1d


signature:
def grid_pixels_1d_to_grid_arcsec_1d ( grid_pixels_1d , shape , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """Convert a grid of ( y , x ) pixel coordinates to a grid of ( y , x ) arc second values .
 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 origin is defined by the class attribute origin , and coordinates are shifted to this origin after computing their values from the 1D grid pixel indexes .
 The input and output grids are both of shape ( total _ pixels , 2 ) .
 Parameters
 grid _ pixels _ 1d : ndarray
 The grid of ( y , x ) coordinates in pixel values which is converted to arc - second 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 .
 Returns
 ndarray
 A grid of 1d arc - second coordinates with dimensions ( total _ pixels , 2 ) .
 Examples
 grid _ pixels _ 1d = np . array ( [ [ 0,0 ] , [ 0,1 ] , [ 1,0 ] , [ 1,1 ] )
 grid _ pixels _ 1d = grid _ pixels _ 1d _ to _ grid _ arcsec _ 1d ( grid _ pixels _ 1d = grid _ pixels _ 1d , shape = ( 2,2 ) ,
 pixel _ scales = ( 0.5 , 0.5 ) , origin = ( 0.0 , 0.0 ) )"""

implementation:
grid_arcsec_1d = np . zeros ( ( grid_pixels_1d . shape [ 0 ] , 2 ) )
centres_arcsec = centres_from_shape_pixel_scales_and_origin ( shape = shape , pixel_scales = pixel_scales , origin = origin )
for i in range ( grid_arcsec_1d . shape [ 0 ] ) :
    grid_arcsec_1d [ i , 0 ] = - ( grid_pixels_1d [ i , 0 ] - centres_arcsec [ 0 ] - 0.5 ) * pixel_scales [ 0 ]
    grid_arcsec_1d [ i , 1 ] = ( grid_pixels_1d [ i , 1 ] - centres_arcsec [ 1 ] - 0.5 ) * pixel_scales [ 1 ]
return grid_arcsec_1d


signature:
def grid_arcsec_2d_to_grid_pixel_centres_2d ( grid_arcsec_2d , shape , pixel_scales , origin = ( 0.0 , 0.0 ) ) :
    """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 ) )"""

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


signature:
def setup_random_seed ( seed ) :
    """Setup the random seed . If the input seed is - 1 , the code will use a random seed for every run . If it is positive , that seed is used for all runs , thereby giving reproducible results .
 Parameters
 seed : int
 The seed of the random number generator ."""

implementation:
if seed == - 1 :
    seed = np . random . randint ( 0 , int ( 1e9 ) )
    # Use one seed , so all regions have identical column non - uniformity .
np . random . seed ( seed )


signature:
def generate_poisson_noise ( image , exposure_time_map , seed = - 1 ) :
    """Generate a two - dimensional poisson noise _ maps - mappers from an image .
 Values are computed from a Poisson distribution using the image ' s input values in units of counts .
 Parameters
 image : ndarray
 The 2D image , whose values in counts are used to draw Poisson noise _ maps values .
 exposure _ time _ map : Union ( ndarray , int )
 2D array of the exposure time in each pixel used to convert to / from counts and electrons per second .
 seed : int
 The seed of the random number generator , used for the random noise _ maps maps .
 Returns
 poisson _ noise _ map : ndarray
 An array describing simulated poisson noise _ maps"""

implementation:
setup_random_seed ( seed )
image_counts = np . multiply ( image , exposure_time_map )
return image - np . divide ( np . random . poisson ( image_counts , image . shape ) , exposure_time_map )


signature:
def load_ccd_data_from_fits ( image_path , pixel_scale , image_hdu = 0 , resized_ccd_shape = None , resized_ccd_origin_pixels = None , resized_ccd_origin_arcsec = None , psf_path = None , psf_hdu = 0 , resized_psf_shape = None , renormalize_psf = True , noise_map_path = None , noise_map_hdu = 0 , noise_map_from_image_and_background_noise_map = False , convert_noise_map_from_weight_map = False , convert_noise_map_from_inverse_noise_map = False , background_noise_map_path = None , background_noise_map_hdu = 0 , convert_background_noise_map_from_weight_map = False , convert_background_noise_map_from_inverse_noise_map = False , poisson_noise_map_path = None , poisson_noise_map_hdu = 0 , poisson_noise_map_from_image = False , convert_poisson_noise_map_from_weight_map = False , convert_poisson_noise_map_from_inverse_noise_map = False , exposure_time_map_path = None , exposure_time_map_hdu = 0 , exposure_time_map_from_single_value = None , exposure_time_map_from_inverse_noise_map = False , background_sky_map_path = None , background_sky_map_hdu = 0 , convert_from_electrons = False , gain = None , convert_from_adus = False , lens_name = None ) :
    """Factory for loading the ccd data from . fits files , as well as computing properties like the noise - map ,
 exposure - time map , etc . from the ccd - data .
 This factory also includes a number of routines for converting the ccd - data from units not supported by PyAutoLens ( e . g . adus , electrons ) to electrons per second .
 Parameters
 lens _ name
 image _ path : str
 The path to the image . fits file containing the image ( e . g . ' / path / to / image . fits ' )
 pixel _ scale : float
 The size of each pixel in arc seconds .
 image _ hdu : int
 The hdu the image is contained in the . fits file specified by * image _ path * .
 image _ hdu : int
 The hdu the image is contained in the . fits file that * image _ path * points too .
 resized _ ccd _ shape : ( int , int ) | None
 If input , the ccd arrays that are image sized , e . g . the image , noise - maps ) are resized to these dimensions .
 resized _ ccd _ origin _ pixels : ( int , int ) | None
 If the ccd arrays are resized , this defines a new origin ( in pixels ) around which recentering occurs .
 resized _ ccd _ origin _ arcsec : ( float , float ) | None
 If the ccd arrays are resized , this defines a new origin ( in arc - seconds ) around which recentering occurs .
 psf _ path : str
 The path to the psf . fits file containing the psf ( e . g . ' / path / to / psf . fits ' )
 psf _ hdu : int
 The hdu the psf is contained in the . fits file specified by * psf _ path * .
 resized _ psf _ shape : ( int , int ) | None
 If input , the psf is resized to these dimensions .
 renormalize _ psf : bool
 If True , the PSF is renoralized such that all elements sum to 1.0.
 noise _ map _ path : str
 The path to the noise _ map . fits file containing the noise _ map ( e . g . ' / path / to / noise _ map . fits ' )
 noise _ map _ hdu : int
 The hdu the noise _ map is contained in the . fits file specified by * noise _ map _ path * .
 noise _ map _ from _ image _ and _ background _ noise _ map : bool
 If True , the noise - map is computed from the observed image and background noise - map ( see NoiseMap . from _ image _ and _ background _ noise _ map ) .
 convert _ noise _ map _ from _ weight _ map : bool
 If True , the noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) .
 background _ noise _ map _ path : str
 The path to the background _ noise _ map . fits file containing the background noise - map \
 ( e . g . ' / path / to / background _ noise _ map . fits ' )
 background _ noise _ map _ hdu : int
 The hdu the background _ noise _ map is contained in the . fits file specified by * background _ noise _ map _ path * .
 convert _ background _ noise _ map _ from _ weight _ map : bool
 If True , the bacground noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ background _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the background noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) .
 poisson _ noise _ map _ path : str
 The path to the poisson _ noise _ map . fits file containing the Poisson noise - map ( e . g . ' / path / to / poisson _ noise _ map . fits ' )
 poisson _ noise _ map _ hdu : int
 The hdu the poisson _ noise _ map is contained in the . fits file specified by * poisson _ noise _ map _ path * .
 poisson _ noise _ map _ from _ image : bool
 If True , the Poisson noise - map is estimated using the image .
 convert _ poisson _ noise _ map _ from _ weight _ map : bool
 If True , the Poisson noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ poisson _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the Poisson noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) .
 exposure _ time _ map _ path : str
 The path to the exposure _ time _ map . fits file containing the exposure time map \
 ( e . g . ' / path / to / exposure _ time _ map . fits ' )
 exposure _ time _ map _ hdu : int
 The hdu the exposure _ time _ map is contained in the . fits file specified by * exposure _ time _ map _ path * .
 exposure _ time _ map _ from _ single _ value : float
 The exposure time of the ccd imaging , which is used to compute the exposure - time map as a single value ( see * ExposureTimeMap . from _ single _ value * ) .
 exposure _ time _ map _ from _ inverse _ noise _ map : bool
 If True , the exposure - time map is computed from the background noise _ map map ( see * ExposureTimeMap . from _ background _ noise _ map * )
 background _ sky _ map _ path : str
 The path to the background _ sky _ map . fits file containing the background sky map ( e . g . ' / path / to / background _ sky _ map . fits ' ) .
 background _ sky _ map _ hdu : int
 The hdu the background _ sky _ map is contained in the . fits file specified by * background _ sky _ map _ path * .
 convert _ from _ electrons : bool
 If True , the input unblurred _ image _ 1d are in units of electrons and all converted to electrons / second using the exposure time map .
 gain : float
 The image gain , used for convert from ADUs .
 convert _ from _ adus : bool
 If True , the input unblurred _ image _ 1d are in units of adus and all converted to electrons / second using the exposure time map and gain ."""

implementation:
image = load_image ( image_path = image_path , image_hdu = image_hdu , pixel_scale = pixel_scale )
background_noise_map = load_background_noise_map ( background_noise_map_path = background_noise_map_path , background_noise_map_hdu = background_noise_map_hdu , pixel_scale = pixel_scale , convert_background_noise_map_from_weight_map = convert_background_noise_map_from_weight_map , convert_background_noise_map_from_inverse_noise_map = convert_background_noise_map_from_inverse_noise_map )
if background_noise_map is not None :
    inverse_noise_map = 1.0 / background_noise_map
else :
    inverse_noise_map = None
exposure_time_map = load_exposure_time_map ( exposure_time_map_path = exposure_time_map_path , exposure_time_map_hdu = exposure_time_map_hdu , pixel_scale = pixel_scale , shape = image . shape , exposure_time = exposure_time_map_from_single_value , exposure_time_map_from_inverse_noise_map = exposure_time_map_from_inverse_noise_map , inverse_noise_map = inverse_noise_map )
poisson_noise_map = load_poisson_noise_map ( poisson_noise_map_path = poisson_noise_map_path , poisson_noise_map_hdu = poisson_noise_map_hdu , pixel_scale = pixel_scale , convert_poisson_noise_map_from_weight_map = convert_poisson_noise_map_from_weight_map , convert_poisson_noise_map_from_inverse_noise_map = convert_poisson_noise_map_from_inverse_noise_map , image = image , exposure_time_map = exposure_time_map , poisson_noise_map_from_image = poisson_noise_map_from_image , convert_from_electrons = convert_from_electrons , gain = gain , convert_from_adus = convert_from_adus )
noise_map = load_noise_map ( noise_map_path = noise_map_path , noise_map_hdu = noise_map_hdu , pixel_scale = pixel_scale , image = image , background_noise_map = background_noise_map , exposure_time_map = exposure_time_map , convert_noise_map_from_weight_map = convert_noise_map_from_weight_map , convert_noise_map_from_inverse_noise_map = convert_noise_map_from_inverse_noise_map , noise_map_from_image_and_background_noise_map = noise_map_from_image_and_background_noise_map , convert_from_electrons = convert_from_electrons , gain = gain , convert_from_adus = convert_from_adus )
psf = load_psf ( psf_path = psf_path , psf_hdu = psf_hdu , pixel_scale = pixel_scale , renormalize = renormalize_psf )
background_sky_map = load_background_sky_map ( background_sky_map_path = background_sky_map_path , background_sky_map_hdu = background_sky_map_hdu , pixel_scale = pixel_scale )
image = CCDData ( image = image , pixel_scale = pixel_scale , psf = psf , noise_map = noise_map , background_noise_map = background_noise_map , poisson_noise_map = poisson_noise_map , exposure_time_map = exposure_time_map , background_sky_map = background_sky_map , gain = gain , name = lens_name )
if resized_ccd_shape is not None :
    image = image . new_ccd_data_with_resized_arrays ( new_shape = resized_ccd_shape , new_centre_pixels = resized_ccd_origin_pixels , new_centre_arcsec = resized_ccd_origin_arcsec )
if resized_psf_shape is not None :
    image = image . new_ccd_data_with_resized_psf ( new_shape = resized_psf_shape )
if convert_from_electrons :
    image = image . new_ccd_data_converted_from_electrons ( )
elif convert_from_adus :
    image = image . new_ccd_data_converted_from_adus ( gain = gain )
return image


signature:
def load_image ( image_path , image_hdu , pixel_scale ) :
    """Factory for loading the image from a . fits file
 Parameters
 image _ path : str
 The path to the image . fits file containing the image ( e . g . ' / path / to / image . fits ' )
 image _ hdu : int
 The hdu the image is contained in the . fits file specified by * image _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds . ."""

implementation: return ScaledSquarePixelArray . from_fits_with_pixel_scale ( file_path = image_path , hdu = image_hdu , pixel_scale = pixel_scale )


signature:
def load_noise_map ( noise_map_path , noise_map_hdu , pixel_scale , image , background_noise_map , exposure_time_map , convert_noise_map_from_weight_map , convert_noise_map_from_inverse_noise_map , noise_map_from_image_and_background_noise_map , convert_from_electrons , gain , convert_from_adus ) :
    """Factory for loading the noise - map from a . fits file .
 This factory also includes a number of routines for converting the noise - map from from other units ( e . g . a weight map ) or computing the noise - map from other unblurred _ image _ 1d ( e . g . the ccd image and background noise - map ) .
 Parameters
 noise _ map _ path : str
 The path to the noise _ map . fits file containing the noise _ map ( e . g . ' / path / to / noise _ map . fits ' )
 noise _ map _ hdu : int
 The hdu the noise _ map is contained in the . fits file specified by * noise _ map _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds .
 image : ndarray
 The image - image , which the noise - map can be calculated using .
 background _ noise _ map : ndarray
 The background noise - map , which the noise - map can be calculated using .
 exposure _ time _ map : ndarray
 The exposure - time map , which the noise - map can be calculated using .
 convert _ noise _ map _ from _ weight _ map : bool
 If True , the noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) .
 background _ noise _ map _ path : str
 The path and filename of the . fits image containing the background noise - map .
 background _ noise _ map _ hdu : int
 The hdu the background noise - map is contained in the . fits file that * background _ noise _ map _ path * points too .
 convert _ background _ noise _ map _ from _ weight _ map : bool
 If True , the bacground noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ background _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the background noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) .
 noise _ map _ from _ image _ and _ background _ noise _ map : bool
 If True , the noise - map is computed from the observed image and background noise - map ( see NoiseMap . from _ image _ and _ background _ noise _ map ) .
 convert _ from _ electrons : bool
 If True , the input unblurred _ image _ 1d are in units of electrons and all converted to electrons / second using the exposure time map .
 gain : float
 The image gain , used for convert from ADUs .
 convert _ from _ adus : bool
 If True , the input unblurred _ image _ 1d are in units of adus and all converted to electrons / second using the exposure time map and gain ."""

implementation:
noise_map_options = sum ( [ convert_noise_map_from_weight_map , convert_noise_map_from_inverse_noise_map , noise_map_from_image_and_background_noise_map ] )
if noise_map_options > 1 :
    raise exc . DataException ( 'You have specified more than one method to load the noise_map map, e.g.:' 'convert_noise_map_from_weight_map | ' 'convert_noise_map_from_inverse_noise_map |' 'noise_map_from_image_and_background_noise_map' )
if noise_map_options == 0 and noise_map_path is not None :
    return NoiseMap . from_fits_with_pixel_scale ( file_path = noise_map_path , hdu = noise_map_hdu , pixel_scale = pixel_scale )
elif convert_noise_map_from_weight_map and noise_map_path is not None :
    weight_map = Array . from_fits ( file_path = noise_map_path , hdu = noise_map_hdu )
    return NoiseMap . from_weight_map ( weight_map = weight_map , pixel_scale = pixel_scale )
elif convert_noise_map_from_inverse_noise_map and noise_map_path is not None :
    inverse_noise_map = Array . from_fits ( file_path = noise_map_path , hdu = noise_map_hdu )
    return NoiseMap . from_inverse_noise_map ( inverse_noise_map = inverse_noise_map , pixel_scale = pixel_scale )
elif noise_map_from_image_and_background_noise_map :
    if background_noise_map is None :
        raise exc . DataException ( 'Cannot compute the noise-map from the image and background noise_map map if a ' 'background noise_map map is not supplied.' )
    if not ( convert_from_electrons or convert_from_adus ) and exposure_time_map is None :
        raise exc . DataException ( 'Cannot compute the noise-map from the image and background noise_map map if an ' 'exposure-time (or exposure time map) is not supplied to convert to adus' )
    if convert_from_adus and gain is None :
        raise exc . DataException ( 'Cannot compute the noise-map from the image and background noise_map map if a' 'gain is not supplied to convert from adus' )
    return NoiseMap . from_image_and_background_noise_map ( pixel_scale = pixel_scale , image = image , background_noise_map = background_noise_map , exposure_time_map = exposure_time_map , convert_from_electrons = convert_from_electrons , gain = gain , convert_from_adus = convert_from_adus )
else :
    raise exc . DataException ( 'A noise_map map was not loaded, specify a noise_map_path or option to compute a noise_map map.' )


signature:
def load_background_noise_map ( background_noise_map_path , background_noise_map_hdu , pixel_scale , convert_background_noise_map_from_weight_map , convert_background_noise_map_from_inverse_noise_map ) :
    """Factory for loading the background noise - map from a . fits file .
 This factory also includes a number of routines for converting the background noise - map from from other units ( e . g . a weight map ) .
 Parameters
 background _ noise _ map _ path : str
 The path to the background _ noise _ map . fits file containing the background noise - map ( e . g . ' / path / to / background _ noise _ map . fits ' )
 background _ noise _ map _ hdu : int
 The hdu the background _ noise _ map is contained in the . fits file specified by * background _ noise _ map _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds .
 convert _ background _ noise _ map _ from _ weight _ map : bool
 If True , the bacground noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ background _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the background noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) ."""

implementation:
background_noise_map_options = sum ( [ convert_background_noise_map_from_weight_map , convert_background_noise_map_from_inverse_noise_map ] )
if background_noise_map_options == 0 and background_noise_map_path is not None :
    return NoiseMap . from_fits_with_pixel_scale ( file_path = background_noise_map_path , hdu = background_noise_map_hdu , pixel_scale = pixel_scale )
elif convert_background_noise_map_from_weight_map and background_noise_map_path is not None :
    weight_map = Array . from_fits ( file_path = background_noise_map_path , hdu = background_noise_map_hdu )
    return NoiseMap . from_weight_map ( weight_map = weight_map , pixel_scale = pixel_scale )
elif convert_background_noise_map_from_inverse_noise_map and background_noise_map_path is not None :
    inverse_noise_map = Array . from_fits ( file_path = background_noise_map_path , hdu = background_noise_map_hdu )
    return NoiseMap . from_inverse_noise_map ( inverse_noise_map = inverse_noise_map , pixel_scale = pixel_scale )
else :
    return None


signature:
def load_poisson_noise_map ( poisson_noise_map_path , poisson_noise_map_hdu , pixel_scale , convert_poisson_noise_map_from_weight_map , convert_poisson_noise_map_from_inverse_noise_map , poisson_noise_map_from_image , image , exposure_time_map , convert_from_electrons , gain , convert_from_adus ) :
    """Factory for loading the Poisson noise - map from a . fits file .
 This factory also includes a number of routines for converting the Poisson noise - map from from other units ( e . g . a weight map ) or computing the Poisson noise _ map from other unblurred _ image _ 1d ( e . g . the ccd image ) .
 Parameters
 poisson _ noise _ map _ path : str
 The path to the poisson _ noise _ map . fits file containing the Poisson noise - map ( e . g . ' / path / to / poisson _ noise _ map . fits ' )
 poisson _ noise _ map _ hdu : int
 The hdu the poisson _ noise _ map is contained in the . fits file specified by * poisson _ noise _ map _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds .
 convert _ poisson _ noise _ map _ from _ weight _ map : bool
 If True , the Poisson noise - map loaded from the . fits file is converted from a weight - map to a noise - map ( see * NoiseMap . from _ weight _ map ) .
 convert _ poisson _ noise _ map _ from _ inverse _ noise _ map : bool
 If True , the Poisson noise - map loaded from the . fits file is converted from an inverse noise - map to a noise - map ( see * NoiseMap . from _ inverse _ noise _ map ) .
 poisson _ noise _ map _ from _ image : bool
 If True , the Poisson noise - map is estimated using the image .
 image : ndarray
 The image , which the Poisson noise - map can be calculated using .
 background _ noise _ map : ndarray
 The background noise - map , which the Poisson noise - map can be calculated using .
 exposure _ time _ map : ndarray
 The exposure - time map , which the Poisson noise - map can be calculated using .
 convert _ from _ electrons : bool
 If True , the input unblurred _ image _ 1d are in units of electrons and all converted to electrons / second using the exposure time map .
 gain : float
 The image gain , used for convert from ADUs .
 convert _ from _ adus : bool
 If True , the input unblurred _ image _ 1d are in units of adus and all converted to electrons / second using the exposure time map and gain ."""

implementation:
poisson_noise_map_options = sum ( [ convert_poisson_noise_map_from_weight_map , convert_poisson_noise_map_from_inverse_noise_map , poisson_noise_map_from_image ] )
if poisson_noise_map_options == 0 and poisson_noise_map_path is not None :
    return PoissonNoiseMap . from_fits_with_pixel_scale ( file_path = poisson_noise_map_path , hdu = poisson_noise_map_hdu , pixel_scale = pixel_scale )
elif poisson_noise_map_from_image :
    if not ( convert_from_electrons or convert_from_adus ) and exposure_time_map is None :
        raise exc . DataException ( 'Cannot compute the Poisson noise-map from the image if an ' 'exposure-time (or exposure time map) is not supplied to convert to adus' )
    if convert_from_adus and gain is None :
        raise exc . DataException ( 'Cannot compute the Poisson noise-map from the image if a' 'gain is not supplied to convert from adus' )
    return PoissonNoiseMap . from_image_and_exposure_time_map ( pixel_scale = pixel_scale , image = image , exposure_time_map = exposure_time_map , convert_from_electrons = convert_from_electrons , gain = gain , convert_from_adus = convert_from_adus )
elif convert_poisson_noise_map_from_weight_map and poisson_noise_map_path is not None :
    weight_map = Array . from_fits ( file_path = poisson_noise_map_path , hdu = poisson_noise_map_hdu )
    return PoissonNoiseMap . from_weight_map ( weight_map = weight_map , pixel_scale = pixel_scale )
elif convert_poisson_noise_map_from_inverse_noise_map and poisson_noise_map_path is not None :
    inverse_noise_map = Array . from_fits ( file_path = poisson_noise_map_path , hdu = poisson_noise_map_hdu )
    return PoissonNoiseMap . from_inverse_noise_map ( inverse_noise_map = inverse_noise_map , pixel_scale = pixel_scale )
else :
    return None


signature:
def load_psf ( psf_path , psf_hdu , pixel_scale , renormalize = False ) :
    """Factory for loading the psf from a . fits file .
 Parameters
 psf _ path : str
 The path to the psf . fits file containing the psf ( e . g . ' / path / to / psf . fits ' )
 psf _ hdu : int
 The hdu the psf is contained in the . fits file specified by * psf _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds .
 renormalize : bool
 If True , the PSF is renoralized such that all elements sum to 1.0."""

implementation:
if renormalize :
    return PSF . from_fits_renormalized ( file_path = psf_path , hdu = psf_hdu , pixel_scale = pixel_scale )
if not renormalize :
    return PSF . from_fits_with_scale ( file_path = psf_path , hdu = psf_hdu , pixel_scale = pixel_scale )


signature:
def load_exposure_time_map ( exposure_time_map_path , exposure_time_map_hdu , pixel_scale , shape , exposure_time , exposure_time_map_from_inverse_noise_map , inverse_noise_map ) :
    """Factory for loading the exposure time map from a . fits file .
 This factory also includes a number of routines for computing the exposure - time map from other unblurred _ image _ 1d ( e . g . the background noise - map ) .
 Parameters
 exposure _ time _ map _ path : str
 The path to the exposure _ time _ map . fits file containing the exposure time map ( e . g . ' / path / to / exposure _ time _ map . fits ' )
 exposure _ time _ map _ hdu : int
 The hdu the exposure _ time _ map is contained in the . fits file specified by * exposure _ time _ map _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds .
 shape : ( int , int )
 The shape of the image , required if a single value is used to calculate the exposure time map .
 exposure _ time : float
 The exposure - time used to compute the expsure - time map if only a single value is used .
 exposure _ time _ map _ from _ inverse _ noise _ map : bool
 If True , the exposure - time map is computed from the background noise _ map map ( see * ExposureTimeMap . from _ background _ noise _ map * )
 inverse _ noise _ map : ndarray
 The background noise - map , which the Poisson noise - map can be calculated using ."""

implementation:
exposure_time_map_options = sum ( [ exposure_time_map_from_inverse_noise_map ] )
if exposure_time is not None and exposure_time_map_path is not None :
    raise exc . DataException ( 'You have supplied both a exposure_time_map_path to an exposure time map and an exposure time. Only' 'one quantity should be supplied.' )
if exposure_time_map_options == 0 :
    if exposure_time is not None and exposure_time_map_path is None :
        return ExposureTimeMap . single_value ( value = exposure_time , pixel_scale = pixel_scale , shape = shape )
    elif exposure_time is None and exposure_time_map_path is not None :
        return ExposureTimeMap . from_fits_with_pixel_scale ( file_path = exposure_time_map_path , hdu = exposure_time_map_hdu , pixel_scale = pixel_scale )
else :
    if exposure_time_map_from_inverse_noise_map :
        return ExposureTimeMap . from_exposure_time_and_inverse_noise_map ( pixel_scale = pixel_scale , exposure_time = exposure_time , inverse_noise_map = inverse_noise_map )


signature:
def load_background_sky_map ( background_sky_map_path , background_sky_map_hdu , pixel_scale ) :
    """Factory for loading the background sky from a . fits file .
 Parameters
 background _ sky _ map _ path : str
 The path to the background _ sky _ map . fits file containing the background sky map ( e . g . ' / path / to / background _ sky _ map . fits ' ) .
 background _ sky _ map _ hdu : int
 The hdu the background _ sky _ map is contained in the . fits file specified by * background _ sky _ map _ path * .
 pixel _ scale : float
 The size of each pixel in arc seconds ."""

implementation:
if background_sky_map_path is not None :
    return ScaledSquarePixelArray . from_fits_with_pixel_scale ( file_path = background_sky_map_path , hdu = background_sky_map_hdu , pixel_scale = pixel_scale )
else :
    return None


signature:
def load_positions ( positions_path ) :
    """Load the positions of an image .
 Positions correspond to a set of pixels in the lensed source galaxy that are anticipated to come from the same multiply - imaged region of the source - plane . Mass models which do not trace the pixels within a threshold value of one another are resampled during the non - linear search .
 Positions are stored in a . dat file , where each line of the file gives a list of list of ( y , x ) positions which correspond to the same region of the source - plane . Thus , multiple source - plane regions can be input over multiple lines of the same positions file .
 Parameters
 positions _ path : str
 The path to the positions . dat file containing the positions ( e . g . ' / path / to / positions . dat ' )"""

implementation:
with open ( positions_path ) as f :
    position_string = f . readlines ( )
positions = [ ]
for line in position_string :
    position_list = ast . literal_eval ( line )
    positions . append ( position_list )
return positions


signature:
def output_positions ( positions , positions_path ) :
    """Output the positions of an image to a positions . dat file .
 Positions correspond to a set of pixels in the lensed source galaxy that are anticipated to come from the same multiply - imaged region of the source - plane . Mass models which do not trace the pixels within a threshold value of one another are resampled during the non - linear search .
 Positions are stored in a . dat file , where each line of the file gives a list of list of ( y , x ) positions which correspond to the same region of the source - plane . Thus , multiple source - plane regions can be input over multiple lines of the same positions file .
 Parameters
 positions : [ [ [ ] ] ]
 The lists of positions ( e . g . [ [ [ 1.0 , 1.0 ] , [ 2.0 , 2.0 ] ] , [ [ 3.0 , 3.0 ] , [ 4.0 , 4.0 ] ] ] )
 positions _ path : str
 The path to the positions . dat file containing the positions ( e . g . ' / path / to / positions . dat ' )"""

implementation:
with open ( positions_path , 'w' ) as f :
    for position in positions :
        f . write ( "%s\n" % position )


signature:
def simulate_variable_arrays ( cls , array , pixel_scale , exposure_time_map , psf = None , background_sky_map = None , add_noise = True , noise_if_add_noise_false = 0.1 , noise_seed = - 1 , name = None ) :
    """Create a realistic simulated image by applying effects to a plain simulated image .
 Parameters
 name
 array : ndarray
 The image before simulating ( e . g . the lens and source galaxies before optics blurring and CCD read - out ) .
 pixel _ scale : float
 The scale of each pixel in arc seconds
 exposure _ time _ map : ndarray
 An array representing the effective exposure time of each pixel .
 psf : PSF
 An array describing the PSF the simulated image is blurred with .
 background _ sky _ map : ndarray
 The value of background sky in every image pixel ( electrons per second ) .
 add _ noise : Bool
 If True poisson noise _ maps is simulated and added to the image , based on the total counts in each image
 pixel
 noise _ seed : int
 A seed for random noise _ maps generation"""

implementation:
if background_sky_map is not None :
    array += background_sky_map
if psf is not None :
    array = psf . convolve ( array )
    array = cls . trim_psf_edges ( array , psf )
    exposure_time_map = cls . trim_psf_edges ( exposure_time_map , psf )
    if background_sky_map is not None :
        background_sky_map = cls . trim_psf_edges ( background_sky_map , psf )
if add_noise is True :
    array += generate_poisson_noise ( array , exposure_time_map , noise_seed )
    array_counts = np . multiply ( array , exposure_time_map )
    noise_map = np . divide ( np . sqrt ( array_counts ) , exposure_time_map )
else :
    noise_map = noise_if_add_noise_false * np . ones ( array . shape )
if np . isnan ( noise_map ) . any ( ) :
    raise exc . DataException ( 'The noise-map has NaN values in it. This suggests your exposure time and / or' 'background sky levels are too low, create signal counts at or close to 0.0.' )
if background_sky_map is not None :
    array -= background_sky_map
# ESTIMATE THE BACKGROUND NOISE MAP FROM THE IMAGE
if background_sky_map is not None :
    background_noise_map_counts = np . sqrt ( np . multiply ( background_sky_map , exposure_time_map ) )
    background_noise_map = np . divide ( background_noise_map_counts , exposure_time_map )
else :
    background_noise_map = None
# ESTIMATE THE POISSON NOISE MAP FROM THE IMAGE
array_counts = np . multiply ( array , exposure_time_map )
poisson_noise_map = np . divide ( np . sqrt ( np . abs ( array_counts ) ) , exposure_time_map )
array = ScaledSquarePixelArray ( array = array , pixel_scale = pixel_scale )
noise_map = NoiseMap ( array = noise_map , pixel_scale = pixel_scale )
if background_noise_map is not None :
    background_noise_map = NoiseMap ( array = background_noise_map , pixel_scale = pixel_scale )
if poisson_noise_map is not None :
    poisson_noise_map = PoissonNoiseMap ( array = poisson_noise_map , pixel_scale = pixel_scale )
return CCDData ( array , pixel_scale = pixel_scale , psf = psf , noise_map = noise_map , background_noise_map = background_noise_map , poisson_noise_map = poisson_noise_map , exposure_time_map = exposure_time_map , background_sky_map = background_sky_map , name = name )


signature:
def simulate_to_target_signal_to_noise ( cls , array , pixel_scale , target_signal_to_noise , exposure_time_map , psf = None , background_sky_map = None , seed = - 1 ) :
    """Create a realistic simulated image by applying effects to a plain simulated image .
 Parameters
 target _ signal _ to _ noise
 array : ndarray
 The image before simulating ( e . g . the lens and source galaxies before optics blurring and CCD read - out ) .
 pixel _ scale : float
 The scale of each pixel in arc seconds
 exposure _ time _ map : ndarray
 An array representing the effective exposure time of each pixel .
 psf : PSF
 An array describing the PSF the simulated image is blurred with .
 background _ sky _ map : ndarray
 The value of background sky in every image pixel ( electrons per second ) .
 seed : int
 A seed for random noise _ maps generation"""

implementation:
max_index = np . unravel_index ( array . argmax ( ) , array . shape )
max_image = array [ max_index ]
max_effective_exposure_time = exposure_time_map [ max_index ]
max_array_counts = np . multiply ( max_image , max_effective_exposure_time )
if background_sky_map is not None :
    max_background_sky_map = background_sky_map [ max_index ]
    max_background_sky_map_counts = np . multiply ( max_background_sky_map , max_effective_exposure_time )
else :
    max_background_sky_map_counts = None
scale_factor = 1.
if background_sky_map is None :
    scale_factor = target_signal_to_noise ** 2.0 / max_array_counts
elif background_sky_map is not None :
    scale_factor = ( max_array_counts + max_background_sky_map_counts ) * target_signal_to_noise ** 2.0 / max_array_counts ** 2.0
scaled_effective_exposure_time = np . multiply ( scale_factor , exposure_time_map )
return cls . simulate_variable_arrays ( array = array , pixel_scale = pixel_scale , exposure_time_map = scaled_effective_exposure_time , psf = psf , background_sky_map = background_sky_map , add_noise = True , noise_seed = seed )


signature:
def signal_to_noise_map ( self ) :
    """The estimated signal - to - noise _ maps mappers of the image ."""

implementation:
signal_to_noise_map = np . divide ( self . image , self . noise_map )
signal_to_noise_map [ signal_to_noise_map < 0 ] = 0
return signal_to_noise_map


signature:
def absolute_signal_to_noise_map ( self ) :
    """The estimated absolute _ signal - to - noise _ maps mappers of the image ."""

implementation: return np . divide ( np . abs ( self . image ) , self . noise_map )


signature:
def array_from_adus_to_electrons_per_second ( self , array , gain ) :
    """For an array ( in counts ) and an exposure time mappers , convert the array to units electrons per second
 Parameters
 array : ndarray
 The array the values are to be converted from counts to electrons per second ."""

implementation:
if array is not None :
    return np . divide ( gain * array , self . exposure_time_map )
else :
    return None


signature:
def estimated_noise_map_counts ( self ) :
    """The estimated noise _ maps mappers of the image ( using its background noise _ maps mappers and image values
 in counts ) in counts ."""

implementation: return np . sqrt ( ( np . abs ( self . image_counts ) + np . square ( self . background_noise_map_counts ) ) )


signature:
def background_noise_from_edges ( self , no_edges ) :
    """Estimate the background signal _ to _ noise _ ratio by binning data _ to _ image located at the edge ( s ) of an image
 into a histogram and fitting a Gaussian profiles to this histogram . The standard deviation ( sigma ) of this
 Gaussian gives a signal _ to _ noise _ ratio estimate .
 Parameters
 no _ edges : int
 Number of edges used to estimate the background signal _ to _ noise _ ratio ."""

implementation:
edges = [ ]
for edge_no in range ( no_edges ) :
    top_edge = self . image [ edge_no , edge_no : self . image . shape [ 1 ] - edge_no ]
    bottom_edge = self . image [ self . image . shape [ 0 ] - 1 - edge_no , edge_no : self . image . shape [ 1 ] - edge_no ]
    left_edge = self . image [ edge_no + 1 : self . image . shape [ 0 ] - 1 - edge_no , edge_no ]
    right_edge = self . image [ edge_no + 1 : self . image . shape [ 0 ] - 1 - edge_no , self . image . shape [ 1 ] - 1 - edge_no ]
    edges = np . concatenate ( ( edges , top_edge , bottom_edge , right_edge , left_edge ) )
return norm . fit ( edges ) [ 1 ]


signature:
def from_weight_map ( cls , pixel_scale , weight_map ) :
    """Setup the noise - map from a weight map , which is a form of noise - map that comes via HST image - reduction and the software package MultiDrizzle .
 The variance in each pixel is computed as :
 Variance = 1.0 / sqrt ( weight _ map ) .
 The weight map may contain zeros , in which cause the variances are converted to large values to omit them from the analysis .
 Parameters
 pixel _ scale : float
 The size of each pixel in arc seconds .
 weight _ map : ndarray
 The weight - value of each pixel which is converted to a variance ."""

implementation:
np . seterr ( divide = 'ignore' )
noise_map = 1.0 / np . sqrt ( weight_map )
noise_map [ noise_map == np . inf ] = 1.0e8
return NoiseMap ( array = noise_map , pixel_scale = pixel_scale )


signature:
def from_inverse_noise_map ( cls , pixel_scale , inverse_noise_map ) :
    """Setup the noise - map from an root - mean square standard deviation map , which is a form of noise - map that comes via HST image - reduction and the software package MultiDrizzle .
 The variance in each pixel is computed as :
 Variance = 1.0 / inverse _ std _ map .
 The weight map may contain zeros , in which cause the variances are converted to large values to omit them from the analysis .
 Parameters
 pixel _ scale : float
 The size of each pixel in arc seconds .
 inverse _ noise _ map : ndarray
 The inverse noise _ map value of each pixel which is converted to a variance ."""

implementation:
noise_map = 1.0 / inverse_noise_map
return NoiseMap ( array = noise_map , pixel_scale = pixel_scale )


signature:
def simulate_as_gaussian ( cls , shape , pixel_scale , sigma , centre = ( 0.0 , 0.0 ) , axis_ratio = 1.0 , phi = 0.0 ) :
    """Simulate the PSF as an elliptical Gaussian profile ."""

implementation:
from autolens . model . profiles . light_profiles import EllipticalGaussian
gaussian = EllipticalGaussian ( centre = centre , axis_ratio = axis_ratio , phi = phi , intensity = 1.0 , sigma = sigma )
grid_1d = grid_util . regular_grid_1d_masked_from_mask_pixel_scales_and_origin ( mask = np . full ( shape , False ) , pixel_scales = ( pixel_scale , pixel_scale ) )
gaussian_1d = gaussian . intensities_from_grid ( grid = grid_1d )
gaussian_2d = mapping_util . map_unmasked_1d_array_to_2d_array_from_array_1d_and_shape ( array_1d = gaussian_1d , shape = shape )
return PSF ( array = gaussian_2d , pixel_scale = pixel_scale , renormalize = True )


signature:
def from_fits_renormalized ( cls , file_path , hdu , pixel_scale ) :
    """Loads a PSF from fits and renormalizes it
 Parameters
 pixel _ scale
 file _ path : String
 The path to the file containing the PSF
 hdu : int
 The HDU the PSF is stored in the . fits file .
 Returns
 psf : PSF
 A renormalized PSF instance"""

implementation:
psf = PSF . from_fits_with_scale ( file_path , hdu , pixel_scale )
psf [ : , : ] = np . divide ( psf , np . sum ( psf ) )
return psf


signature:
def from_fits_with_scale ( cls , file_path , hdu , pixel_scale ) :
    """Loads the PSF from a . fits file .
 Parameters
 pixel _ scale
 file _ path : String
 The path to the file containing the PSF
 hdu : int
 The HDU the PSF is stored in the . fits file ."""

implementation: return cls ( array = array_util . numpy_array_2d_from_fits ( file_path , hdu ) , pixel_scale = pixel_scale )


signature:
def new_psf_with_renormalized_array ( self ) :
    """Renormalize the PSF such that its data _ vector values sum to unity ."""

implementation: return PSF ( array = self , pixel_scale = self . pixel_scale , renormalize = True )


signature:
def convolve ( self , array ) :
    """Convolve an array with this PSF
 Parameters
 image : ndarray
 An array representing the image the PSF is convolved with .
 Returns
 convolved _ image : ndarray
 An array representing the image after convolution .
 Raises
 KernelException if either PSF psf dimension is odd"""

implementation:
if self . shape [ 0 ] % 2 == 0 or self . shape [ 1 ] % 2 == 0 :
    raise exc . KernelException ( "PSF Kernel must be odd" )
return scipy . signal . convolve2d ( array , self , mode = 'same' )


signature:
def setup_image_plane_pixelization_grid_from_galaxies_and_grid_stack ( galaxies , grid_stack ) :
    """An image - plane pixelization is one where its pixel centres are computed by tracing a sparse grid of pixels from the image ' s regular grid to other planes ( e . g . the source - plane ) .
 Provided a galaxy has an image - plane pixelization , this function returns a new * GridStack * instance where the image - plane pixelization ' s sparse grid is added to it as an attibute .
 Thus , when the * GridStack * are are passed to the * ray _ tracing * module this sparse grid is also traced and the traced coordinates represent the centre of each pixelization pixel .
 Parameters
 galaxies : [ model . galaxy . galaxy . Galaxy ]
 A list of galaxies , which may contain pixelizations and an * ImagePlanePixelization * .
 grid _ stacks : image . array . grid _ stacks . GridStack
 The collection of grid _ stacks ( regular , sub , etc . ) which the image - plane pixelization grid ( referred to as pix ) may be added to ."""

implementation:
if not isinstance ( grid_stack . regular , grids . PaddedRegularGrid ) :
    for galaxy in galaxies :
        if hasattr ( galaxy , 'pixelization' ) :
            if isinstance ( galaxy . pixelization , ImagePlanePixelization ) :
                image_plane_pix_grid = galaxy . pixelization . image_plane_pix_grid_from_regular_grid ( regular_grid = grid_stack . regular )
                return grid_stack . new_grid_stack_with_pix_grid_added ( pix_grid = image_plane_pix_grid . sparse_grid , regular_to_nearest_pix = image_plane_pix_grid . regular_to_sparse )
return grid_stack


signature:
def image_plane_pix_grid_from_regular_grid ( self , regular_grid ) :
    """Calculate the image - plane pixelization from a regular - grid of coordinates ( and its mask ) .
 See * grid _ stacks . SparseToRegularGrid * for details on how this grid is calculated .
 Parameters
 regular _ grid : grids . RegularGrid
 The grid of ( y , x ) arc - second coordinates at the centre of every image value ( e . g . image - pixels ) ."""

implementation:
pixel_scale = regular_grid . mask . pixel_scale
pixel_scales = ( ( regular_grid . masked_shape_arcsec [ 0 ] + pixel_scale ) / ( self . shape [ 0 ] ) , ( regular_grid . masked_shape_arcsec [ 1 ] + pixel_scale ) / ( self . shape [ 1 ] ) )
return grids . SparseToRegularGrid ( unmasked_sparse_grid_shape = self . shape , pixel_scales = pixel_scales , regular_grid = regular_grid , origin = regular_grid . mask . centre )


signature:
def geometry_from_grid ( self , grid , buffer = 1e-8 ) :
    """Determine the geometry of the rectangular grid , by overlaying it over a grid of coordinates such that its outer - most pixels align with the grid ' s outer most coordinates plus a small buffer .
 Parameters
 grid : ndarray
 The ( y , x ) grid of coordinates over which the rectangular pixelization is placed to determine its geometry .
 buffer : float
 The size the pixelization is buffered relative to the grid ."""

implementation:
y_min = np . min ( grid [ : , 0 ] ) - buffer
y_max = np . max ( grid [ : , 0 ] ) + buffer
x_min = np . min ( grid [ : , 1 ] ) - buffer
x_max = np . max ( grid [ : , 1 ] ) + buffer
pixel_scales = ( float ( ( y_max - y_min ) / self . shape [ 0 ] ) , float ( ( x_max - x_min ) / self . shape [ 1 ] ) )
origin = ( ( y_max + y_min ) / 2.0 , ( x_max + x_min ) / 2.0 )
pixel_neighbors , pixel_neighbors_size = self . neighbors_from_pixelization ( )
return self . Geometry ( shape = self . shape , pixel_scales = pixel_scales , origin = origin , pixel_neighbors = pixel_neighbors , pixel_neighbors_size = pixel_neighbors_size )


signature:
def mapper_from_grid_stack_and_border ( self , grid_stack , border ) :
    """Setup a rectangular mapper from a rectangular pixelization , as follows :
 1 ) If a border is supplied , relocate all of the grid - stack ' s regular and sub grid pixels beyond the border .
 2 ) Determine the rectangular pixelization ' s geometry , by laying the pixelization over the sub - grid .
 3 ) Setup the rectangular mapper from the relocated grid - stack and rectangular pixelization .
 Parameters
 grid _ stack : grids . GridStack
 A stack of grid describing the observed image ' s pixel coordinates ( e . g . an image - grid , sub - grid , etc . ) .
 border : grids . RegularGridBorder | None
 The border of the grid - stack ' s regular - grid ."""

implementation:
if border is not None :
    relocated_grid_stack = border . relocated_grid_stack_from_grid_stack ( grid_stack )
else :
    relocated_grid_stack = grid_stack
geometry = self . geometry_from_grid ( grid = relocated_grid_stack . sub )
return mappers . RectangularMapper ( pixels = self . pixels , grid_stack = relocated_grid_stack , border = border , shape = self . shape , geometry = geometry )