From 8dfe9955e950af266f0350fe13bb1cf91625ea34 Mon Sep 17 00:00:00 2001 From: Anowar Shajib Date: Thu, 16 May 2024 12:24:10 -0500 Subject: [PATCH 01/20] Update codecov.yml --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codecov.yml b/codecov.yml index ba5fddb1a..f62badc1d 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,5 @@ +codecov: + token: 69d31c95-1c33-44f1-883e-0886d62a01d4 comment: # this is a top-level key layout: " diff, flags, files" behavior: default From 0f5ea0666c226442e8d4546a2f2783d8a092c8db Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Sun, 19 May 2024 10:53:24 -0500 Subject: [PATCH 02/20] Created LineProfile class --- .../LightModel/Profiles/lineprofile.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 lenstronomy/LightModel/Profiles/lineprofile.py diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py new file mode 100644 index 000000000..638c58f96 --- /dev/null +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -0,0 +1,69 @@ + +import numpy as np + +__all__ = ["LineProfile"] + +class LineProfile(object): + """ + Horizontal line segment class. + Parameters: + start_x: ra-coordiinate of start of line + start_y: dec-coordinate of start of line + length: length of line (arcseconds) + width: width of line (arcseconds), line centered at start_x, start_y in perpendicular direction + amp: surface brightness of line + angle: angle of jet to the horizontal (degrees, 0 = constant RA) + """ + + 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": 0, + "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): + """ + + :param x: x-coordinate + :param y: y-coordinate + :param kwargs: keyword arguments of profile + :return: surface brightness, raise as definition is not defined + """ + + ang = np.deg2rad(angle) + rot = np.array([[np.cos(ang), np.sin(ang)],[-1*np.sin(ang), np.cos(ang)]]) + out = rot.dot([[x],[y]]) + + if ((out[0]) > 0) and ((out[0]) < length) and (abs(([out[1]])/2) < width): + return amp + return 0 + + + + def light_3d(self, *args, **kwargs): + """ + + :param r: 3d radius + :param kwargs: keyword arguments of profile + :return: 3d light profile, raise as definition is not defined + """ + raise ValueError("light_3d definition not defined in the light profile.") \ No newline at end of file From 845937c8cc694df0b4fbc99fb0dad5c0789d0696 Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Sun, 19 May 2024 13:25:53 -0500 Subject: [PATCH 03/20] Fixed surface brightness function, added to light_model_base --- lenstronomy/LightModel/Profiles/lineprofile.py | 12 +++++------- lenstronomy/LightModel/light_model_base.py | 5 +++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 638c58f96..39cbfc735 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -25,7 +25,7 @@ class LineProfile(object): "start_y": -100, } upper_limit_default = { - "amp": 0, + "amp": 10, "angle": 180, "length": 10, "width": 5, @@ -49,13 +49,11 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): :return: surface brightness, raise as definition is not defined """ - ang = np.deg2rad(angle) - rot = np.array([[np.cos(ang), np.sin(ang)],[-1*np.sin(ang), np.cos(ang)]]) - out = rot.dot([[x],[y]]) + ang = -np.deg2rad(angle) + out = (np.cos(ang)*(start_x - x) + np.sin(ang)*(start_y - y), np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x)) - if ((out[0]) > 0) and ((out[0]) < length) and (abs(([out[1]])/2) < width): - return amp - return 0 + return amp * ((out[0]) > 0) * ((out[0]) < length) * (abs((out[1])) < width/2) + diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index 0582557b2..48c74b258 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -41,6 +41,7 @@ "SLIT_STARLETS_GEN2", "LINEAR", "LINEAR_ELLIPSE", + "LINEPROFILE" ] @@ -193,6 +194,10 @@ def __init__(self, light_model_list, smoothing=0.001, sersic_major_axis=None): from lenstronomy.LightModel.Profiles.linear import LinearEllipse self.func_list.append(LinearEllipse()) + elif profile_type == "LINEPROFILE": + from lenstronomy.LightModel.Profiles.lineprofile import LineProfile + + self.func_list.append(LineProfile()) else: raise ValueError( "No light model of type %s found! Supported are the following models: %s" From 6ce15af186b9086e27dc7e88264ed9ebe261007f Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Sun, 19 May 2024 13:47:40 -0500 Subject: [PATCH 04/20] style fixes, added total_flux --- .../LightModel/Profiles/lineprofile.py | 44 ++++++++++++------- lenstronomy/LightModel/light_model_base.py | 3 +- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 39cbfc735..cb2c2f7d4 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -7,12 +7,6 @@ class LineProfile(object): """ Horizontal line segment class. Parameters: - start_x: ra-coordiinate of start of line - start_y: dec-coordinate of start of line - length: length of line (arcseconds) - width: width of line (arcseconds), line centered at start_x, start_y in perpendicular direction - amp: surface brightness of line - angle: angle of jet to the horizontal (degrees, 0 = constant RA) """ param_names = ["amp", "angle", "length", "width", "start_x", "start_y"] @@ -41,19 +35,37 @@ def __init__(self): def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param kwargs: keyword arguments of profile + """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) - out = (np.cos(ang)*(start_x - x) + np.sin(ang)*(start_y - y), np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x)) - - return amp * ((out[0]) > 0) * ((out[0]) < length) * (abs((out[1])) < width/2) - + x_ = np.cos(ang)*(start_x - x) + np.sin(ang)*(start_y - y) + y_ = np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x) + return amp * (x_ > 0) * (x_ < length) * (abs(y_) < width/2) + + + def total_flux(self, amp, angle, length, width, start_x=0, start_y=0): + """Integrated flux of the profile. + + :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: total flux + """ + return amp * length * width diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index 48c74b258..be86c3271 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -256,7 +256,7 @@ def light_3d(self, r, kwargs_list, k=None): "MULTI_GAUSSIAN_ELLIPSE", "NIE", "POWER_LAW", - "TRIPLE_CHAMELEON", + "TRIPLE_CHAMELEON" ]: flux += func.light_3d(r, **kwargs) else: @@ -291,6 +291,7 @@ def total_flux(self, kwargs_list, norm=False, k=None): "GAUSSIAN_ELLIPSE", "MULTI_GAUSSIAN", "MULTI_GAUSSIAN_ELLIPSE", + "LINEPROFILE" ]: kwargs_new = kwargs_list_standard[i].copy() if norm is True: From 5388d6d59bac4d640ef0f3fda98326727656d3ca Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Sun, 19 May 2024 13:58:51 -0500 Subject: [PATCH 05/20] flake8 --- lenstronomy/LightModel/Profiles/lineprofile.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index cb2c2f7d4..43910ab2c 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -1,12 +1,12 @@ - import numpy as np + __all__ = ["LineProfile"] + class LineProfile(object): """ Horizontal line segment class. - Parameters: """ param_names = ["amp", "angle", "length", "width", "start_x", "start_y"] @@ -27,13 +27,9 @@ class LineProfile(object): "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 @@ -41,7 +37,7 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): :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 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 @@ -51,7 +47,6 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): y_ = np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x) return amp * (x_ > 0) * (x_ < length) * (abs(y_) < width/2) - def total_flux(self, amp, angle, length, width, start_x=0, start_y=0): """Integrated flux of the profile. @@ -60,15 +55,13 @@ def total_flux(self, amp, angle, length, width, start_x=0, start_y=0): :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 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 - - def light_3d(self, *args, **kwargs): """ @@ -76,4 +69,4 @@ def light_3d(self, *args, **kwargs): :param kwargs: keyword arguments of profile :return: 3d light profile, raise as definition is not defined """ - raise ValueError("light_3d definition not defined in the light profile.") \ No newline at end of file + raise ValueError("light_3d definition not defined in the light profile.") From 9ba8558bb10b778d4680fb92f94ad339b99b875a Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Sun, 19 May 2024 14:36:56 -0500 Subject: [PATCH 06/20] minor docstring fix in total_flux --- lenstronomy/LightModel/Profiles/lineprofile.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 43910ab2c..9fa2ee7b3 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -49,9 +49,6 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): def total_flux(self, amp, angle, length, width, start_x=0, start_y=0): """Integrated flux of the profile. - - :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) From d2191f099697603ab48c02eb89af543ab3e3689a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 May 2024 19:40:06 +0000 Subject: [PATCH 07/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lenstronomy/LightModel/Profiles/lineprofile.py | 12 ++++++------ lenstronomy/LightModel/light_model_base.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 9fa2ee7b3..260caac0c 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -5,9 +5,7 @@ class LineProfile(object): - """ - Horizontal line segment class. - """ + """Horizontal line segment class.""" param_names = ["amp", "angle", "length", "width", "start_x", "start_y"] lower_limit_default = { @@ -32,6 +30,7 @@ def __init__(self): 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 @@ -43,12 +42,13 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): :return: surface brightness, raise as definition is not defined """ ang = -np.deg2rad(angle) - x_ = np.cos(ang)*(start_x - x) + np.sin(ang)*(start_y - y) - y_ = np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x) - return amp * (x_ > 0) * (x_ < length) * (abs(y_) < width/2) + x_ = np.cos(ang) * (start_x - x) + np.sin(ang) * (start_y - y) + y_ = np.cos(ang) * (start_y - y) - np.sin(ang) * (start_x - x) + return amp * (x_ > 0) * (x_ < length) * (abs(y_) < width / 2) 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) diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index be86c3271..98a9554e4 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -41,7 +41,7 @@ "SLIT_STARLETS_GEN2", "LINEAR", "LINEAR_ELLIPSE", - "LINEPROFILE" + "LINEPROFILE", ] @@ -256,7 +256,7 @@ def light_3d(self, r, kwargs_list, k=None): "MULTI_GAUSSIAN_ELLIPSE", "NIE", "POWER_LAW", - "TRIPLE_CHAMELEON" + "TRIPLE_CHAMELEON", ]: flux += func.light_3d(r, **kwargs) else: @@ -291,7 +291,7 @@ def total_flux(self, kwargs_list, norm=False, k=None): "GAUSSIAN_ELLIPSE", "MULTI_GAUSSIAN", "MULTI_GAUSSIAN_ELLIPSE", - "LINEPROFILE" + "LINEPROFILE", ]: kwargs_new = kwargs_list_standard[i].copy() if norm is True: From a967827791a722e256adb869f6a1137989a5eee9 Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Mon, 20 May 2024 10:31:28 -0500 Subject: [PATCH 08/20] More elaborate documentation, slight flux calculation speedup, changed name in light_model_base.py from 'LINEPROFILE' to 'LINE_PROFILE' --- lenstronomy/LightModel/Profiles/lineprofile.py | 11 +++++++++-- lenstronomy/LightModel/light_model_base.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 9fa2ee7b3..584940379 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -6,7 +6,11 @@ class LineProfile(object): """ - Horizontal line segment class. + 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"] @@ -45,7 +49,10 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): ang = -np.deg2rad(angle) x_ = np.cos(ang)*(start_x - x) + np.sin(ang)*(start_y - y) y_ = np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x) - return amp * (x_ > 0) * (x_ < length) * (abs(y_) < width/2) + 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. diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index be86c3271..40d30763f 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -41,7 +41,7 @@ "SLIT_STARLETS_GEN2", "LINEAR", "LINEAR_ELLIPSE", - "LINEPROFILE" + "LINE_PROFILE" ] From f30d3007b86453d04bee3371974933305a65ac1e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 15:34:08 +0000 Subject: [PATCH 09/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lenstronomy/LightModel/Profiles/lineprofile.py | 14 +++++++------- lenstronomy/LightModel/light_model_base.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index cc0bd29a6..0fdf3206c 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -5,11 +5,12 @@ class LineProfile(object): - """ - Horizontal line segment class. The line extends `length` arcseconds from + """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 + and `angle=0` will span -0.5 to 0.5 in the y-direction. Surface brightness is constant and given by `amp`. """ @@ -48,13 +49,12 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): :return: surface brightness, raise as definition is not defined """ ang = -np.deg2rad(angle) - x_ = np.cos(ang)*(start_x - x) + np.sin(ang)*(start_y - y) - y_ = np.cos(ang)*(start_y - y) - np.sin(ang)*(start_x - x) + x_ = np.cos(ang) * (start_x - x) + np.sin(ang) * (start_y - y) + y_ = np.cos(ang) * (start_y - y) - np.sin(ang) * (start_x - x) flux = np.zeros_like(x_) - flux[(x_ > 0) * (x_ < length) * (abs(y_) < width/2)] = amp + 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. diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index 152eaeb57..d5a1ce423 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -41,7 +41,7 @@ "SLIT_STARLETS_GEN2", "LINEAR", "LINEAR_ELLIPSE", - "LINE_PROFILE" + "LINE_PROFILE", ] From c630d83f1d4fdfb1ae41d54ee1eaeedd175eabe2 Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Mon, 20 May 2024 15:25:25 -0500 Subject: [PATCH 10/20] added tests --- .../test_Profiles/test_lineprofile.py | 28 +++++++++++++++++++ test/test_LightModel/test_light_model.py | 9 ++++++ 2 files changed, 37 insertions(+) create mode 100644 test/test_LightModel/test_Profiles/test_lineprofile.py diff --git a/test/test_LightModel/test_Profiles/test_lineprofile.py b/test/test_LightModel/test_Profiles/test_lineprofile.py new file mode 100644 index 000000000..e3280bc1e --- /dev/null +++ b/test/test_LightModel/test_Profiles/test_lineprofile.py @@ -0,0 +1,28 @@ +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(57))]) + y = np.array([0, 0, 0.5*np.sin(np.deg2rad(57))]) + flux_true = np.array([amp, 0, amp]) + flux = self.lineprofile.function(x, y, amp, angle, length, width) + npt.assert_equal(flux_true, flux) + + def test_total_flux(self): + amp = 1 + length = 1 + width = 0.01 + angle = 57 + total_flux = self.lineprofile.total_flux(amp, length, width, angle) + total_flux_true = length * width * amp + npt.assert_equal(total_flux_true, total_flux) diff --git a/test/test_LightModel/test_light_model.py b/test/test_LightModel/test_light_model.py index 6eb4454ba..d3bb06122 100644 --- a/test/test_LightModel/test_light_model.py +++ b/test/test_LightModel/test_light_model.py @@ -31,6 +31,7 @@ def setup_method(self): "INTERPOL", "SHAPELETS_POLAR_EXP", "ELLIPSOID", + "LINE_PROFILE" ] phi_G, q = 0.5, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) @@ -129,6 +130,14 @@ def setup_method(self): "center_x": 0, "center_y": 0, }, # 'ELLIPSOID' + { + "amp": 1, + "length": 1.0, + "width": 0.01, + "angle": 57, + "start_x": 0, + "start_y": 0, + }, # 'LINE_PROFILE' ] self.LightModel = LightModel( From 63e56323b24ae1d1c2b91462876d7ec9705b7e96 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 20:26:36 +0000 Subject: [PATCH 11/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_LightModel/test_Profiles/test_lineprofile.py | 4 ++-- test/test_LightModel/test_light_model.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_LightModel/test_Profiles/test_lineprofile.py b/test/test_LightModel/test_Profiles/test_lineprofile.py index e3280bc1e..e28c4148d 100644 --- a/test/test_LightModel/test_Profiles/test_lineprofile.py +++ b/test/test_LightModel/test_Profiles/test_lineprofile.py @@ -12,8 +12,8 @@ def test_function(self): length = 1 width = 0.01 angle = 57 - x = np.array([0, 1, 0.5*np.cos(np.deg2rad(57))]) - y = np.array([0, 0, 0.5*np.sin(np.deg2rad(57))]) + x = np.array([0, 1, 0.5 * np.cos(np.deg2rad(57))]) + y = np.array([0, 0, 0.5 * np.sin(np.deg2rad(57))]) flux_true = np.array([amp, 0, amp]) flux = self.lineprofile.function(x, y, amp, angle, length, width) npt.assert_equal(flux_true, flux) diff --git a/test/test_LightModel/test_light_model.py b/test/test_LightModel/test_light_model.py index d3bb06122..06969865f 100644 --- a/test/test_LightModel/test_light_model.py +++ b/test/test_LightModel/test_light_model.py @@ -31,7 +31,7 @@ def setup_method(self): "INTERPOL", "SHAPELETS_POLAR_EXP", "ELLIPSOID", - "LINE_PROFILE" + "LINE_PROFILE", ] phi_G, q = 0.5, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) @@ -130,7 +130,7 @@ def setup_method(self): "center_x": 0, "center_y": 0, }, # 'ELLIPSOID' - { + { "amp": 1, "length": 1.0, "width": 0.01, From e05d61f1d79d8a739b4f14d603ac4694dd5fde0b Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Mon, 20 May 2024 15:47:20 -0500 Subject: [PATCH 12/20] Added single input test, changed < and > to <= and >= --- lenstronomy/LightModel/Profiles/lineprofile.py | 2 +- .../test_LightModel/test_Profiles/test_lineprofile.py | 11 ++++++++--- test/test_LightModel/test_light_model.py | 11 ++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 0fdf3206c..d31b16eca 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -52,7 +52,7 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): x_ = np.cos(ang) * (start_x - x) + np.sin(ang) * (start_y - y) y_ = np.cos(ang) * (start_y - y) - np.sin(ang) * (start_x - x) flux = np.zeros_like(x_) - flux[(x_ > 0) * (x_ < length) * (abs(y_) < width / 2)] = amp + 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): diff --git a/test/test_LightModel/test_Profiles/test_lineprofile.py b/test/test_LightModel/test_Profiles/test_lineprofile.py index e3280bc1e..8bd378819 100644 --- a/test/test_LightModel/test_Profiles/test_lineprofile.py +++ b/test/test_LightModel/test_Profiles/test_lineprofile.py @@ -12,17 +12,22 @@ def test_function(self): length = 1 width = 0.01 angle = 57 - x = np.array([0, 1, 0.5*np.cos(np.deg2rad(57))]) - y = np.array([0, 0, 0.5*np.sin(np.deg2rad(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, length, width, angle) + total_flux = self.lineprofile.total_flux(amp, angle, length, width) total_flux_true = length * width * amp npt.assert_equal(total_flux_true, total_flux) diff --git a/test/test_LightModel/test_light_model.py b/test/test_LightModel/test_light_model.py index d3bb06122..d781634f9 100644 --- a/test/test_LightModel/test_light_model.py +++ b/test/test_LightModel/test_light_model.py @@ -130,7 +130,7 @@ def setup_method(self): "center_x": 0, "center_y": 0, }, # 'ELLIPSOID' - { + { "amp": 1, "length": 1.0, "width": 0.01, @@ -208,6 +208,7 @@ def test_total_flux(self): "GAUSSIAN_ELLIPSE", "MULTI_GAUSSIAN", "MULTI_GAUSSIAN_ELLIPSE", + "LINE_PROFILE" ] kwargs_list = [ { @@ -256,6 +257,14 @@ def test_total_flux(self): "center_x": 0, "center_y": 0, }, # 'MULTI_GAUSSIAN_ELLIPSE' + { + "amp": 1, + "length": 1.0, + "width": 0.01, + "angle": 57, + "start_x": 0, + "start_y": 0, + }, # 'LINE_PROFILE' ] lightModel = LightModel(light_model_list=light_model_list) total_flux_list = lightModel.total_flux(kwargs_list) From 9db76cce60af0353fb8f59d70dffb05f2ff05166 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 20:49:25 +0000 Subject: [PATCH 13/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_LightModel/test_Profiles/test_lineprofile.py | 4 +++- test/test_LightModel/test_light_model.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_LightModel/test_Profiles/test_lineprofile.py b/test/test_LightModel/test_Profiles/test_lineprofile.py index 8bd378819..981637597 100644 --- a/test/test_LightModel/test_Profiles/test_lineprofile.py +++ b/test/test_LightModel/test_Profiles/test_lineprofile.py @@ -19,7 +19,9 @@ def test_function(self): 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) + 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) diff --git a/test/test_LightModel/test_light_model.py b/test/test_LightModel/test_light_model.py index 3140e741f..8e3d20ac8 100644 --- a/test/test_LightModel/test_light_model.py +++ b/test/test_LightModel/test_light_model.py @@ -208,7 +208,7 @@ def test_total_flux(self): "GAUSSIAN_ELLIPSE", "MULTI_GAUSSIAN", "MULTI_GAUSSIAN_ELLIPSE", - "LINE_PROFILE" + "LINE_PROFILE", ] kwargs_list = [ { From fd04c6145f1f1de0da03565a5301f054c48ebed8 Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Mon, 20 May 2024 15:52:48 -0500 Subject: [PATCH 14/20] shortened line --- test/test_LightModel/test_Profiles/test_lineprofile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_LightModel/test_Profiles/test_lineprofile.py b/test/test_LightModel/test_Profiles/test_lineprofile.py index 8bd378819..5d1a81ac6 100644 --- a/test/test_LightModel/test_Profiles/test_lineprofile.py +++ b/test/test_LightModel/test_Profiles/test_lineprofile.py @@ -19,7 +19,8 @@ def test_function(self): 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) + 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) From bd94b138b5a770f39bb609c1c8b8d281ac7481c7 Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Mon, 20 May 2024 16:15:45 -0500 Subject: [PATCH 15/20] fixed typo in light_model_base --- lenstronomy/LightModel/light_model_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index d5a1ce423..4f5437163 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -194,7 +194,7 @@ def __init__(self, light_model_list, smoothing=0.001, sersic_major_axis=None): from lenstronomy.LightModel.Profiles.linear import LinearEllipse self.func_list.append(LinearEllipse()) - elif profile_type == "LINEPROFILE": + elif profile_type == "LINE_PROFILE": from lenstronomy.LightModel.Profiles.lineprofile import LineProfile self.func_list.append(LineProfile()) From 17fa0eb80d291b17458b0f485622c1f5b705b388 Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Mon, 20 May 2024 22:34:46 -0500 Subject: [PATCH 16/20] FIxed additional typo in light_model_base, sign error --- lenstronomy/LightModel/Profiles/lineprofile.py | 4 ++-- lenstronomy/LightModel/light_model_base.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index d31b16eca..0c740d72a 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -49,8 +49,8 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): :return: surface brightness, raise as definition is not defined """ ang = -np.deg2rad(angle) - x_ = np.cos(ang) * (start_x - x) + np.sin(ang) * (start_y - y) - y_ = np.cos(ang) * (start_y - y) - np.sin(ang) * (start_x - x) + x_ = np.cos(ang) * (x - start_x) + np.sin(ang) * (start_y - y) + y_ = np.cos(ang) * (start_y - y) - np.sin(ang) * (x - start_x) flux = np.zeros_like(x_) flux[(x_ >= 0) * (x_ <= length) * (abs(y_) <= width / 2)] = amp return flux diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index 4f5437163..aaccaf213 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -291,7 +291,7 @@ def total_flux(self, kwargs_list, norm=False, k=None): "GAUSSIAN_ELLIPSE", "MULTI_GAUSSIAN", "MULTI_GAUSSIAN_ELLIPSE", - "LINEPROFILE", + "LINE_PROFILE", ]: kwargs_new = kwargs_list_standard[i].copy() if norm is True: From 5a34f44c6606df3048ed086c769d58c38606593a Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Tue, 21 May 2024 09:55:57 -0500 Subject: [PATCH 17/20] Added lineProfile to linear_basis, updated test_num_param_linear to 20 components, redid sign error fix from previous commit --- lenstronomy/LightModel/Profiles/lineprofile.py | 4 ++-- lenstronomy/LightModel/linear_basis.py | 3 +++ test/test_LightModel/test_Profiles/test_lineprofile.py | 8 ++++---- test/test_LightModel/test_light_model.py | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 0c740d72a..902c71791 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -49,8 +49,8 @@ def function(self, x, y, amp, angle, length, width, start_x=0, start_y=0): :return: surface brightness, raise as definition is not defined """ ang = -np.deg2rad(angle) - x_ = np.cos(ang) * (x - start_x) + np.sin(ang) * (start_y - y) - y_ = np.cos(ang) * (start_y - y) - np.sin(ang) * (x - start_x) + 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 diff --git a/lenstronomy/LightModel/linear_basis.py b/lenstronomy/LightModel/linear_basis.py index 2a3eb79fc..b8871f47f 100644 --- a/lenstronomy/LightModel/linear_basis.py +++ b/lenstronomy/LightModel/linear_basis.py @@ -77,6 +77,7 @@ def functions_split(self, x, y, kwargs_list, k=None): "ELLIPSOID", "LINEAR", "LINEAR_ELLIPSE", + "LINE_PROFILE", ]: kwargs_new = kwargs_list[i].copy() new = {"amp": 1} @@ -156,6 +157,7 @@ def num_param_linear_list(self, kwargs_list): "ELLIPSOID", "LINEAR", "LINEAR_ELLIPSE", + "LINE_PROFILE", ]: n_list += [1] elif model in ["MULTI_GAUSSIAN", "MULTI_GAUSSIAN_ELLIPSE"]: @@ -215,6 +217,7 @@ def update_linear(self, param, i, kwargs_list): "ELLIPSOID", "LINEAR", "LINEAR_ELLIPSE", + "LINE_PROFILE" ]: kwargs_list[k]["amp"] = param[i] i += 1 diff --git a/test/test_LightModel/test_Profiles/test_lineprofile.py b/test/test_LightModel/test_Profiles/test_lineprofile.py index 981637597..91a2ddd74 100644 --- a/test/test_LightModel/test_Profiles/test_lineprofile.py +++ b/test/test_LightModel/test_Profiles/test_lineprofile.py @@ -12,10 +12,10 @@ def test_function(self): 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)) + 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 diff --git a/test/test_LightModel/test_light_model.py b/test/test_LightModel/test_light_model.py index 8e3d20ac8..764bf5702 100644 --- a/test/test_LightModel/test_light_model.py +++ b/test/test_LightModel/test_light_model.py @@ -185,7 +185,7 @@ def test_param_name_list_latex(self): def test_num_param_linear(self): num = self.LightModel.num_param_linear(self.kwargs, list_return=False) - assert num == 19 + assert num == 20 num_list = self.LightModel.num_param_linear(self.kwargs, list_return=True) assert num_list[0] == 1 From bd3ed89ae48fe9bf9bf00a673f9e5fb2c2b2bc2d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 14:56:33 +0000 Subject: [PATCH 18/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lenstronomy/LightModel/linear_basis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lenstronomy/LightModel/linear_basis.py b/lenstronomy/LightModel/linear_basis.py index b8871f47f..bee589ed4 100644 --- a/lenstronomy/LightModel/linear_basis.py +++ b/lenstronomy/LightModel/linear_basis.py @@ -217,7 +217,7 @@ def update_linear(self, param, i, kwargs_list): "ELLIPSOID", "LINEAR", "LINEAR_ELLIPSE", - "LINE_PROFILE" + "LINE_PROFILE", ]: kwargs_list[k]["amp"] = param[i] i += 1 From 945eb7f47ea9f82797dc9126a9ce9f13d65ac59a Mon Sep 17 00:00:00 2001 From: Michael Martinez Date: Tue, 21 May 2024 10:23:21 -0500 Subject: [PATCH 19/20] removed light_3d --- lenstronomy/LightModel/Profiles/lineprofile.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lenstronomy/LightModel/Profiles/lineprofile.py b/lenstronomy/LightModel/Profiles/lineprofile.py index 902c71791..5b49d369a 100644 --- a/lenstronomy/LightModel/Profiles/lineprofile.py +++ b/lenstronomy/LightModel/Profiles/lineprofile.py @@ -67,12 +67,3 @@ def total_flux(self, amp, angle, length, width, start_x=0, start_y=0): :return: total flux """ return amp * length * width - - def light_3d(self, *args, **kwargs): - """ - - :param r: 3d radius - :param kwargs: keyword arguments of profile - :return: 3d light profile, raise as definition is not defined - """ - raise ValueError("light_3d definition not defined in the light profile.") From 573d8d0130ca89b95195030fb3181789d60bf7fc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 May 2024 20:58:45 +0000 Subject: [PATCH 20/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lenstronomy/LightModel/light_model_base.py | 5 ++--- test/test_ImSim/test_Numerics/test_convolution.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lenstronomy/LightModel/light_model_base.py b/lenstronomy/LightModel/light_model_base.py index a83a9058e..d37a255f7 100644 --- a/lenstronomy/LightModel/light_model_base.py +++ b/lenstronomy/LightModel/light_model_base.py @@ -228,13 +228,12 @@ def surface_brightness(self, x, y, kwargs_list, k=None): return flux def light_3d(self, r, kwargs_list, k=None): - """Computes 3d density at radius r (3D radius) - such that integrated in projection in units of angle results in the projected surface brightness + """Computes 3d density at radius r (3D radius) such that integrated in + projection in units of angle results in the projected surface brightness. :param r: 3d radius units of arcsec relative to the center of the light profile :param kwargs_list: keyword argument list of light profile :param k: integer or list of integers for selecting subsets of light profiles. - :return: flux density """ kwargs_list_standard = self._transform_kwargs(kwargs_list) diff --git a/test/test_ImSim/test_Numerics/test_convolution.py b/test/test_ImSim/test_Numerics/test_convolution.py index 6c5b3ea92..51980ec9f 100644 --- a/test/test_ImSim/test_Numerics/test_convolution.py +++ b/test/test_ImSim/test_Numerics/test_convolution.py @@ -46,9 +46,9 @@ def test_pixel_kernel(self): npt.assert_equal(pixel_conv.pixel_kernel(num_pix=3), kernel[1:-1, 1:-1]) def test_centroiding(self): - """ - this test convolves a Gaussian source centered in a centered pixel with a Gaussian and checks whether the - pixelated FFT convolution returns a centered image as well + """This test convolves a Gaussian source centered in a centered pixel with a + Gaussian and checks whether the pixelated FFT convolution returns a centered + image as well. :return: """