From 8e8a90def56d966901ce06c199a5e337df11a236 Mon Sep 17 00:00:00 2001 From: RashmikaReddy Date: Thu, 1 Feb 2024 19:19:23 -0800 Subject: [PATCH 01/14] Added units to the docstrings --- src/caustics/cosmology.py | 22 +++++++++-- src/caustics/lenses/base.py | 7 ++++ src/caustics/lenses/epl.py | 8 ++++ src/caustics/lenses/multiplane.py | 6 ++- src/caustics/lenses/nfw.py | 11 ++++++ src/caustics/lenses/pixelated_convergence.py | 1 + src/caustics/lenses/point.py | 4 ++ src/caustics/lenses/pseudo_jaffe.py | 25 ++++++++++++ src/caustics/lenses/sie.py | 24 +++++++++++- src/caustics/lenses/singleplane.py | 10 +++++ src/caustics/lenses/sis.py | 5 +++ src/caustics/lenses/tnfw.py | 40 ++++++++++++++++++++ src/caustics/lenses/utils.py | 6 +++ 13 files changed, 163 insertions(+), 6 deletions(-) diff --git a/src/caustics/cosmology.py b/src/caustics/cosmology.py index 51cee50f..aafd37a6 100644 --- a/src/caustics/cosmology.py +++ b/src/caustics/cosmology.py @@ -43,12 +43,10 @@ class Cosmology(Parametrized): This class provides an interface for cosmological computations used in lensing such as comoving distance and critical surface density. - Units - ----- Distance - Mpc + *Unit: Mpc* Mass - solar mass + *Unit: SolMass* Attributes ---------- @@ -83,6 +81,7 @@ def critical_density(self, z: Tensor, params: Optional["Packed"] = None) -> Tens ------- Tensor The critical density at each redshift. + *Unit: solMass/Mpc^3* """ ... @@ -105,6 +104,7 @@ def comoving_distance( ------- Tensor The comoving distance to each redshift. + *Unit: Mpc* """ ... @@ -127,6 +127,7 @@ def transverse_comoving_distance( ------- Tensor The transverse comoving distance to each redshift in Mpc. + *Unit: Mpc* """ ... @@ -150,6 +151,7 @@ def comoving_distance_z1z2( ------- Tensor The comoving distance between each pair of redshifts. + *Unit: Mpc* """ return self.comoving_distance(z2, params) - self.comoving_distance(z1, params) @@ -173,6 +175,7 @@ def transverse_comoving_distance_z1z2( ------- Tensor The transverse comoving distance between each pair of redshifts in Mpc. + *Unit: Mpc* """ return self.transverse_comoving_distance( z2, params @@ -196,6 +199,7 @@ def angular_diameter_distance( ------- Tensor The angular diameter distance to each redshift. + *Unit: Mpc* """ return self.comoving_distance(z, params, **kwargs) / (1 + z) @@ -219,6 +223,7 @@ def angular_diameter_distance_z1z2( ------- Tensor The angular diameter distance between each pair of redshifts. + *Unit: Mpc* """ return self.comoving_distance_z1z2(z1, z2, params, **kwargs) / (1 + z2) @@ -247,6 +252,7 @@ def time_delay_distance( ------- Tensor The time delay distance for each pair of lens and source redshifts. + *Unit: Mpc* """ d_l = self.angular_diameter_distance(z_l, params) d_s = self.angular_diameter_distance(z_s, params) @@ -278,6 +284,7 @@ def critical_surface_density( ------- Tensor The critical surface density for each pair of lens and source redshifts. + *Unit: SolMass/Mpc^2* """ d_l = self.angular_diameter_distance(z_l, params) d_s = self.angular_diameter_distance(z_s, params) @@ -309,6 +316,7 @@ def __init__( Hubble constant over 100. Default is h0_default. critical_density_0: (Optional[Tensor]) Critical density at z=0. Default is critical_density_0_default. + *Unit: Msol/Mpc^3* Om0: Optional[Tensor] Matter density parameter at z=0. Default is Om0_default. """ @@ -349,6 +357,7 @@ def hubble_distance(self, h0): ------- Tensor Hubble distance. + *Unit: Mpc* """ return c_Mpc_s / (100 * km_to_Mpc) / h0 @@ -377,6 +386,8 @@ def critical_density( ------- torch.Tensor Critical density at redshift z. + *Unit: Msol/Mpc^3* + """ Ode0 = 1 - Om0 return critical_density_0 * (Om0 * (1 + z) ** 3 + Ode0) # fmt: skip @@ -397,6 +408,8 @@ def _comoving_distance_helper( ------- Tensor Computed comoving distances. + *Unit: Mpc* + """ return interp1d( self._comoving_distance_helper_x_grid, @@ -429,6 +442,7 @@ def comoving_distance( ------- Tensor Comoving distance to redshift z. + *Unit: Mpc* """ Ode0 = 1 - Om0 ratio = (Om0 / Ode0) ** (1 / 3) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 9232e17e..0dadb959 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -129,13 +129,18 @@ def forward_raytrace( Tensor of source redshifts. params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. + epsilon: Tensor maximum distance between two images (arcsec) before they are considered the same image. + *Unit: arcsec* + n_init: int number of random initialization points used to try and find image plane points. fov: float the field of view in which the initial random samples are taken. + *Unit: radians* + Returns ------- tuple[Tensor, Tensor] @@ -787,6 +792,7 @@ def surface_density( ------- Tensor Surface mass density at the given coordinates in solar masses per Mpc^2. + *Unit: solar masses per Mpc^2* """ critical_surface_density = self.cosmology.critical_surface_density( z_l, z_s, params @@ -884,6 +890,7 @@ def time_delay( ------- Tensor Time delay at the given coordinates. + *Units: seconds/milli-seconds* References ---------- diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index ab177b54..fe3a9163 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -27,6 +27,7 @@ class EPL(ThinLens): Number of iterations for the iterative solver. s: float Softening length for the elliptical power-law profile. + *Unit: Meters* Parameters ---------- @@ -46,10 +47,12 @@ class EPL(ThinLens): This is the orientation of the lens on the sky, typically given as an angle measured counter-clockwise from some reference direction. + *Unit: radians* b: Optional[Union[Tensor, float]] This is the scale length of the lens, which sets the overall scale of the lensing effect. In some contexts, this is referred to as the Einstein radius. + *Unit: arcseconds* t: Optional[Union[Tensor, float]] This is the power-law slope parameter of the lens model. In the context of the EPL model, @@ -106,14 +109,17 @@ def __init__( phi: Optional[Tensor] Position angle of the lens. If not provided, it is considered as a free parameter. + *Unit: radians* b: Optional[Tensor] Scale length of the lens. If not provided, it is considered as a free parameter. + *Unit: arcseconds* t: Optional[Tensor] Power law slope (`gamma-1`) of the lens. If not provided, it is considered as a free parameter. s: float Softening length for the elliptical power-law profile. + *Unit: meters* n_iter: int Number of iterations for the iterative solver. """ @@ -187,6 +193,7 @@ def _r_omega(self, z, t, q): ---------- z: Tensor `R * e^(i * phi)`, position vector in the lens plane. + *Unit: meters* t: Tensor Power law slow (`gamma-1`). q: Tensor @@ -196,6 +203,7 @@ def _r_omega(self, z, t, q): -------- Tensor The value of `R * omega(phi)`. + *Unit: meters* """ # constants f = (1.0 - q) / (1.0 + q) diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index 8ae1b641..e1fac9ce 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -177,8 +177,10 @@ def raytrace( ---------- x: Tensor angular x-coordinates in the image plane. + *Unit: radians* y: Tensor angular y-coordinates in the image plane. + *Unit: radians* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -188,6 +190,7 @@ def raytrace( ------- (Tensor, Tensor) The reduced deflection angle. + *Unit: radians* References ---------- @@ -246,7 +249,7 @@ def surface_density( ------- Tensor Projected mass density [solMass / Mpc^2]. - + *Unit: solMass/Mpc^2* Raises ------- NotImplementedError @@ -304,6 +307,7 @@ def time_delay( ------- Tensor Time delay caused by the lensing. + *Unit: seconds* References ---------- diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index cfe68f18..86379dc5 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -32,6 +32,7 @@ class NFW(ThinLens): y-coordinate of the lens center in the lens plane. Default is None. m: Optional[Tensor] Mass of the lens. Default is None. + *Unit: SolMass* c: Optional[Tensor] Concentration parameter of the lens. Default is None. s: float @@ -45,12 +46,15 @@ class NFW(ThinLens): ------- get_scale_radius Returns the scale radius of the lens. + *Unit: meters* get_scale_density Returns the scale density of the lens. + get_convergence_s Returns the dimensionless surface mass density of the lens. _f Helper method for computing deflection angles. + *Unit: radians* _g Helper method for computing lensing potential. _h @@ -104,6 +108,7 @@ def __init__( Default is None. m: Optional[Union[Tensor, float]] Mass of the lens. Default is None. + *Unit: SolMass* c: Optional[Union[Tensor, float]] Concentration parameter of the lens. Default is None. s: float @@ -149,6 +154,7 @@ def get_scale_radius( Redshift of the lens. m: Tensor Mass of the lens. + *Unit: SolMass* c: Tensor Concentration parameter of the lens. x: dict @@ -191,6 +197,7 @@ def get_scale_density( ------- Tensor The scale density of the lens in solar masses per Mpc cubed. + *Unit: solMass/Mpc^3* """ sigma_crit = self.cosmology.critical_density(z_l, params) return DELTA / 3 * sigma_crit * c**3 / ((1 + c).log() - c / (1 + c)) # fmt: skip @@ -219,6 +226,7 @@ def get_convergence_s( Redshift of the source. m: Tensor Mass of the lens. + *Unit: Solar mass* c: Tensor Concentration parameter of the lens. params: (Packed, optional) @@ -248,6 +256,7 @@ def _f_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the deflection angle computation. + *Unit: radians* """ # TODO: generalize beyond torch, or patch Tensor f = torch.zeros_like(x) @@ -269,6 +278,7 @@ def _f_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the deflection angle computation. + *Unit: radians* """ # TODO: generalize beyond torch, or patch Tensor # fmt: off @@ -298,6 +308,7 @@ def _g_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the lensing potential computation. + *Unit: units of energy per unit mass* """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 diff --git a/src/caustics/lenses/pixelated_convergence.py b/src/caustics/lenses/pixelated_convergence.py index 10cda750..acc2f4a2 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -53,6 +53,7 @@ def __init__( The name of the PixelatedConvergence object. fov: float The field of view in arcseconds. + *Unit: arcseconds* n_pix: int The number of pixels on each side of the grid. cosmology: Cosmology diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index b640f84d..fb4ea2d0 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -30,8 +30,10 @@ class Point(ThinLens): y-coordinate of the center of the lens. th_ein: Optional[Union[Tensor, float]] Einstein radius of the lens. + *Unit: arcseconds* s: float Softening parameter to prevent numerical instabilities. + *Unit: meters* """ _null_params = { @@ -67,8 +69,10 @@ def __init__( y-coordinate of the center of the lens. th_ein: Optional[Tensor] Einstein radius of the lens. + *Unit: arcseconds* s: float Softening parameter to prevent numerical instabilities. + *Unit: meters* """ super().__init__(cosmology, z_l, name=name) diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index 671333bf..4d06ffbf 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -30,14 +30,19 @@ class PseudoJaffe(ThinLens): Redshift of the lens. x0: Optional[Union[Tensor, float]] x-coordinate of the center of the lens (arcsec). + *Unit: arcsec* y0: Optional[Union[Tensor, float]] y-coordinate of the center of the lens (arcsec). + *Unit: arcsec* mass: Optional[Union[Tensor, float]] Total mass of the lens (Msol). + *Unit: Msol* core_radius: Optional[Union[Tensor, float]] Core radius of the lens (arcsec). + *Unit: arcsec* scale_radius: Optional[Union[Tensor, float]] Scaling radius of the lens (arcsec). + *Unit: arcsec* s: float Softening parameter to prevent numerical instabilities. """ @@ -75,14 +80,19 @@ def __init__( Redshift of the lens. x0: Optional[Tensor] x-coordinate of the center of the lens. + *Unit: arcsec* y0: Optional[Tensor] y-coordinate of the center of the lens. + *Unit: arcsec* mass: Optional[Tensor] Total mass of the lens (Msol). + *Unit: Msol* core_radius: Optional[Tensor] Core radius of the lens. + *Unit: arcsec* scale_radius: Optional[Tensor] Scaling radius of the lens. + *Unit: arcsec* s: float Softening parameter to prevent numerical instabilities. """ @@ -135,6 +145,8 @@ def mass_enclosed_2d( ---------- theta: Tensor Radius at which to calculate enclosed mass (arcsec). + *Unit: arcsec* + z_s: Tensor Source redshift. params: (Packed, optional) @@ -144,6 +156,7 @@ def mass_enclosed_2d( ------- Tensor The mass enclosed within the given radius. + *Unit: Msol* """ # fmt: off theta = theta + self.s @@ -177,10 +190,13 @@ def central_convergence( Source redshift. rho_0: Tensor Central mass density. + *Unit: Msol/Mpc^3* core_radius: Tensor Core radius of the lens (must be in Mpc). + *Unit: Mpc* scale_radius: Tensor Scaling radius of the lens (must be in Mpc). + *Unit: Mpc* cosmology: Cosmology The cosmology used for calculations. @@ -213,8 +229,10 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinate of the lens. + *Unit: arcsec* y: Tensor y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor Source redshift. params: (Packed, optional) @@ -224,6 +242,7 @@ def reduced_deflection_angle( -------- Tuple[Tensor, Tensor] The deflection angle in the x and y directions. + *Unit: radians* """ x, y = translate_rotate(x, y, x0, y0) R = (x**2 + y**2).sqrt() + self.s @@ -256,8 +275,10 @@ def potential( -------- x: Tensor x-coordinate of the lens. + *Unit: arcsec* y: Tensor y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor Source redshift. params: (Packed, optional) @@ -267,6 +288,7 @@ def potential( -------- Tensor The lensing potential (arcsec^2). + *Unit: arcsec^2* """ # fmt: off @@ -313,8 +335,10 @@ def convergence( ----------- x: Tensor x-coordinate of the lens. + *Unit: arcsec* y: Tensor y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor Source redshift. params: (Packed, optional) @@ -324,6 +348,7 @@ def convergence( ------- Tensor The projected mass density. + *Unit: Msol/Mpc^2* """ x, y = translate_rotate(x, y, x0, y0) R_squared = x**2 + y**2 + self.s diff --git a/src/caustics/lenses/sie.py b/src/caustics/lenses/sie.py index 7ea2a5e7..482b29a0 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -26,16 +26,21 @@ class SIE(ThinLens): The redshift of the lens. x0: Optional[Union[Tensor, float]] The x-coordinate of the lens center. + *Unit: arcsec* y0: Optional[Union[Tensor, float]] The y-coordinate of the lens center. + *Unit: arcsec* q: Optional[Union[Tensor, float]] The axis ratio of the lens. phi: Optional[Union[Tensor, float]] The orientation angle of the lens (position angle). + *Unit: radians* b: Optional[Union[Tensor, float]] The Einstein radius of the lens. + *Unit: arcsec* s: float The core radius of the lens (defaults to 0.0). + *Unit: radians* """ _null_params = { @@ -78,8 +83,10 @@ def _get_potential(self, x, y, q): ---------- x: Tensor The x-coordinate in the lens plane. + *Unit: arcsec* y: Tensor The y-coordinate in the lens plane. + *Unit: arcsec* q: Tensor The axis ratio of the lens. @@ -87,6 +94,7 @@ def _get_potential(self, x, y, q): -------- Tensor The radial coordinate in the lens plane. + *Unit: arcsec* """ return (q**2 * (x**2 + self.s**2) + y**2).sqrt() # fmt: skip @@ -113,8 +121,12 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. params: (Packed, optional) @@ -124,6 +136,8 @@ def reduced_deflection_angle( -------- Tuple[Tensor, Tensor] The deflection angle in the x and y directions. + *Unit: radians* + """ x, y = translate_rotate(x, y, x0, y0, phi) psi = self._get_potential(x, y, q) @@ -156,8 +170,10 @@ def potential( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -167,6 +183,7 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) ax, ay = derotate(ax, ay, -phi) @@ -196,8 +213,12 @@ def convergence( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. params: (Packed, optional) @@ -206,7 +227,8 @@ def convergence( Returns ------- Tensor - The projected mass. + The projected mass density. + *Unit: Msol/Mpc^2* """ x, y = translate_rotate(x, y, x0, y0, phi) psi = self._get_potential(x, y, q) diff --git a/src/caustics/lenses/singleplane.py b/src/caustics/lenses/singleplane.py index 9644f7d2..e9128e24 100644 --- a/src/caustics/lenses/singleplane.py +++ b/src/caustics/lenses/singleplane.py @@ -56,8 +56,10 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -67,6 +69,7 @@ def reduced_deflection_angle( ------- Tuple[Tensor, Tensor] The total deflection angle in the x and y directions. + *Unit: radians* """ ax = torch.zeros_like(x) ay = torch.zeros_like(x) @@ -94,8 +97,10 @@ def convergence( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -105,6 +110,7 @@ def convergence( ------- Tensor The total projected mass density. + *Unit: Msol/Mpc^2* """ convergence = torch.zeros_like(x) for lens in self.lenses: @@ -130,8 +136,10 @@ def potential( ----------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -141,6 +149,8 @@ def potential( ------- Tensor The total lensing potential. + *Unit: arcsec^2* + """ potential = torch.zeros_like(x) for lens in self.lenses: diff --git a/src/caustics/lenses/sis.py b/src/caustics/lenses/sis.py index 15a54172..9c384358 100644 --- a/src/caustics/lenses/sis.py +++ b/src/caustics/lenses/sis.py @@ -26,11 +26,16 @@ class SIS(ThinLens): The lens redshift. x0: Optional[Union[Tensor, float]] The x-coordinate of the lens center. + *Unit: arcsec* + y0: Optional[Union[Tensor, float]] The y-coordinate of the lens center. + *Unit: arcsec* th_ein (Optional[Union[Tensor, float]]): The Einstein radius of the lens. + *Unit: arcsec* s: float A smoothing factor, default is 0.0. + *Unit: radians* """ _null_params = { diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index 3c9478d6..250346ac 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -52,12 +52,19 @@ class TNFW(ThinLens): Redshift of the lens. x0: Optional[Tensor] Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Optional[Tensor] Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). s: float @@ -168,12 +175,16 @@ def get_concentration( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -183,6 +194,7 @@ def get_concentration( ------- Tensor The scale radius of the lens in Mpc. + *Unit: Mpc* """ critical_density = self.cosmology.critical_density(z_l, params) d_l = self.cosmology.angular_diameter_distance(z_l, params) @@ -211,12 +223,16 @@ def get_truncation_radius( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dictionary @@ -226,6 +242,7 @@ def get_truncation_radius( ------- Tensor The truncation radius of the lens in arcsec. + *Unit: arcsec* """ return tau * scale_radius @@ -253,12 +270,16 @@ def get_M0( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dictionary @@ -268,6 +289,7 @@ def get_M0( ------- Tensor The reference mass of the lens in Msol. + *Unit: Msol* """ if self.interpret_m_total_mass: return mass * (tau**2 + 1) ** 2 / (tau**2 * ((tau**2 - 1) * tau.log() + torch.pi * tau - (tau**2 + 1))) # fmt: skip @@ -297,12 +319,16 @@ def get_scale_density( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -312,6 +338,7 @@ def get_scale_density( -------- Tensor The scale density of the lens in solar masses per Mpc cubed. + *Unit: SolMass/Mpc^3* """ c = self.get_concentration(params) return DELTA / 3 * self.cosmology.critical_density(z_l, params) * c**3 / ((1 + c).log() - c / (1 + c)) # fmt: skip @@ -342,12 +369,16 @@ def convergence( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -401,12 +432,16 @@ def mass_enclosed_2d( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -514,12 +549,16 @@ def potential( Redshift of the lens. x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* mass: Optional[Tensor] Mass of the lens (Msol). + *Unit: Msol* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -529,6 +568,7 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* """ x, y = translate_rotate(x, y, x0, y0) r = (x**2 + y**2).sqrt() + self.s diff --git a/src/caustics/lenses/utils.py b/src/caustics/lenses/utils.py index eeba3e90..bea6910b 100644 --- a/src/caustics/lenses/utils.py +++ b/src/caustics/lenses/utils.py @@ -22,8 +22,10 @@ def get_pix_jacobian( A function that maps the lensing plane coordinates to the source plane coordinates. x: Tensor The x-coordinate on the lensing plane. + *Unit: arcsec* y: Tensor The y-coordinate on the lensing plane. + *Unit: arcsec* z_s: Tensor The redshift of the source. @@ -49,8 +51,10 @@ def get_pix_magnification(raytrace, x, y, z_s) -> Tensor: A function that maps the lensing plane coordinates to the source plane coordinates. x: Tensor The x-coordinate on the lensing plane. + *Unit: arcsec* y: Tensor The y-coordinate on the lensing plane. + *Unit: arcsec* z_s: Tensor The redshift of the source. @@ -75,8 +79,10 @@ def get_magnification(raytrace, x, y, z_s) -> Tensor: A function that maps the lensing plane coordinates to the source plane coordinates. x: Tensor The x-coordinates on the lensing plane. + *Unit: arcsec* y: Tensor The y-coordinates on the lensing plane. + *Unit: arcsec* z_s: Tensor The redshift of the source. From a93555bb0912d9710d48a3cdc9ad60ee0d321139 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 03:22:41 +0000 Subject: [PATCH 02/14] style: pre-commit fixes --- src/caustics/lenses/base.py | 2 +- src/caustics/lenses/multiplane.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 0dadb959..ec174a86 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -139,7 +139,7 @@ def forward_raytrace( fov: float the field of view in which the initial random samples are taken. - *Unit: radians* + *Unit: radians* Returns ------- diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index e1fac9ce..ae3b662c 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -249,7 +249,7 @@ def surface_density( ------- Tensor Projected mass density [solMass / Mpc^2]. - *Unit: solMass/Mpc^2* + *Unit: solMass/Mpc^2* Raises ------- NotImplementedError From ce7a7c2845149f0c7743dc7ef2514fd88b2a5657 Mon Sep 17 00:00:00 2001 From: RashmikaReddy Date: Thu, 1 Feb 2024 19:33:49 -0800 Subject: [PATCH 03/14] Adding another file --- src/caustics/lenses/external_shear.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index 6aee98a7..efdbcd98 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -82,8 +82,12 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -127,8 +131,12 @@ def potential( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -138,6 +146,8 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) x, y = translate_rotate(x, y, x0, y0) @@ -165,8 +175,12 @@ def convergence( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. params: (Packed, optional) From d0ca82547936aa78985a13d8651a4d31559513fa Mon Sep 17 00:00:00 2001 From: RashmikaReddy Date: Sun, 11 Feb 2024 01:25:29 -0800 Subject: [PATCH 04/14] Made changes to the docstrings --- src/caustics/cosmology.py | 32 ++++++------- src/caustics/lenses/base.py | 46 ++++++++++++++++--- src/caustics/lenses/epl.py | 25 +++++++---- src/caustics/lenses/external_shear.py | 10 +---- src/caustics/lenses/mass_sheet.py | 4 ++ src/caustics/lenses/multiplane.py | 16 ++++--- src/caustics/lenses/nfw.py | 36 ++++++++++----- src/caustics/lenses/pixelated_convergence.py | 13 +++++- src/caustics/lenses/point.py | 20 +++++++-- src/caustics/lenses/pseudo_jaffe.py | 14 +++--- src/caustics/lenses/sie.py | 2 +- src/caustics/lenses/singleplane.py | 2 +- src/caustics/lenses/sis.py | 5 +++ src/caustics/lenses/tnfw.py | 47 +++++++++----------- src/caustics/light/pixelated.py | 6 +++ src/caustics/light/sersic.py | 10 +++++ 16 files changed, 194 insertions(+), 94 deletions(-) diff --git a/src/caustics/cosmology.py b/src/caustics/cosmology.py index aafd37a6..02772615 100644 --- a/src/caustics/cosmology.py +++ b/src/caustics/cosmology.py @@ -44,9 +44,9 @@ class Cosmology(Parametrized): such as comoving distance and critical surface density. Distance - *Unit: Mpc* + *Unit: megaparsec* Mass - *Unit: SolMass* + *Unit: solMass* Attributes ---------- @@ -81,7 +81,7 @@ def critical_density(self, z: Tensor, params: Optional["Packed"] = None) -> Tens ------- Tensor The critical density at each redshift. - *Unit: solMass/Mpc^3* + *Unit: solMass/megaparsec^3* """ ... @@ -104,7 +104,7 @@ def comoving_distance( ------- Tensor The comoving distance to each redshift. - *Unit: Mpc* + *Unit: megaparsec* """ ... @@ -127,7 +127,7 @@ def transverse_comoving_distance( ------- Tensor The transverse comoving distance to each redshift in Mpc. - *Unit: Mpc* + *Unit: megaparsec* """ ... @@ -151,7 +151,7 @@ def comoving_distance_z1z2( ------- Tensor The comoving distance between each pair of redshifts. - *Unit: Mpc* + *Unit: megaparsec* """ return self.comoving_distance(z2, params) - self.comoving_distance(z1, params) @@ -175,7 +175,7 @@ def transverse_comoving_distance_z1z2( ------- Tensor The transverse comoving distance between each pair of redshifts in Mpc. - *Unit: Mpc* + *Unit: megaparsec* """ return self.transverse_comoving_distance( z2, params @@ -199,7 +199,7 @@ def angular_diameter_distance( ------- Tensor The angular diameter distance to each redshift. - *Unit: Mpc* + *Unit: megaparsec* """ return self.comoving_distance(z, params, **kwargs) / (1 + z) @@ -223,7 +223,7 @@ def angular_diameter_distance_z1z2( ------- Tensor The angular diameter distance between each pair of redshifts. - *Unit: Mpc* + *Unit: megaparsec* """ return self.comoving_distance_z1z2(z1, z2, params, **kwargs) / (1 + z2) @@ -252,7 +252,7 @@ def time_delay_distance( ------- Tensor The time delay distance for each pair of lens and source redshifts. - *Unit: Mpc* + *Unit: megaparsec* """ d_l = self.angular_diameter_distance(z_l, params) d_s = self.angular_diameter_distance(z_s, params) @@ -284,7 +284,7 @@ def critical_surface_density( ------- Tensor The critical surface density for each pair of lens and source redshifts. - *Unit: SolMass/Mpc^2* + *Unit: solMass/megaparsec^2* """ d_l = self.angular_diameter_distance(z_l, params) d_s = self.angular_diameter_distance(z_s, params) @@ -316,7 +316,7 @@ def __init__( Hubble constant over 100. Default is h0_default. critical_density_0: (Optional[Tensor]) Critical density at z=0. Default is critical_density_0_default. - *Unit: Msol/Mpc^3* + *Unit: solMass/megaparsec^3* Om0: Optional[Tensor] Matter density parameter at z=0. Default is Om0_default. """ @@ -357,7 +357,7 @@ def hubble_distance(self, h0): ------- Tensor Hubble distance. - *Unit: Mpc* + *Unit: megaparsec* """ return c_Mpc_s / (100 * km_to_Mpc) / h0 @@ -386,7 +386,7 @@ def critical_density( ------- torch.Tensor Critical density at redshift z. - *Unit: Msol/Mpc^3* + *Unit: solMass/megaparsec^3* """ Ode0 = 1 - Om0 @@ -408,7 +408,7 @@ def _comoving_distance_helper( ------- Tensor Computed comoving distances. - *Unit: Mpc* + *Unit: megaparsec* """ return interp1d( @@ -442,7 +442,7 @@ def comoving_distance( ------- Tensor Comoving distance to redshift z. - *Unit: Mpc* + *Unit: megaparsec* """ Ode0 = 1 - Om0 ratio = (Om0 / Ode0) ** (1 / 3) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 0dadb959..4f51d0a1 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -87,8 +87,10 @@ def magnification( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -132,14 +134,13 @@ def forward_raytrace( epsilon: Tensor maximum distance between two images (arcsec) before they are considered the same image. - *Unit: arcsec* + *Unit: arcsec* n_init: int number of random initialization points used to try and find image plane points. fov: float the field of view in which the initial random samples are taken. - - *Unit: radians* + *Unit: arcsec* Returns ------- @@ -214,8 +215,10 @@ def reduced_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: Packed, optional @@ -258,8 +261,10 @@ def effective_reduced_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -287,8 +292,10 @@ def physical_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -299,7 +306,7 @@ def physical_deflection_angle( tuple[Tensor, Tensor] Tuple of Tensors representing the x and y components of the deflection angle, respectively. - + *Unit: (arcsec, arcsec)* """ raise NotImplementedError( "Physical deflection angles are computed with respect to a lensing plane. " @@ -326,8 +333,10 @@ def raytrace( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -361,8 +370,10 @@ def surface_density( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -373,6 +384,7 @@ def surface_density( Tensor The projected mass density at the given coordinates in units of solar masses per square Megaparsec. + *Unit: solMass/megaparsec^2* """ ... @@ -394,8 +406,10 @@ def time_delay( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor ofsource redshifts. params: (Packed, optional) @@ -405,6 +419,7 @@ def time_delay( ------- Tensor The gravitational time delay at the given coordinates. + *Unit: milliseconds* """ ... @@ -637,8 +652,10 @@ def reduced_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -648,6 +665,7 @@ def reduced_deflection_angle( -------- tuple[Tensor, Tensor] Reduced deflection angle in x and y directions. + *Unit: (arcsec, arcsec)* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -677,8 +695,10 @@ def physical_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -688,6 +708,7 @@ def physical_deflection_angle( ------- tuple[Tensor, Tensor] Physical deflection angle in x and y directions in arcseconds. + *Unit: (arcsec, arcsec)* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -717,8 +738,10 @@ def convergence( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -749,8 +772,10 @@ def potential( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -760,6 +785,7 @@ def potential( ------- Tensor Gravitational lensing potential at the given coordinates in arcsec^2. + *Unit: arsec^2* """ ... @@ -781,8 +807,10 @@ def surface_density( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -792,7 +820,7 @@ def surface_density( ------- Tensor Surface mass density at the given coordinates in solar masses per Mpc^2. - *Unit: solar masses per Mpc^2* + *Unit: solMass/megaparsec^2* """ critical_surface_density = self.cosmology.critical_surface_density( z_l, z_s, params @@ -817,8 +845,10 @@ def raytrace( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -828,6 +858,8 @@ def raytrace( ------- tuple[Tensor, Tensor] Ray-traced coordinates in the x and y directions. + *Unit: (arcsec, arcsec)* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params, **kwargs) return x - ax, y - ay @@ -873,8 +905,10 @@ def time_delay( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Tensor of source redshifts. z_l: Tensor @@ -890,7 +924,7 @@ def time_delay( ------- Tensor Time delay at the given coordinates. - *Units: seconds/milli-seconds* + *Units: milliseconds* References ---------- diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index fe3a9163..f2612086 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -27,7 +27,7 @@ class EPL(ThinLens): Number of iterations for the iterative solver. s: float Softening length for the elliptical power-law profile. - *Unit: Meters* + *Unit: Meters* Parameters ---------- @@ -40,6 +40,7 @@ class EPL(ThinLens): These are the coordinates of the lens center in the lens plane. The lens plane is the plane perpendicular to the line of sight in which the deflection of light by the lens is considered. + *Unit: arcsec* q: Optional[Union[Tensor, float]] This is the axis ratio of the lens, i.e., the ratio of the minor axis to the major axis of the elliptical lens. @@ -47,12 +48,12 @@ class EPL(ThinLens): This is the orientation of the lens on the sky, typically given as an angle measured counter-clockwise from some reference direction. - *Unit: radians* + *Unit: radians* b: Optional[Union[Tensor, float]] This is the scale length of the lens, which sets the overall scale of the lensing effect. In some contexts, this is referred to as the Einstein radius. - *Unit: arcseconds* + *Unit: arcsec* t: Optional[Union[Tensor, float]] This is the power-law slope parameter of the lens model. In the context of the EPL model, @@ -100,26 +101,28 @@ def __init__( x0: Optional[Tensor] X coordinate of the lens center. If not provided, it is considered as a free parameter. + *Unit: arcsec* y0: Optional[Tensor] Y coordinate of the lens center. If not provided, it is considered as a free parameter. + *Unit: arcsec* q: Optional[Tensor] Axis ratio of the lens. If not provided, it is considered as a free parameter. phi: Optional[Tensor] Position angle of the lens. If not provided, it is considered as a free parameter. - *Unit: radians* + *Unit: radians* b: Optional[Tensor] Scale length of the lens. If not provided, it is considered as a free parameter. - *Unit: arcseconds* + *Unit: arcsec* t: Optional[Tensor] Power law slope (`gamma-1`) of the lens. If not provided, it is considered as a free parameter. s: float Softening length for the elliptical power-law profile. - *Unit: meters* + *Unit: meters* n_iter: int Number of iterations for the iterative solver. """ @@ -159,8 +162,10 @@ def reduced_deflection_angle( ---------- x: Tensor X coordinates in the lens plane. + *Unit: arcsec* y: Tensor Y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Source redshifts. params: (Packed, optional) @@ -170,6 +175,7 @@ def reduced_deflection_angle( -------- tuple[Tensor, Tensor] Reduced deflection angles in the x and y directions. + *Unit: (arcsec, arcsec)* """ x, y = translate_rotate(x, y, x0, y0, phi) @@ -193,7 +199,7 @@ def _r_omega(self, z, t, q): ---------- z: Tensor `R * e^(i * phi)`, position vector in the lens plane. - *Unit: meters* + *Unit: meters* t: Tensor Power law slow (`gamma-1`). q: Tensor @@ -203,7 +209,7 @@ def _r_omega(self, z, t, q): -------- Tensor The value of `R * omega(phi)`. - *Unit: meters* + *Unit: meters* """ # constants f = (1.0 - q) / (1.0 + q) @@ -244,8 +250,10 @@ def potential( ---------- x: Tensor X coordinates in the lens plane. + *Unit: arcsec* y: Tensor Y coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Source redshifts. params: (Packed, optional) @@ -255,6 +263,7 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) ax, ay = derotate(ax, ay, -phi) diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index efdbcd98..f0b3fa33 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -25,6 +25,7 @@ class ExternalShear(ThinLens): The redshift of the lens. x0, y0: Optional[Union[Tensor, float]] Coordinates of the shear center in the lens plane. + *Unit: arcsec* gamma_1, gamma_2: Optional[Union[Tensor, float]] Shear components. @@ -83,11 +84,9 @@ def reduced_deflection_angle( x: Tensor x-coordinates in the lens plane. *Unit: arcsec* - y: Tensor y-coordinates in the lens plane. *Unit: arcsec* - z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -97,6 +96,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. + *Unit: (arcsec, arcsec)* """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.83 @@ -132,11 +132,9 @@ def potential( x: Tensor x-coordinates in the lens plane. *Unit: arcsec* - y: Tensor y-coordinates in the lens plane. *Unit: arcsec* - z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -147,7 +145,6 @@ def potential( Tensor The lensing potential. *Unit: arcsec^2* - """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) x, y = translate_rotate(x, y, x0, y0) @@ -176,16 +173,13 @@ def convergence( x: Tensor x-coordinates in the lens plane. *Unit: arcsec* - y: Tensor y-coordinates in the lens plane. *Unit: arcsec* - z_s: Tensor Redshifts of the sources. params: (Packed, optional) Dynamic parameter container. - Raises ------ NotImplementedError diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index d51c5a0c..e8a35a26 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -26,6 +26,7 @@ class MassSheet(ThinLens): The redshift of the lens. x0, y0: Optional[Union[Tensor, float]] Coordinates of the shear center in the lens plane. + *Unit: arcsec* gamma_1, gamma_2: Optional[Union[Tensor, float]] Shear components. @@ -77,8 +78,10 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -88,6 +91,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. + *Unit: (arcsec, arcsec)* """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.84 diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index e1fac9ce..3478dfa1 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -177,10 +177,10 @@ def raytrace( ---------- x: Tensor angular x-coordinates in the image plane. - *Unit: radians* + *Unit: radians* y: Tensor angular y-coordinates in the image plane. - *Unit: radians* + *Unit: radians* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -190,7 +190,7 @@ def raytrace( ------- (Tensor, Tensor) The reduced deflection angle. - *Unit: radians* + *Unit: radians* References ---------- @@ -238,8 +238,10 @@ def surface_density( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -248,8 +250,8 @@ def surface_density( Returns ------- Tensor - Projected mass density [solMass / Mpc^2]. - *Unit: solMass/Mpc^2* + Projected mass density [Solar Mass / Mpc^2]. + *Unit: solMass / megaparsec^2* Raises ------- NotImplementedError @@ -292,8 +294,10 @@ def time_delay( ---------- x: Tensor x-coordinates in the image plane. + *Unit: radians* y: Tensor y-coordinates in the image plane. + *Unit: radians* z_s: Tensor Redshifts of the source. params: (Packed, optional) @@ -307,7 +311,7 @@ def time_delay( ------- Tensor Time delay caused by the lensing. - *Unit: seconds* + *Unit: seconds* References ---------- diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index 86379dc5..f812e17c 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -28,11 +28,13 @@ class NFW(ThinLens): Redshift of the lens. Default is None. x0: Optional[Tensor] x-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* y0: Optional[Tensor] y-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* m: Optional[Tensor] Mass of the lens. Default is None. - *Unit: SolMass* + *Unit: solMass* c: Optional[Tensor] Concentration parameter of the lens. Default is None. s: float @@ -46,15 +48,13 @@ class NFW(ThinLens): ------- get_scale_radius Returns the scale radius of the lens. - *Unit: meters* get_scale_density - Returns the scale density of the lens. + Returns the scale density of1` the lens. get_convergence_s Returns the dimensionless surface mass density of the lens. _f Helper method for computing deflection angles. - *Unit: radians* _g Helper method for computing lensing potential. _h @@ -103,12 +103,14 @@ def __init__( x0: Optional[Union[Tensor, float]] x-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* y0: Optional[Union[Tensor, float]] y-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* m: Optional[Union[Tensor, float]] Mass of the lens. Default is None. - *Unit: SolMass* + *Unit: solMass* c: Optional[Union[Tensor, float]] Concentration parameter of the lens. Default is None. s: float @@ -154,7 +156,7 @@ def get_scale_radius( Redshift of the lens. m: Tensor Mass of the lens. - *Unit: SolMass* + *Unit: solMass* c: Tensor Concentration parameter of the lens. x: dict @@ -164,6 +166,7 @@ def get_scale_radius( ------- Tensor The scale radius of the lens in Mpc. + *Unit: megaparsec* """ critical_density = self.cosmology.critical_density(z_l, params) r_delta = (3 * m / (4 * pi * DELTA * critical_density)) ** (1 / 3) # fmt: skip @@ -197,7 +200,7 @@ def get_scale_density( ------- Tensor The scale density of the lens in solar masses per Mpc cubed. - *Unit: solMass/Mpc^3* + *Unit: solMass/megaparsec^3* """ sigma_crit = self.cosmology.critical_density(z_l, params) return DELTA / 3 * sigma_crit * c**3 / ((1 + c).log() - c / (1 + c)) # fmt: skip @@ -226,7 +229,7 @@ def get_convergence_s( Redshift of the source. m: Tensor Mass of the lens. - *Unit: Solar mass* + *Unit: solMass* c: Tensor Concentration parameter of the lens. params: (Packed, optional) @@ -256,7 +259,7 @@ def _f_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the deflection angle computation. - *Unit: radians* + *Unit: radians* """ # TODO: generalize beyond torch, or patch Tensor f = torch.zeros_like(x) @@ -278,7 +281,7 @@ def _f_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the deflection angle computation. - *Unit: radians* + *Unit: radians* """ # TODO: generalize beyond torch, or patch Tensor # fmt: off @@ -308,7 +311,7 @@ def _g_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the lensing potential computation. - *Unit: units of energy per unit mass* + *Unit: arcsec^2* """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 @@ -331,6 +334,7 @@ def _g_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the lensing potential computation. + *Unit: arcsec^2* """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 @@ -359,6 +363,7 @@ def _h_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the reduced deflection angle computation. + *Unit: radians* """ term_1 = (x / 2).log() term_2 = torch.ones_like(x) @@ -380,6 +385,7 @@ def _h_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the reduced deflection angle computation. + *Unit: radians* """ term_1 = (x / 2).log() term_2 = torch.where( @@ -413,8 +419,10 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -424,6 +432,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. + *Unit: radians* """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -462,8 +471,10 @@ def convergence( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -505,8 +516,10 @@ def potential( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -516,6 +529,7 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s diff --git a/src/caustics/lenses/pixelated_convergence.py b/src/caustics/lenses/pixelated_convergence.py index acc2f4a2..190a6644 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -53,7 +53,7 @@ def __init__( The name of the PixelatedConvergence object. fov: float The field of view in arcseconds. - *Unit: arcseconds* + *Unit: arcsec* n_pix: int The number of pixels on each side of the grid. cosmology: Cosmology @@ -62,8 +62,10 @@ def __init__( The redshift of the lens. x0: Optional[Tensor] The x-coordinate of the center of the grid. + *Unit: arcsec* y0: Optional[Tensor] The y-coordinate of the center of the grid. + *Unit: arcsec* convergence_map: Optional[Tensor] A 2D tensor representing the convergence map. shape: Optional[tuple[int, ...]] @@ -274,8 +276,10 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinates of the positions to compute the deflection angles for. + *Unit: arcsec* y: Tensor The y-coordinates of the positions to compute the deflection angles for. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -381,8 +385,10 @@ def potential( ---------- x: Tensor The x-coordinates of the positions to compute the lensing potential for. + *Unit: arcsec* y: Tensor The y-coordinates of the positions to compute the lensing potential for. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -392,6 +398,7 @@ def potential( ------- Tensor The lensing potential at the specified positions. + *Unit: arcsec^2* """ if self.convolution_mode == "fft": potential_map = self._potential_fft(convergence_map) @@ -417,6 +424,7 @@ def _potential_fft(self, convergence_map: Tensor) -> Tensor: ------- Tensor The lensing potential. + *Unit: arcsec^2* """ convergence_tilde = self._fft2_padded(convergence_map) potential = torch.fft.irfft2( @@ -437,6 +445,7 @@ def _potential_conv2d(self, convergence_map: Tensor) -> Tensor: ------- Tensor The lensing potential. + *Unit: arcsec^2* """ # Use convergence_map as kernel since the kernel is twice as large. Flip since # we actually want the cross-correlation. @@ -467,8 +476,10 @@ def convergence( ---------- x: Tensor The x-coordinates of the positions to compute the convergence for. + *Unit: arcsec* y: Tensor The y-coordinates of the positions to compute the convergence for. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index fb4ea2d0..4dba4d17 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -26,14 +26,16 @@ class Point(ThinLens): Redshift of the lens. x0: Optional[Union[Tensor, float]] x-coordinate of the center of the lens. + *Unit: arcsec* y0: Optional[Union[Tensor, float]] y-coordinate of the center of the lens. + *Unit: arcsec* th_ein: Optional[Union[Tensor, float]] Einstein radius of the lens. - *Unit: arcseconds* + *Unit: arcsec* s: float Softening parameter to prevent numerical instabilities. - *Unit: meters* + *Unit: meters* """ _null_params = { @@ -65,14 +67,16 @@ def __init__( Redshift of the lens. x0: Optional[Tensor] x-coordinate of the center of the lens. + *Unit: arcsec* y0: Optional[Tensor] y-coordinate of the center of the lens. + *Unit: arcsec* th_ein: Optional[Tensor] Einstein radius of the lens. - *Unit: arcseconds* + *Unit: arcsec* s: float Softening parameter to prevent numerical instabilities. - *Unit: meters* + *Unit: meters* """ super().__init__(cosmology, z_l, name=name) @@ -102,8 +106,10 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -113,6 +119,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The deflection angles in the x and y directions. + *Unit: (arcsec, arcsec)* """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -141,8 +148,10 @@ def potential( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -152,6 +161,7 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -178,8 +188,10 @@ def convergence( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index 4d06ffbf..653f3f5c 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -35,8 +35,8 @@ class PseudoJaffe(ThinLens): y-coordinate of the center of the lens (arcsec). *Unit: arcsec* mass: Optional[Union[Tensor, float]] - Total mass of the lens (Msol). - *Unit: Msol* + Total mass of the lens (solMass). + *Unit: solMass* core_radius: Optional[Union[Tensor, float]] Core radius of the lens (arcsec). *Unit: arcsec* @@ -85,8 +85,8 @@ def __init__( y-coordinate of the center of the lens. *Unit: arcsec* mass: Optional[Tensor] - Total mass of the lens (Msol). - *Unit: Msol* + Total mass of the lens (solMass). + *Unit: solMass* core_radius: Optional[Tensor] Core radius of the lens. *Unit: arcsec* @@ -156,7 +156,7 @@ def mass_enclosed_2d( ------- Tensor The mass enclosed within the given radius. - *Unit: Msol* + *Unit: solMass* """ # fmt: off theta = theta + self.s @@ -190,7 +190,7 @@ def central_convergence( Source redshift. rho_0: Tensor Central mass density. - *Unit: Msol/Mpc^3* + *Unit: solMass/megaparsec^3* core_radius: Tensor Core radius of the lens (must be in Mpc). *Unit: Mpc* @@ -348,7 +348,7 @@ def convergence( ------- Tensor The projected mass density. - *Unit: Msol/Mpc^2* + *Unit: solMass/Mpc^2* """ x, y = translate_rotate(x, y, x0, y0) R_squared = x**2 + y**2 + self.s diff --git a/src/caustics/lenses/sie.py b/src/caustics/lenses/sie.py index 482b29a0..181d49b7 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -228,7 +228,7 @@ def convergence( ------- Tensor The projected mass density. - *Unit: Msol/Mpc^2* + *Unit: solMass/Mpc^2* """ x, y = translate_rotate(x, y, x0, y0, phi) psi = self._get_potential(x, y, q) diff --git a/src/caustics/lenses/singleplane.py b/src/caustics/lenses/singleplane.py index e9128e24..4d12dc6b 100644 --- a/src/caustics/lenses/singleplane.py +++ b/src/caustics/lenses/singleplane.py @@ -110,7 +110,7 @@ def convergence( ------- Tensor The total projected mass density. - *Unit: Msol/Mpc^2* + *Unit: solMass/megaparsec^2* """ convergence = torch.zeros_like(x) for lens in self.lenses: diff --git a/src/caustics/lenses/sis.py b/src/caustics/lenses/sis.py index 9c384358..4d110e7a 100644 --- a/src/caustics/lenses/sis.py +++ b/src/caustics/lenses/sis.py @@ -124,8 +124,10 @@ def potential( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) @@ -135,6 +137,7 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -161,8 +164,10 @@ def convergence( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. params: (Packed, optional) diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index 250346ac..f5331b2f 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -53,15 +53,12 @@ class TNFW(ThinLens): x0: Optional[Tensor] Center of lens position on x-axis (arcsec). *Unit: arcsec* - y0: Optional[Tensor] Center of lens position on y-axis (arcsec). *Unit: arcsec* - mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* - + Mass of the lens. + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -180,8 +177,8 @@ def get_concentration( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens (solMass). + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -228,8 +225,8 @@ def get_truncation_radius( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens. + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -275,8 +272,8 @@ def get_M0( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens. + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -288,8 +285,8 @@ def get_M0( Returns ------- Tensor - The reference mass of the lens in Msol. - *Unit: Msol* + The reference mass of the lens in solMass. + *Unit: solMass* """ if self.interpret_m_total_mass: return mass * (tau**2 + 1) ** 2 / (tau**2 * ((tau**2 - 1) * tau.log() + torch.pi * tau - (tau**2 + 1))) # fmt: skip @@ -324,8 +321,8 @@ def get_scale_density( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens. + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -338,7 +335,7 @@ def get_scale_density( -------- Tensor The scale density of the lens in solar masses per Mpc cubed. - *Unit: SolMass/Mpc^3* + *Unit: solMass/Mpc^3* """ c = self.get_concentration(params) return DELTA / 3 * self.cosmology.critical_density(z_l, params) * c**3 / ((1 + c).log() - c / (1 + c)) # fmt: skip @@ -374,8 +371,8 @@ def convergence( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens. + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -424,7 +421,7 @@ def mass_enclosed_2d( **kwargs, ) -> Tensor: """ - Total projected mass (Msol) within a radius r (arcsec). + Total projected mass (solMass) within a radius r (arcsec). Parameters ----------- @@ -437,8 +434,8 @@ def mass_enclosed_2d( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens. + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* @@ -494,7 +491,7 @@ def physical_deflection_angle( y0: Tensor Center of lens position on y-axis (arcsec). mass: Optional[Tensor] - Mass of the lens (Msol). + Mass of the lens (solMass). scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). tau: Optional[Tensor] @@ -506,7 +503,7 @@ def physical_deflection_angle( -------- tuple[Tensor, Tensor] The physical deflection angles in the x and y directions (arcsec). - + *Unit : (arcsec, arcsec)* """ d_l = self.cosmology.angular_diameter_distance(z_l, params) x, y = translate_rotate(x, y, x0, y0) @@ -554,8 +551,8 @@ def potential( Center of lens position on y-axis (arcsec). *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (Msol). - *Unit: Msol* + Mass of the lens (solMass). + *Unit: solMass* scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). *Unit: arcsec* diff --git a/src/caustics/light/pixelated.py b/src/caustics/light/pixelated.py index c445c4d0..bdb1d017 100644 --- a/src/caustics/light/pixelated.py +++ b/src/caustics/light/pixelated.py @@ -25,8 +25,10 @@ class Pixelated(Source): ---------- x0 : Tensor, optional The x-coordinate of the source image's center. + *Unit: arcsec* y0 : Tensor, optional The y-coordinate of the source image's center. + *Unit: arcsec* image : Tensor, optional The source image from which brightness values will be interpolated. pixelscale : Tensor, optional @@ -53,8 +55,10 @@ def __init__( The name of the source. x0 : Tensor, optional The x-coordinate of the source image's center. + *Unit: arcsec* y0 : Tensor, optional The y-coordinate of the source image's center. + *Unit: arcsec* image : Tensor, optional The source image from which brightness values will be interpolated. pixelscale : Tensor, optional @@ -99,9 +103,11 @@ def brightness( x : Tensor The x-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* y : Tensor The y-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* params : Packed, optional A dictionary containing additional parameters that might be required to calculate the brightness. diff --git a/src/caustics/light/sersic.py b/src/caustics/light/sersic.py index 11bc5e05..5e3bac93 100644 --- a/src/caustics/light/sersic.py +++ b/src/caustics/light/sersic.py @@ -24,16 +24,20 @@ class Sersic(Source): ----------- x0: Optional[Tensor] The x-coordinate of the Sersic source's center. + *Unit: arcsec* y0: Optional[Tensor] The y-coordinate of the Sersic source's center. + *Unit: arcsec* q: Optional[Tensor] The axis ratio of the Sersic source. phi: Optional[Tensor] The orientation of the Sersic source (position angle). + *Unit: radians* n: Optional[Tensor] The Sersic index, which describes the degree of concentration of the source. Re: Optional[Tensor] The scale length of the Sersic source. + *Unit: arcsec* Ie: Optional[Tensor] The intensity at the effective radius. s: float @@ -64,16 +68,20 @@ def __init__( The name of the source. x0: Optional[Tensor] The x-coordinate of the Sersic source's center. + *Unit: arcsec* y0: Optional[Tensor] The y-coordinate of the Sersic source's center. + *Unit: arcsec* q: Optional[Tensor]) The axis ratio of the Sersic source. phi: Optional[Tensor] The orientation of the Sersic source. + *Unit: radians* n: Optional[Tensor] The Sersic index, which describes the degree of concentration of the source. Re: Optional[Tensor] The scale length of the Sersic source. + *Unit: arcsec* Ie: Optional[Tensor] The intensity at the effective radius. s: float @@ -118,9 +126,11 @@ def brightness( x: Tensor The x-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* y: Tensor The y-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* params: Packed, optional Dynamic parameter container. From 08bf8d46eaced9322c3110074d93767753a5a4ff Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 11 Feb 2024 09:59:29 +0000 Subject: [PATCH 05/14] style: pre-commit fixes --- src/caustics/lenses/base.py | 2 +- src/caustics/lenses/mass_sheet.py | 2 +- src/caustics/lenses/multiplane.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 4f51d0a1..803a1c2c 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -140,7 +140,7 @@ def forward_raytrace( number of random initialization points used to try and find image plane points. fov: float the field of view in which the initial random samples are taken. - *Unit: arcsec* + *Unit: arcsec* Returns ------- diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index e8a35a26..7e2d41c6 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -78,7 +78,7 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. - *Unit: arcsec* + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. *Unit: arcsec* diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index 3478dfa1..7fc6c84a 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -238,10 +238,10 @@ def surface_density( ---------- x: Tensor x-coordinates in the lens plane. - *Unit: arcsec* + *Unit: arcsec* y: Tensor y-coordinates in the lens plane. - *Unit: arcsec* + *Unit: arcsec* z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -251,7 +251,7 @@ def surface_density( ------- Tensor Projected mass density [Solar Mass / Mpc^2]. - *Unit: solMass / megaparsec^2* + *Unit: solMass / megaparsec^2* Raises ------- NotImplementedError From 9f21ab550fd4df69ec44dd397de3fcab27b40684 Mon Sep 17 00:00:00 2001 From: RashmikaReddy Date: Tue, 13 Feb 2024 12:09:27 -0500 Subject: [PATCH 06/14] Made the changes, fixed indentation --- src/caustics/lenses/base.py | 28 +++++++++++++++++++++++---- src/caustics/lenses/epl.py | 9 +++++++-- src/caustics/lenses/external_shear.py | 7 ++++++- src/caustics/lenses/mass_sheet.py | 7 ++++++- src/caustics/lenses/multiplane.py | 2 +- src/caustics/lenses/nfw.py | 2 +- src/caustics/lenses/point.py | 7 ++++++- src/caustics/lenses/pseudo_jaffe.py | 6 +++--- src/caustics/lenses/sie.py | 2 +- 9 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 803a1c2c..0794b7ab 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -306,7 +306,12 @@ def physical_deflection_angle( tuple[Tensor, Tensor] Tuple of Tensors representing the x and y components of the deflection angle, respectively. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ raise NotImplementedError( "Physical deflection angles are computed with respect to a lensing plane. " @@ -665,7 +670,12 @@ def reduced_deflection_angle( -------- tuple[Tensor, Tensor] Reduced deflection angle in x and y directions. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -708,7 +718,12 @@ def physical_deflection_angle( ------- tuple[Tensor, Tensor] Physical deflection angle in x and y directions in arcseconds. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -858,7 +873,12 @@ def raytrace( ------- tuple[Tensor, Tensor] Ray-traced coordinates in the x and y directions. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params, **kwargs) diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index f2612086..9905d062 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -27,7 +27,7 @@ class EPL(ThinLens): Number of iterations for the iterative solver. s: float Softening length for the elliptical power-law profile. - *Unit: Meters* + *Unit: meters* Parameters ---------- @@ -175,7 +175,12 @@ def reduced_deflection_angle( -------- tuple[Tensor, Tensor] Reduced deflection angles in the x and y directions. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0, phi) diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index f0b3fa33..77f0d2be 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -96,7 +96,12 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.83 diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index 7e2d41c6..e539577b 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -91,7 +91,12 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.84 diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index 7fc6c84a..ea16e783 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -250,7 +250,7 @@ def surface_density( Returns ------- Tensor - Projected mass density [Solar Mass / Mpc^2]. + Projected mass density. *Unit: solMass / megaparsec^2* Raises ------- diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index f812e17c..f2d61618 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -49,7 +49,7 @@ class NFW(ThinLens): get_scale_radius Returns the scale radius of the lens. get_scale_density - Returns the scale density of1` the lens. + Returns the scale density of the lens. get_convergence_s Returns the dimensionless surface mass density of the lens. diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index 4dba4d17..72686b2e 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -119,7 +119,12 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The deflection angles in the x and y directions. - *Unit: (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + *Unit: arcsec* + y_component: Tensor + Deflection Angle + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index 653f3f5c..0d2bfd16 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -190,13 +190,13 @@ def central_convergence( Source redshift. rho_0: Tensor Central mass density. - *Unit: solMass/megaparsec^3* + *Unit: solMass/megaparsec^3* core_radius: Tensor Core radius of the lens (must be in Mpc). - *Unit: Mpc* + *Unit: megaparsec* scale_radius: Tensor Scaling radius of the lens (must be in Mpc). - *Unit: Mpc* + *Unit: megaparsec* cosmology: Cosmology The cosmology used for calculations. diff --git a/src/caustics/lenses/sie.py b/src/caustics/lenses/sie.py index 181d49b7..8d53747c 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -228,7 +228,7 @@ def convergence( ------- Tensor The projected mass density. - *Unit: solMass/Mpc^2* + *Unit: solMass/megaparsec^2* """ x, y = translate_rotate(x, y, x0, y0, phi) psi = self._get_potential(x, y, q) From 052870c4bfc6f244f70b51c0676ea52320cc383c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:09:48 +0000 Subject: [PATCH 07/14] style: pre-commit fixes --- src/caustics/lenses/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 0794b7ab..4bdb33e7 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -311,7 +311,7 @@ def physical_deflection_angle( *Unit: arcsec* y_component: Tensor Deflection Angle - *Unit: arcsec* + *Unit: arcsec* """ raise NotImplementedError( "Physical deflection angles are computed with respect to a lensing plane. " @@ -675,7 +675,7 @@ def reduced_deflection_angle( *Unit: arcsec* y_component: Tensor Deflection Angle - *Unit: arcsec* + *Unit: arcsec* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) From ae7ddad4ac76cb816e7be2ae619727fa648f5c21 Mon Sep 17 00:00:00 2001 From: RashmikaReddy Date: Wed, 14 Feb 2024 01:32:17 -0500 Subject: [PATCH 08/14] Added spacing, fixed indentation, added unitless --- src/caustics/cosmology.py | 86 ++++++++++ src/caustics/lenses/base.py | 152 +++++++++++++++++- src/caustics/lenses/epl.py | 62 ++++++++ src/caustics/lenses/external_shear.py | 34 ++++ src/caustics/lenses/mass_sheet.py | 18 +++ src/caustics/lenses/multiplane.py | 25 +++ src/caustics/lenses/nfw.py | 99 ++++++++++++ src/caustics/lenses/pixelated_convergence.py | 86 ++++++++++ src/caustics/lenses/point.py | 54 ++++++- src/caustics/lenses/pseudo_jaffe.py | 42 +++++ src/caustics/lenses/sie.py | 47 +++++- src/caustics/lenses/singleplane.py | 26 +++ src/caustics/lenses/sis.py | 53 ++++++- src/caustics/lenses/tnfw.py | 158 ++++++++++++++++++- src/caustics/lenses/utils.py | 24 +++ src/caustics/light/sersic.py | 47 ++++++ 16 files changed, 1001 insertions(+), 12 deletions(-) diff --git a/src/caustics/cosmology.py b/src/caustics/cosmology.py index 02772615..0b5d4716 100644 --- a/src/caustics/cosmology.py +++ b/src/caustics/cosmology.py @@ -44,7 +44,9 @@ class Cosmology(Parametrized): such as comoving distance and critical surface density. Distance + *Unit: megaparsec* + Mass *Unit: solMass* @@ -74,6 +76,9 @@ def critical_density(self, z: Tensor, params: Optional["Packed"] = None) -> Tens ---------- z: Tensor The redshifts. + + *Unit: unitless* + params: Packed, optional Dynamic parameter container for the computation. @@ -81,7 +86,9 @@ def critical_density(self, z: Tensor, params: Optional["Packed"] = None) -> Tens ------- Tensor The critical density at each redshift. + *Unit: solMass/megaparsec^3* + """ ... @@ -97,6 +104,9 @@ def comoving_distance( ---------- z: Tensor The redshifts. + + *Unit: unitless* + params: (Packed, optional0 Dynamic parameter container for the computation. @@ -104,7 +114,9 @@ def comoving_distance( ------- Tensor The comoving distance to each redshift. + *Unit: megaparsec* + """ ... @@ -120,6 +132,9 @@ def transverse_comoving_distance( ---------- z: Tensor The redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -127,7 +142,9 @@ def transverse_comoving_distance( ------- Tensor The transverse comoving distance to each redshift in Mpc. + *Unit: megaparsec* + """ ... @@ -142,8 +159,14 @@ def comoving_distance_z1z2( ---------- z1: Tensor The starting redshifts. + + *Unit: unitless* + z2: Tensor The ending redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -151,7 +174,9 @@ def comoving_distance_z1z2( ------- Tensor The comoving distance between each pair of redshifts. + *Unit: megaparsec* + """ return self.comoving_distance(z2, params) - self.comoving_distance(z1, params) @@ -166,8 +191,14 @@ def transverse_comoving_distance_z1z2( ---------- z1: Tensor The starting redshifts. + + *Unit: unitless* + z2: Tensor The ending redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -175,7 +206,9 @@ def transverse_comoving_distance_z1z2( ------- Tensor The transverse comoving distance between each pair of redshifts in Mpc. + *Unit: megaparsec* + """ return self.transverse_comoving_distance( z2, params @@ -192,6 +225,9 @@ def angular_diameter_distance( ----------- z: Tensor The redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -199,7 +235,9 @@ def angular_diameter_distance( ------- Tensor The angular diameter distance to each redshift. + *Unit: megaparsec* + """ return self.comoving_distance(z, params, **kwargs) / (1 + z) @@ -214,8 +252,14 @@ def angular_diameter_distance_z1z2( ---------- z1: Tensor The starting redshifts. + + *Unit: unitless* + z2: Tensor The ending redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -223,7 +267,9 @@ def angular_diameter_distance_z1z2( ------- Tensor The angular diameter distance between each pair of redshifts. + *Unit: megaparsec* + """ return self.comoving_distance_z1z2(z1, z2, params, **kwargs) / (1 + z2) @@ -243,8 +289,14 @@ def time_delay_distance( ---------- z_l: Tensor The lens redshifts. + + *Unit: unitless* + z_s: Tensor The source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -252,7 +304,9 @@ def time_delay_distance( ------- Tensor The time delay distance for each pair of lens and source redshifts. + *Unit: megaparsec* + """ d_l = self.angular_diameter_distance(z_l, params) d_s = self.angular_diameter_distance(z_s, params) @@ -275,8 +329,14 @@ def critical_surface_density( ---------- z_l: Tensor The lens redshifts. + + *Unit: unitless* + z_s: Tensor The source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -284,7 +344,9 @@ def critical_surface_density( ------- Tensor The critical surface density for each pair of lens and source redshifts. + *Unit: solMass/megaparsec^2* + """ d_l = self.angular_diameter_distance(z_l, params) d_s = self.angular_diameter_distance(z_s, params) @@ -314,11 +376,19 @@ def __init__( Name of the cosmology. h0: Optional[Tensor] Hubble constant over 100. Default is h0_default. + + *Unit: unitless* + critical_density_0: (Optional[Tensor]) Critical density at z=0. Default is critical_density_0_default. + *Unit: solMass/megaparsec^3* + Om0: Optional[Tensor] Matter density parameter at z=0. Default is Om0_default. + + *Unit: unitless* + """ super().__init__(name) @@ -353,11 +423,15 @@ def hubble_distance(self, h0): h0: Tensor Hubble constant. + *Unit: unitless* + Returns ------- Tensor Hubble distance. + *Unit: megaparsec* + """ return c_Mpc_s / (100 * km_to_Mpc) / h0 @@ -379,6 +453,9 @@ def critical_density( ---------- z: Tensor Redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -386,6 +463,7 @@ def critical_density( ------- torch.Tensor Critical density at redshift z. + *Unit: solMass/megaparsec^3* """ @@ -404,10 +482,13 @@ def _comoving_distance_helper( x: Tensor Input tensor. + *Unit: megaparsec* + Returns ------- Tensor Computed comoving distances. + *Unit: megaparsec* """ @@ -435,6 +516,9 @@ def comoving_distance( ---------- z: Tensor Redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -442,7 +526,9 @@ def comoving_distance( ------- Tensor Comoving distance to redshift z. + *Unit: megaparsec* + """ Ode0 = 1 - Om0 ratio = (Om0 / Ode0) ** (1 / 3) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 0794b7ab..28a4f84c 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -87,12 +87,19 @@ def magnification( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -100,6 +107,9 @@ def magnification( ------- Tensor Gravitational magnification at the given coordinates. + + *Unit: unitless* + """ return get_magnification( partial(self.raytrace, params=params), x, y, z_s, **kwargs @@ -124,22 +134,33 @@ def forward_raytrace( Parameters ---------- bx: Tensor - Tensor of x coordinate in the source plane (scalar). + Tensor of x coordinate in the source plane. + + *Unit: scalar* + by: Tensor - Tensor of y coordinate in the source plane (scalar). + Tensor of y coordinate in the source plane. + + *Unit: scalar* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. epsilon: Tensor maximum distance between two images (arcsec) before they are considered the same image. + *Unit: arcsec* n_init: int number of random initialization points used to try and find image plane points. fov: float the field of view in which the initial random samples are taken. + *Unit: arcsec* Returns @@ -215,10 +236,14 @@ def reduced_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. params: Packed, optional @@ -261,12 +286,19 @@ def effective_reduced_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -292,10 +324,14 @@ def physical_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. params: (Packed, optional) @@ -308,10 +344,14 @@ def physical_deflection_angle( of the deflection angle, respectively. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle - *Unit: arcsec* + + *Unit: arcsec* + """ raise NotImplementedError( "Physical deflection angles are computed with respect to a lensing plane. " @@ -338,12 +378,19 @@ def raytrace( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -351,9 +398,14 @@ def raytrace( ------- x: Tensor x coordinate Tensor of the ray-traced light rays + + *Unit: arcsec* + y: Tensor y coordinate Tensor of the ray-traced light rays + *Unit: arcsec* + """ ... @@ -375,12 +427,19 @@ def surface_density( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -389,7 +448,9 @@ def surface_density( Tensor The projected mass density at the given coordinates in units of solar masses per square Megaparsec. + *Unit: solMass/megaparsec^2* + """ ... @@ -411,12 +472,19 @@ def time_delay( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor ofsource redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -424,7 +492,9 @@ def time_delay( ------- Tensor The gravitational time delay at the given coordinates. + *Unit: milliseconds* + """ ... @@ -628,6 +698,9 @@ class ThinLens(Lens): z_l: (Optional[Tensor], optional) Redshift of the lens. Defaults to None. + *Unit: unitless* + + """ def __init__( @@ -657,12 +730,19 @@ def reduced_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -672,10 +752,14 @@ def reduced_deflection_angle( Reduced deflection angle in x and y directions. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle - *Unit: arcsec* + + *Unit: arcsec* + """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -705,12 +789,19 @@ def physical_deflection_angle( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -720,10 +811,14 @@ def physical_deflection_angle( Physical deflection angle in x and y directions in arcseconds. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle + *Unit: arcsec* + """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -753,12 +848,19 @@ def convergence( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -787,12 +889,19 @@ def potential( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -800,7 +909,9 @@ def potential( ------- Tensor Gravitational lensing potential at the given coordinates in arcsec^2. + *Unit: arsec^2* + """ ... @@ -822,12 +933,19 @@ def surface_density( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -835,7 +953,9 @@ def surface_density( ------- Tensor Surface mass density at the given coordinates in solar masses per Mpc^2. + *Unit: solMass/megaparsec^2* + """ critical_surface_density = self.cosmology.critical_surface_density( z_l, z_s, params @@ -860,12 +980,19 @@ def raytrace( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -875,11 +1002,15 @@ def raytrace( Ray-traced coordinates in the x and y directions. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle + *Unit: arcsec* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params, **kwargs) return x - ax, y - ay @@ -925,14 +1056,24 @@ def time_delay( ---------- x: Tensor Tensor of x coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Tensor of y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + z_l: Tensor Redshift of the lens. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. shapiro_time_delay: bool @@ -944,7 +1085,8 @@ def time_delay( ------- Tensor Time delay at the given coordinates. - *Units: milliseconds* + + *Unit: milliseconds* References ---------- diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index 9905d062..2b70ce60 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -27,8 +27,10 @@ class EPL(ThinLens): Number of iterations for the iterative solver. s: float Softening length for the elliptical power-law profile. + *Unit: meters* + Parameters ---------- z_l: Optional[Union[Tensor, float]] @@ -40,7 +42,9 @@ class EPL(ThinLens): These are the coordinates of the lens center in the lens plane. The lens plane is the plane perpendicular to the line of sight in which the deflection of light by the lens is considered. + *Unit: arcsec* + q: Optional[Union[Tensor, float]] This is the axis ratio of the lens, i.e., the ratio of the minor axis to the major axis of the elliptical lens. @@ -98,31 +102,50 @@ def __init__( z_l: Optional[Tensor] Redshift of the lens. If not provided, it is considered as a free parameter. + + *Unit: unitless* + x0: Optional[Tensor] X coordinate of the lens center. If not provided, it is considered as a free parameter. + *Unit: arcsec* + y0: Optional[Tensor] Y coordinate of the lens center. If not provided, it is considered as a free parameter. + *Unit: arcsec* + q: Optional[Tensor] Axis ratio of the lens. If not provided, it is considered as a free parameter. + + *Unit: unitless* + phi: Optional[Tensor] Position angle of the lens. If not provided, it is considered as a free parameter. + *Unit: radians* + b: Optional[Tensor] Scale length of the lens. If not provided, it is considered as a free parameter. + *Unit: arcsec* + t: Optional[Tensor] Power law slope (`gamma-1`) of the lens. If not provided, it is considered as a free parameter. + + *Unit: unitless* + s: float Softening length for the elliptical power-law profile. + *Unit: meters* + n_iter: int Number of iterations for the iterative solver. """ @@ -162,12 +185,19 @@ def reduced_deflection_angle( ---------- x: Tensor X coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. @@ -177,10 +207,14 @@ def reduced_deflection_angle( Reduced deflection angles in the x and y directions. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle + *Unit: arcsec* + """ x, y = translate_rotate(x, y, x0, y0, phi) @@ -204,9 +238,14 @@ def _r_omega(self, z, t, q): ---------- z: Tensor `R * e^(i * phi)`, position vector in the lens plane. + *Unit: meters* + t: Tensor Power law slow (`gamma-1`). + + *Unit: unitless* + q: Tensor Axis ratio. @@ -214,7 +253,9 @@ def _r_omega(self, z, t, q): -------- Tensor The value of `R * omega(phi)`. + *Unit: meters* + """ # constants f = (1.0 - q) / (1.0 + q) @@ -255,12 +296,19 @@ def potential( ---------- x: Tensor X coordinates in the lens plane. + *Unit: arcsec* + y: Tensor Y coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. @@ -268,7 +316,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) ax, ay = derotate(ax, ay, -phi) @@ -299,10 +349,19 @@ def convergence( ---------- x: Tensor X coordinates in the lens plane. + + *Unit: arcsec* + y: Tensor Y coordinates in the lens plane. + + *Unit: arcsec* + z_s: Tensor Source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. @@ -310,6 +369,9 @@ def convergence( ------- Tensor The convergence of the lens. + + *Unit: unitless* + """ x, y = translate_rotate(x, y, x0, y0, phi) psi = (q**2 * (x**2 + self.s**2) + y**2).sqrt() # fmt: skip diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index 77f0d2be..466ff3dc 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -23,12 +23,19 @@ class ExternalShear(ThinLens): The cosmological model used for lensing calculations. z_l: Optional[Union[Tensor, float]] The redshift of the lens. + + *Unit: unitless* + x0, y0: Optional[Union[Tensor, float]] Coordinates of the shear center in the lens plane. + *Unit: arcsec* + gamma_1, gamma_2: Optional[Union[Tensor, float]] Shear components. + *Unit: unitless* + Notes ------ The shear components gamma_1 and gamma_2 represent an external shear, a gravitational @@ -83,12 +90,19 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -98,10 +112,14 @@ def reduced_deflection_angle( The reduced deflection angles in the x and y directions. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle + *Unit: arcsec* + """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.83 @@ -136,12 +154,19 @@ def potential( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -149,7 +174,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) x, y = translate_rotate(x, y, x0, y0) @@ -177,12 +204,19 @@ def convergence( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. Raises diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index e539577b..9e3bc95d 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -24,12 +24,19 @@ class MassSheet(ThinLens): The cosmological model used for lensing calculations. z_l: Optional[Union[Tensor, float]] The redshift of the lens. + + *Unit: unitless* + x0, y0: Optional[Union[Tensor, float]] Coordinates of the shear center in the lens plane. + *Unit: arcsec* + gamma_1, gamma_2: Optional[Union[Tensor, float]] Shear components. + *Unit: unitless* + Notes ------ The shear components gamma_1 and gamma_2 represent an external shear, a gravitational @@ -78,12 +85,19 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -93,10 +107,14 @@ def reduced_deflection_angle( The reduced deflection angles in the x and y directions. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle + *Unit: arcsec* + """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.84 diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index ea16e783..65cfed52 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -177,12 +177,19 @@ def raytrace( ---------- x: Tensor angular x-coordinates in the image plane. + *Unit: radians* + y: Tensor angular y-coordinates in the image plane. + *Unit: radians* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -190,6 +197,7 @@ def raytrace( ------- (Tensor, Tensor) The reduced deflection angle. + *Unit: radians* References @@ -238,12 +246,19 @@ def surface_density( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -251,7 +266,9 @@ def surface_density( ------- Tensor Projected mass density. + *Unit: solMass / megaparsec^2* + Raises ------- NotImplementedError @@ -294,12 +311,19 @@ def time_delay( ---------- x: Tensor x-coordinates in the image plane. + *Unit: radians* + y: Tensor y-coordinates in the image plane. + *Unit: radians* + z_s: Tensor Redshifts of the source. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. shapiro_time_delay: bool @@ -311,6 +335,7 @@ def time_delay( ------- Tensor Time delay caused by the lensing. + *Unit: seconds* References diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index f2d61618..a3ff2632 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -26,19 +26,34 @@ class NFW(ThinLens): ----------- z_l: Optional[Tensor] Redshift of the lens. Default is None. + + *Unit: unitless* + x0: Optional[Tensor] x-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* + y0: Optional[Tensor] y-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* + m: Optional[Tensor] Mass of the lens. Default is None. + *Unit: solMass* + c: Optional[Tensor] Concentration parameter of the lens. Default is None. + + *Unit: unitless* + s: float Softening parameter to avoid singularities at the center of the lens. Default is 0.0. + + *Unit: meters* + use_case: str Due to an idyosyncratic behaviour of PyTorch, the NFW/TNFW profile specifically can't be both batchable and differentiable. You may select which version @@ -100,22 +115,37 @@ def __init__( information about the cosmological model and parameters. z_l: Optional[Union[Tensor, float]] Redshift of the lens. Default is None. + + *Unit: unitless* + x0: Optional[Union[Tensor, float]] x-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* + y0: Optional[Union[Tensor, float]] y-coordinate of the lens center in the lens plane. Default is None. + *Unit: arcsec* + m: Optional[Union[Tensor, float]] Mass of the lens. Default is None. + *Unit: solMass* + c: Optional[Union[Tensor, float]] Concentration parameter of the lens. Default is None. + + *Unit: unitless* + s: float Softening parameter to avoid singularities at the center of the lens. Default is 0.0. + + *Unit: meters* + """ super().__init__(cosmology, z_l, name=name) @@ -154,11 +184,19 @@ def get_scale_radius( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + m: Tensor Mass of the lens. + *Unit: solMass* + c: Tensor Concentration parameter of the lens. + + *Unit: unitless* + x: dict Dynamic parameter container. @@ -166,7 +204,9 @@ def get_scale_radius( ------- Tensor The scale radius of the lens in Mpc. + *Unit: megaparsec* + """ critical_density = self.cosmology.critical_density(z_l, params) r_delta = (3 * m / (4 * pi * DELTA * critical_density)) ** (1 / 3) # fmt: skip @@ -191,8 +231,14 @@ def get_scale_density( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + c: Tensor Concentration parameter of the lens. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -200,7 +246,9 @@ def get_scale_density( ------- Tensor The scale density of the lens in solar masses per Mpc cubed. + *Unit: solMass/megaparsec^3* + """ sigma_crit = self.cosmology.critical_density(z_l, params) return DELTA / 3 * sigma_crit * c**3 / ((1 + c).log() - c / (1 + c)) # fmt: skip @@ -225,13 +273,24 @@ def get_convergence_s( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + z_s: Tensor Redshift of the source. + + *Unit: unitless* + m: Tensor Mass of the lens. + *Unit: solMass* + c: Tensor Concentration parameter of the lens. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -239,6 +298,9 @@ def get_convergence_s( ------- Tensor The dimensionless surface mass density of the lens. + + *Unit: unitless* + """ critical_surface_density = self.cosmology.critical_surface_density( z_l, z_s, params @@ -259,7 +321,9 @@ def _f_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the deflection angle computation. + *Unit: radians* + """ # TODO: generalize beyond torch, or patch Tensor f = torch.zeros_like(x) @@ -281,7 +345,9 @@ def _f_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the deflection angle computation. + *Unit: radians* + """ # TODO: generalize beyond torch, or patch Tensor # fmt: off @@ -311,7 +377,9 @@ def _g_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the lensing potential computation. + *Unit: arcsec^2* + """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 @@ -334,7 +402,9 @@ def _g_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the lensing potential computation. + *Unit: arcsec^2* + """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 @@ -363,7 +433,9 @@ def _h_differentiable(x: Tensor) -> Tensor: ------- Tensor Result of the reduced deflection angle computation. + *Unit: radians* + """ term_1 = (x / 2).log() term_2 = torch.ones_like(x) @@ -385,7 +457,9 @@ def _h_batchable(x: Tensor) -> Tensor: ------- Tensor Result of the reduced deflection angle computation. + *Unit: radians* + """ term_1 = (x / 2).log() term_2 = torch.where( @@ -419,12 +493,19 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -432,7 +513,9 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. + *Unit: radians* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -471,10 +554,14 @@ def convergence( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. params: (Packed, optional) @@ -484,6 +571,9 @@ def convergence( ------- Tensor The convergence (dimensionless surface mass density). + + *Unit: unitless* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -516,12 +606,19 @@ def potential( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -529,7 +626,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s diff --git a/src/caustics/lenses/pixelated_convergence.py b/src/caustics/lenses/pixelated_convergence.py index 190a6644..a707db24 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -53,34 +53,60 @@ def __init__( The name of the PixelatedConvergence object. fov: float The field of view in arcseconds. + *Unit: arcsec* + n_pix: int The number of pixels on each side of the grid. + + *Unit: unitless* + cosmology: Cosmology An instance of the cosmological parameters. z_l: Optional[Tensor] The redshift of the lens. + + *Unit: unitless* + x0: Optional[Tensor] The x-coordinate of the center of the grid. + *Unit: arcsec* + y0: Optional[Tensor] The y-coordinate of the center of the grid. + *Unit: arcsec* + convergence_map: Optional[Tensor] A 2D tensor representing the convergence map. + + *Unit: unitless* + shape: Optional[tuple[int, ...]] The shape of the convergence map. + + *Unit: unitless* + convolution_mode: (str, optional) The convolution mode for calculating deflection angles and lensing potential. It can be either "fft" (Fast Fourier Transform) or "conv2d" (2D convolution). Default is "fft". + + *Unit: unitless* + use_next_fast_len: (bool, optional) If True, adds additional padding to speed up the FFT by calling `scipy.fft.next_fast_len`. The speed boost can be substantial when `n_pix` is a multiple of a small prime number. Default is True. + + *Unit: unitless* + padding: { "zero", "circular", "reflect", "tile" } + *Unit: unitless* + Specifies the type of padding to use: "zero" will do zero padding, "circular" will do cyclic boundaries. @@ -195,6 +221,8 @@ def _unpad_fft(self, x: Tensor) -> Tensor: x: Tensor The input tensor with padding. + *Unit: arcsec* + Returns ------- Tensor @@ -276,12 +304,19 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinates of the positions to compute the deflection angles for. + *Unit: arcsec* + y: Tensor The y-coordinates of the positions to compute the deflection angles for. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) A dictionary containing additional parameters. @@ -318,10 +353,23 @@ def _deflection_angle_fft(self, convergence_map: Tensor) -> tuple[Tensor, Tensor convergence_map: Tensor The 2D tensor representing the convergence map. + *Unit: unitless* + Returns ------- tuple[Tensor, Tensor] The x and y components of the deflection angles. + + x_component: Tensor + Deflection Angle + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle + + *Unit: arcsec* + """ convergence_tilde = self._fft2_padded(convergence_map) deflection_angle_x = torch.fft.irfft2( @@ -343,10 +391,22 @@ def _deflection_angle_conv2d( convergence_map: Tensor The 2D tensor representing the convergence map. + *Unit: unitless* + Returns ------- tuple[Tensor, Tensor] The x and y components of the deflection angles. + x_component: Tensor + Deflection Angle + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle + + *Unit: arcsec* + """ # Use convergence_map as kernel since the kernel is twice as large. Flip since # we actually want the cross-correlation. @@ -385,12 +445,19 @@ def potential( ---------- x: Tensor The x-coordinates of the positions to compute the lensing potential for. + *Unit: arcsec* + y: Tensor The y-coordinates of the positions to compute the lensing potential for. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) A dictionary containing additional parameters. @@ -398,7 +465,9 @@ def potential( ------- Tensor The lensing potential at the specified positions. + *Unit: arcsec^2* + """ if self.convolution_mode == "fft": potential_map = self._potential_fft(convergence_map) @@ -420,11 +489,15 @@ def _potential_fft(self, convergence_map: Tensor) -> Tensor: convergence_map: Tensor The 2D tensor representing the convergence map. + *Unit: unitless* + Returns ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ convergence_tilde = self._fft2_padded(convergence_map) potential = torch.fft.irfft2( @@ -441,11 +514,15 @@ def _potential_conv2d(self, convergence_map: Tensor) -> Tensor: convergence_map: Tensor The 2D tensor representing the convergence map. + *Unit: unitless* + Returns ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ # Use convergence_map as kernel since the kernel is twice as large. Flip since # we actually want the cross-correlation. @@ -476,12 +553,19 @@ def convergence( ---------- x: Tensor The x-coordinates of the positions to compute the convergence for. + *Unit: arcsec* + y: Tensor The y-coordinates of the positions to compute the convergence for. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) A dictionary containing additional parameters. @@ -490,6 +574,8 @@ def convergence( Tensor The convergence at the specified positions. + *Unit: unitless* + Raises ------ NotImplementedError diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index 72686b2e..bbf56cbb 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -24,18 +24,29 @@ class Point(ThinLens): The cosmology used for calculations. z_l: Optional[Union[Tensor, float]] Redshift of the lens. + + *Unit: unitless* + x0: Optional[Union[Tensor, float]] x-coordinate of the center of the lens. + *Unit: arcsec* + y0: Optional[Union[Tensor, float]] y-coordinate of the center of the lens. + *Unit: arcsec* + th_ein: Optional[Union[Tensor, float]] Einstein radius of the lens. + *Unit: arcsec* + s: float Softening parameter to prevent numerical instabilities. + *Unit: meters* + """ _null_params = { @@ -65,18 +76,29 @@ def __init__( The cosmology used for calculations. z_l: Optional[Tensor] Redshift of the lens. + + *Unit: unitless* + x0: Optional[Tensor] x-coordinate of the center of the lens. + *Unit: arcsec* + y0: Optional[Tensor] y-coordinate of the center of the lens. + *Unit: arcsec* + th_ein: Optional[Tensor] Einstein radius of the lens. - *Unit: arcsec* + + *Unit: arcsec* + s: float Softening parameter to prevent numerical instabilities. + *Unit: meters* + """ super().__init__(cosmology, z_l, name=name) @@ -106,12 +128,19 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -121,10 +150,14 @@ def reduced_deflection_angle( The deflection angles in the x and y directions. x_component: Tensor Deflection Angle + *Unit: arcsec* + y_component: Tensor Deflection Angle + *Unit: arcsec* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -153,12 +186,19 @@ def potential( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -166,7 +206,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -193,12 +235,19 @@ def convergence( ---------- x: Tensor x-coordinates in the lens plane. + *Unit: arcsec* + y: Tensor y-coordinates in the lens plane. + *Unit: arcsec* + z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -206,6 +255,9 @@ def convergence( -------- Tensor The convergence (dimensionless surface mass density). + + *Unit: unitless* + """ x, y = translate_rotate(x, y, x0, y0) return torch.where((x == 0) & (y == 0), torch.inf, 0.0) diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index 0d2bfd16..03a90ad6 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -186,17 +186,29 @@ def central_convergence( ----------- z_l: Tensor Lens redshift. + + *Unit: unitless* + z_s: Tensor Source redshift. + + *Unit: unitless* + rho_0: Tensor Central mass density. + *Unit: solMass/megaparsec^3* + core_radius: Tensor Core radius of the lens (must be in Mpc). + *Unit: megaparsec* + scale_radius: Tensor Scaling radius of the lens (must be in Mpc). + *Unit: megaparsec* + cosmology: Cosmology The cosmology used for calculations. @@ -204,6 +216,9 @@ def central_convergence( -------- Tensor The central convergence. + + *Unit: unitless* + """ return pi * rho_0 * core_radius * scale_radius / ((core_radius + scale_radius) * critical_surface_density) # fmt: skip @@ -229,12 +244,19 @@ def reduced_deflection_angle( ---------- x: Tensor x-coordinate of the lens. + *Unit: arcsec* + y: Tensor y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor Source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -242,7 +264,9 @@ def reduced_deflection_angle( -------- Tuple[Tensor, Tensor] The deflection angle in the x and y directions. + *Unit: radians* + """ x, y = translate_rotate(x, y, x0, y0) R = (x**2 + y**2).sqrt() + self.s @@ -275,12 +299,19 @@ def potential( -------- x: Tensor x-coordinate of the lens. + *Unit: arcsec* + y: Tensor y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor Source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -288,7 +319,9 @@ def potential( -------- Tensor The lensing potential (arcsec^2). + *Unit: arcsec^2* + """ # fmt: off @@ -335,12 +368,19 @@ def convergence( ----------- x: Tensor x-coordinate of the lens. + *Unit: arcsec* + y: Tensor y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor Source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -348,7 +388,9 @@ def convergence( ------- Tensor The projected mass density. + *Unit: solMass/Mpc^2* + """ x, y = translate_rotate(x, y, x0, y0) R_squared = x**2 + y**2 + self.s diff --git a/src/caustics/lenses/sie.py b/src/caustics/lenses/sie.py index 8d53747c..f00f032c 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -24,23 +24,39 @@ class SIE(ThinLens): An instance of the Cosmology class. z_l: Optional[Union[Tensor, float]] The redshift of the lens. + + *Unit: unitless* + x0: Optional[Union[Tensor, float]] The x-coordinate of the lens center. + *Unit: arcsec* + y0: Optional[Union[Tensor, float]] The y-coordinate of the lens center. - *Unit: arcsec* + + *Unit: arcsec* + q: Optional[Union[Tensor, float]] The axis ratio of the lens. + + *Unit: unitless* + phi: Optional[Union[Tensor, float]] The orientation angle of the lens (position angle). + *Unit: radians* + b: Optional[Union[Tensor, float]] The Einstein radius of the lens. + *Unit: arcsec* + s: float The core radius of the lens (defaults to 0.0). - *Unit: radians* + + *Unit: meters* + """ _null_params = { @@ -83,18 +99,26 @@ def _get_potential(self, x, y, q): ---------- x: Tensor The x-coordinate in the lens plane. + *Unit: arcsec* + y: Tensor The y-coordinate in the lens plane. + *Unit: arcsec* + q: Tensor The axis ratio of the lens. + *Unit: unitless* + Returns -------- Tensor The radial coordinate in the lens plane. + *Unit: arcsec* + """ return (q**2 * (x**2 + self.s**2) + y**2).sqrt() # fmt: skip @@ -121,10 +145,12 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor @@ -136,6 +162,7 @@ def reduced_deflection_angle( -------- Tuple[Tensor, Tensor] The deflection angle in the x and y directions. + *Unit: radians* """ @@ -170,12 +197,19 @@ def potential( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -183,7 +217,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) ax, ay = derotate(ax, ay, -phi) @@ -213,14 +249,19 @@ def convergence( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* y: Tensor The y-coordinate of the lens. + *Unit: arcsec* z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -228,7 +269,9 @@ def convergence( ------- Tensor The projected mass density. + *Unit: solMass/megaparsec^2* + """ x, y = translate_rotate(x, y, x0, y0, phi) psi = self._get_potential(x, y, q) diff --git a/src/caustics/lenses/singleplane.py b/src/caustics/lenses/singleplane.py index 4d12dc6b..5a93ff1b 100644 --- a/src/caustics/lenses/singleplane.py +++ b/src/caustics/lenses/singleplane.py @@ -56,12 +56,19 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -69,7 +76,9 @@ def reduced_deflection_angle( ------- Tuple[Tensor, Tensor] The total deflection angle in the x and y directions. + *Unit: radians* + """ ax = torch.zeros_like(x) ay = torch.zeros_like(x) @@ -97,12 +106,19 @@ def convergence( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -110,7 +126,9 @@ def convergence( ------- Tensor The total projected mass density. + *Unit: solMass/megaparsec^2* + """ convergence = torch.zeros_like(x) for lens in self.lenses: @@ -136,12 +154,19 @@ def potential( ----------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -149,6 +174,7 @@ def potential( ------- Tensor The total lensing potential. + *Unit: arcsec^2* """ diff --git a/src/caustics/lenses/sis.py b/src/caustics/lenses/sis.py index 4d110e7a..0e64cdd1 100644 --- a/src/caustics/lenses/sis.py +++ b/src/caustics/lenses/sis.py @@ -24,18 +24,28 @@ class SIS(ThinLens): An instance of the Cosmology class. z_l: Optional[Union[Tensor, float]] The lens redshift. + + *Unit: unitless* + x0: Optional[Union[Tensor, float]] The x-coordinate of the lens center. + *Unit: arcsec* y0: Optional[Union[Tensor, float]] The y-coordinate of the lens center. + *Unit: arcsec* - th_ein (Optional[Union[Tensor, float]]): The Einstein radius of the lens. + + th_ein (Optional[Union[Tensor, float]]): The Einstein radius of the lens. + *Unit: arcsec* + s: float A smoothing factor, default is 0.0. - *Unit: radians* + + *Unit: meters* + """ _null_params = { @@ -85,10 +95,19 @@ def reduced_deflection_angle( ---------- x: Tensor The x-coordinate of the lens. + + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -96,6 +115,17 @@ def reduced_deflection_angle( ------- Tuple[Tensor, Tensor] The deflection angle in the x and y directions. + + x_component: Tensor + Deflection Angle + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle + + *Unit: arcsec* + """ x, y = translate_rotate(x, y, x0, y0) R = (x**2 + y**2).sqrt() + self.s @@ -124,12 +154,19 @@ def potential( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -137,7 +174,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -164,12 +203,19 @@ def convergence( ---------- x: Tensor The x-coordinate of the lens. + *Unit: arcsec* + y: Tensor The y-coordinate of the lens. + *Unit: arcsec* + z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -177,6 +223,9 @@ def convergence( ------- Tensor The projected mass density. + + *Unit: solMass/megaparsec^2* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index f5331b2f..ea7459ba 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -50,28 +50,48 @@ class TNFW(ThinLens): information about the cosmological model and parameters. z_l: Optional[Tensor] Redshift of the lens. + + *Unit: unitless* + x0: Optional[Tensor] Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Optional[Tensor] Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens. + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + s: float Softening parameter to avoid singularities at the center of the lens. Default is 0.0. + + *Unit: unitless* + interpret_m_total_mass: boolean Indicates how to interpret the mass variable "m". If true the mass is interpreted as the total mass of the halo (good because it makes sense). If false it is interpreted as what the mass would have been within R200 of a an NFW that isn't truncated (good because it is easily compared with an NFW). + + *Unit: unitless* + use_case: str Due to an idyosyncratic behaviour of PyTorch, the NFW/TNFW profile specifically can't be both batchable and differentiable. You may select which version @@ -170,18 +190,29 @@ def get_concentration( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens (solMass). + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -191,7 +222,9 @@ def get_concentration( ------- Tensor The scale radius of the lens in Mpc. - *Unit: Mpc* + + *Unit: megaparsec* + """ critical_density = self.cosmology.critical_density(z_l, params) d_l = self.cosmology.angular_diameter_distance(z_l, params) @@ -218,20 +251,34 @@ def get_truncation_radius( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens. + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + params: dictionary Dynamic parameter container. @@ -239,7 +286,9 @@ def get_truncation_radius( ------- Tensor The truncation radius of the lens in arcsec. + *Unit: arcsec* + """ return tau * scale_radius @@ -265,20 +314,34 @@ def get_M0( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens. + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + params: dictionary Dynamic parameter container. @@ -286,7 +349,9 @@ def get_M0( ------- Tensor The reference mass of the lens in solMass. + *Unit: solMass* + """ if self.interpret_m_total_mass: return mass * (tau**2 + 1) ** 2 / (tau**2 * ((tau**2 - 1) * tau.log() + torch.pi * tau - (tau**2 + 1))) # fmt: skip @@ -314,20 +379,34 @@ def get_scale_density( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens. + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + params: dict Dynamic parameter container. @@ -335,7 +414,9 @@ def get_scale_density( -------- Tensor The scale density of the lens in solar masses per Mpc cubed. + *Unit: solMass/Mpc^3* + """ c = self.get_concentration(params) return DELTA / 3 * self.cosmology.critical_density(z_l, params) * c**3 / ((1 + c).log() - c / (1 + c)) # fmt: skip @@ -364,18 +445,29 @@ def convergence( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens. + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). params: dict @@ -386,6 +478,8 @@ def convergence( Tensor unitless convergence at requested position + *Unit: unitless* + """ x, y = translate_rotate(x, y, x0, y0) r = (x**2 + y**2).sqrt() + self.s @@ -427,20 +521,34 @@ def mass_enclosed_2d( ----------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens. + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + params: dict Dynamic parameter container. @@ -448,6 +556,9 @@ def mass_enclosed_2d( ------- Tensor Integrated mass projected in infinite cylinder within radius r. + + *Unit: arcsec* + """ g = r / scale_radius t2 = tau**2 @@ -486,16 +597,34 @@ def physical_deflection_angle( ---------- z_l: Tensor Redshift of the lens. + + + x0: Tensor Center of lens position on x-axis (arcsec). + + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens (solMass). + + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + params: dict Dynamic parameter container. @@ -503,7 +632,16 @@ def physical_deflection_angle( -------- tuple[Tensor, Tensor] The physical deflection angles in the x and y directions (arcsec). - *Unit : (arcsec, arcsec)* + x_component: Tensor + Deflection Angle + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle + + *Unit: arcsec* + """ d_l = self.cosmology.angular_diameter_distance(z_l, params) x, y = translate_rotate(x, y, x0, y0) @@ -544,20 +682,34 @@ def potential( ----------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + x0: Tensor Center of lens position on x-axis (arcsec). + *Unit: arcsec* + y0: Tensor Center of lens position on y-axis (arcsec). + *Unit: arcsec* + mass: Optional[Tensor] Mass of the lens (solMass). + *Unit: solMass* + scale_radius: Optional[Tensor] Scale radius of the TNFW lens (arcsec). + *Unit: arcsec* + tau: Optional[Tensor] Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + + *Unit: unitless* + params: dict Dynamic parameter container. @@ -565,7 +717,9 @@ def potential( ------- Tensor The lensing potential. + *Unit: arcsec^2* + """ x, y = translate_rotate(x, y, x0, y0) r = (x**2 + y**2).sqrt() + self.s diff --git a/src/caustics/lenses/utils.py b/src/caustics/lenses/utils.py index bea6910b..432473ff 100644 --- a/src/caustics/lenses/utils.py +++ b/src/caustics/lenses/utils.py @@ -22,13 +22,19 @@ def get_pix_jacobian( A function that maps the lensing plane coordinates to the source plane coordinates. x: Tensor The x-coordinate on the lensing plane. + *Unit: arcsec* + y: Tensor The y-coordinate on the lensing plane. + *Unit: arcsec* + z_s: Tensor The redshift of the source. + *Unit: unitless* + Returns -------- The Jacobian matrix of the image position with respect @@ -51,17 +57,26 @@ def get_pix_magnification(raytrace, x, y, z_s) -> Tensor: A function that maps the lensing plane coordinates to the source plane coordinates. x: Tensor The x-coordinate on the lensing plane. + *Unit: arcsec* + y: Tensor The y-coordinate on the lensing plane. + *Unit: arcsec* + z_s: Tensor The redshift of the source. + *Unit: unitless* + Returns ------- Tensor The magnification at the given point on the lensing plane. + + *Unit: unitless* + """ jac = get_pix_jacobian(raytrace, x, y, z_s) return 1 / (jac[0][0] * jac[1][1] - jac[0][1] * jac[1][0]).abs() # fmt: skip @@ -79,16 +94,25 @@ def get_magnification(raytrace, x, y, z_s) -> Tensor: A function that maps the lensing plane coordinates to the source plane coordinates. x: Tensor The x-coordinates on the lensing plane. + *Unit: arcsec* + y: Tensor The y-coordinates on the lensing plane. + *Unit: arcsec* + z_s: Tensor The redshift of the source. + *Unit: unitless* + Returns -------- Tensor A tensor representing the magnification at each point on the grid. + + *Unit: unitless* + """ return vmap_n(get_pix_magnification, 2, (None, 0, 0, None))(raytrace, x, y, z_s) diff --git a/src/caustics/light/sersic.py b/src/caustics/light/sersic.py index 5e3bac93..f5648c46 100644 --- a/src/caustics/light/sersic.py +++ b/src/caustics/light/sersic.py @@ -24,26 +24,49 @@ class Sersic(Source): ----------- x0: Optional[Tensor] The x-coordinate of the Sersic source's center. + *Unit: arcsec* + y0: Optional[Tensor] The y-coordinate of the Sersic source's center. + *Unit: arcsec* + q: Optional[Tensor] The axis ratio of the Sersic source. + + *Unit: unitless* + phi: Optional[Tensor] The orientation of the Sersic source (position angle). + *Unit: radians* + n: Optional[Tensor] The Sersic index, which describes the degree of concentration of the source. + + *Unit: unitless* + Re: Optional[Tensor] The scale length of the Sersic source. + *Unit: arcsec* + Ie: Optional[Tensor] The intensity at the effective radius. + + *Unit: unitless* + s: float A small constant for numerical stability. + + *Unit: unitless* + lenstronomy_k_mode: bool A flag indicating whether to use lenstronomy to compute the value of k. + + *Unit: unitless* + """ def __init__( @@ -68,26 +91,46 @@ def __init__( The name of the source. x0: Optional[Tensor] The x-coordinate of the Sersic source's center. + *Unit: arcsec* + y0: Optional[Tensor] The y-coordinate of the Sersic source's center. + *Unit: arcsec* + q: Optional[Tensor]) The axis ratio of the Sersic source. + + *Unit: unitless* + phi: Optional[Tensor] The orientation of the Sersic source. + *Unit: radians* + n: Optional[Tensor] The Sersic index, which describes the degree of concentration of the source. + + *Unit: unitless* + Re: Optional[Tensor] The scale length of the Sersic source. + *Unit: arcsec* + Ie: Optional[Tensor] The intensity at the effective radius. s: float A small constant for numerical stability. + + *Unit: unitless* + use_lenstronomy_k: bool A flag indicating whether to use lenstronomy to compute the value of k. + + *Unit: unitless* + """ super().__init__(name=name) self.add_param("x0", x0) @@ -126,11 +169,15 @@ def brightness( x: Tensor The x-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* + y: Tensor The y-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* + params: Packed, optional Dynamic parameter container. From 6b44f2d39d19a5f5970560160fc86f46f6562b0a Mon Sep 17 00:00:00 2001 From: RashmikaReddy Date: Wed, 14 Feb 2024 12:16:10 -0500 Subject: [PATCH 09/14] Made changes and adjusted the spacing --- src/caustics/lenses/base.py | 9 +++++- src/caustics/lenses/epl.py | 14 +++++++++ src/caustics/lenses/external_shear.py | 1 + src/caustics/lenses/mass_sheet.py | 1 + src/caustics/lenses/nfw.py | 3 ++ src/caustics/lenses/pixelated_convergence.py | 11 +++++++ src/caustics/lenses/point.py | 1 + src/caustics/lenses/pseudo_jaffe.py | 32 ++++++++++++++++++++ src/caustics/lenses/sie.py | 5 ++- src/caustics/lenses/tnfw.py | 3 +- src/caustics/light/pixelated.py | 14 ++++++++- 11 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 28a4f84c..c1ed15b5 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -334,6 +334,9 @@ def physical_deflection_angle( z_s: Tensor Tensor of source redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. @@ -341,7 +344,8 @@ def physical_deflection_angle( ------- tuple[Tensor, Tensor] Tuple of Tensors representing the x and y components - of the deflection angle, respectively. + of the deflection angle, respectively + x_component: Tensor Deflection Angle @@ -750,6 +754,7 @@ def reduced_deflection_angle( -------- tuple[Tensor, Tensor] Reduced deflection angle in x and y directions. + x_component: Tensor Deflection Angle @@ -809,6 +814,7 @@ def physical_deflection_angle( ------- tuple[Tensor, Tensor] Physical deflection angle in x and y directions in arcseconds. + x_component: Tensor Deflection Angle @@ -1000,6 +1006,7 @@ def raytrace( ------- tuple[Tensor, Tensor] Ray-traced coordinates in the x and y directions. + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index 2b70ce60..b8830d1b 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -38,6 +38,9 @@ class EPL(ThinLens): In the context of gravitational lensing, the lens is the galaxy or other mass distribution that is bending the light from a more distant source. + + *Unit: unitless* + x0 and y0: Optional[Union[Tensor, float]] These are the coordinates of the lens center in the lens plane. The lens plane is the plane perpendicular to the line of sight @@ -48,16 +51,23 @@ class EPL(ThinLens): q: Optional[Union[Tensor, float]] This is the axis ratio of the lens, i.e., the ratio of the minor axis to the major axis of the elliptical lens. + + *Unit: unitless* + phi: Optional[Union[Tensor, float]] This is the orientation of the lens on the sky, typically given as an angle measured counter-clockwise from some reference direction. + *Unit: radians* + b: Optional[Union[Tensor, float]] This is the scale length of the lens, which sets the overall scale of the lensing effect. In some contexts, this is referred to as the Einstein radius. + *Unit: arcsec* + t: Optional[Union[Tensor, float]] This is the power-law slope parameter of the lens model. In the context of the EPL model, @@ -65,6 +75,8 @@ class EPL(ThinLens): where gamma is the power-law index of the radial mass distribution of the lens. + *Unit: unitless* + """ _null_params = { @@ -249,6 +261,8 @@ def _r_omega(self, z, t, q): q: Tensor Axis ratio. + *Unit: unitless* + Returns -------- Tensor diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index 466ff3dc..9c86b25a 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -110,6 +110,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index 9e3bc95d..40dd3762 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -105,6 +105,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index a3ff2632..c379b642 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -564,6 +564,9 @@ def convergence( z_s: Tensor Redshifts of the sources. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. diff --git a/src/caustics/lenses/pixelated_convergence.py b/src/caustics/lenses/pixelated_convergence.py index a707db24..d4e649a6 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -324,6 +324,17 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The x and y components of the deflection angles at the specified positions. + + x_component: Tensor + Deflection Angle + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle + + *Unit: arcsec* + """ if self.convolution_mode == "fft": deflection_angle_x_map, deflection_angle_y_map = self._deflection_angle_fft( diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index bbf56cbb..9c3d7cc7 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -148,6 +148,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The deflection angles in the x and y directions. + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index 03a90ad6..c9e0b79d 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -28,21 +28,34 @@ class PseudoJaffe(ThinLens): The cosmology used for calculations. z_l: Optional[Union[Tensor, float]] Redshift of the lens. + + *Unit: unitless* + x0: Optional[Union[Tensor, float]] x-coordinate of the center of the lens (arcsec). + *Unit: arcsec* + y0: Optional[Union[Tensor, float]] y-coordinate of the center of the lens (arcsec). + *Unit: arcsec* + mass: Optional[Union[Tensor, float]] Total mass of the lens (solMass). + *Unit: solMass* + core_radius: Optional[Union[Tensor, float]] Core radius of the lens (arcsec). + *Unit: arcsec* + scale_radius: Optional[Union[Tensor, float]] Scaling radius of the lens (arcsec). + *Unit: arcsec* + s: float Softening parameter to prevent numerical instabilities. """ @@ -78,21 +91,34 @@ def __init__( The cosmology used for calculations. z_l: Optional[Tensor] Redshift of the lens. + + *Unit: unitless* + x0: Optional[Tensor] x-coordinate of the center of the lens. + *Unit: arcsec* + y0: Optional[Tensor] y-coordinate of the center of the lens. + *Unit: arcsec* + mass: Optional[Tensor] Total mass of the lens (solMass). + *Unit: solMass* + core_radius: Optional[Tensor] Core radius of the lens. + *Unit: arcsec* + scale_radius: Optional[Tensor] Scaling radius of the lens. + *Unit: arcsec* + s: float Softening parameter to prevent numerical instabilities. """ @@ -145,10 +171,14 @@ def mass_enclosed_2d( ---------- theta: Tensor Radius at which to calculate enclosed mass (arcsec). + *Unit: arcsec* z_s: Tensor Source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. @@ -156,7 +186,9 @@ def mass_enclosed_2d( ------- Tensor The mass enclosed within the given radius. + *Unit: solMass* + """ # fmt: off theta = theta + self.s diff --git a/src/caustics/lenses/sie.py b/src/caustics/lenses/sie.py index f00f032c..55f49fa0 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -35,7 +35,7 @@ class SIE(ThinLens): y0: Optional[Union[Tensor, float]] The y-coordinate of the lens center. - *Unit: arcsec* + *Unit: arcsec* q: Optional[Union[Tensor, float]] The axis ratio of the lens. @@ -155,6 +155,9 @@ def reduced_deflection_angle( z_s: Tensor The source redshift. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container. diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index ea7459ba..ec417f4b 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -598,7 +598,7 @@ def physical_deflection_angle( z_l: Tensor Redshift of the lens. - + *Unit: unitless* x0: Tensor Center of lens position on x-axis (arcsec). @@ -632,6 +632,7 @@ def physical_deflection_angle( -------- tuple[Tensor, Tensor] The physical deflection angles in the x and y directions (arcsec). + x_component: Tensor Deflection Angle diff --git a/src/caustics/light/pixelated.py b/src/caustics/light/pixelated.py index bdb1d017..9d72c07b 100644 --- a/src/caustics/light/pixelated.py +++ b/src/caustics/light/pixelated.py @@ -25,10 +25,14 @@ class Pixelated(Source): ---------- x0 : Tensor, optional The x-coordinate of the source image's center. - *Unit: arcsec* + + *Unit: arcsec* + y0 : Tensor, optional The y-coordinate of the source image's center. + *Unit: arcsec* + image : Tensor, optional The source image from which brightness values will be interpolated. pixelscale : Tensor, optional @@ -55,10 +59,14 @@ def __init__( The name of the source. x0 : Tensor, optional The x-coordinate of the source image's center. + *Unit: arcsec* + y0 : Tensor, optional The y-coordinate of the source image's center. + *Unit: arcsec* + image : Tensor, optional The source image from which brightness values will be interpolated. pixelscale : Tensor, optional @@ -103,11 +111,15 @@ def brightness( x : Tensor The x-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* + y : Tensor The y-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* + params : Packed, optional A dictionary containing additional parameters that might be required to calculate the brightness. From ff61932d2b14784dabea6de1df7b9cb0b1354f1d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:16:38 +0000 Subject: [PATCH 10/14] style: pre-commit fixes --- src/caustics/lenses/base.py | 4 ++-- src/caustics/lenses/epl.py | 6 +++--- src/caustics/lenses/external_shear.py | 2 +- src/caustics/lenses/mass_sheet.py | 2 +- src/caustics/lenses/point.py | 2 +- src/caustics/lenses/pseudo_jaffe.py | 24 ++++++++++++------------ src/caustics/lenses/tnfw.py | 2 +- src/caustics/light/pixelated.py | 14 +++++++------- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index c1ed15b5..6fe3e977 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -345,7 +345,7 @@ def physical_deflection_angle( tuple[Tensor, Tensor] Tuple of Tensors representing the x and y components of the deflection angle, respectively - + x_component: Tensor Deflection Angle @@ -1006,7 +1006,7 @@ def raytrace( ------- tuple[Tensor, Tensor] Ray-traced coordinates in the x and y directions. - + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index b8830d1b..30fa29a2 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -58,14 +58,14 @@ class EPL(ThinLens): This is the orientation of the lens on the sky, typically given as an angle measured counter-clockwise from some reference direction. - + *Unit: radians* b: Optional[Union[Tensor, float]] This is the scale length of the lens, which sets the overall scale of the lensing effect. In some contexts, this is referred to as the Einstein radius. - + *Unit: arcsec* t: Optional[Union[Tensor, float]] @@ -75,7 +75,7 @@ class EPL(ThinLens): where gamma is the power-law index of the radial mass distribution of the lens. - *Unit: unitless* + *Unit: unitless* """ diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index 9c86b25a..d37c445b 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -110,7 +110,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. - + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index 40dd3762..fe02566c 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -105,7 +105,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The reduced deflection angles in the x and y directions. - + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index 9c3d7cc7..78dd73c8 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -148,7 +148,7 @@ def reduced_deflection_angle( ------- tuple[Tensor, Tensor] The deflection angles in the x and y directions. - + x_component: Tensor Deflection Angle diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index c9e0b79d..987c0ef2 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -33,27 +33,27 @@ class PseudoJaffe(ThinLens): x0: Optional[Union[Tensor, float]] x-coordinate of the center of the lens (arcsec). - + *Unit: arcsec* y0: Optional[Union[Tensor, float]] y-coordinate of the center of the lens (arcsec). - + *Unit: arcsec* mass: Optional[Union[Tensor, float]] Total mass of the lens (solMass). - + *Unit: solMass* core_radius: Optional[Union[Tensor, float]] Core radius of the lens (arcsec). - + *Unit: arcsec* scale_radius: Optional[Union[Tensor, float]] Scaling radius of the lens (arcsec). - + *Unit: arcsec* s: float @@ -96,27 +96,27 @@ def __init__( x0: Optional[Tensor] x-coordinate of the center of the lens. - + *Unit: arcsec* y0: Optional[Tensor] y-coordinate of the center of the lens. - + *Unit: arcsec* mass: Optional[Tensor] Total mass of the lens (solMass). - + *Unit: solMass* core_radius: Optional[Tensor] Core radius of the lens. - + *Unit: arcsec* scale_radius: Optional[Tensor] Scaling radius of the lens. - + *Unit: arcsec* s: float @@ -171,7 +171,7 @@ def mass_enclosed_2d( ---------- theta: Tensor Radius at which to calculate enclosed mass (arcsec). - + *Unit: arcsec* z_s: Tensor @@ -186,7 +186,7 @@ def mass_enclosed_2d( ------- Tensor The mass enclosed within the given radius. - + *Unit: solMass* """ diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index ec417f4b..edfd937e 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -632,7 +632,7 @@ def physical_deflection_angle( -------- tuple[Tensor, Tensor] The physical deflection angles in the x and y directions (arcsec). - + x_component: Tensor Deflection Angle diff --git a/src/caustics/light/pixelated.py b/src/caustics/light/pixelated.py index 9d72c07b..9c9c36ff 100644 --- a/src/caustics/light/pixelated.py +++ b/src/caustics/light/pixelated.py @@ -25,12 +25,12 @@ class Pixelated(Source): ---------- x0 : Tensor, optional The x-coordinate of the source image's center. - + *Unit: arcsec* - + y0 : Tensor, optional The y-coordinate of the source image's center. - + *Unit: arcsec* image : Tensor, optional @@ -59,12 +59,12 @@ def __init__( The name of the source. x0 : Tensor, optional The x-coordinate of the source image's center. - + *Unit: arcsec* y0 : Tensor, optional The y-coordinate of the source image's center. - + *Unit: arcsec* image : Tensor, optional @@ -111,13 +111,13 @@ def brightness( x : Tensor The x-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. - + *Unit: arcsec* y : Tensor The y-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. - + *Unit: arcsec* params : Packed, optional From 6aea7b7cf04e3a7d3ce0f1c0dcfd2da63da20987 Mon Sep 17 00:00:00 2001 From: uwcdc <127983572+uwcdc@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:29:25 -0800 Subject: [PATCH 11/14] docs: Updated units and formatting including cosmology, lenses, and sources --- src/caustics/cosmology.py | 19 ++-- src/caustics/lenses/base.py | 61 ++++++----- src/caustics/lenses/epl.py | 15 ++- src/caustics/lenses/external_shear.py | 18 ++-- src/caustics/lenses/mass_sheet.py | 35 ++++--- src/caustics/lenses/multiplane.py | 19 +++- src/caustics/lenses/nfw.py | 39 +++++-- src/caustics/lenses/pixelated_convergence.py | 59 ++++++----- src/caustics/lenses/point.py | 25 ++--- src/caustics/lenses/pseudo_jaffe.py | 20 ++-- src/caustics/lenses/sie.py | 17 ++- src/caustics/lenses/singleplane.py | 18 +++- src/caustics/lenses/sis.py | 20 ++-- src/caustics/lenses/tnfw.py | 105 ++++++++++--------- src/caustics/lenses/utils.py | 2 + src/caustics/light/base.py | 4 + src/caustics/light/pixelated.py | 22 +++- src/caustics/light/sersic.py | 3 + 18 files changed, 306 insertions(+), 195 deletions(-) diff --git a/src/caustics/cosmology.py b/src/caustics/cosmology.py index 0b5d4716..1879f041 100644 --- a/src/caustics/cosmology.py +++ b/src/caustics/cosmology.py @@ -48,6 +48,7 @@ class Cosmology(Parametrized): *Unit: megaparsec* Mass + *Unit: solMass* Attributes @@ -107,7 +108,7 @@ def comoving_distance( *Unit: unitless* - params: (Packed, optional0 + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -167,7 +168,7 @@ def comoving_distance_z1z2( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -199,7 +200,7 @@ def transverse_comoving_distance_z1z2( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -228,7 +229,7 @@ def angular_diameter_distance( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -260,7 +261,7 @@ def angular_diameter_distance_z1z2( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -297,7 +298,7 @@ def time_delay_distance( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -337,7 +338,7 @@ def critical_surface_density( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -456,7 +457,7 @@ def critical_density( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns @@ -519,7 +520,7 @@ def comoving_distance( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the computation. Returns diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 6fe3e977..dbf4de11 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -29,6 +29,7 @@ def __init__(self, cosmology: Cosmology, name: str = None): ---------- name: string The name of the lens model. + cosmology: Cosmology An instance of a Cosmology class that describes the cosmological parametersof the model. @@ -100,7 +101,7 @@ def magnification( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. Returns @@ -148,7 +149,7 @@ def forward_raytrace( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. epsilon: Tensor @@ -158,6 +159,9 @@ def forward_raytrace( n_init: int number of random initialization points used to try and find image plane points. + + *Unit: unitless* + fov: float the field of view in which the initial random samples are taken. @@ -165,8 +169,15 @@ def forward_raytrace( Returns ------- - tuple[Tensor, Tensor] - Ray-traced coordinates in the x and y directions. + x_component: Tensor + x-coordinate Tensor of the ray-traced light rays + + *Unit: arcsec* + + y_component: Tensor + y-coordinate Tensor of the ray-traced light rays + + *Unit: arcsec* """ bxy = torch.stack((bx, by)).repeat(n_init, 1) # has shape (n_init, Dout:2) @@ -246,6 +257,7 @@ def reduced_deflection_angle( z_s: Tensor Tensor of source redshifts. + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. @@ -299,7 +311,7 @@ def effective_reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. """ @@ -337,24 +349,20 @@ def physical_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. Returns ------- - tuple[Tensor, Tensor] - Tuple of Tensors representing the x and y components - of the deflection angle, respectively - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in x direction. - *Unit: arcsec* + *Unit: arcsec* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in y direction. - *Unit: arcsec* + *Unit: arcsec* """ raise NotImplementedError( @@ -697,14 +705,15 @@ class ThinLens(Lens): ---------- name: string Name of the lens model. + cosmology: Cosmology Cosmology object that encapsulates cosmological parameters and distances. + z_l: (Optional[Tensor], optional) Redshift of the lens. Defaults to None. *Unit: unitless* - """ def __init__( @@ -1004,19 +1013,15 @@ def raytrace( Returns ------- - tuple[Tensor, Tensor] - Ray-traced coordinates in the x and y directions. - - x_component: Tensor - Deflection Angle - - *Unit: arcsec* + x_component: Tensor + Deflection Angle in x direction. - y_component: Tensor - Deflection Angle + *Unit: arcsec* - *Unit: arcsec* + y_component: Tensor + Deflection Angle in y direction. + *Unit: arcsec* """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params, **kwargs) @@ -1083,8 +1088,10 @@ def time_delay( params: (Packed, optional) Dynamic parameter container for the lens model. Defaults to None. + shapiro_time_delay: bool Whether to include the Shapiro time delay component. + geometric_time_delay: bool Whether to include the geometric time delay component. diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index 30fa29a2..5f86e5fb 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -28,6 +28,7 @@ class EPL(ThinLens): s: float Softening length for the elliptical power-law profile. + *Unit: meters* @@ -215,17 +216,15 @@ def reduced_deflection_angle( Returns -------- - tuple[Tensor, Tensor] - Reduced deflection angles in the x and y directions. - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle - *Unit: arcsec* + *Unit: arcsec* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle - *Unit: arcsec* + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0, phi) diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index d37c445b..a82ae4a4 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -19,8 +19,10 @@ class ExternalShear(ThinLens): ---------- name: str Identifier for the lens instance. + cosmology: Cosmology The cosmological model used for lensing calculations. + z_l: Optional[Union[Tensor, float]] The redshift of the lens. @@ -108,18 +110,15 @@ def reduced_deflection_angle( Returns ------- - tuple[Tensor, Tensor] - The reduced deflection angles in the x and y directions. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in x-direction. - *Unit: arcsec* + *Unit: arcsec* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in y-direction. - *Unit: arcsec* + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0) @@ -220,6 +219,7 @@ def convergence( params: (Packed, optional) Dynamic parameter container. + Raises ------ NotImplementedError diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index fe02566c..4aa15224 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -20,20 +20,32 @@ class MassSheet(ThinLens): ---------- name: string Identifier for the lens instance. + cosmology: Cosmology The cosmological model used for lensing calculations. + z_l: Optional[Union[Tensor, float]] The redshift of the lens. *Unit: unitless* - x0, y0: Optional[Union[Tensor, float]] - Coordinates of the shear center in the lens plane. + x0: Optional[Union[Tensor, float]] + x-coordinate of the shear center in the lens plane. + + *Unit: arcsec* + + y0: Optional[Union[Tensor, float]] + y-coordinate of the shear center in the lens plane. *Unit: arcsec* - gamma_1, gamma_2: Optional[Union[Tensor, float]] - Shear components. + gamma_1: Optional[Union[Tensor, float]] + Shear component [--> domain expertise needed here <--]. + + *Unit: unitless* + + gamma_2: Optional[Union[Tensor, float]] + Shear component [--> domain expertise needed here <--]. *Unit: unitless* @@ -103,18 +115,15 @@ def reduced_deflection_angle( Returns ------- - tuple[Tensor, Tensor] - The reduced deflection angles in the x and y directions. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in x-direction. - *Unit: arcsec* + *Unit: arcsec* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in y-direction. - *Unit: arcsec* + *Unit: arcsec* """ x, y = translate_rotate(x, y, x0, y0) diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index 65cfed52..53c1c4e8 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -54,6 +54,8 @@ def get_z_ls( -------- List[Tensor] Redshifts of the lenses. + + *Unit: unitless* """ # Relies on z_l being the first element to be unpacked, which should always # be the case for a ThinLens @@ -190,13 +192,18 @@ def raytrace( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns ------- - (Tensor, Tensor) - The reduced deflection angle. + x_component: Tensor + Reduced deflection angle in the x-direction. + + *Unit: radians* + + y_component: Tensor + Reduced deflection angle in the y-direction. *Unit: radians* @@ -259,7 +266,7 @@ def surface_density( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -324,10 +331,12 @@ def time_delay( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. + shapiro_time_delay: bool Whether to include the Shapiro time delay component. + geometric_time_delay: bool Whether to include the geometric time delay component. diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index c379b642..64b5ac5a 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -63,6 +63,7 @@ class NFW(ThinLens): ------- get_scale_radius Returns the scale radius of the lens. + get_scale_density Returns the scale density of the lens. @@ -74,14 +75,19 @@ class NFW(ThinLens): Helper method for computing lensing potential. _h Helper method for computing reduced deflection angles. + deflection_angle_hat Computes the reduced deflection angle. + deflection_angle Computes the deflection angle. + convergence Computes the convergence (dimensionless surface mass density). + potential Computes the lensing potential. + """ _null_params = { @@ -110,9 +116,11 @@ def __init__( ---------- name: str Name of the lens instance. + cosmology: Cosmology An instance of the Cosmology class which contains information about the cosmological model and parameters. + z_l: Optional[Union[Tensor, float]] Redshift of the lens. Default is None. @@ -239,7 +247,7 @@ def get_scale_density( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -291,7 +299,7 @@ def get_convergence_s( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -317,6 +325,8 @@ def _f_differentiable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor @@ -341,6 +351,8 @@ def _f_batchable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor @@ -373,6 +385,8 @@ def _g_differentiable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor @@ -398,6 +412,8 @@ def _g_batchable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor @@ -429,6 +445,8 @@ def _h_differentiable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor @@ -453,6 +471,8 @@ def _h_batchable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor @@ -506,13 +526,18 @@ def reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns ------- - tuple[Tensor, Tensor] - The reduced deflection angles in the x and y directions. + x_component: Tensor + The x-component of the reduced deflection angle. + + *Unit: radians* + + y_component: Tensor + The y-component of the reduced deflection angle. *Unit: radians* @@ -567,7 +592,7 @@ def convergence( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -622,7 +647,7 @@ def potential( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns diff --git a/src/caustics/lenses/pixelated_convergence.py b/src/caustics/lenses/pixelated_convergence.py index d4e649a6..d995af20 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -51,6 +51,7 @@ def __init__( ---------- name: string The name of the PixelatedConvergence object. + fov: float The field of view in arcseconds. @@ -63,6 +64,7 @@ def __init__( cosmology: Cosmology An instance of the cosmological parameters. + z_l: Optional[Tensor] The redshift of the lens. @@ -88,14 +90,14 @@ def __init__( *Unit: unitless* - convolution_mode: (str, optional) + convolution_mode: str, optional The convolution mode for calculating deflection angles and lensing potential. It can be either "fft" (Fast Fourier Transform) or "conv2d" (2D convolution). Default is "fft". *Unit: unitless* - use_next_fast_len: (bool, optional) + use_next_fast_len: bool, optional If True, adds additional padding to speed up the FFT by calling `scipy.fft.next_fast_len`. The speed boost can be substantial when `n_pix` is a multiple of a @@ -105,8 +107,6 @@ def __init__( padding: { "zero", "circular", "reflect", "tile" } - *Unit: unitless* - Specifies the type of padding to use: "zero" will do zero padding, "circular" will do cyclic boundaries. @@ -116,6 +116,8 @@ def __init__( Generally you should use either "zero" or "tile". + *Unit: unitless* + """ super().__init__(cosmology, z_l, name=name) @@ -169,8 +171,10 @@ def to( ---------- device: Optional[torch.device] The target device to move the tensors to. + dtype: Optional[torch.dtype] The target data type to cast the tensors to. + """ super().to(device, dtype) self.potential_kernel = self.potential_kernel.to(device=device, dtype=dtype) @@ -191,10 +195,15 @@ def _fft2_padded(self, x: Tensor) -> Tensor: x: Tensor The input tensor to be transformed. + *Unit: unitless* + Returns ------- Tensor The 2D FFT of the input tensor with zero-padding. + + *Unit: unitless* + """ pad = 2 * self.n_pix if self.use_next_fast_len: @@ -227,6 +236,9 @@ def _unpad_fft(self, x: Tensor) -> Tensor: ------- Tensor The input tensor without padding. + + *Unit: unitless* + """ return torch.roll(x, (-self._s[0] // 2, -self._s[1] // 2), dims=(-2, -1))[..., : self.n_pix, : self.n_pix] # fmt: skip @@ -243,6 +255,7 @@ def _unpad_conv2d(self, x: Tensor) -> Tensor: ------- Tensor The input tensor without padding. + """ return x # noqa: E501 torch.roll(x, (-self.padding_range * self.ax_kernel.shape[0]//4,-self.padding_range * self.ax_kernel.shape[1]//4), dims = (-2,-1))[..., :self.n_pix, :self.n_pix] #[..., 1:, 1:] @@ -255,6 +268,7 @@ def convolution_mode(self): ------- string The convolution mode, either "fft" or "conv2d". + """ return self._convolution_mode @@ -267,6 +281,7 @@ def convolution_mode(self, convolution_mode: str): ---------- mode: string The convolution mode to be set, either "fft" or "conv2d". + """ if convolution_mode == "fft": # Create FFTs of kernels @@ -317,7 +332,7 @@ def reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional A dictionary containing additional parameters. Returns @@ -328,12 +343,12 @@ def reduced_deflection_angle( x_component: Tensor Deflection Angle - *Unit: arcsec* + *Unit: radians* y_component: Tensor Deflection Angle - *Unit: arcsec* + *Unit: radians* """ if self.convolution_mode == "fft": @@ -368,18 +383,15 @@ def _deflection_angle_fft(self, convergence_map: Tensor) -> tuple[Tensor, Tensor Returns ------- - tuple[Tensor, Tensor] - The x and y components of the deflection angles. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in x-component. - *Unit: arcsec* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in y-component. - *Unit: arcsec* + *Unit: radians* """ convergence_tilde = self._fft2_padded(convergence_map) @@ -406,17 +418,15 @@ def _deflection_angle_conv2d( Returns ------- - tuple[Tensor, Tensor] - The x and y components of the deflection angles. - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle - *Unit: arcsec* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle - *Unit: arcsec* + *Unit: radians* """ # Use convergence_map as kernel since the kernel is twice as large. Flip since @@ -591,6 +601,7 @@ def convergence( ------ NotImplementedError This method is not implemented. + """ return interp2d( convergence_map, diff --git a/src/caustics/lenses/point.py b/src/caustics/lenses/point.py index 78dd73c8..28b3a104 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -20,8 +20,10 @@ class Point(ThinLens): ---------- name: str The name of the point lens. + cosmology: Cosmology The cosmology used for calculations. + z_l: Optional[Union[Tensor, float]] Redshift of the lens. @@ -72,8 +74,10 @@ def __init__( ---------- name: string The name of the point lens. + cosmology: Cosmology The cosmology used for calculations. + z_l: Optional[Tensor] Redshift of the lens. @@ -141,23 +145,20 @@ def reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns ------- - tuple[Tensor, Tensor] - The deflection angles in the x and y directions. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in the x-direction. - *Unit: arcsec* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in the y-direction. - *Unit: arcsec* + *Unit: radians* """ x, y = translate_rotate(x, y, x0, y0) @@ -200,7 +201,7 @@ def potential( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -249,7 +250,7 @@ def convergence( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns diff --git a/src/caustics/lenses/pseudo_jaffe.py b/src/caustics/lenses/pseudo_jaffe.py index 987c0ef2..b9eb4dc6 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -87,8 +87,10 @@ def __init__( ---------- name: string The name of the Pseudo Jaffe lens. + cosmology: Cosmology The cosmology used for calculations. + z_l: Optional[Tensor] Redshift of the lens. @@ -121,6 +123,7 @@ def __init__( s: float Softening parameter to prevent numerical instabilities. + """ super().__init__(cosmology, z_l, name=name) @@ -179,7 +182,7 @@ def mass_enclosed_2d( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -289,13 +292,18 @@ def reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns -------- - Tuple[Tensor, Tensor] - The deflection angle in the x and y directions. + x_component: Tensor + x-component of the deflection angle. + + *Unit: radians* + + y_component: Tensor + y-component of the deflection angle. *Unit: radians* @@ -344,7 +352,7 @@ def potential( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -413,7 +421,7 @@ def convergence( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns diff --git a/src/caustics/lenses/sie.py b/src/caustics/lenses/sie.py index 55f49fa0..779c8701 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -20,8 +20,10 @@ class SIE(ThinLens): ---------- name: str The name of the lens. + cosmology: Cosmology An instance of the Cosmology class. + z_l: Optional[Union[Tensor, float]] The redshift of the lens. @@ -158,13 +160,18 @@ def reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns -------- - Tuple[Tensor, Tensor] - The deflection angle in the x and y directions. + x_component: Tensor + The x-component of the deflection angle. + + *Unit: radians* + + y_component: Tensor + The y-component of the deflection angle. *Unit: radians* @@ -213,7 +220,7 @@ def potential( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -265,7 +272,7 @@ def convergence( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns diff --git a/src/caustics/lenses/singleplane.py b/src/caustics/lenses/singleplane.py index 5a93ff1b..82ba54fb 100644 --- a/src/caustics/lenses/singleplane.py +++ b/src/caustics/lenses/singleplane.py @@ -20,10 +20,13 @@ class SinglePlane(ThinLens): ---------- name: str The name of the single plane lens. + cosmology: Cosmology An instance of the Cosmology class. + lenses: List[ThinLens] A list of ThinLens objects that are being combined into a single lensing plane. + """ def __init__( @@ -69,13 +72,18 @@ def reduced_deflection_angle( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns ------- - Tuple[Tensor, Tensor] - The total deflection angle in the x and y directions. + x_component: Tensor + The x-component of the deflection angle. + + *Unit: radians* + + y_component: Tensor + The y-component of the deflection angle. *Unit: radians* @@ -119,7 +127,7 @@ def convergence( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns @@ -167,7 +175,7 @@ def potential( *Unit: unitless* - params: (Packed, optional) + params: Packed, optional Dynamic parameter container. Returns diff --git a/src/caustics/lenses/sis.py b/src/caustics/lenses/sis.py index 0e64cdd1..ff515d8c 100644 --- a/src/caustics/lenses/sis.py +++ b/src/caustics/lenses/sis.py @@ -20,8 +20,10 @@ class SIS(ThinLens): ---------- name: str The name of the SIS lens. + cosmology: Cosmology An instance of the Cosmology class. + z_l: Optional[Union[Tensor, float]] The lens redshift. @@ -37,7 +39,8 @@ class SIS(ThinLens): *Unit: arcsec* - th_ein (Optional[Union[Tensor, float]]): The Einstein radius of the lens. + th_ein (Optional[Union[Tensor, float]]) + The Einstein radius of the lens. *Unit: arcsec* @@ -113,18 +116,15 @@ def reduced_deflection_angle( Returns ------- - Tuple[Tensor, Tensor] - The deflection angle in the x and y directions. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle - *Unit: arcsec* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle - *Unit: arcsec* + *Unit: radians* """ x, y = translate_rotate(x, y, x0, y0) diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index edfd937e..a0164c71 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -45,21 +45,23 @@ class TNFW(ThinLens): ----- name: string Name of the lens instance. + cosmology: Cosmology An instance of the Cosmology class which contains information about the cosmological model and parameters. + z_l: Optional[Tensor] Redshift of the lens. *Unit: unitless* x0: Optional[Tensor] - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Optional[Tensor] - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -69,12 +71,12 @@ class TNFW(ThinLens): *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* @@ -194,34 +196,35 @@ def get_concentration( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (solMass). + Mass of the lens. *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. + params: dict Dynamic parameter container. Returns ------- Tensor - The scale radius of the lens in Mpc. + The scale radius of the lens. *Unit: megaparsec* @@ -255,12 +258,12 @@ def get_truncation_radius( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -270,12 +273,12 @@ def get_truncation_radius( *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* @@ -285,7 +288,7 @@ def get_truncation_radius( Returns ------- Tensor - The truncation radius of the lens in arcsec. + The truncation radius of the lens. *Unit: arcsec* @@ -318,12 +321,12 @@ def get_M0( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -333,12 +336,12 @@ def get_M0( *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* @@ -383,12 +386,12 @@ def get_scale_density( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -398,12 +401,12 @@ def get_scale_density( *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* @@ -413,7 +416,7 @@ def get_scale_density( Returns -------- Tensor - The scale density of the lens in solar masses per Mpc cubed. + The scale density of the lens. *Unit: solMass/Mpc^3* @@ -449,12 +452,12 @@ def convergence( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -464,19 +467,22 @@ def convergence( *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. + + *Unit: unitless* + params: dict Dynamic parameter container. Returns --------- Tensor - unitless convergence at requested position + Convergence at requested position. *Unit: unitless* @@ -525,12 +531,12 @@ def mass_enclosed_2d( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -540,12 +546,12 @@ def mass_enclosed_2d( *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* @@ -601,12 +607,12 @@ def physical_deflection_angle( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* @@ -616,12 +622,12 @@ def physical_deflection_angle( *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* @@ -630,18 +636,15 @@ def physical_deflection_angle( Returns -------- - tuple[Tensor, Tensor] - The physical deflection angles in the x and y directions (arcsec). - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in x-direction. - *Unit: arcsec* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in y-direction. - *Unit: arcsec* + *Unit: radians* """ d_l = self.cosmology.angular_diameter_distance(z_l, params) @@ -687,27 +690,27 @@ def potential( *Unit: unitless* x0: Tensor - Center of lens position on x-axis (arcsec). + Center of lens position on x-axis. *Unit: arcsec* y0: Tensor - Center of lens position on y-axis (arcsec). + Center of lens position on y-axis. *Unit: arcsec* mass: Optional[Tensor] - Mass of the lens (solMass). + Mass of the lens. *Unit: solMass* scale_radius: Optional[Tensor] - Scale radius of the TNFW lens (arcsec). + Scale radius of the TNFW lens. *Unit: arcsec* tau: Optional[Tensor] - Truncation scale. Ratio of truncation radius to scale radius (rt/rs). + Truncation scale. Ratio of truncation radius to scale radius. *Unit: unitless* diff --git a/src/caustics/lenses/utils.py b/src/caustics/lenses/utils.py index 432473ff..6db5f014 100644 --- a/src/caustics/lenses/utils.py +++ b/src/caustics/lenses/utils.py @@ -55,6 +55,7 @@ def get_pix_magnification(raytrace, x, y, z_s) -> Tensor: ---------- raytrace: function A function that maps the lensing plane coordinates to the source plane coordinates. + x: Tensor The x-coordinate on the lensing plane. @@ -92,6 +93,7 @@ def get_magnification(raytrace, x, y, z_s) -> Tensor: ---------- raytrace: function A function that maps the lensing plane coordinates to the source plane coordinates. + x: Tensor The x-coordinates on the lensing plane. diff --git a/src/caustics/light/base.py b/src/caustics/light/base.py index 7f7b9d0d..505a6bf0 100644 --- a/src/caustics/light/base.py +++ b/src/caustics/light/base.py @@ -41,11 +41,15 @@ def brightness( the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* + y: Tensor The y-coordinate(s) at which to calculate the source brightness. This could be a single value or a tensor of values. + *Unit: arcsec* + params: Packed, optional Dynamic parameter container that might be required to calculate the brightness. diff --git a/src/caustics/light/pixelated.py b/src/caustics/light/pixelated.py index 9c9c36ff..86e2ade8 100644 --- a/src/caustics/light/pixelated.py +++ b/src/caustics/light/pixelated.py @@ -35,10 +35,15 @@ class Pixelated(Source): image : Tensor, optional The source image from which brightness values will be interpolated. + pixelscale : Tensor, optional - The pixelscale of the source image in the lens plane in units of arcsec/pixel. - shape : tuple of ints, optional + The pixelscale of the source image in the lens plane. + + *Unit: arcsec/pixel* + + shape : Tuple of ints, optional The shape of the source image. + """ def __init__( @@ -57,6 +62,7 @@ def __init__( ---------- name : str The name of the source. + x0 : Tensor, optional The x-coordinate of the source image's center. @@ -69,10 +75,15 @@ def __init__( image : Tensor, optional The source image from which brightness values will be interpolated. + pixelscale : Tensor, optional - The pixelscale of the source image in the lens plane in units of arcsec/pixel. - shape : tuple of ints, optional + The pixelscale of the source image in the lens plane. + + *Unit: arcsec/pixel* + + shape : Tuple of ints, optional The shape of the source image. + """ if image is not None and image.ndim not in [2, 3]: raise ValueError( @@ -130,6 +141,9 @@ def brightness( The brightness of the source at the given coordinate(s). The brightness is determined by interpolating values from the source image. + + *Unit: unitless* + """ fov_x = pixelscale * image.shape[0] fov_y = pixelscale * image.shape[1] diff --git a/src/caustics/light/sersic.py b/src/caustics/light/sersic.py index f5648c46..ded71f4d 100644 --- a/src/caustics/light/sersic.py +++ b/src/caustics/light/sersic.py @@ -89,6 +89,7 @@ def __init__( ---------- name: str The name of the source. + x0: Optional[Tensor] The x-coordinate of the Sersic source's center. @@ -187,6 +188,8 @@ def brightness( The brightness of the source at the given point(s). The output tensor has the same shape as `x` and `y`. + *Unit: unitless* + Notes ----- The Sersic profile is defined as: I(r) = Ie * exp(-k * ((r / r_e)^(1/n) - 1)), From 5e669d9eb4e3ed2d0d50df8cfc7a1a159a9a605a Mon Sep 17 00:00:00 2001 From: Cordero Core <127983572+uwcdc@users.noreply.github.com> Date: Thu, 15 Feb 2024 10:19:09 -0800 Subject: [PATCH 12/14] fix: Removed tuple and moved returns --- src/caustics/lenses/pixelated_convergence.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/caustics/lenses/pixelated_convergence.py b/src/caustics/lenses/pixelated_convergence.py index d995af20..3d24fff4 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -337,18 +337,15 @@ def reduced_deflection_angle( Returns ------- - tuple[Tensor, Tensor] - The x and y components of the deflection angles at the specified positions. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in the x-direction. - *Unit: radians* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in the y-direction. - *Unit: radians* + *Unit: radians* """ if self.convolution_mode == "fft": From 0b6c1277a45312b0b0ed4f0cb15f04ff49d03bc0 Mon Sep 17 00:00:00 2001 From: Cordero Core <127983572+uwcdc@users.noreply.github.com> Date: Thu, 15 Feb 2024 10:24:18 -0800 Subject: [PATCH 13/14] fix: Remove tuple from return and moved separated returns --- src/caustics/lenses/base.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index dbf4de11..98c73b47 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -761,18 +761,15 @@ def reduced_deflection_angle( Returns -------- - tuple[Tensor, Tensor] - Reduced deflection angle in x and y directions. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in the x-direction. - *Unit: arcsec* + *Unit: radians* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in the y-direction. - *Unit: arcsec* + *Unit: radians* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) @@ -821,18 +818,15 @@ def physical_deflection_angle( Returns ------- - tuple[Tensor, Tensor] - Physical deflection angle in x and y directions in arcseconds. - - x_component: Tensor - Deflection Angle + x_component: Tensor + Deflection Angle in x-direction. - *Unit: arcsec* + *Unit: arcsec* - y_component: Tensor - Deflection Angle + y_component: Tensor + Deflection Angle in y-direction. - *Unit: arcsec* + *Unit: arcsec* """ d_s = self.cosmology.angular_diameter_distance(z_s, params) @@ -883,6 +877,7 @@ def convergence( ------- Tensor Convergence at the given coordinates. + """ ... From d8f5a83f73d191742d35344ae262741b05ad99b4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:24:32 +0000 Subject: [PATCH 14/14] style: pre-commit fixes --- src/caustics/lenses/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 98c73b47..51b829f4 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -877,7 +877,7 @@ def convergence( ------- Tensor Convergence at the given coordinates. - + """ ...