Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 16, 2023
1 parent de575e6 commit 687e651
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 192 deletions.
53 changes: 9 additions & 44 deletions docs/source/tutorials/InvertLensEquation.ipynb

Large diffs are not rendered by default.

110 changes: 20 additions & 90 deletions docs/source/tutorials/MultiplaneDemo.ipynb

Large diffs are not rendered by default.

42 changes: 7 additions & 35 deletions docs/source/tutorials/VisualizeCaustics.ipynb

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions src/caustics/lenses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def jacobian_lens_equation(
"and known pixelscale. "
"Please include the pixelscale argument"
)
return self._jacobian_lens_equation_finitediff(x, y, z_s, pixelscale, params, **kwargs)
return self._jacobian_lens_equation_finitediff(
x, y, z_s, pixelscale, params, **kwargs
)
else:
raise ValueError("method should be one of: autograd, finitediff")

Expand Down Expand Up @@ -145,7 +147,9 @@ def forward_raytrace(
raise ValueError("fov must be given to generate initial guesses")

# Random starting points in image plane
guesses = torch.as_tensor(fov) * (torch.rand(n_init, 2) - 0.5) # Has shape (n_init, Din:2)
guesses = torch.as_tensor(fov) * (
torch.rand(n_init, 2) - 0.5
) # Has shape (n_init, Din:2)

# Optimize guesses in image plane
x, l, c = batch_lm( # noqa: E741 Unused `l` variable
Expand Down Expand Up @@ -528,7 +532,9 @@ def _jacobian_lens_equation_autograd(
This equates to a (2,2) matrix at each (x,y) point.
"""
# Build Jacobian
J = self._jacobian_effective_deflection_angle_autograd(x, y, z_s, params, **kwargs)
J = self._jacobian_effective_deflection_angle_autograd(
x, y, z_s, params, **kwargs
)
return torch.eye(2) - J.detach()

@unpack(3)
Expand Down Expand Up @@ -638,7 +644,9 @@ def reduced_deflection_angle(
"""
d_s = self.cosmology.angular_diameter_distance(z_s, params)
d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params)
deflection_angle_x, deflection_angle_y = self.physical_deflection_angle(x, y, z_s, params)
deflection_angle_x, deflection_angle_y = self.physical_deflection_angle(
x, y, z_s, params
)
return (
(d_ls / d_s) * deflection_angle_x,
(d_ls / d_s) * deflection_angle_y,
Expand Down Expand Up @@ -676,7 +684,9 @@ def physical_deflection_angle(
"""
d_s = self.cosmology.angular_diameter_distance(z_s, params)
d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params)
deflection_angle_x, deflection_angle_y = self.reduced_deflection_angle(x, y, z_s, params)
deflection_angle_x, deflection_angle_y = self.reduced_deflection_angle(
x, y, z_s, params
)
return (
(d_s / d_ls) * deflection_angle_x,
(d_s / d_ls) * deflection_angle_y,
Expand Down Expand Up @@ -776,7 +786,9 @@ def surface_density(
Tensor
Surface mass density at the given coordinates in solar masses per Mpc^2.
"""
critical_surface_density = self.cosmology.critical_surface_density(z_l, z_s, params)
critical_surface_density = self.cosmology.critical_surface_density(
z_l, z_s, params
)
return self.convergence(x, y, z_s, params) * critical_surface_density # fmt: skip

@unpack(3)
Expand Down Expand Up @@ -847,8 +859,12 @@ def time_delay_gravitational(
d_ls = self.cosmology.angular_diameter_distance_z1z2(z_l, z_s, params)
potential = self.potential(x, y, z_s, params)
factor = (1 + z_l) / c_Mpc_s * d_s * d_l / d_ls
print(self.potential(0., 0., z_s, params))
return -factor * (potential - self.potential(0., 0., z_s, params)) * arcsec_to_rad**2
print(self.potential(0.0, 0.0, z_s, params))
return (

Check warning on line 863 in src/caustics/lenses/base.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/base.py#L861-L863

Added lines #L861 - L863 were not covered by tests
-factor
* (potential - self.potential(0.0, 0.0, z_s, params))
* arcsec_to_rad**2
)

@unpack(5)
def time_delay_geometric_source(
Expand Down Expand Up @@ -958,7 +974,6 @@ def time_delay_geometric(
factor = (1 + z_l) / c_Mpc_s * d_s * d_l / d_ls
fp = 0.5 * (ax**2 + ay**2)
return factor * fp * arcsec_to_rad**2

Check warning on line 976 in src/caustics/lenses/base.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/base.py#L970-L976

Added lines #L970 - L976 were not covered by tests


@unpack(3)
def time_delay(
Expand Down Expand Up @@ -1091,7 +1106,9 @@ def jacobian_deflection_angle(
"Finite differences lensing jacobian requires regular grid "
"and known pixelscale. Please include the pixelscale argument"
)
return self._jacobian_deflection_angle_finitediff(x, y, z_s, pixelscale, params)
return self._jacobian_deflection_angle_finitediff(
x, y, z_s, pixelscale, params
)
else:
raise ValueError("method should be one of: autograd, finitediff")

Expand All @@ -1111,7 +1128,9 @@ def _jacobian_lens_equation_finitediff(
This equates to a (2,2) matrix at each (x,y) point.
"""
# Build Jacobian
J = self._jacobian_deflection_angle_finitediff(x, y, z_s, pixelscale, params, **kwargs)
J = self._jacobian_deflection_angle_finitediff(
x, y, z_s, pixelscale, params, **kwargs
)
return torch.eye(2) - J

@unpack(3)
Expand Down
44 changes: 32 additions & 12 deletions src/caustics/lenses/multiplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def __init__(self, cosmology: Cosmology, lenses: list[ThinLens], name: str = Non
self.add_parametrized(lens)

@unpack(0)
def get_z_ls(self, *args, params: Optional["Packed"] = None, **kwargs) -> list[Tensor]:
def get_z_ls(
self, *args, params: Optional["Packed"] = None, **kwargs
) -> list[Tensor]:
"""
Get the redshifts of each lens in the multiplane.
Expand Down Expand Up @@ -131,7 +133,9 @@ def raytrace_z1z2(
lens_planes = [i for i, _ in sorted(enumerate(z_ls), key=itemgetter(1))]

# Compute physical position on first lens plane
D = self.cosmology.transverse_comoving_distance_z1z2(z_start, z_ls[lens_planes[0]], params)
D = self.cosmology.transverse_comoving_distance_z1z2(
z_start, z_ls[lens_planes[0]], params
)
X, Y = x * arcsec_to_rad * D, y * arcsec_to_rad * D # fmt: skip

# Initial angles are observation angles
Expand All @@ -140,7 +144,9 @@ def raytrace_z1z2(

for i in lens_planes:
# Compute deflection angle at current ray positions
D_l = self.cosmology.transverse_comoving_distance_z1z2(z_start, z_ls[i], params)
D_l = self.cosmology.transverse_comoving_distance_z1z2(
z_start, z_ls[i], params
)
alpha_x, alpha_y = self.lenses[i].physical_deflection_angle(
X * rad_to_arcsec / D_l,
Y * rad_to_arcsec / D_l,
Expand All @@ -154,7 +160,9 @@ def raytrace_z1z2(

# Propagate rays to next plane (basically eq 18)
z_next = z_ls[i + 1] if i != lens_planes[-1] else z_end
D = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_next, params)
D = self.cosmology.transverse_comoving_distance_z1z2(
z_ls[i], z_next, params
)
X = X + D * theta_x * arcsec_to_rad
Y = Y + D * theta_y * arcsec_to_rad

Expand Down Expand Up @@ -214,7 +222,7 @@ def surface_density(
"""
# TODO: rescale mass densities of each lens and sum
raise NotImplementedError()

@unpack(3)
def time_delay_gravitational(
self,
Expand Down Expand Up @@ -268,8 +276,12 @@ def time_delay_gravitational(
z_next = z_ls[i + 1] if i != lens_planes[-1] else z_s

Check warning on line 276 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L275-L276

Added lines #L275 - L276 were not covered by tests
# Compute deflection angle at current ray positions
D_l = self.cosmology.transverse_comoving_distance(z_ls[i], params)
D = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_next, params)
D_is = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_s, params)
D = self.cosmology.transverse_comoving_distance_z1z2(

Check warning on line 279 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L278-L279

Added lines #L278 - L279 were not covered by tests
z_ls[i], z_next, params
)
D_is = self.cosmology.transverse_comoving_distance_z1z2(

Check warning on line 282 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L282

Added line #L282 was not covered by tests
z_ls[i], z_s, params
)
D_next = self.cosmology.transverse_comoving_distance(z_next, params)
alpha_x, alpha_y = self.lenses[i].physical_deflection_angle(

Check warning on line 286 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L285-L286

Added lines #L285 - L286 were not covered by tests
X * rad_to_arcsec / D_l,
Expand All @@ -295,7 +307,7 @@ def time_delay_gravitational(
Y = Y + D * theta_y * arcsec_to_rad

Check warning on line 307 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L306-L307

Added lines #L306 - L307 were not covered by tests

return TD

Check warning on line 309 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L309

Added line #L309 was not covered by tests

@unpack(3)
def time_delay_geometric(
self,
Expand Down Expand Up @@ -349,8 +361,12 @@ def time_delay_geometric(
z_next = z_ls[i + 1] if i != lens_planes[-1] else z_s

Check warning on line 361 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L360-L361

Added lines #L360 - L361 were not covered by tests
# Compute deflection angle at current ray positions
D_l = self.cosmology.transverse_comoving_distance(z_ls[i], params)
D = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_next, params)
D_is = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_s, params)
D = self.cosmology.transverse_comoving_distance_z1z2(

Check warning on line 364 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L363-L364

Added lines #L363 - L364 were not covered by tests
z_ls[i], z_next, params
)
D_is = self.cosmology.transverse_comoving_distance_z1z2(

Check warning on line 367 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L367

Added line #L367 was not covered by tests
z_ls[i], z_s, params
)
D_next = self.cosmology.transverse_comoving_distance(z_next, params)
alpha_x, alpha_y = self.lenses[i].physical_deflection_angle(

Check warning on line 371 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L370-L371

Added lines #L370 - L371 were not covered by tests
X * rad_to_arcsec / D_l,
Expand Down Expand Up @@ -427,8 +443,12 @@ def time_delay(
z_next = z_ls[i + 1] if i != lens_planes[-1] else z_s

Check warning on line 443 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L442-L443

Added lines #L442 - L443 were not covered by tests
# Compute deflection angle at current ray positions
D_l = self.cosmology.transverse_comoving_distance(z_ls[i], params)
D = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_next, params)
D_is = self.cosmology.transverse_comoving_distance_z1z2(z_ls[i], z_s, params)
D = self.cosmology.transverse_comoving_distance_z1z2(

Check warning on line 446 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L445-L446

Added lines #L445 - L446 were not covered by tests
z_ls[i], z_next, params
)
D_is = self.cosmology.transverse_comoving_distance_z1z2(

Check warning on line 449 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L449

Added line #L449 was not covered by tests
z_ls[i], z_s, params
)
D_next = self.cosmology.transverse_comoving_distance(z_next, params)
alpha_x, alpha_y = self.lenses[i].physical_deflection_angle(

Check warning on line 453 in src/caustics/lenses/multiplane.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/multiplane.py#L452-L453

Added lines #L452 - L453 were not covered by tests
X * rad_to_arcsec / D_l,
Expand Down

0 comments on commit 687e651

Please sign in to comment.