autoarray.inversion.mesh.image_mesh.Hilbert#

class Hilbert[source]#

Bases: AbstractImageMeshWeighted

Computes an image-mesh by computing the Hilbert curve of the adapt data and drawing points from it.

This requires an adapt-image, which is the image that the Hilbert curve algorithm adapts to in order to compute the image mesh. This could simply be the image itself, or a model fit to the image which removes certain features or noise.

For example, using the adapt image, the image mesh is computed as follows:

  1. Convert the adapt image to a weight map, which is a 2D array of weight values.

2) Run the Hilbert algorithm on the weight map, such that the image mesh pixels cluster around the weight map values with higher values.

Parameters:
  • pixels – The total number of pixels in the image mesh and drawn from the Hilbert curve.

  • weight_floor – The minimum weight value in the weight map, which allows more pixels to be drawn from the lower weight regions of the adapt image.

  • weight_power – The power the weight values are raised too, which allows more pixels to be drawn from the higher weight regions of the adapt image.

  • image_mesh_min_mesh_pixels_per_pixel – If not None, the image-mesh must place this many mesh pixels per image pixels in the N highest weighted regions of the adapt data, or an InversionException is raised. This can be used to force the image-mesh to cluster large numbers of source pixels to the adapt-datas brightest regions.

  • image_mesh_min_mesh_number – The value N given above in the docstring for image_mesh_min_mesh_pixels_per_pixel, indicating how many image pixels are checked for having a threshold number of mesh pixels.

  • image_mesh_adapt_background_percent_threshold – If not None, the image-mesh must place this percentage of mesh-pixels in the background regions of the adapt_data, where the background is the image_mesh_adapt_background_percent_check masked data pixels with the lowest values.

  • image_mesh_adapt_background_percent_check – The percentage of masked data pixels which are checked for the background criteria.

Methods

check_adapt_background_pixels

Checks the number of mesh pixels in the background of the image-mesh and raises an InversionException if there are fewer mesh pixels in the background than the input settings.

check_mesh_pixels_per_image_pixels

Checks the number of mesh pixels in every image pixel and raises an InversionException if there are fewer mesh pixels inside a certain number of image-pixels than the input settings.

image_plane_mesh_grid_from

Returns an image mesh by running the Hilbert curve on the weight map.

mesh_pixels_per_image_pixels_from

Returns an array containing the number of mesh pixels in every pixel of the data's mask.

weight_map_from

Returns the weight-map used by the image-mesh to compute the mesh pixel centres.

Attributes

uses_adapt_images

image_plane_mesh_grid_from(mask, adapt_data)[source]#

Returns an image mesh by running the Hilbert curve on the weight map.

See the __init__ docstring for a full description of how this is performed.

Parameters:
  • grid – The grid of (y,x) coordinates of the image data the pixelization fits, which the Hilbert curve adapts to.

  • adapt_data (Optional[ndarray]) – The weights defining the regions of the image the Hilbert curve adapts to.

check_mesh_pixels_per_image_pixels(mask, mesh_grid, image_mesh_min_mesh_pixels_per_pixel=None, image_mesh_min_mesh_number=5, image_mesh_adapt_background_percent_threshold=None, image_mesh_adapt_background_percent_check=0.8)[source]#

Checks the number of mesh pixels in every image pixel and raises an InversionException if there are fewer mesh pixels inside a certain number of image-pixels than the input settings.

This allows a user to force a model-fit to use image-mesh’s which cluster a large number of mesh pixels to the brightest regions of the image data (E.g. the highst weighted regions).

The check works as follows:

  1. Compute the 2D array of the number of mesh pixels in every masked data image pixel.

  2. Find the number of mesh pixels in the N data pixels with the larger number of mesh pixels, where N is given by image_mesh_min_mesh_number. For example, if image_mesh_min_mesh_number=5 then the number of mesh pixels in the 5 data pixels with the most data pixels is computed.

  3. Compare the lowest value above to the value image_mesh_min_mesh_pixels_per_pixel. If the value is below this value, raise an InversionException.

Therefore, by settings image_mesh_min_mesh_pixels_per_pixel to a value above 1 the code is forced to adapt the image mesh enough to put many mesh pixels in the brightest image pixels.

Parameters:
  • mask (Mask2D) – The mask of the dataset being analysed, which the pixelization grid maps too. The number of mesh pixels mapped inside each of this mask’s image-pixels is returned.

  • mesh_grid (Grid2DIrregular) – The image mesh-grid computed by the class which adapts to the data’s mask. The number of image mesh pixels that fall within each of the data’s mask pixels is returned.

  • settings – The inversion settings, which have the criteria dictating if the image-mesh has clustered enough or if an exception is raised.

check_adapt_background_pixels(mask, mesh_grid, adapt_data, image_mesh_min_mesh_pixels_per_pixel=None, image_mesh_min_mesh_number=5, image_mesh_adapt_background_percent_threshold=None, image_mesh_adapt_background_percent_check=0.8)[source]#

Checks the number of mesh pixels in the background of the image-mesh and raises an InversionException if there are fewer mesh pixels in the background than the input settings.

This allows a user to force a model-fit to use image-mesh’s which cluster a minimum number of mesh pixels to the faintest regions of the image data (E.g. the lowest weighted regions). This prevents too few image-mesh pixels being allocated to the background of the data.

The check works as follows:

  1. Find all pixels in the background of the adapt_data, which are N pixels with the lowest values, where N is a percentage given by image_mesh_adapt_background_percent_check. If N is 50%, then the half of

    pixels in adapt_data with the lowest values will be checked.

  2. Sum the total number of mesh pixels in these background pixels, thereby estimating the number of mesh pixels

    assigned to background pixels.

  3. Compare this value to the total number of mesh pixels multiplied by image_mesh_adapt_background_percent_threshold and raise an InversionException if the number of mesh pixels is below this value, meaning the background did not have sufficient mesh pixels in it.

Therefore, by setting image_mesh_adapt_background_percent_threshold the code is forced to adapt the image mesh in a way that places many mesh pixels in the background regions.

Parameters:
  • mask (Mask2D) – The mask of the dataset being analysed, which the pixelization grid maps too. The number of mesh pixels mapped inside each of this mask’s image-pixels is returned.

  • mesh_grid (Grid2DIrregular) – The image mesh-grid computed by the class which adapts to the data’s mask. The number of image mesh pixels that fall within each of the data’s mask pixels is returned.

  • adapt_data (Optional[ndarray]) – A image which represents one or more components in the masked 2D data in the image-plane.

  • settings – The inversion settings, which have the criteria dictating if the image-mesh has clustered enough or if an exception is raised.