Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 22, 2023
1 parent be9b82e commit 3480fbb
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 183 deletions.
3 changes: 1 addition & 2 deletions autoarray/inversion/inversion/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(
use_w_tilde: bool = True,
use_positive_only_solver: Optional[bool] = None,
positive_only_uses_p_initial: Optional[bool] = None,
relocate_pix_border : Optional[bool] = None,
relocate_pix_border: Optional[bool] = None,
force_edge_pixels_to_zeros: bool = True,
force_edge_image_pixels_to_zeros: bool = False,
image_pixels_source_zero=None,
Expand Down Expand Up @@ -93,7 +93,6 @@ def positive_only_uses_p_initial(self):

@property
def relocate_pix_border(self):

if self._relocate_pix_border is None:
return conf.instance["general"]["inversion"]["relocate_pix_border"]

Expand Down
4 changes: 4 additions & 0 deletions autoarray/inversion/mock/mock_image_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ def image_plane_mesh_grid_from(
return adapt_data * self.image_plane_mesh_grid

return self.image_plane_mesh_grid

@property
def uses_adapt_images(self) -> bool:
return False
4 changes: 4 additions & 0 deletions autoarray/inversion/pixelization/image_mesh/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def __init__(self):
def is_stochastic(self):
return False

@property
def uses_adapt_images(self) -> bool:
raise NotImplementedError

def image_plane_mesh_grid_from(
self, grid: Grid2D, adapt_data: Optional[np.ndarray]
) -> Grid2DIrregular:
Expand Down
4 changes: 4 additions & 0 deletions autoarray/inversion/pixelization/image_mesh/hilbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ def image_plane_mesh_grid_from(

return Grid2DIrregular(values=np.stack((drawn_y, drawn_x), axis=-1))

@property
def uses_adapt_images(self) -> bool:
return True

@property
def is_stochastic(self):
return True
4 changes: 4 additions & 0 deletions autoarray/inversion/pixelization/image_mesh/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def image_plane_mesh_grid_from(
values=kmeans.cluster_centers_,
)

@property
def uses_adapt_images(self) -> bool:
return True

@property
def is_stochastic(self):
return True
4 changes: 4 additions & 0 deletions autoarray/inversion/pixelization/image_mesh/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,7 @@ def image_plane_mesh_grid_from(
)

return Grid2DIrregular(values=mesh_grid)

@property
def uses_adapt_images(self) -> bool:
return False
98 changes: 49 additions & 49 deletions autoarray/inversion/pixelization/mappers/rectangular.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ def __init__(
run_time_dict: Optional[Dict] = None,
):
"""
To understand a `Mapper` one must be familiar `Mesh` objects and the `mesh` and `pixelization` packages, where
the four grids grouped in a `MapperGrids` object are explained (`image_plane_data_grid`, `source_plane_data_grid`,
`image_plane_mesh_grid`,`source_plane_mesh_grid`)
If you are unfamliar withe above objects, read through the docstrings of the `pixelization`, `mesh` and
`mapper_grids` packages.
A `Mapper` determines the mappings between the masked data grid's pixels (`image_plane_data_grid` and
`source_plane_data_grid`) and the mesh's pixels (`image_plane_mesh_grid` and `source_plane_mesh_grid`).
The 1D Indexing of each grid is identical in the `data` and `source` frames (e.g. the transformation does not
change the indexing, such that `source_plane_data_grid[0]` corresponds to the transformed value
of `image_plane_data_grid[0]` and so on).
A mapper therefore only needs to determine the index mappings between the `grid_slim` and `mesh_grid`,
noting that associations are made by pairing `source_plane_mesh_grid` with `source_plane_data_grid`.
Mappings are represented in the 2D ndarray `pix_indexes_for_sub_slim_index`, whereby the index of
a pixel on the `mesh_grid` maps to the index of a pixel on the `grid_slim` as follows:
- pix_indexes_for_sub_slim_index[0, 0] = 0: the data's 1st sub-pixel maps to the mesh's 1st pixel.
- pix_indexes_for_sub_slim_index[1, 0] = 3: the data's 2nd sub-pixel maps to the mesh's 4th pixel.
- pix_indexes_for_sub_slim_index[2, 0] = 1: the data's 3rd sub-pixel maps to the mesh's 2nd pixel.
The second dimension of this array (where all three examples above are 0) is used for cases where a
single pixel on the `grid_slim` maps to multiple pixels on the `mesh_grid`. For example, a
`Delaunay` triangulation, where every `grid_slim` pixel maps to three Delaunay pixels (the corners of the
triangles) with varying interpolation weights .
For a `Rectangular` mesh every pixel in the masked data maps to only one pixel, thus the second
dimension of `pix_indexes_for_sub_slim_index` is always of size 1.
The mapper allows us to create a mapping matrix, which is a matrix representing the mapping between every
unmasked data pixel annd the pixels of a mesh. This matrix is the basis of performing an `Inversion`,
which reconstructs the data using the `source_plane_mesh_grid`.
Parameters
----------
mapper_grids
An object containing the data grid and mesh grid in both the data-frame and source-frame used by the
mapper to map data-points to linear object parameters.
regularization
The regularization scheme which may be applied to this linear object in order to smooth its solution,
which for a mapper smooths neighboring pixels on the mesh.
relocate_pix_border
If `True`, all coordinates of all pixelization source mesh grids have pixels outside their border
relocated to their edge.
run_time_dict
A dictionary which contains timing of certain functions calls which is used for profiling.
To understand a `Mapper` one must be familiar `Mesh` objects and the `mesh` and `pixelization` packages, where
the four grids grouped in a `MapperGrids` object are explained (`image_plane_data_grid`, `source_plane_data_grid`,
`image_plane_mesh_grid`,`source_plane_mesh_grid`)
If you are unfamliar withe above objects, read through the docstrings of the `pixelization`, `mesh` and
`mapper_grids` packages.
A `Mapper` determines the mappings between the masked data grid's pixels (`image_plane_data_grid` and
`source_plane_data_grid`) and the mesh's pixels (`image_plane_mesh_grid` and `source_plane_mesh_grid`).
The 1D Indexing of each grid is identical in the `data` and `source` frames (e.g. the transformation does not
change the indexing, such that `source_plane_data_grid[0]` corresponds to the transformed value
of `image_plane_data_grid[0]` and so on).
A mapper therefore only needs to determine the index mappings between the `grid_slim` and `mesh_grid`,
noting that associations are made by pairing `source_plane_mesh_grid` with `source_plane_data_grid`.
Mappings are represented in the 2D ndarray `pix_indexes_for_sub_slim_index`, whereby the index of
a pixel on the `mesh_grid` maps to the index of a pixel on the `grid_slim` as follows:
- pix_indexes_for_sub_slim_index[0, 0] = 0: the data's 1st sub-pixel maps to the mesh's 1st pixel.
- pix_indexes_for_sub_slim_index[1, 0] = 3: the data's 2nd sub-pixel maps to the mesh's 4th pixel.
- pix_indexes_for_sub_slim_index[2, 0] = 1: the data's 3rd sub-pixel maps to the mesh's 2nd pixel.
The second dimension of this array (where all three examples above are 0) is used for cases where a
single pixel on the `grid_slim` maps to multiple pixels on the `mesh_grid`. For example, a
`Delaunay` triangulation, where every `grid_slim` pixel maps to three Delaunay pixels (the corners of the
triangles) with varying interpolation weights .
For a `Rectangular` mesh every pixel in the masked data maps to only one pixel, thus the second
dimension of `pix_indexes_for_sub_slim_index` is always of size 1.
The mapper allows us to create a mapping matrix, which is a matrix representing the mapping between every
unmasked data pixel annd the pixels of a mesh. This matrix is the basis of performing an `Inversion`,
which reconstructs the data using the `source_plane_mesh_grid`.
Parameters
----------
mapper_grids
An object containing the data grid and mesh grid in both the data-frame and source-frame used by the
mapper to map data-points to linear object parameters.
regularization
The regularization scheme which may be applied to this linear object in order to smooth its solution,
which for a mapper smooths neighboring pixels on the mesh.
relocate_pix_border
If `True`, all coordinates of all pixelization source mesh grids have pixels outside their border
relocated to their edge.
run_time_dict
A dictionary which contains timing of certain functions calls which is used for profiling.
"""
super().__init__(
mapper_grids=mapper_grids,
Expand Down
104 changes: 52 additions & 52 deletions autoarray/inversion/pixelization/mesh/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ def relocated_grid_from(
self,
source_plane_data_grid: Grid2D,
preloads: Preloads = Preloads(),
relocate_pix_border : bool = False,
relocate_pix_border: bool = False,
) -> Grid2D:
"""
Relocates all coordinates of the input `source_plane_data_grid` that are outside of a
border (which is defined by a grid of (y,x) coordinates) to the edge of this border.
The border is determined from the mask of the 2D data in the `data` frame before any transformations of the
data's grid are performed. The border is all pixels in this mask that are pixels at its extreme edge. These
pixel indexes are used to then determine a grid of (y,x) coordinates from the transformed `source_grid_grid` in
the `source` reference frame, whereby points located outside of it are relocated to the border's edge.
A full description of relocation is given in the method grid_2d.relocated_grid_from()`.
This is used in the project PyAutoLens to relocate the coordinates that are ray-traced near the centre of mass
of galaxies, which are heavily demagnified and may trace to outskirts of the source-plane well beyond the
border.
Parameters
----------
source_plane_data_grid
A 2D (y,x) grid of coordinates, whose coordinates outside the border are relocated to its edge.
preloads
Contains quantities which may already be computed and can be preloaded to speed up calculations, in this
case the relocated grid.
relocate_pix_border
If `True`, all coordinates of all pixelization source mesh grids have pixels outside their border
relocated to their edge.
Relocates all coordinates of the input `source_plane_data_grid` that are outside of a
border (which is defined by a grid of (y,x) coordinates) to the edge of this border.
The border is determined from the mask of the 2D data in the `data` frame before any transformations of the
data's grid are performed. The border is all pixels in this mask that are pixels at its extreme edge. These
pixel indexes are used to then determine a grid of (y,x) coordinates from the transformed `source_grid_grid` in
the `source` reference frame, whereby points located outside of it are relocated to the border's edge.
A full description of relocation is given in the method grid_2d.relocated_grid_from()`.
This is used in the project PyAutoLens to relocate the coordinates that are ray-traced near the centre of mass
of galaxies, which are heavily demagnified and may trace to outskirts of the source-plane well beyond the
border.
Parameters
----------
source_plane_data_grid
A 2D (y,x) grid of coordinates, whose coordinates outside the border are relocated to its edge.
preloads
Contains quantities which may already be computed and can be preloaded to speed up calculations, in this
case the relocated grid.
relocate_pix_border
If `True`, all coordinates of all pixelization source mesh grids have pixels outside their border
relocated to their edge.
"""
if preloads.relocated_grid is None:
if relocate_pix_border:
Expand All @@ -60,35 +60,35 @@ def relocated_mesh_grid_from(
self,
source_plane_data_grid: Grid2D,
source_plane_mesh_grid: Grid2DIrregular,
relocate_pix_border : bool = False
relocate_pix_border: bool = False,
):
"""
Relocates all coordinates of the input `source_plane_mesh_grid` that are outside of a border (which
is defined by a grid of (y,x) coordinates) to the edge of this border.
The border is determined from the mask of the 2D data in the `data` frame before any transformations of the
data's grid are performed. The border is all pixels in this mask that are pixels at its extreme edge. These
pixel indexes are used to then determine a grid of (y,x) coordinates from the transformed `source_grid_grid` in
the `source` reference frame, whereby points located outside of it are relocated to the border's edge.
A full description of relocation is given in the method grid_2d.relocated_grid_from()`.
This is used in the project `PyAutoLens` to relocate the coordinates that are ray-traced near the centre of mass
of galaxies, which are heavily demagnified and may trace to outskirts of the source-plane well beyond the
border.
Parameters
----------
source_plane_data_grid
A 2D grid of (y,x) coordinates associated with the unmasked 2D data after it has been transformed to the
`source` reference frame.
source_plane_mesh_grid
The centres of every Voronoi pixel in the `source` frame, which are initially derived by computing a sparse
set of (y,x) coordinates computed from the unmasked data in the `data` frame and applying a transformation
to this.
relocate_pix_border
If `True`, all coordinates of all pixelization source mesh grids have pixels outside their border
relocated to their edge.
Relocates all coordinates of the input `source_plane_mesh_grid` that are outside of a border (which
is defined by a grid of (y,x) coordinates) to the edge of this border.
The border is determined from the mask of the 2D data in the `data` frame before any transformations of the
data's grid are performed. The border is all pixels in this mask that are pixels at its extreme edge. These
pixel indexes are used to then determine a grid of (y,x) coordinates from the transformed `source_grid_grid` in
the `source` reference frame, whereby points located outside of it are relocated to the border's edge.
A full description of relocation is given in the method grid_2d.relocated_grid_from()`.
This is used in the project `PyAutoLens` to relocate the coordinates that are ray-traced near the centre of mass
of galaxies, which are heavily demagnified and may trace to outskirts of the source-plane well beyond the
border.
Parameters
----------
source_plane_data_grid
A 2D grid of (y,x) coordinates associated with the unmasked 2D data after it has been transformed to the
`source` reference frame.
source_plane_mesh_grid
The centres of every Voronoi pixel in the `source` frame, which are initially derived by computing a sparse
set of (y,x) coordinates computed from the unmasked data in the `data` frame and applying a transformation
to this.
relocate_pix_border
If `True`, all coordinates of all pixelization source mesh grids have pixels outside their border
relocated to their edge.
"""
if relocate_pix_border:
return source_plane_data_grid.relocated_mesh_grid_from(
Expand Down
Loading

0 comments on commit 3480fbb

Please sign in to comment.