PyAutoLens
PyAutoLens copied to clipboard
Decide how to pass size of projected grid and whether to remove its centre through code
To create a 1D projected grid from a 2D Grid I use the following:
def grid_2d_radial_projected_from(
self, centre: Tuple[float, float] = (0.0, 0.0), angle: float = 0.0
) -> grid_2d_irregular.Grid2DIrregular:
"""
Determine a projected radial grid of points from a 2D region of coordinates defined by an
extent [xmin, xmax, ymin, ymax] and with a (y,x) centre. This functions operates as follows:
1 Given the region defined by the extent [xmin, xmax, ymin, ymax], the algorithm finds the longest 1D distance
of the 4 paths from the (y,x) centre to the edge of the region e.g. following the positive / negative y and
x axes.
2: Use the pixel-scale corresponding to the direction chosen e.g. if the positive x-axis was the longest, the
pixel_scale in the x dimension is used.
3: Determine the number of pixels between the centre and the edge of the region using the longest path between
the two chosen above.
4: Create a (y,x) grid of radial points where all points are at the centre's y value = 0.0 and the x values
iterate from the centre in increasing steps of the pixel-scale.
5: Rotate these radial coordinates by the input `angle` clockwise.
A schematic is shown below:
-------------------
| |
|<- - - - ->x | x = centre
| | <-> = longest radial path from centre to extent edge
| |
-------------------
4: Create a (y,x) grid of radial points where all points are at the centre's y value = 0.0 and the x values
iterate from the centre in increasing steps of the pixel-scale.
5: Rotate these radial coordinates by the input `angle` clockwise.
Parameters
----------
centre
The (y,x) central coordinate which the radial grid is traced outwards from.
angle
The angle with which the radial coordinates are rotated clockwise.
Returns
-------
grid_2d_irregular.Grid2DIrregular
A radial set of points sampling the longest distance from the centre to the edge of the extent in along the
positive x-axis.
"""
**if hasattr(self, "radial_projected_shape_slim"):**
shape_slim = self.radial_projected_shape_slim
else:
shape_slim = 0
grid_radial_projected_2d = grid_2d_util.grid_scaled_2d_slim_radial_projected_from(
extent=self.extent,
centre=centre,
pixel_scales=self.pixel_scales,
sub_size=self.sub_size,
shape_slim=shape_slim
)
grid_radial_projected_2d = geometry_util.transform_grid_2d_to_reference_frame(
grid_2d=grid_radial_projected_2d, centre=centre, angle=angle
)
grid_radial_projected_2d = geometry_util.transform_grid_2d_from_reference_frame(
grid_2d=grid_radial_projected_2d, centre=centre, angle=0.0
)
**if conf.instance["general"]["grid"]["remove_projected_centre"]:**
grid_radial_projected_2d = grid_radial_projected_2d[1:,:]
return grid_2d_irregular.Grid2DIrregular(grid=grid_radial_projected_2d)
The lines in bold are hacks, which work for getting figures together for a paper but are not great in general.
We probably watch to pass these are an input to all Grid class methods so a user can set them up with a Grid. But we should think about whether this is creating a lot of superflous extra code and if some sort of Settings object might help.