Skip to content

Commit

Permalink
Merge branch 'update_pep8' into fix_e501
Browse files Browse the repository at this point in the history
  • Loading branch information
lsetiawan authored Dec 11, 2023
2 parents f1a5186 + 3ddebd6 commit 0e057a9
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .codespell-whitelist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sie
childs
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ repos:
rev: "v2.2.5"
hooks:
- id: codespell

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.5"
hooks:
- id: shellcheck
args: ["--write-changes", "--ignore-words", ".codespell-whitelist"]

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ipywidgets
jupyter-book
matplotlib
sphinx
sphinx_rtd_theme
matplotlib
ipywidgets
2 changes: 1 addition & 1 deletion docs/source/tutorials/BasicIntroduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"source": [
"## Simulating an SIE lens\n",
"\n",
"Here we will demo the very basics of lensing with a classic `SIE` lens model. We will see what it takes to make an `SIE` model, lens a backgorund `Sersic` source, and sample some examples in a simulator. Caustic simulators can generalize to very complex scenarios. In these cases there can be a lot of parameters moving through the simulator, and the order/number of parameters may change depending on what lens or source is being used. To streamline this process, caustic impliments a class called `Parametrized` which has some knowledge of the parameters moving through it, this way it can keep track of everything for you. For this to work, you must put the parameters into a `Packed` object which it can recognize, each sub function can then unpack the parameters it needs. Below we will show some examples of what this looks like."
"Here we will demo the very basics of lensing with a classic `SIE` lens model. We will see what it takes to make an `SIE` model, lens a background `Sersic` source, and sample some examples in a simulator. Caustic simulators can generalize to very complex scenarios. In these cases there can be a lot of parameters moving through the simulator, and the order/number of parameters may change depending on what lens or source is being used. To streamline this process, caustic implements a class called `Parametrized` which has some knowledge of the parameters moving through it, this way it can keep track of everything for you. For this to work, you must put the parameters into a `Packed` object which it can recognize, each sub function can then unpack the parameters it needs. Below we will show some examples of what this looks like."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/InvertLensEquation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"paths = CS.collections[0].get_paths()\n",
"caustic_paths = []\n",
"for path in paths:\n",
" # Collect the path into a descrete set of points\n",
" # Collect the path into a discrete set of points\n",
" vertices = path.interpolated(5).vertices\n",
" x1 = torch.tensor(list(float(vs[0]) for vs in vertices))\n",
" x2 = torch.tensor(list(float(vs[1]) for vs in vertices))\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/MultiplaneDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Multiplane Lensing\n",
"\n",
"The universe is three dimensional and filled with stuff. A light ray traveling to our telescope may encounter more than a single massive object on its way to our telescopes. This is handled by a multiplane lensing framework. Multiplane lensing involves tracing the path of a ray backwards from our telescope through each individual plane (which is treated similarly to typical single plane lensing, though extra factors account for the ray physically moving in 3D space) getting perturbed at each step until it finally lands on the source we'd like to image. For more mathmatical details see [Petkova et al. 2014](https://doi.org/10.1093/mnras/stu1860) for the formalism we use internally.\n",
"The universe is three dimensional and filled with stuff. A light ray traveling to our telescope may encounter more than a single massive object on its way to our telescopes. This is handled by a multiplane lensing framework. Multiplane lensing involves tracing the path of a ray backwards from our telescope through each individual plane (which is treated similarly to typical single plane lensing, though extra factors account for the ray physically moving in 3D space) getting perturbed at each step until it finally lands on the source we'd like to image. For more mathematical details see [Petkova et al. 2014](https://doi.org/10.1093/mnras/stu1860) for the formalism we use internally.\n",
"\n",
"The main concept to keep in mind is that a lot of quantities we are used to working with, such as \"reduced deflection angles\" don't really exist in multiplane lensing since these are normalized by the redshift of the source and lens, however there is no single \"lens redshift\" for multiplane! Instead we define everything with respect to results from full raytracing, once the raytracing is done we can define effective quantities (like effective reduced deflection angle) which behave similarly in intuition but are not quite the same in detail."
]
Expand Down Expand Up @@ -169,7 +169,7 @@
"paths = CS.collections[0].get_paths()\n",
"\n",
"for path in paths:\n",
" # Collect the path into a descrete set of points\n",
" # Collect the path into a discrete set of points\n",
" vertices = path.interpolated(5).vertices\n",
" x1 = torch.tensor(list(float(vs[0]) for vs in vertices))\n",
" x2 = torch.tensor(list(float(vs[1]) for vs in vertices))\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/VisualizeCaustics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Visualize Caustics\n",
"\n",
"Here we will demonstrate how to collect caustic lines using caustic! Since caustic (the code) uses autodiff and can get exact derivatives, it is actually very acurate at computing caustics. \n",
"Here we will demonstrate how to collect caustic lines using caustic! Since caustic (the code) uses autodiff and can get exact derivatives, it is actually very accurate at computing caustics. \n",
"\n",
"Conceptually a caustic occurs where the magnification of a lens diverges to infinity. A convenient way to measure the magnification in the image plane is by taking the determinant ($det$) of the jacobian of the lens equation ($A$), its reciprocal is the magnification. This means that anywhere that $det(A) = 0$ is a critical line in the image plane (magnification goes to infinity). If we take this line and raytrace it back to the source plane we can see the caustics which define boundaries for lensing phenomena."
]
Expand Down Expand Up @@ -125,7 +125,7 @@
"paths = CS.collections[0].get_paths()\n",
"\n",
"for path in paths:\n",
" # Collect the path into a descrete set of points\n",
" # Collect the path into a discrete set of points\n",
" vertices = path.interpolated(5).vertices\n",
" x1 = torch.tensor(list(float(vs[0]) for vs in vertices))\n",
" x2 = torch.tensor(list(float(vs[1]) for vs in vertices))\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/source/tutorials/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tutorials

