forked from lenstronomy/lenstronomy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lenstronomy:main' into main
- Loading branch information
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import numpy as np | ||
|
||
|
||
__all__ = ["LineProfile"] | ||
|
||
|
||
class LineProfile(object): | ||
"""Horizontal line segment class. | ||
The line extends `length` arcseconds from | ||
(`start_x`, `start_y`) at an angle `angle` degrees to the horizontal. Line `width` | ||
is centered in the perpendicular direction, e.g. a profile with 1 arcsecond width | ||
and `angle=0` will span -0.5 to 0.5 in the y-direction. Surface brightness is | ||
constant and given by `amp`. | ||
""" | ||
|
||
param_names = ["amp", "angle", "length", "width", "start_x", "start_y"] | ||
lower_limit_default = { | ||
"amp": 0, | ||
"angle": -180, | ||
"length": 0.01, | ||
"width": 0.01, | ||
"start_x": -100, | ||
"start_y": -100, | ||
} | ||
upper_limit_default = { | ||
"amp": 10, | ||
"angle": 180, | ||
"length": 10, | ||
"width": 5, | ||
"start_x": 100, | ||
"start_y": 100, | ||
} | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): | ||
"""Surface brightness per angular unit. | ||
:param x: x-coordinate on sky | ||
:param y: y-coordinate on sky | ||
:param amp: constant surface brightness of line | ||
:param angle: angle of line to the horizontal (degrees) | ||
:param length: length of line (arcseconds) | ||
:param width: width of line (arcseconds), line width extends symmetrically | ||
:param start_x: ra coordinate of start of line | ||
:param start_y: dec-coordinate of start of line | ||
:return: surface brightness, raise as definition is not defined | ||
""" | ||
ang = -np.deg2rad(angle) | ||
x_ = np.cos(ang) * (x - start_x) + np.sin(ang) * (y - start_y) | ||
y_ = np.cos(ang) * (y - start_y) - np.sin(ang) * (x - start_x) | ||
flux = np.zeros_like(x_) | ||
flux[(x_ >= 0) * (x_ <= length) * (abs(y_) <= width / 2)] = amp | ||
return flux | ||
|
||
def total_flux(self, amp, angle, length, width, start_x=0, start_y=0): | ||
"""Integrated flux of the profile. | ||
:param amp: constant surface brightness of line | ||
:param angle: angle of line to the horizontal (degrees) | ||
:param length: length of line (arcseconds) | ||
:param width: width of line (arcseconds), line width extends symmetrically | ||
:param start_x: ra coordinate of start of line | ||
:param start_y: dec-coordinate of start of line | ||
:return: total flux | ||
""" | ||
return amp * length * width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from lenstronomy.LightModel.Profiles.lineprofile import LineProfile | ||
import numpy as np | ||
import numpy.testing as npt | ||
|
||
|
||
class TestLineProfile(object): | ||
def setup_method(self): | ||
self.lineprofile = LineProfile() | ||
|
||
def test_function(self): | ||
amp = 1 | ||
length = 1 | ||
width = 0.01 | ||
angle = 57 | ||
x = np.array([0, 1, 0.5 * np.cos(np.deg2rad(-angle))]) | ||
y = np.array([0, 0, 0.5 * np.sin(np.deg2rad(-angle))]) | ||
x_single = 0.2 * np.cos(np.deg2rad(-angle)) | ||
y_single = 0.2 * np.sin(np.deg2rad(-angle)) | ||
flux_true = np.array([amp, 0, amp]) | ||
flux = self.lineprofile.function(x, y, amp, angle, length, width) | ||
single_flux_true = amp | ||
single_flux = self.lineprofile.function( | ||
x_single, y_single, amp, angle, length, width | ||
) | ||
npt.assert_equal(flux_true, flux) | ||
npt.assert_equal(single_flux_true, single_flux) | ||
|
||
def test_total_flux(self): | ||
amp = 1 | ||
length = 1 | ||
width = 0.01 | ||
angle = 57 | ||
total_flux = self.lineprofile.total_flux(amp, angle, length, width) | ||
total_flux_true = length * width * amp | ||
npt.assert_equal(total_flux_true, total_flux) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters