diff --git a/src/caustics/cosmology/base.py b/src/caustics/cosmology/base.py index 31528f1d..4576eba0 100644 --- a/src/caustics/cosmology/base.py +++ b/src/caustics/cosmology/base.py @@ -17,12 +17,13 @@ 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: megaparsec* + Mass - solar mass + + *Unit: solMass* Attributes ---------- @@ -50,6 +51,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. @@ -57,6 +61,9 @@ def critical_density(self, z: Tensor, params: Optional["Packed"] = None) -> Tens ------- Tensor The critical density at each redshift. + + *Unit: solMass/megaparsec^3* + """ ... @@ -72,13 +79,19 @@ def comoving_distance( ---------- z: Tensor The redshifts. - params: (Packed, optional0 + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- Tensor The comoving distance to each redshift. + + *Unit: megaparsec* + """ ... @@ -94,6 +107,9 @@ def transverse_comoving_distance( ---------- z: Tensor The redshifts. + + *Unit: unitless* + params: (Packed, optional) Dynamic parameter container for the computation. @@ -101,6 +117,9 @@ def transverse_comoving_distance( ------- Tensor The transverse comoving distance to each redshift in Mpc. + + *Unit: megaparsec* + """ ... @@ -115,15 +134,24 @@ def comoving_distance_z1z2( ---------- z1: Tensor The starting redshifts. + + *Unit: unitless* + z2: Tensor The ending redshifts. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- Tensor The comoving distance between each pair of redshifts. + + *Unit: megaparsec* + """ return self.comoving_distance(z2, params) - self.comoving_distance(z1, params) @@ -138,15 +166,24 @@ def transverse_comoving_distance_z1z2( ---------- z1: Tensor The starting redshifts. + + *Unit: unitless* + z2: Tensor The ending redshifts. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- Tensor The transverse comoving distance between each pair of redshifts in Mpc. + + *Unit: megaparsec* + """ return self.transverse_comoving_distance( z2, params @@ -163,13 +200,19 @@ def angular_diameter_distance( ----------- z: Tensor The redshifts. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- Tensor The angular diameter distance to each redshift. + + *Unit: megaparsec* + """ return self.comoving_distance(z, params, **kwargs) / (1 + z) @@ -184,15 +227,24 @@ def angular_diameter_distance_z1z2( ---------- z1: Tensor The starting redshifts. + + *Unit: unitless* + z2: Tensor The ending redshifts. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- Tensor The angular diameter distance between each pair of redshifts. + + *Unit: megaparsec* + """ return self.comoving_distance_z1z2(z1, z2, params, **kwargs) / (1 + z2) @@ -212,15 +264,24 @@ def time_delay_distance( ---------- z_l: Tensor The lens redshifts. + + *Unit: unitless* + z_s: Tensor The source redshifts. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- 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) @@ -243,15 +304,24 @@ def critical_surface_density( ---------- z_l: Tensor The lens redshifts. + + *Unit: unitless* + z_s: Tensor The source redshifts. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the computation. Returns ------- 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) diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index 9dced0dd..f184d996 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -30,6 +30,7 @@ def __init__(self, cosmology: Cosmology, name: Optional[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. @@ -88,17 +89,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. Returns ------- Tensor Gravitational magnification at the given coordinates. + + *Unit: unitless* + """ return get_magnification(partial(self.raytrace, params=params), x, y, z_s) @@ -121,24 +134,49 @@ 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. - params: (Packed, optional) + + *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. + + *Unit: unitless* + fov: float the field of view in which the initial random samples are taken. + *Unit: arcsec* + 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) @@ -208,10 +246,17 @@ 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 Dynamic parameter container for the lens model. Defaults to None. @@ -252,11 +297,20 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container for the lens model. Defaults to None. """ @@ -281,18 +335,33 @@ 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) + + *Unit: unitless* + + 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 in x direction. + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle in y direction. + + *Unit: arcsec* """ raise NotImplementedError( @@ -320,10 +389,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. @@ -331,9 +409,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* + """ ... @@ -355,10 +438,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. @@ -367,6 +459,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* + """ ... @@ -388,10 +483,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. @@ -399,6 +503,9 @@ def time_delay( ------- Tensor The gravitational time delay at the given coordinates. + + *Unit: milliseconds* + """ ... @@ -597,11 +704,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__( @@ -631,17 +742,34 @@ 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. Returns -------- - tuple[Tensor, Tensor] - Reduced deflection angle in x and y directions. + x_component: Tensor + Deflection Angle in the x-direction. + + *Unit: radians* + + y_component: Tensor + Deflection Angle in the y-direction. + + *Unit: radians* + """ d_s = self.cosmology.angular_diameter_distance(z_s, params) d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params) @@ -671,17 +799,34 @@ 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. Returns ------- - tuple[Tensor, Tensor] - Physical deflection angle in x and y directions in arcseconds. + x_component: Tensor + Deflection Angle in x-direction. + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle in y-direction. + + *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) @@ -711,10 +856,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. @@ -722,6 +876,7 @@ def convergence( ------- Tensor Convergence at the given coordinates. + """ ... @@ -743,10 +898,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. @@ -754,6 +918,9 @@ def potential( ------- Tensor Gravitational lensing potential at the given coordinates in arcsec^2. + + *Unit: arsec^2* + """ ... @@ -775,10 +942,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. @@ -786,6 +962,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 @@ -810,17 +989,34 @@ 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. Returns ------- - tuple[Tensor, Tensor] - Ray-traced coordinates in the x and y directions. + x_component: Tensor + Deflection Angle in x direction. + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle in y direction. + + *Unit: arcsec* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params, **kwargs) return x - ax, y - ay @@ -866,16 +1062,30 @@ 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 Whether to include the Shapiro time delay component. + geometric_time_delay: bool Whether to include the geometric time delay component. @@ -884,6 +1094,8 @@ def time_delay( Tensor Time delay at the given coordinates. + *Unit: milliseconds* + References ---------- 1. Irwin I. Shapiro (1964). "Fourth Test of General Relativity". Physical Review Letters. 13 (26): 789-791 diff --git a/src/caustics/lenses/epl.py b/src/caustics/lenses/epl.py index d4b09577..8c8f6d9d 100644 --- a/src/caustics/lenses/epl.py +++ b/src/caustics/lenses/epl.py @@ -29,6 +29,10 @@ class EPL(ThinLens): s: float Softening length for the elliptical power-law profile. + + *Unit: meters* + + Parameters ---------- z_l: Optional[Union[Tensor, float]] @@ -36,21 +40,36 @@ 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 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. + + *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, @@ -58,6 +77,8 @@ class EPL(ThinLens): where gamma is the power-law index of the radial mass distribution of the lens. + *Unit: unitless* + """ _null_params = { @@ -95,26 +116,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. """ @@ -154,17 +199,34 @@ 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. Returns -------- - tuple[Tensor, Tensor] - 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) @@ -188,15 +250,26 @@ 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. + *Unit: unitless* + Returns -------- Tensor The value of `R * omega(phi)`. + + *Unit: meters* + """ # constants f = (1.0 - q) / (1.0 + q) @@ -237,10 +310,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. @@ -248,6 +330,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) @@ -278,10 +363,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. @@ -289,6 +383,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 3f4c226a..d67a7275 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -19,15 +19,25 @@ 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. + + *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 @@ -82,17 +92,34 @@ 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. Returns ------- - tuple[Tensor, Tensor] - The reduced deflection angles in the x and y directions. + x_component: Tensor + Deflection Angle in x-direction. + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle in y-direction. + + *Unit: arcsec* + """ x, y = translate_rotate(x, y, x0, y0) # Meneghetti eq 3.83 @@ -127,10 +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. @@ -138,6 +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) @@ -165,10 +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. diff --git a/src/caustics/lenses/mass_sheet.py b/src/caustics/lenses/mass_sheet.py index 612e5e2d..76b46aa1 100644 --- a/src/caustics/lenses/mass_sheet.py +++ b/src/caustics/lenses/mass_sheet.py @@ -21,14 +21,34 @@ 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. - x0, y0: Optional[Union[Tensor, float]] - Coordinates of the shear center in the lens plane. - gamma_1, gamma_2: Optional[Union[Tensor, float]] - Shear components. + + *Unit: unitless* + + 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: 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* Notes ------ @@ -78,17 +98,34 @@ 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. Returns ------- - tuple[Tensor, Tensor] - The reduced deflection angles in the x and y directions. + x_component: Tensor + Deflection Angle in x-direction. + + *Unit: arcsec* + + y_component: Tensor + Deflection Angle in y-direction. + + *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 90b6f812..4edc79ae 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -56,6 +56,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 @@ -177,17 +179,33 @@ 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) + + *Unit: unitless* + + 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* References ---------- @@ -235,17 +253,28 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor - Projected mass density [solMass / Mpc^2]. + Projected mass density. + + *Unit: solMass / megaparsec^2* Raises ------- @@ -289,14 +318,25 @@ 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) + + *Unit: unitless* + + 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. @@ -305,6 +345,8 @@ def time_delay( Tensor Time delay caused by the lensing. + *Unit: seconds* + References ---------- 1. Petters A. O., Levine H., Wambsganss J., 2001, Singularity Theory and Gravitational Lensing. Birkhauser, Boston diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index 148ac1ae..25037c5a 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -27,16 +27,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 @@ -46,8 +64,10 @@ class NFW(ThinLens): ------- get_scale_radius Returns the scale radius of the lens. + get_scale_density Returns the scale density of the lens. + get_convergence_s Returns the dimensionless surface mass density of the lens. _f @@ -56,14 +76,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 = { @@ -92,24 +117,44 @@ 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. + + *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) @@ -148,10 +193,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. @@ -159,6 +213,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 @@ -183,15 +240,24 @@ def get_scale_density( ---------- z_l: Tensor Redshift of the lens. + + *Unit: unitless* + c: Tensor Concentration parameter of the lens. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- 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 @@ -216,19 +282,34 @@ 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. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor The dimensionless surface mass density of the lens. + + *Unit: unitless* + """ critical_surface_density = self.cosmology.critical_surface_density( z_l, z_s, params @@ -245,10 +326,15 @@ def _f_differentiable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor Result of the deflection angle computation. + + *Unit: radians* + """ # TODO: generalize beyond torch, or patch Tensor f = torch.zeros_like(x) @@ -266,10 +352,15 @@ def _f_batchable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor Result of the deflection angle computation. + + *Unit: radians* + """ # TODO: generalize beyond torch, or patch Tensor # fmt: off @@ -295,10 +386,15 @@ def _g_differentiable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor Result of the lensing potential computation. + + *Unit: arcsec^2* + """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 @@ -317,10 +413,15 @@ def _g_batchable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor Result of the lensing potential computation. + + *Unit: arcsec^2* + """ # TODO: generalize beyond torch, or patch Tensor term_1 = (x / 2).log() ** 2 @@ -345,10 +446,15 @@ def _h_differentiable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor Result of the reduced deflection angle computation. + + *Unit: radians* + """ term_1 = (x / 2).log() term_2 = torch.ones_like(x) @@ -366,10 +472,15 @@ def _h_batchable(x: Tensor) -> Tensor: x: Tensor The scaled radius (xi / xi_0). + *Unit: unitless* + Returns ------- Tensor Result of the reduced deflection angle computation. + + *Unit: radians* + """ term_1 = (x / 2).log() term_2 = torch.where( @@ -403,17 +514,34 @@ 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) + + *Unit: unitless* + + 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* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -452,17 +580,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- 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 @@ -495,17 +635,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- 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 af2b84f5..d4755436 100644 --- a/src/caustics/lenses/pixelated_convergence.py +++ b/src/caustics/lenses/pixelated_convergence.py @@ -52,31 +52,60 @@ def __init__( ---------- name: string 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. - convolution_mode: (str, optional) + + *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". - use_next_fast_len: (bool, optional) + + *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" } Specifies the type of padding to use: @@ -88,6 +117,8 @@ def __init__( Generally you should use either "zero" or "tile". + *Unit: unitless* + """ super().__init__(cosmology, z_l, name=name) @@ -141,8 +172,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) @@ -163,10 +196,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: @@ -193,10 +231,15 @@ def _unpad_fft(self, x: Tensor) -> Tensor: x: Tensor The input tensor with padding. + *Unit: arcsec* + Returns ------- 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 @@ -213,6 +256,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:] @@ -225,6 +269,7 @@ def convolution_mode(self): ------- string The convolution mode, either "fft" or "conv2d". + """ return self._convolution_mode @@ -237,6 +282,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 @@ -274,17 +320,34 @@ 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) + + *Unit: unitless* + + params: Packed, optional A dictionary containing additional parameters. Returns ------- - tuple[Tensor, Tensor] - The x and y components of the deflection angles at the specified positions. + x_component: Tensor + Deflection Angle in the x-direction. + + *Unit: radians* + + y_component: Tensor + Deflection Angle in the y-direction. + + *Unit: radians* + """ if self.convolution_mode == "fft": deflection_angle_x_map, deflection_angle_y_map = self._deflection_angle_fft( @@ -314,10 +377,20 @@ 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 in x-component. + + *Unit: radians* + + y_component: Tensor + Deflection Angle in y-component. + + *Unit: radians* + """ convergence_tilde = self._fft2_padded(convergence_map) deflection_angle_x = torch.fft.irfft2( @@ -339,10 +412,20 @@ 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: radians* + + y_component: Tensor + Deflection Angle + + *Unit: radians* + """ # Use convergence_map as kernel since the kernel is twice as large. Flip since # we actually want the cross-correlation. @@ -381,10 +464,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. @@ -392,6 +484,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) @@ -413,10 +508,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( @@ -433,10 +533,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. @@ -467,10 +572,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. @@ -479,10 +593,13 @@ def convergence( Tensor The convergence at the specified positions. + *Unit: unitless* + Raises ------ 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 619a1482..f1dc9bb2 100644 --- a/src/caustics/lenses/point.py +++ b/src/caustics/lenses/point.py @@ -21,18 +21,35 @@ 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. + + *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 = { @@ -58,18 +75,35 @@ 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. + + *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* + s: float Softening parameter to prevent numerical instabilities. + + *Unit: meters* + """ super().__init__(cosmology, z_l, name=name) @@ -99,17 +133,34 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- - tuple[Tensor, Tensor] - The deflection angles in the x and y directions. + x_component: Tensor + Deflection Angle in the x-direction. + + *Unit: radians* + + y_component: Tensor + Deflection Angle in the y-direction. + + *Unit: radians* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -138,17 +189,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor The lensing potential. + + *Unit: arcsec^2* + """ x, y = translate_rotate(x, y, x0, y0) th = (x**2 + y**2).sqrt() + self.s @@ -175,17 +238,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns -------- 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 ebf1cb3b..63fa0506 100644 --- a/src/caustics/lenses/pseudo_jaffe.py +++ b/src/caustics/lenses/pseudo_jaffe.py @@ -29,16 +29,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 (Msol). + 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. """ @@ -70,22 +88,43 @@ 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. + + *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 (Msol). + 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. + """ super().__init__(cosmology, z_l, name=name) @@ -136,15 +175,24 @@ def mass_enclosed_2d( ---------- theta: Tensor Radius at which to calculate enclosed mass (arcsec). + + *Unit: arcsec* + z_s: Tensor Source redshift. - params: (Packed, optional) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor The mass enclosed within the given radius. + + *Unit: solMass* + """ # fmt: off theta = theta + self.s @@ -174,14 +222,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. @@ -189,6 +252,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 @@ -214,17 +280,34 @@ 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) + + *Unit: unitless* + + 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* + """ x, y = translate_rotate(x, y, x0, y0) R = (x**2 + y**2).sqrt() + self.s @@ -257,17 +340,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns -------- Tensor The lensing potential (arcsec^2). + + *Unit: arcsec^2* + """ # fmt: off @@ -314,17 +409,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- 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 85f6dde9..ba9d08fe 100644 --- a/src/caustics/lenses/sie.py +++ b/src/caustics/lenses/sie.py @@ -21,22 +21,45 @@ 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. + + *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* + 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: meters* + """ _null_params = { @@ -79,15 +102,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 @@ -114,17 +148,34 @@ 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) + + *Unit: unitless* + + 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* + """ x, y = translate_rotate(x, y, x0, y0, phi) psi = self._get_potential(x, y, q) @@ -157,17 +208,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor The lensing potential. + + *Unit: arcsec^2* + """ ax, ay = self.reduced_deflection_angle(x, y, z_s, params) ax, ay = derotate(ax, ay, -phi) @@ -197,17 +260,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor - The projected mass. + 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 f9b858c1..8a23f172 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__( @@ -60,17 +63,34 @@ 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) + + *Unit: unitless* + + 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* + """ ax = torch.zeros_like(x) ay = torch.zeros_like(x) @@ -98,17 +118,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- Tensor The total projected mass density. + + *Unit: solMass/megaparsec^2* + """ convergence = torch.zeros_like(x) for lens in self.lenses: @@ -134,17 +166,29 @@ 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) + + *Unit: unitless* + + params: Packed, optional Dynamic parameter container. Returns ------- 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 df4f4d76..3482dfa8 100644 --- a/src/caustics/lenses/sis.py +++ b/src/caustics/lenses/sis.py @@ -21,17 +21,35 @@ 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. + + *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. - th_ein (Optional[Union[Tensor, float]]): The Einstein radius of the lens. + + *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: meters* + """ _null_params = { @@ -81,17 +99,34 @@ 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. Returns ------- - Tuple[Tensor, Tensor] - The deflection angle in the x and y directions. + x_component: Tensor + Deflection Angle + + *Unit: radians* + + y_component: Tensor + Deflection Angle + + *Unit: radians* + """ x, y = translate_rotate(x, y, x0, y0) R = (x**2 + y**2).sqrt() + self.s @@ -120,10 +155,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. @@ -131,6 +175,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 @@ -157,10 +204,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. @@ -168,6 +224,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 cb613687..2534b815 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -46,29 +46,55 @@ 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* + mass: Optional[Tensor] - Mass of the lens (Msol). + 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* + 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 @@ -167,23 +193,42 @@ def get_concentration( ---------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + """ critical_density = self.cosmology.critical_density(z_l, params) d_l = self.cosmology.angular_diameter_distance(z_l, params) @@ -210,23 +255,44 @@ def get_truncation_radius( ---------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + params: dictionary Dynamic parameter container. Returns ------- Tensor - The truncation radius of the lens in arcsec. + The truncation radius of the lens. + + *Unit: arcsec* + """ return tau * scale_radius @@ -252,23 +318,44 @@ def get_M0( ---------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + params: dictionary Dynamic parameter container. Returns ------- Tensor - The reference mass of the lens in 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 @@ -296,23 +383,44 @@ def get_scale_density( ---------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + params: dict Dynamic parameter container. Returns -------- Tensor - The scale density of the lens in solar masses per Mpc cubed. + The scale density of the lens. + + *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 @@ -341,23 +449,43 @@ def convergence( ---------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + params: dict Dynamic parameter container. Returns --------- Tensor - unitless convergence at requested position + Convergence at requested position. + + *Unit: unitless* """ x, y = translate_rotate(x, y, x0, y0) @@ -394,22 +522,40 @@ 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 ----------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + params: dict Dynamic parameter container. @@ -417,6 +563,9 @@ def mass_enclosed_2d( ------- Tensor Integrated mass projected in infinite cylinder within radius r. + + *Unit: arcsec* + """ g = r / scale_radius t2 = tau**2 @@ -455,23 +604,48 @@ def physical_deflection_angle( ---------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + Mass of the lens (solMass). + + *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 -------- - tuple[Tensor, Tensor] - The physical deflection angles in the x and y directions (arcsec). + x_component: Tensor + Deflection Angle in x-direction. + + *Unit: radians* + + y_component: Tensor + Deflection Angle in y-direction. + + *Unit: radians* """ d_l = self.cosmology.angular_diameter_distance(z_l, params) @@ -513,16 +687,34 @@ def potential( ----------- z_l: Tensor Redshift of the lens. + + *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 (Msol). + 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* + params: dict Dynamic parameter container. @@ -530,6 +722,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 eeba3e90..6db5f014 100644 --- a/src/caustics/lenses/utils.py +++ b/src/caustics/lenses/utils.py @@ -22,11 +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 @@ -47,17 +55,29 @@ 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. + + *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 @@ -73,16 +93,28 @@ 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. + + *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/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 7ea08408..8ba4eaec 100644 --- a/src/caustics/light/pixelated.py +++ b/src/caustics/light/pixelated.py @@ -26,14 +26,25 @@ 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 - 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__( @@ -52,16 +63,28 @@ def __init__( ---------- name : str 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 - 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( @@ -100,9 +123,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. @@ -113,6 +142,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 a5b8067c..69b8f7f3 100644 --- a/src/caustics/light/sersic.py +++ b/src/caustics/light/sersic.py @@ -25,22 +25,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__( @@ -63,24 +90,49 @@ def __init__( ---------- name: str 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) @@ -119,9 +171,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. @@ -131,6 +189,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)),