From 23f64f3c1d717c0a7a8ea9c80a946bc331180eea Mon Sep 17 00:00:00 2001 From: Sydney Date: Tue, 25 Nov 2025 16:57:56 -0800 Subject: [PATCH 1/2] update epl documentation and raise errors for edge cases --- slsim/Deflectors/DeflectorTypes/epl.py | 21 +++++++++++++++---- slsim/Deflectors/DeflectorTypes/epl_sersic.py | 6 ++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/slsim/Deflectors/DeflectorTypes/epl.py b/slsim/Deflectors/DeflectorTypes/epl.py index d3bf63389..69a4198cd 100644 --- a/slsim/Deflectors/DeflectorTypes/epl.py +++ b/slsim/Deflectors/DeflectorTypes/epl.py @@ -9,16 +9,21 @@ class EPL(DeflectorBase): """Deflector with an elliptical power-law and a Sersic light model. required quantities in dictionary: - - 'vel_disp': SIS equivalent velocity dispersion of the deflector + - 'vel_disp' OR 'theta_E': SIS equivalent velocity dispersion of the deflector, + or Einstein radius of the EPL profile. - 'gamma_pl': power-law slope - 'e1_mass': eccentricity of EPL profile - 'e2_mass': eccentricity of EPL profile - - 'stellar_mass': stellar mass in physical M_sol - - 'angular_size': half-light radius of stellar/light profile in radian - 'z': redshift of deflector + optional quantities in dictionary: + - 'angular_size': half-light radius of stellar/light profile in radian. + If None, uses numerical option in MGE decomposition when computing + theta_E from v_disp + - center_x: RA coordinate (relative arcseconds) + - center_y: DEC coordinate (relative arcseconds) + If None, draws random center coordinates (see DeflectorBase) """ - # TODO: add center_x center_y to documentation def __init__(self, sis_convention=True, theta_E=None, gamma_pl=2, **deflector_dict): """ @@ -34,6 +39,11 @@ def __init__(self, sis_convention=True, theta_E=None, gamma_pl=2, **deflector_di self._theta_E = theta_E self._gamma_pl = gamma_pl + # edge case: what happens if user provides both of these? + # how can you guarantee they are consistent, esp. if cosmology changes? + if self._theta_E is not None and self._vel_disp is not None: + raise ValueError('Provide theta_E OR vel_disp, not both, to guarantee consistency') + def velocity_dispersion(self, cosmo=None): """Velocity dispersion of deflector. If velocity dispersion is not provided in the deflector dict, None will be returned. Then, @@ -56,6 +66,9 @@ def _einstein_radius(self, lens_cosmo=None): :return: Einstein radius of the deflector """ if self._theta_E is None: + if lens_cosmo is None: + raise ValueError('Must provide lens_cosmo to compute theta_E from v_disp') + lens_light_model_list, kwargs_lens_light = self.light_model_lenstronomy() theta_E = theta_E_from_vel_disp_epl( vel_disp=float(self.velocity_dispersion()), diff --git a/slsim/Deflectors/DeflectorTypes/epl_sersic.py b/slsim/Deflectors/DeflectorTypes/epl_sersic.py index ebccd7fdb..d32410d72 100644 --- a/slsim/Deflectors/DeflectorTypes/epl_sersic.py +++ b/slsim/Deflectors/DeflectorTypes/epl_sersic.py @@ -9,15 +9,17 @@ class EPLSersic(EPL): - 'vel_disp': SIS equivalent velocity dispersion of the deflector - 'e1_mass': eccentricity of EPL profile - 'e2_mass': eccentricity of EPL profile - - 'stellar_mass': stellar mass in physical M_sol - 'angular_size': half-light radius of stellar/light profile in radian - 'n_sersic': Sersic index of deflector light - 'e1_light': eccentricity of light - 'e2_light': eccentricity of light - 'z': redshift of deflector + optional quantities in dictionary: + - center_x: RA coordinate (relative arcseconds) + - center_y: DEC coordinate (relative arcseconds) + If None, draws random center coordinates (see DeflectorBase) """ - # TODO: add center_x center_y to documentation def __init__(self, **deflector_dict): """ From 192a417ed69c21898f336ccf3a8eb3a430f9748d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 01:06:05 +0000 Subject: [PATCH 2/2] Autofix formatting from pre-commit.com hooks --- slsim/Deflectors/DeflectorTypes/epl.py | 17 ++++++++++------- slsim/Deflectors/DeflectorTypes/epl_sersic.py | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/slsim/Deflectors/DeflectorTypes/epl.py b/slsim/Deflectors/DeflectorTypes/epl.py index 69a4198cd..d0e287f07 100644 --- a/slsim/Deflectors/DeflectorTypes/epl.py +++ b/slsim/Deflectors/DeflectorTypes/epl.py @@ -16,15 +16,14 @@ class EPL(DeflectorBase): - 'e2_mass': eccentricity of EPL profile - 'z': redshift of deflector optional quantities in dictionary: - - 'angular_size': half-light radius of stellar/light profile in radian. - If None, uses numerical option in MGE decomposition when computing + - 'angular_size': half-light radius of stellar/light profile in radian. + If None, uses numerical option in MGE decomposition when computing theta_E from v_disp - center_x: RA coordinate (relative arcseconds) - center_y: DEC coordinate (relative arcseconds) If None, draws random center coordinates (see DeflectorBase) """ - def __init__(self, sis_convention=True, theta_E=None, gamma_pl=2, **deflector_dict): """ @@ -39,10 +38,12 @@ def __init__(self, sis_convention=True, theta_E=None, gamma_pl=2, **deflector_di self._theta_E = theta_E self._gamma_pl = gamma_pl - # edge case: what happens if user provides both of these? + # edge case: what happens if user provides both of these? # how can you guarantee they are consistent, esp. if cosmology changes? if self._theta_E is not None and self._vel_disp is not None: - raise ValueError('Provide theta_E OR vel_disp, not both, to guarantee consistency') + raise ValueError( + "Provide theta_E OR vel_disp, not both, to guarantee consistency" + ) def velocity_dispersion(self, cosmo=None): """Velocity dispersion of deflector. If velocity dispersion is not @@ -67,8 +68,10 @@ def _einstein_radius(self, lens_cosmo=None): """ if self._theta_E is None: if lens_cosmo is None: - raise ValueError('Must provide lens_cosmo to compute theta_E from v_disp') - + raise ValueError( + "Must provide lens_cosmo to compute theta_E from v_disp" + ) + lens_light_model_list, kwargs_lens_light = self.light_model_lenstronomy() theta_E = theta_E_from_vel_disp_epl( vel_disp=float(self.velocity_dispersion()), diff --git a/slsim/Deflectors/DeflectorTypes/epl_sersic.py b/slsim/Deflectors/DeflectorTypes/epl_sersic.py index d32410d72..83d9c7252 100644 --- a/slsim/Deflectors/DeflectorTypes/epl_sersic.py +++ b/slsim/Deflectors/DeflectorTypes/epl_sersic.py @@ -20,7 +20,6 @@ class EPLSersic(EPL): If None, draws random center coordinates (see DeflectorBase) """ - def __init__(self, **deflector_dict): """