Here you will find the jupyter notebook tutorials.
It is recommended that you go through the tutorials yourself,
but for quick reference a version of each tutorial is available here.
Here you will find the jupyter notebook tutorials. It is recommended that you go
through the tutorials yourself, but for quick reference a version of each
tutorial is available here.
4 changes: 2 additions & 2 deletions src/caustics/lenses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def forward_raytrace(
Ray-traced coordinates in the x and y directions.
"""

bxy = torch.stack((bx, by)).repeat(n_init, 1) # has shape (n_init, Dout:2)
bxy = torch.stack((bx, by)).repeat(n_init, 1) # has shape (n_init, Doubt:2)

# TODO make FOV more general so that it doesnt have to be centered on zero,zero
# TODO make FOV more general so that it doesn't have to be centered on zero,zero
if fov is None:
raise ValueError("fov must be given to generate initial guesses")

Expand Down
2 changes: 1 addition & 1 deletion src/caustics/lenses/multiplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def raytrace_z1z2(
theta_x = theta_x - alpha_x
theta_y = theta_y - alpha_y

# Propogate rays to next plane (basically eq 18)
# 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
Expand Down
2 changes: 1 addition & 1 deletion src/caustics/lenses/nfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NFW(ThinLens):
Softening parameter to avoid singularities at the center of the lens. Default is 0.0.
use_case: str
Due to an idyosyncratic behaviour of PyTorch, the NFW/TNFW profile
specifically cant be both batchable and differentiable. You may select which version
specifically can't be both batchable and differentiable. You may select which version
you wish to use by setting this parameter to one of: batchable, differentiable.
Methods
Expand Down
8 changes: 4 additions & 4 deletions src/caustics/lenses/tnfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TNFW(ThinLens):
`interpret_m_total_mass = False` on initialization of the
object. However, the mass within R200 will be computed for an
NFW profile, not a TNFW profile. This is in line with how
lenstronomy inteprets the mass parameter.
lenstronomy interprets the mass parameter.
Parameters
-----
Expand All @@ -64,12 +64,12 @@ class TNFW(ThinLens):
Default is 0.0.
interpret_m_total_mass: boolean
Indicates how to interpret the mass variable "m". If true
the mass is intepreted as the total mass of the halo (good because it makes sense). If
false it is intepreted as what the mass would have been within R200 of a an NFW that
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).
use_case: str
Due to an idyosyncratic behaviour of PyTorch, the NFW/TNFW profile
specifically cant be both batchable and differentiable. You may select which version
specifically can't be both batchable and differentiable. You may select which version
you wish to use by setting this parameter to one of: batchable, differentiable.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/caustics/namespace_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class NestedNamespaceDict(_NestedNamespaceDict):
nested_namespace.foo = 'Hello'
nested_namespace.bar = {'baz': 'World'}
nested_namespace.bar.qux = 42
# works also in the follwoing way
# works also in the following way
nested_namespace["bar.qux"] = 42
print(nested_namespace)
Expand Down
4 changes: 2 additions & 2 deletions src/caustics/sims/lens_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
class Lens_Source(Simulator):
"""Lens image of a source.
Striaghtforward simulator to sample a lensed image of a source
Straightforward simulator to sample a lensed image of a source
object. Constructs a sampling grid internally based on the
pixelscale and gridding parameters. It can automatically upscale
and fine sample an image. This is the most straightforward
simulator to view the image if you aready have a lens and source
simulator to view the image if you already have a lens and source
chosen.
Example usage::
Expand Down
10 changes: 5 additions & 5 deletions src/caustics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ def _lm_step(f, X, Y, Cinv, L, Lup, Ldn, epsilon):

def batch_lm(
X, # B, Din
Y, # B, Dout
f, # Din -> Dout
C=None, # B, Dout, Dout
Y, # B, Doubt
f, # Din -> Doubt
C=None, # B, Doubt, Doubt
epsilon=1e-1,
L=1e0,
L_dn=11.0,
Expand All @@ -655,13 +655,13 @@ def batch_lm(
f_kwargs={},
):
B, Din = X.shape
B, Dout = Y.shape
B, Doubt = Y.shape

if len(X) != len(Y):
raise ValueError("x and y must having matching batch dimension")

if C is None:
C = torch.eye(Dout).repeat(B, 1, 1)
C = torch.eye(Doubt).repeat(B, 1, 1)
Cinv = torch.linalg.inv(C)

v_lm_step = torch.vmap(partial(_lm_step, lambda x: f(x, *f_args, **f_kwargs)))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parametrized.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self):

sim = Sim()
assert len(sim.module_params) == 2 # dynamic and static
assert len(sim.module_params.dynamic) == 0 # simulator has no dynmaic params
assert len(sim.module_params.dynamic) == 0 # simulator has no dynamic params
assert len(sim.module_params.static) == 1 # and 1 static param (z_s)
assert len(sim.params) == 2 # dynamic and static
assert len(sim.params.dynamic) == 3 # cosmo, epl and sersic
Expand Down Expand Up @@ -143,7 +143,7 @@ def __init__(self):
self.lens2 = EPL(self.cosmo)

sim = Sim()
# Current way names are updated. Could be chnaged so that all params in collision
# Current way names are updated. Could be changed so that all params in collision
# Get a number
assert sim.lens1.name == "EPL"
assert sim.lens2.name == "EPL_1"
Expand Down

0 comments on commit 0e057a9

Please sign in to comment.