diff --git a/.codespell-whitelist b/.codespell-whitelist new file mode 100644 index 00000000..a0c3bfca --- /dev/null +++ b/.codespell-whitelist @@ -0,0 +1,2 @@ +sie +childs \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7cc05c4a..8085bcc6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/docs/requirements.txt b/docs/requirements.txt index 3aee37f7..431bdaf2 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ +ipywidgets jupyter-book +matplotlib sphinx sphinx_rtd_theme -matplotlib -ipywidgets diff --git a/docs/source/tutorials/BasicIntroduction.ipynb b/docs/source/tutorials/BasicIntroduction.ipynb index 67c288a3..b6be9b96 100644 --- a/docs/source/tutorials/BasicIntroduction.ipynb +++ b/docs/source/tutorials/BasicIntroduction.ipynb @@ -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." ] }, { diff --git a/docs/source/tutorials/InvertLensEquation.ipynb b/docs/source/tutorials/InvertLensEquation.ipynb index db75ab0c..3e18b05f 100644 --- a/docs/source/tutorials/InvertLensEquation.ipynb +++ b/docs/source/tutorials/InvertLensEquation.ipynb @@ -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", diff --git a/docs/source/tutorials/MultiplaneDemo.ipynb b/docs/source/tutorials/MultiplaneDemo.ipynb index e6c12d53..185c3eef 100644 --- a/docs/source/tutorials/MultiplaneDemo.ipynb +++ b/docs/source/tutorials/MultiplaneDemo.ipynb @@ -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." ] @@ -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", diff --git a/docs/source/tutorials/VisualizeCaustics.ipynb b/docs/source/tutorials/VisualizeCaustics.ipynb index 8e163d5c..bcc0758e 100644 --- a/docs/source/tutorials/VisualizeCaustics.ipynb +++ b/docs/source/tutorials/VisualizeCaustics.ipynb @@ -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." ] @@ -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", diff --git a/docs/source/tutorials/index.md b/docs/source/tutorials/index.md index 75d2e53c..53484277 100644 --- a/docs/source/tutorials/index.md +++ b/docs/source/tutorials/index.md @@ -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. \ No newline at end of file +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. diff --git a/src/caustics/lenses/base.py b/src/caustics/lenses/base.py index b05f7767..172f9f9b 100644 --- a/src/caustics/lenses/base.py +++ b/src/caustics/lenses/base.py @@ -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") diff --git a/src/caustics/lenses/multiplane.py b/src/caustics/lenses/multiplane.py index f9db73c8..66e4c267 100644 --- a/src/caustics/lenses/multiplane.py +++ b/src/caustics/lenses/multiplane.py @@ -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 diff --git a/src/caustics/lenses/nfw.py b/src/caustics/lenses/nfw.py index 4f70ed27..841e3ca7 100644 --- a/src/caustics/lenses/nfw.py +++ b/src/caustics/lenses/nfw.py @@ -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 diff --git a/src/caustics/lenses/tnfw.py b/src/caustics/lenses/tnfw.py index 5a255f83..77edaec5 100644 --- a/src/caustics/lenses/tnfw.py +++ b/src/caustics/lenses/tnfw.py @@ -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 ----- @@ -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. """ diff --git a/src/caustics/namespace_dict.py b/src/caustics/namespace_dict.py index 7106f5df..e96026bb 100644 --- a/src/caustics/namespace_dict.py +++ b/src/caustics/namespace_dict.py @@ -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) diff --git a/src/caustics/sims/lens_source.py b/src/caustics/sims/lens_source.py index 86a3951f..dcb22807 100644 --- a/src/caustics/sims/lens_source.py +++ b/src/caustics/sims/lens_source.py @@ -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:: diff --git a/src/caustics/utils.py b/src/caustics/utils.py index be5bdcc8..d69a3c62 100644 --- a/src/caustics/utils.py +++ b/src/caustics/utils.py @@ -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, @@ -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))) diff --git a/tests/test_parametrized.py b/tests/test_parametrized.py index 7ba5c765..0cbcfa49 100644 --- a/tests/test_parametrized.py +++ b/tests/test_parametrized.py @@ -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 @@ -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"