Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions autogalaxy/ellipse/ellipse/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def total_points_from(self, pixel_scale: float) -> int:

return np.min([500, int(np.round(circular_radius_pixels, 1))])

def angles_from_x0_from(self, pixel_scale: float, n_i : int = 0) -> np.ndarray:
def angles_from_x0_from(self, pixel_scale: float, n_i: int = 0) -> np.ndarray:
"""
Returns the angles from the x-axis to a discrete number of points ranging from 0.0 to 2.0 * np.pi radians.

Expand Down Expand Up @@ -138,7 +138,9 @@ def angles_from_x0_from(self, pixel_scale: float, n_i : int = 0) -> np.ndarray:

return np.linspace(0.0, 2.0 * np.pi, total_points + n_i)[:-1]

def ellipse_radii_from_major_axis_from(self, pixel_scale: float, n_i : int = 0) -> np.ndarray:
def ellipse_radii_from_major_axis_from(
self, pixel_scale: float, n_i: int = 0
) -> np.ndarray:
"""
Returns the distance from the centre of the ellipse to every point on the ellipse, which are called
the ellipse radii.
Expand Down Expand Up @@ -173,7 +175,7 @@ def ellipse_radii_from_major_axis_from(self, pixel_scale: float, n_i : int = 0)
),
)

def x_from_major_axis_from(self, pixel_scale: float, n_i : int = 0) -> np.ndarray:
def x_from_major_axis_from(self, pixel_scale: float, n_i: int = 0) -> np.ndarray:
"""
Returns the x-coordinates of the points on the ellipse, starting from the x-coordinate of the major-axis
of the ellipse after rotation by its `angle` and moving counter-clockwise.
Expand All @@ -198,9 +200,7 @@ def x_from_major_axis_from(self, pixel_scale: float, n_i : int = 0) -> np.ndarra

return ellipse_radii_from_major_axis * np.cos(angles_from_x0) + self.centre[1]

def y_from_major_axis_from(
self, pixel_scale: float, n_i : int = 0
) -> np.ndarray:
def y_from_major_axis_from(self, pixel_scale: float, n_i: int = 0) -> np.ndarray:
"""
Returns the y-coordinates of the points on the ellipse, starting from the y-coordinate of the major-axis
of the ellipse after rotation by its `angle` and moving counter-clockwise.
Expand Down Expand Up @@ -231,7 +231,10 @@ def y_from_major_axis_from(
- self.centre[0]
)

