11import numpy as np
22from typing import Tuple
3+ from autogalaxy .convert import multipole_k_m_and_phi_m_from , multipole_comps_from
34
45
56from 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 )
0 commit comments