Skip to content

Commit

Permalink
Merge pull request lenstronomy#614 from sibirrer/main
Browse files Browse the repository at this point in the history
total_flux() routine for Hernquist light models
  • Loading branch information
sibirrer committed May 25, 2024
2 parents c1e3a9e + fc3bd0d commit 5b6cde8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 25 deletions.
74 changes: 49 additions & 25 deletions lenstronomy/LightModel/Profiles/hernquist.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import lenstronomy.Util.param_util as param_util
import numpy as np

__all__ = ["Hernquist", "HernquistEllipse"]


class Hernquist(object):
"""Class for pseudo Jaffe lens light (2d projected light/mass distribution."""
"""Class for Hernquist lens light (2d projected light/mass distribution)."""

def __init__(self):
from lenstronomy.LensModel.Profiles.hernquist import Hernquist as Hernquist_lens
Expand All @@ -27,28 +28,40 @@ def __init__(self):
def function(self, x, y, amp, Rs, center_x=0, center_y=0):
"""
:param x:
:param y:
:param amp:
:param x: x-position
:param y: y-position
:param amp: surface brightness amplitude
:param Rs: scale radius: half-light radius = Rs / 0.551
:param center_x:
:param center_y:
:return:
:param center_x: centroid in x-direction
:param center_y: centroid in y-direction
:return: surface brightness
"""
rho0 = self.lens.sigma2rho(amp, Rs)
return self.lens.density_2d(x, y, rho0, Rs, center_x, center_y)

def light_3d(self, r, amp, Rs):
"""
:param r:
:param amp:
:param Rs:
:param r: 3d radius (in angular units)
:param amp: surface brightness amplitude
:param Rs: scale radius: half-light radius = Rs / 0.551
:return:
"""
rho0 = self.lens.sigma2rho(amp, Rs)
return self.lens.density(r, rho0, Rs)

@staticmethod
def total_flux(amp, Rs):
"""
:param amp: surface brightness amplitude
:param Rs: scale radius: half-light radius = Rs / 0.551
:return: total integrated flux of profile
"""
rhos = amp / Rs
m_tot = 2 * np.pi * rhos * Rs**3
return m_tot


class HernquistEllipse(object):
"""Class for elliptical pseudo Jaffe lens light (2d projected light/mass
Expand Down Expand Up @@ -81,15 +94,15 @@ def __init__(self):
def function(self, x, y, amp, Rs, e1, e2, center_x=0, center_y=0):
"""
:param x:
:param y:
:param amp:
:param Rs:
:param e1:
:param e2:
:param center_x:
:param center_y:
:return:
:param x: x-position
:param y: y-position
:param amp: surface brightness amplitude
:param Rs: scale radius: half-light radius = Rs / 0.551
:param e1: eccentricity component
:param e2: eccentricity component
:param center_x: centroid in x-direction
:param center_y: centroid in y-direction
:return: surface brightness
"""
x_, y_ = param_util.transform_e1e2_product_average(
x, y, e1, e2, center_x, center_y
Expand All @@ -99,12 +112,23 @@ def function(self, x, y, amp, Rs, e1, e2, center_x=0, center_y=0):
def light_3d(self, r, amp, Rs, e1=0, e2=0):
"""
:param r:
:param amp:
:param Rs:
:param e1:
:param e2:
:return:
:param r: 3d radius (in angular units)
:param amp: surface brightness amplitude
:param Rs: scale radius: half-light radius = Rs / 0.551
:param e1: eccentricity component
:param e2: eccentricity component
:return: flux density in 3d
"""
rho0 = self.lens.sigma2rho(amp, Rs)
return self.lens.density(r, rho0, Rs)

def total_flux(self, amp, Rs, e1=0, e2=0):
"""
:param amp: surface brightness amplitude
:param Rs: scale radius: half-light radius = Rs / 0.551
:param e1: eccentricity component
:param e2: eccentricity component
:return: total integrated flux
"""
return self.spherical.total_flux(amp=amp, Rs=Rs)
24 changes: 24 additions & 0 deletions test/test_LightModel/test_Profiles/test_hernquist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from lenstronomy.LightModel.Profiles.hernquist import Hernquist, HernquistEllipse
from lenstronomy.Util.util import make_grid
import numpy as np
import numpy.testing as npt


class TestHernquist(object):

def setup_method(self):
self.hernquist = Hernquist()
self.hernquist_ellipse = HernquistEllipse()

def test_total_flux(self):
delta_pix = 0.2
x, y = make_grid(numPix=1000, deltapix=delta_pix)

rs, amp = 1, 1
total_flux = self.hernquist.total_flux(amp=amp, Rs=rs)
flux = self.hernquist.function(x, y, amp=amp, Rs=rs)
total_flux_numerics = np.sum(flux) * delta_pix**2
npt.assert_almost_equal(total_flux_numerics / total_flux, 1, decimal=1)

total_flux_ellipse = self.hernquist_ellipse.total_flux(amp=amp, Rs=rs)
npt.assert_almost_equal(total_flux_ellipse, total_flux)

0 comments on commit 5b6cde8

Please sign in to comment.