-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH(lensing): deflections from weak lensing (#108)
Adds functions to simulate deflections due to weak gravitational lensing: * `from_convergence()` computes other weak lensing fields from the convergence * `deflect()` applies deflections to a set of positions An exact definition of what "deflection" means in GLASS is added to the glossary. This functionality so far only covers the raw physical process of deflecting a point. To compute the observed positions of a set of sources under weak lensing, we will need a new high-level function `lensed_positions()`, say, that solves the lensing equation by repeatedly calling `deflect()`. Closes: #106 Added: `deflect()` applies deflections to positions Added: `from_convergence()` returns other lensing fields given the convergence Deprecated: `shear_from_convergence()` is deprecated in favour of `from_convergence()`
- Loading branch information
Showing
3 changed files
with
286 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import numpy as np | ||
import numpy.testing as npt | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("usecomplex", [True, False]) | ||
def test_deflect_nsew(usecomplex): | ||
from glass.lensing import deflect | ||
|
||
d = 5. | ||
r = np.radians(d) | ||
|
||
if usecomplex: | ||
def alpha(re, im): | ||
return re + 1j*im | ||
else: | ||
def alpha(re, im): | ||
return [re, im] | ||
|
||
# north | ||
lon, lat = deflect(0., 0., alpha(r, 0)) | ||
assert np.allclose([lon, lat], [0., d]) | ||
|
||
# south | ||
lon, lat = deflect(0., 0., alpha(-r, 0)) | ||
assert np.allclose([lon, lat], [0., -d]) | ||
|
||
# east | ||
lon, lat = deflect(0., 0., alpha(0, r)) | ||
assert np.allclose([lon, lat], [-d, 0.]) | ||
|
||
# west | ||
lon, lat = deflect(0., 0., alpha(0, -r)) | ||
assert np.allclose([lon, lat], [d, 0.]) | ||
|
||
|
||
def test_deflect_many(): | ||
import healpix | ||
from glass.lensing import deflect | ||
|
||
n = 1000 | ||
abs_alpha = np.random.uniform(0, 2*np.pi, size=n) | ||
arg_alpha = np.random.uniform(-np.pi, np.pi, size=n) | ||
|
||
lon_ = np.degrees(np.random.uniform(-np.pi, np.pi, size=n)) | ||
lat_ = np.degrees(np.arcsin(np.random.uniform(-1, 1, size=n))) | ||
|
||
lon, lat = deflect(lon_, lat_, abs_alpha*np.exp(1j*arg_alpha)) | ||
|
||
x_, y_, z_ = healpix.ang2vec(lon_, lat_, lonlat=True) | ||
x, y, z = healpix.ang2vec(lon, lat, lonlat=True) | ||
|
||
dotp = x*x_ + y*y_ + z*z_ | ||
|
||
npt.assert_allclose(dotp, np.cos(abs_alpha)) |