def points_from_major_axis_from(self, pixel_scale: float, n_i : int = 0,
def points_from_major_axis_from(
self,
pixel_scale: float,
n_i: int = 0,
) -> np.ndarray:
"""
Returns the (y,x) coordinates of the points on the ellipse, starting from the major-axis of the ellipse
Expand Down
55 changes: 3 additions & 52 deletions autogalaxy/ellipse/fit_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def points_from_major_axis_from(self) -> np.ndarray:
if total_points_required == total_points - total_points_masked:
continue

points = self.ellipse.points_from_major_axis_from(pixel_scale=self.dataset.pixel_scales[0],
n_i=i)
points = self.ellipse.points_from_major_axis_from(
pixel_scale=self.dataset.pixel_scales[0], n_i=i
)

if i == i_total:

Expand Down Expand Up @@ -108,52 +109,6 @@ def _points_from_major_axis(self) -> np.ndarray:
"""
return self.points_from_major_axis_from()

# @property
# def mask_interp(self) -> np.ndarray:
# """
# Returns the mask values of the dataset that the ellipse fits, which are computed by overlaying the ellipse over
# the 2D data and performing a 2D interpolation at discrete (y,x) coordinates on the ellipse on the dataset's
# mask.
#
# When an input (y,x) coordinate intepolates only unmasked values (`data.mask=False`) the intepolatred value
# is 0.0, where if it interpolates one or a masked value (`data.mask=True`), the interpolated value is positive.
# To mask all values which interpolate a masked value, all interpolated values above 1 and converted to `True`.
#
# This mask is used to remove these pixels from a fit and evaluate how many ellipse points are used for each
# ellipse fit.
#
# The (y,x) coordinates on the ellipse where the interpolation occurs are computed in the
# `points_from_major_axis` property of the `Ellipse` class, with the documentation describing how these points
# are computed.
#
# Returns
# -------
# The data values of the ellipse fits, computed via a 2D interpolation of where the ellipse
# overlaps the data.
# """
# return self.interp.mask_interp(self._points_from_major_axis) > 0.0

# @property
# def total_points_interp(self) -> int:
# """
# Returns the total number of points used to interpolate the data and noise-map values of the ellipse.
#
# For example, if the ellipse spans 10 pixels, the total number of points will be 10.
#
# The calculation removes points if one or more interpolated value uses a masked value, meaning the interpolation
# is not reliable.
#
# The (y,x) coordinates on the ellipse where the interpolation occurs are computed in the
# `points_from_major_axis` property of the `Ellipse` class, with the documentation describing how these points
# are computed.
#
# Returns
# -------
# The noise-map values of the ellipse fits, computed via a 2D interpolation of where the ellipse
# overlaps the noise-map.
# """
# return self.data_interp[np.invert(self.mask_interp)].shape[0]

@property
def data_interp(self) -> aa.ArrayIrregular:
"""
Expand All @@ -174,8 +129,6 @@ def data_interp(self) -> aa.ArrayIrregular:
"""
data = self.interp.data_interp(self._points_from_major_axis)

# data[self.mask_interp] = np.nan

return aa.ArrayIrregular(values=data)

@property
Expand All @@ -198,8 +151,6 @@ def noise_map_interp(self) -> aa.ArrayIrregular:
"""
noise_map = self.interp.noise_map_interp(self._points_from_major_axis)

# noise_map[self.mask_interp] = np.nan

return aa.ArrayIrregular(values=noise_map)

@property
Expand Down
6 changes: 2 additions & 4 deletions autogalaxy/ellipse/plot/fit_ellipse_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,14 @@ def figures_2d(
points = fit.points_from_major_axis_from()

x = points[:, 1]
y = points[:, 0] * -1.0 # flip for plot
y = points[:, 0] * -1.0 # flip for plot

ellipse_list.append(aa.Grid2DIrregular.from_yx_1d(y=y, x=x))

visuals_2d = self.get_visuals_2d() + Visuals2D(
positions=ellipse_list,
lines=ellipse_list
positions=ellipse_list, lines=ellipse_list
)


self.mat_plot_2d.plot_array(
array=self.fit_list[0].data,
visuals_2d=visuals_2d,
Expand Down
9 changes: 5 additions & 4 deletions autogalaxy/gui/scribbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import matplotlib.pyplot as plt
from typing import Tuple


class Scribbler:
def __init__(
self,
Expand Down Expand Up @@ -31,25 +32,25 @@ def __init__(
origin = image.geometry.origin
pixel_scales = image.geometry.pixel_scales

x0_pix = int(
x0_pix = int(
(extent[0] - origin[1]) / pixel_scales[1]
+ central_pixel_coordinates[1]
+ 0.5
)

x1_pix = int(
x1_pix = int(
(extent[1] - origin[1]) / pixel_scales[1]
+ central_pixel_coordinates[1]
+ 0.5
)

y0_pix = int(
y0_pix = int(
(extent[2] - origin[0]) / pixel_scales[0]
+ central_pixel_coordinates[0]
+ 0.5
)

y1_pix = int(
y1_pix = int(
(extent[3] - origin[0]) / pixel_scales[0]
+ central_pixel_coordinates[0]
+ 0.5
Expand Down
35 changes: 18 additions & 17 deletions autogalaxy/operate/deflections.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@ def __eq__(self, other):

def time_delay_geometry_term_from(self, grid) -> aa.Array2D:
"""
Returns the geometric time delay term of the Fermat potential for a given grid of image-plane positions.
Returns the geometric time delay term of the Fermat potential for a given grid of image-plane positions.

This term is given by:
This term is given by:

.. math::
\[\tau_{\text{geom}}(\boldsymbol{\theta}) = \frac{1}{2} |\boldsymbol{\theta} - \boldsymbol{\beta}|^2\]
.. math::
\[\tau_{\text{geom}}(\boldsymbol{\theta}) = \frac{1}{2} |\boldsymbol{\theta} - \boldsymbol{\beta}|^2\]

where:
- \( \boldsymbol{\theta} \) is the image-plane coordinate,
- \( \boldsymbol{\beta} = \boldsymbol{\theta} - \boldsymbol{\alpha}(\boldsymbol{\theta}) \) is the source-plane coordinate,
- \( \boldsymbol{\alpha} \) is the deflection angle at each image-plane coordinate.
where:
- \( \boldsymbol{\theta} \) is the image-plane coordinate,
- \( \boldsymbol{\beta} = \boldsymbol{\theta} - \boldsymbol{\alpha}(\boldsymbol{\theta}) \) is the source-plane coordinate,
- \( \boldsymbol{\alpha} \) is the deflection angle at each image-plane coordinate.

Parameters
----------
grid
The 2D grid of (y,x) arc-second coordinates the deflection angles and time delay geometric term are computed
on.
Parameters
----------
grid
The 2D grid of (y,x) arc-second coordinates the deflection angles and time delay geometric term are computed
on.

Returns
-------
The geometric time delay term at each grid position.
Returns
-------
The geometric time delay term at each grid position.
"""
deflections = self.deflections_yx_2d_from(grid=grid)

Expand Down Expand Up @@ -194,7 +194,8 @@ def time_delays_from(self, grid) -> aa.Array2D:
deflections_yx = self.deflections_yx_2d_from(grid=grid)

return aa.Array2D(
values=deflections_yx[:, 0] * grid[:, 0] + deflections_yx[:, 1] * grid[:, 1],
values=deflections_yx[:, 0] * grid[:, 0]
+ deflections_yx[:, 1] * grid[:, 1],
mask=grid.mask,
)

Expand Down
1 change: 0 additions & 1 deletion test_autogalaxy/ellipse/ellipse/test_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ def test__points_from_major_axis():
assert ellipse.points_from_major_axis_from(pixel_scale=1.0)[1][0] == pytest.approx(
-0.2123224755, 1.0e-4
)

8 changes: 4 additions & 4 deletions test_autogalaxy/ellipse/model/test_analysis_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
def test__make_result__result_imaging_is_returned(masked_imaging_7x7):
ellipse_list = af.Collection(af.Model(ag.Ellipse) for _ in range(2))

ellipse_list[0].major_axis = 1.0
ellipse_list[1].major_axis = 2.0
ellipse_list[0].major_axis = 0.2
ellipse_list[1].major_axis = 0.4

model = af.Collection(ellipses=ellipse_list)

Expand All @@ -30,8 +30,8 @@ def test__figure_of_merit(
):
ellipse_list = af.Collection(af.Model(ag.Ellipse) for _ in range(2))

ellipse_list[0].major_axis = 1.0
ellipse_list[1].major_axis = 2.0
ellipse_list[0].major_axis = 0.2
ellipse_list[1].major_axis = 0.4

multipole_0_prior_0 = af.UniformPrior(lower_limit=0.0, upper_limit=0.1)
multipole_0_prior_1 = af.UniformPrior(lower_limit=0.0, upper_limit=0.1)
Expand Down
Loading
Loading