Skip to content

Commit

Permalink
update docs and some variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Nov 21, 2023
1 parent f103185 commit 7858816
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion autogalaxy/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def raise_linear_light_profile_in_unmasked():


def raise_linear_light_profile_in_plot(
plotter_type: str,
plotter_type: str,
):
raise ProfileException(
f"""
Expand Down
26 changes: 18 additions & 8 deletions autogalaxy/operate/deflections.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def magnification_2d_from(self, grid) -> aa.Array2D:
def hessian_from(self, grid, buffer: float = 0.01, deflections_func=None) -> Tuple:
"""
Returns the Hessian of the lensing object, where the Hessian is the second partial derivatives of the
potential (see equation 55 https://www.tau.ac.il/~lab3/MICROLENSING/JeruLect.pdf):
potential (see equation 55 https://inspirehep.net/literature/419263):
`hessian_{i,j} = d^2 / dtheta_i dtheta_j`
Expand Down Expand Up @@ -237,7 +237,7 @@ def convergence_2d_via_hessian_from(
) -> aa.ArrayIrregular:
"""
Returns the convergence of the lensing object, which is computed from the 2D deflection angle map via the
Hessian using the expression (see equation 56 https://www.tau.ac.il/~lab3/MICROLENSING/JeruLect.pdf):
Hessian using the expression (see equation 56 https://inspirehep.net/literature/419263):
`convergence = 0.5 * (hessian_{0,0} + hessian_{1,1}) = 0.5 * (hessian_xx + hessian_yy)`
Expand Down Expand Up @@ -266,7 +266,7 @@ def shear_yx_2d_via_hessian_from(
) -> ShearYX2DIrregular:
"""
Returns the 2D (y,x) shear vectors of the lensing object, which are computed from the 2D deflection angle map
via the Hessian using the expressions (see equation 57 https://www.tau.ac.il/~lab3/MICROLENSING/JeruLect.pdf):
via the Hessian using the expressions (see equation 57 https://inspirehep.net/literature/419263):
`shear_y = hessian_{1,0} = hessian_{0,1} = hessian_yx = hessian_xy`
`shear_x = 0.5 * (hessian_{0,0} - hessian_{1,1}) = 0.5 * (hessian_xx - hessian_yy)`
Expand All @@ -277,6 +277,12 @@ def shear_yx_2d_via_hessian_from(
This calculation of the shear vectors is independent of analytic calculations defined within `MassProfile`
objects and can therefore be used as a cross-check.
The result is returned as a `ShearYX2D` dats structure, which has shape [total_shear_vectors, 2], where
entries for [:,0] are the gamma_2 values and entries for [:,1] are the gamma_1 values.
Note therefore that this convention means the FIRST entries in the array are the gamma_2 values and the SECOND
entries are the gamma_1 values.
Parameters
----------
grid
Expand All @@ -289,9 +295,13 @@ def shear_yx_2d_via_hessian_from(
grid=grid, buffer=buffer
)

gamma_1 = 0.5 * (hessian_xx - hessian_yy)
gamma_2 = hessian_xy

shear_yx_2d = np.zeros(shape=(grid.sub_shape_slim, 2))
shear_yx_2d[:, 0] = hessian_xy
shear_yx_2d[:, 1] = 0.5 * (hessian_xx - hessian_yy)

shear_yx_2d[:, 0] = gamma_2
shear_yx_2d[:, 1] = gamma_1

return ShearYX2DIrregular(values=shear_yx_2d, grid=grid)

Expand All @@ -300,7 +310,7 @@ def magnification_2d_via_hessian_from(
) -> aa.ArrayIrregular:
"""
Returns the 2D magnification map of lensing object, which is computed from the 2D deflection angle map
via the Hessian using the expressions (see equation 60 https://www.tau.ac.il/~lab3/MICROLENSING/JeruLect.pdf):
via the Hessian using the expressions (see equation 60 https://inspirehep.net/literature/419263):
`magnification = 1.0 / det(Jacobian) = 1.0 / abs((1.0 - convergence)**2.0 - shear**2.0)`
`magnification = (1.0 - hessian_{0,0}) * (1.0 - hessian_{1, 1)) - hessian_{0,1}*hessian_{1,0}`
Expand Down Expand Up @@ -782,7 +792,7 @@ def jacobian_from(self, grid):
def convergence_2d_via_jacobian_from(self, grid, jacobian=None) -> aa.Array2D:
"""
Returns the convergence of the lensing object, which is computed from the 2D deflection angle map via the
Jacobian using the expression (see equation 58 https://www.tau.ac.il/~lab3/MICROLENSING/JeruLect.pdf):
Jacobian using the expression (see equation 58 https://inspirehep.net/literature/419263):
`convergence = 1.0 - 0.5 * (jacobian_{0,0} + jacobian_{1,1}) = 0.5 * (jacobian_xx + jacobian_yy)`
Expand All @@ -808,7 +818,7 @@ def shear_yx_2d_via_jacobian_from(
) -> Union[ShearYX2D, ShearYX2DIrregular]:
"""
Returns the 2D (y,x) shear vectors of the lensing object, which are computed from the 2D deflection angle map
via the Jacobian using the expression (see equation 58 https://www.tau.ac.il/~lab3/MICROLENSING/JeruLect.pdf):
via the Jacobian using the expression (see equation 58 https://inspirehep.net/literature/419263):
`shear_y = -0.5 * (jacobian_{0,1} + jacobian_{1,0} = -0.5 * (jacobian_yx + jacobian_xy)`
`shear_x = 0.5 * (jacobian_{1,1} + jacobian_{0,0} = 0.5 * (jacobian_yy + jacobian_xx)`
Expand Down
4 changes: 3 additions & 1 deletion autogalaxy/profiles/geometry_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ def angle_to_profile_grid_from(self, grid_angles):
return np.cos(theta_coordinate_to_profile), np.sin(theta_coordinate_to_profile)

@aa.grid_dec.grid_2d_to_structure
def rotated_grid_from_reference_frame_from(self, grid, angle : Optional[float] = None):
def rotated_grid_from_reference_frame_from(
self, grid, angle: Optional[float] = None
):
"""
Rotate a grid of (y,x) coordinates which have been transformed to the elliptical reference frame of a profile
back to the original unrotated coordinate grid reference frame.
Expand Down
14 changes: 10 additions & 4 deletions autogalaxy/profiles/mass/total/isothermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,32 @@ def shear_yx_2d_from(self, grid: aa.type.Grid2DLike):
"""
Calculate the (gamma_y, gamma_x) shear vector field on a grid of (y,x) arc-second coordinates.
The result is returned as a `ShearYX2D` dats structure, which has shape [total_shear_vectors, 2], where
entries for [:,0] are the gamma_2 values and entries for [:,1] are the gamma_1 values.
Note therefore that this convention means the FIRST entries in the array are the gamma_2 values and the SECOND
entries are the gamma_1 values.
Parameters
----------
grid
The grid of (y,x) arc-second coordinates the deflection angles are computed on.
"""

convergence = self.convergence_2d_from(grid=grid)

shear_y = (
gamma_2 = (
-2
* convergence
* np.divide(grid[:, 1] * grid[:, 0], grid[:, 1] ** 2 + grid[:, 0] ** 2)
)
shear_x = -convergence * np.divide(
gamma_1 = -convergence * np.divide(
grid[:, 1] ** 2 - grid[:, 0] ** 2, grid[:, 1] ** 2 + grid[:, 0] ** 2
)

shear_field = self.rotated_grid_from_reference_frame_from(
grid=np.vstack((shear_y, shear_x)).T,
angle=self.angle*2
grid=np.vstack((gamma_2, gamma_1)).T, angle=self.angle * 2
)

return aa.VectorYX2DIrregular(values=shear_field, grid=grid)
Expand Down
13 changes: 13 additions & 0 deletions autogalaxy/util/shear_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class ShearYX2D(aa.VectorYX2D, AbstractShearField):
This class extends `VectorYX2D` to include methods that are specific to a shear field, typically
used for weak lensing calculations.
This data structure is of shape [total_vectors, 2], where entries for [:,0] are the gamma_2 values and
entries for [:,1] are the gamma_1 values.
Note therefore that this convention means the FIRST entries in the array are the gamma_2 values and the SECOND
entries are the gamma_1 values.
Parameters
----------
vectors
Expand All @@ -99,6 +105,13 @@ class ShearYX2DIrregular(aa.VectorYX2DIrregular, AbstractShearField):
This class extends `VectorYX2DIrregular` to include methods that are specific to a shear field, typically
used for weak lensing calculations.
This data structure is of shape [total_vectors, 2], where entries for [:,0] are the gamma_2 values and
entries for [:,1] are the gamma_1 values.
Note therefore that this convention means the FIRST entries in the array are the gamma_2 values and the SECOND
entries are the gamma_1 values.
Parameters
----------
vectors
Expand Down

0 comments on commit 7858816

Please sign in to comment.