Skip to content

Commit

Permalink
move flip all the way up to visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Nov 25, 2024
1 parent 7322ad6 commit 3f95ce9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
20 changes: 3 additions & 17 deletions autogalaxy/ellipse/ellipse/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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, flip_y: bool = False, n_i : int = 0
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
Expand All @@ -209,15 +209,10 @@ def y_from_major_axis_from(
that the convention of the y-axis increasing upwards is followed, meaning that `ell_comps` adopt the
same definition as used for evaluating light profiles in PyAutoGalaxy.
When plotting the ellipses, y coordinates must be flipped to match the convention of the y-axis increasing
downwards in 2D data, which is performed by setting `flip_y=True`.
Parameters
----------
pixel_scale
The pixel scale of the data that the ellipse is fitted to and interpolated over.
flip_y
If True, the y-coordinates are flipped to match the convention of the y-axis increasing downwards in 2D data.
n_i
The number of points on the ellipse which hit a masked regions and cannot be computed, where this
value is used to change the range of angles computed.
Expand All @@ -231,18 +226,12 @@ def y_from_major_axis_from(
pixel_scale=pixel_scale, n_i=n_i
)

if flip_y:
return (
ellipse_radii_from_major_axis * np.sin(angles_from_x0) + self.centre[0]
)

return (
-1.0 * (ellipse_radii_from_major_axis * np.sin(angles_from_x0))
- self.centre[0]
)

def points_from_major_axis_from(
self, pixel_scale: float, flip_y: bool = False, 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 All @@ -251,9 +240,6 @@ def points_from_major_axis_from(
This is the format inputs into the inteprolation functions which match the ellipse to 2D data and enable
us to determine how well the ellipse represents the data.
When plotting the ellipses, y coordinates must be flipped to match the convention of the y-axis increasing
downwards in 2D data, which is performed by setting `flip_y=True`.
Parameters
----------
pixel_scale
Expand All @@ -268,7 +254,7 @@ def points_from_major_axis_from(
"""

x = self.x_from_major_axis_from(pixel_scale=pixel_scale, n_i=n_i)
y = self.y_from_major_axis_from(pixel_scale=pixel_scale, flip_y=flip_y, n_i=n_i)
y = self.y_from_major_axis_from(pixel_scale=pixel_scale, n_i=n_i)

idx = np.logical_or(np.isnan(x), np.isnan(y))
if np.sum(idx) > 0.0:
Expand Down
9 changes: 3 additions & 6 deletions autogalaxy/ellipse/fit_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def interp(self) -> DatasetInterp:
"""
return DatasetInterp(dataset=self.dataset)

def points_from_major_axis_from(self, flip_y: bool = False) -> np.ndarray:
def points_from_major_axis_from(self) -> np.ndarray:
"""
Returns the (y,x) coordinates on the ellipse that are used to interpolate the data and noise-map values.
Expand All @@ -48,15 +48,12 @@ def points_from_major_axis_from(self, flip_y: bool = False) -> np.ndarray:
If multipole components are used, the points are also perturbed by the multipole components.
When plotting the ellipses, y coordinates must be flipped to match the convention of the y-axis increasing
downwards in 2D data, which is performed by setting `flip_y=True`.
Returns
-------
The (y,x) coordinates on the ellipse where the interpolation occurs.
"""
points = self.ellipse.points_from_major_axis_from(
pixel_scale=self.dataset.pixel_scales[0], flip_y=flip_y,
pixel_scale=self.dataset.pixel_scales[0],
)

if self.interp.mask_interp is not None:
Expand All @@ -74,7 +71,7 @@ def points_from_major_axis_from(self, flip_y: bool = False) -> np.ndarray:
continue

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

if i == i_total:

Expand Down
4 changes: 2 additions & 2 deletions autogalaxy/ellipse/plot/fit_ellipse_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def figures_2d(
ellipse_list = []

for fit in self.fit_list:
points = fit.points_from_major_axis_from(flip_y=True)
points = fit.points_from_major_axis_from()

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

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

Expand Down

0 comments on commit 3f95ce9

Please sign in to comment.