Skip to content

Commit 4da0590

Browse files
committed
commit new changes
1 parent 3f95ce9 commit 4da0590

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

autogalaxy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from .ellipse.dataset_interp import DatasetInterp
6363
from .ellipse.ellipse.ellipse import Ellipse
6464
from .ellipse.ellipse.ellipse_multipole import EllipseMultipole
65+
from .ellipse.ellipse.ellipse_multipole import EllipseMultipoleRelative
6566
from .ellipse.fit_ellipse import FitEllipse
6667
from .ellipse.model.analysis import AnalysisEllipse
6768
from .operate.image import OperateImage

autogalaxy/ellipse/ellipse/ellipse_multipole.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
from typing import Tuple
3+
from autogalaxy.convert import multipole_k_m_and_phi_m_from, multipole_comps_from
34

45

56
from autogalaxy.ellipse.ellipse.ellipse import Ellipse
@@ -12,7 +13,7 @@ def __init__(
1213
multipole_comps: Tuple[float, float] = (0.0, 0.0),
1314
):
1415
"""
15-
class representing the multipole of an ellispe with, which is used to perform ellipse fitting to
16+
class representing the multipole of an ellipse with, which is used to perform ellipse fitting to
1617
2D data (e.g. an image).
1718
1819
The multipole is added to the (y,x) coordinates of an ellipse that are already computed via the `Ellipse` class.
@@ -68,3 +69,54 @@ def points_perturbed_from(
6869
y = points[:, 0] + (radial * np.sin(angles))
6970

7071
return np.stack(arrays=(y, x), axis=-1)
72+
73+
74+
class EllipseMultipoleRelative(EllipseMultipole):
75+
def __init__(
76+
self,
77+
m=4,
78+
input_multipole_comps: Tuple[float, float] = (0.0, 0.0),
79+
major_axis=1.,
80+
):
81+
82+
k, phi = multipole_k_m_and_phi_m_from(multipole_comps=input_multipole_comps, m=m)
83+
k_adjusted = k*major_axis
84+
85+
adjusted_multipole_comps = multipole_comps_from(k_adjusted, phi, m)
86+
87+
super().__init__(m, adjusted_multipole_comps)
88+
89+
self.adjusted_multipole_comps = adjusted_multipole_comps
90+
self.m = m
91+
92+
def points_perturbed_from(
93+
self, pixel_scale, points, ellipse: Ellipse
94+
) -> np.ndarray:
95+
"""
96+
Returns the (y,x) coordinates of the input points, which are perturbed by the multipole of the ellipse.
97+
98+
Parameters
99+
----------
100+
pixel_scale
101+
The pixel scale of the data that the ellipse is fitted to and interpolated over.
102+
points
103+
The (y,x) coordinates of the ellipse that are perturbed by the multipole.
104+
ellipse
105+
The ellipse that is perturbed by the multipole, which is used to compute the angles of the ellipse.
106+
107+
Returns
108+
-------
109+
The (y,x) coordinates of the input points, which are perturbed by the multipole.
110+
"""
111+
112+
angles = ellipse.angles_from_x0_from(pixel_scale=pixel_scale)
113+
114+
radial = np.add(
115+
self.adjusted_multipole_comps[1] * np.cos(self.m * (angles - ellipse.angle_radians)),
116+
self.adjusted_multipole_comps[0] * np.sin(self.m * (angles - ellipse.angle_radians)),
117+
)
118+
119+
x = points[:, 1] + (radial * np.cos(angles))
120+
y = points[:, 0] + (radial * np.sin(angles))
121+
122+
return np.stack(arrays=(y, x), axis=-1)

autogalaxy/ellipse/fit_ellipse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,4 @@ def figure_of_merit(self) -> float:
328328
-------
329329
The figure of merit of the fit.
330330
"""
331-
return self.log_likelihood
331+
return -0.5* (self.chi_squared + self.noise_normalization)

0 commit comments

Comments
 (0)