-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsersic.py
More file actions
228 lines (197 loc) · 8.23 KB
/
sersic.py
File metadata and controls
228 lines (197 loc) · 8.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
"""
Sersic light profiles.
The Sersic profile is one of the most widely used models for describing the surface brightness of galaxies.
It has the functional form:
I(r) = I_eff * exp{ -b_n * [(r / r_eff)^(1/n) - 1] }
where `r_eff` is the effective (half-light) radius, `n` is the Sersic index controlling concentration, and
`b_n` is derived from `n` to ensure that `r_eff` encloses half the total flux.
Special cases: n=1 is the exponential (disk) profile, n=4 is the de Vaucouleurs (bulge) profile.
This module provides both elliptical (`Sersic`) and spherical (`SersicSph`) variants.
"""
import numpy as np
from numpy import seterr
from typing import Optional, Tuple
import autoarray as aa
from autogalaxy.profiles.light.abstract import LightProfile
from autogalaxy.profiles.light.decorators import (
check_operated_only,
)
class AbstractSersic(LightProfile):
def __init__(
self,
centre: Tuple[float, float] = (0.0, 0.0),
ell_comps: Tuple[float, float] = (0.0, 0.0),
intensity: float = 0.1,
effective_radius: float = 0.6,
sersic_index: float = 4.0,
):
"""
Abstract base class for elliptical Sersic light profiles.
Parameters
----------
centre
The (y,x) arc-second coordinates of the profile centre.
ell_comps
The first and second ellipticity components of the elliptical coordinate system.
intensity
Overall intensity normalisation of the light profile (units are dimensionless and derived from the data
the light profile's image is compared too, which is expected to be electrons per second).
effective_radius
The circular radius containing half the light of this light profile.
sersic_index
Controls the concentration of the profile (lower -> less concentrated, higher -> more concentrated).
"""
super().__init__(centre=centre, ell_comps=ell_comps, intensity=intensity)
self.effective_radius = effective_radius
self.sersic_index = sersic_index
@property
def elliptical_effective_radius(self) -> float:
"""
The `effective_radius` of a Sersic light profile is defined as the circular effective radius, which is the
radius within which a circular aperture contains half the profile's total integrated light.
For elliptical systems, this will not robustly capture the light profile's elliptical shape.
The elliptical effective radius instead describes the major-axis radius of the ellipse containing
half the light, and may be more appropriate for highly flattened systems like disk galaxies.
"""
return self.effective_radius / xp.sqrt(self.axis_ratio(xp))
@property
def sersic_constant(self) -> float:
"""
A parameter derived from Sersic index which ensures that effective radius contains 50% of the profile's
total integrated light.
"""
return (
(2 * self.sersic_index)
- (1.0 / 3.0)
+ (4.0 / (405.0 * self.sersic_index))
+ (46.0 / (25515.0 * self.sersic_index**2))
+ (131.0 / (1148175.0 * self.sersic_index**3))
- (2194697.0 / (30690717750.0 * self.sersic_index**4))
)
def image_2d_via_radii_from(self, radius: np.ndarray) -> np.ndarray:
"""
Returns the 2D image of the Sersic light profile from a grid of coordinates which are the radial distances of
each coordinate from the its `centre`.
Parameters
----------
grid_radii
The radial distances from the centre of the profile, for each coordinate on the grid.
"""
return self._intensity * xp.exp(
-self.sersic_constant
* (((radius / self.effective_radius) ** (1.0 / self.sersic_index)) - 1)
)
class Sersic(AbstractSersic, LightProfile):
def __init__(
self,
centre: Tuple[float, float] = (0.0, 0.0),
ell_comps: Tuple[float, float] = (0.0, 0.0),
intensity: float = 0.1,
effective_radius: float = 0.6,
sersic_index: float = 4.0,
):
"""
The elliptical Sersic light profile.
Parameters
----------
centre
The (y,x) arc-second coordinates of the profile centre.
ell_comps
The first and second ellipticity components of the elliptical coordinate system.
intensity
Overall intensity normalisation of the light profile (units are dimensionless and derived from the data
the light profile's image is compared too, which is expected to be electrons per second).
effective_radius
The circular radius containing half the light of this profile.
sersic_index
Controls the concentration of the profile (lower -> less concentrated, higher -> more concentrated).
"""
super().__init__(
centre=centre,
ell_comps=ell_comps,
intensity=intensity,
effective_radius=effective_radius,
sersic_index=sersic_index,
)
def image_2d_via_radii_from(
self, grid_radii: np.ndarray, xp=np, **kwargs
) -> np.ndarray:
"""
Returns the 2D image of the Sersic light profile from a grid of coordinates which are the radial distances of
each coordinate from the its `centre`.
Parameters
----------
grid_radii
The radial distances from the centre of the profile, for each coordinate on the grid.
"""
seterr(all="ignore")
return xp.multiply(
self._intensity,
xp.exp(
xp.multiply(
-self.sersic_constant,
xp.add(
xp.power(
xp.divide(grid_radii.array, self.effective_radius),
1.0 / self.sersic_index,
),
-1,
),
)
),
)
@aa.over_sample
@aa.decorators.to_array
@check_operated_only
@aa.decorators.transform
def image_2d_from(
self,
grid: aa.type.Grid2DLike,
xp=np,
operated_only: Optional[bool] = None,
**kwargs,
) -> aa.Array2D:
"""
Returns the Sersic light profile's 2D image from a 2D grid of Cartesian (y,x) coordinates.
If the coordinates have not been transformed to the profile's geometry (e.g. translated to the
profile `centre`), this is performed automatically.
Parameters
----------
grid
The 2D (y, x) coordinates in the original reference frame of the grid.
Returns
-------
image
The image of the Sersic evaluated at every (y,x) coordinate on the transformed grid.
"""
grid_radii = self.eccentric_radii_grid_from(grid=grid, xp=xp, **kwargs)
return self.image_2d_via_radii_from(grid_radii=grid_radii, xp=xp, **kwargs)
class SersicSph(Sersic):
def __init__(
self,
centre: Tuple[float, float] = (0.0, 0.0),
intensity: float = 0.1,
effective_radius: float = 0.6,
sersic_index: float = 4.0,
):
"""
The spherical Sersic light profile.
Parameters
----------
centre
The (y,x) arc-second coordinates of the profile centre.
intensity
Overall intensity normalisation of the light profile (units are dimensionless and derived from the data
the light profile's image is compared too, which is expected to be electrons per second).
effective_radius
The circular radius containing half the light of this profile.
sersic_index
Controls the concentration of the of the light profile.
"""
super().__init__(
centre=centre,
ell_comps=(0.0, 0.0),
intensity=intensity,
effective_radius=effective_radius,
sersic_index=sersic_index,
)