Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: normalize variable names across caustics objects #302

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/examples/Example_ImageFit_LM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
" \"y0\": 0.0,\n",
" \"q\": 0.86,\n",
" \"phi\": -0.20,\n",
" \"b\": 0.66,\n",
" \"Rein\": 0.66,\n",
" },\n",
" \"externalshear\": {\"gamma_1\": 0.0, \"gamma_2\": -0.05},\n",
" \"sourcelight\": {\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/Example_ImageFit_MCMC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
" \"y0\": 0.0,\n",
" \"q\": 0.86,\n",
" \"phi\": -0.20,\n",
" \"b\": 0.66,\n",
" \"Rein\": 0.66,\n",
" },\n",
" \"externalshear\": {\"gamma_1\": 0.0, \"gamma_2\": -0.05},\n",
" \"sourcelight\": {\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/Example_QSOLensFit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"sp_x = torch.tensor(0.2)\n",
"sp_y = torch.tensor(0.2)\n",
"\n",
"# true parameters x0 y0 q phi b\n",
"# true parameters x0 y0 q phi Rein\n",
"params = torch.tensor([0.0, 0.0, 0.4, np.pi / 5, 1.0])\n",
"# Points in image plane\n",
"x, y = lens.forward_raytrace(sp_x, sp_y, z_s, params)\n",
Expand Down Expand Up @@ -191,7 +191,7 @@
"# If you decrease the threshold from 1e-8 to 1e-10 you will get better fits, but fewer of them\n",
"avg_fit = torch.mean(fit_params[0][fit_params[2] < 1e-8], dim=0)\n",
"print(avg_fit.numpy())\n",
"# Note that the order is: x0, y0, q, phi, b"
"# Note that the order is: x0, y0, q, phi, Rein"
]
},
{
Expand Down
46 changes: 29 additions & 17 deletions docs/source/gravlensingintro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"# Define a cosmology for the lensing\n",
"cosmology = caustics.FlatLambdaCDM()\n",
"# Define a point mass for the lens plane\n",
"lens = caustics.Point(cosmology=cosmology, x0=0.0, y0=0.0, th_ein=1.0, z_l=z_l)\n",
"lens = caustics.Point(cosmology=cosmology, x0=0.0, y0=0.0, Rein=1.0, z_l=z_l)\n",
"\n",
"# Make a bunch of theta values at which to raytrace\n",
"theta_x = torch.linspace(-fov / 2, fov / 2, F, dtype=torch.float32)\n",
Expand Down Expand Up @@ -292,7 +292,9 @@
"fig.suptitle(\"Lens Convergence Examples\")\n",
"kappa_map = np.load(\"tutorials/assets/kappa_maps.npz\")[\"kappa_maps\"][1]\n",
"lenses = [\n",
" caustics.SIE(cosmology=cosmology, x0=0, y0=0, q=0.6, phi=np.pi / 3, b=1, z_l=z_l),\n",
" caustics.SIE(\n",
" cosmology=cosmology, x0=0, y0=0, q=0.6, phi=np.pi / 3, Rein=1, z_l=z_l\n",
" ),\n",
" caustics.PixelatedConvergence(\n",
" cosmology=cosmology,\n",
" x0=0,\n",
Expand All @@ -301,14 +303,14 @@
" pixelscale=fov / kappa_map.shape[0],\n",
" z_l=z_l,\n",
" ),\n",
" caustics.NFW(cosmology=cosmology, x0=0, y0=0, m=1e12, c=5, z_l=z_l),\n",
" caustics.NFW(cosmology=cosmology, x0=0, y0=0, mass=1e12, c=5, z_l=z_l),\n",
" caustics.PseudoJaffe(\n",
" cosmology=cosmology,\n",
" x0=0,\n",
" y0=0,\n",
" mass=1e12,\n",
" core_radius=0.2,\n",
" scale_radius=1.0,\n",
" Rc=0.2,\n",
" Rs=1.0,\n",
" z_l=z_l,\n",
" ),\n",
" caustics.Multipole(\n",
Expand Down Expand Up @@ -400,7 +402,7 @@
"# Define a cosmology for the lensing\n",
"cosmology = caustics.FlatLambdaCDM()\n",
"# Define a point mass for the lens plane\n",
"lens = caustics.Point(cosmology=cosmology, x0=0.0, y0=0.0, th_ein=1.0, z_l=z_l)\n",
"lens = caustics.Point(cosmology=cosmology, x0=0.0, y0=0.0, Rein=1.0, z_l=z_l)\n",
"\n",
"# Make a bunch of theta values at which to raytrace\n",
"theta_x, theta_y = caustics.utils.meshgrid(res, n_pix)\n",
Expand Down Expand Up @@ -485,7 +487,7 @@
" extent=[-fov / 2, fov / 2, -fov / 2, fov / 2],\n",
")\n",
"ax2.scatter([0], [0], color=\"r\")\n",
"c = Circle((0, 0), lens.th_ein.value.item(), fill=False, color=\"r\", linestyle=\"--\")\n",
"c = Circle((0, 0), lens.Rein.value.item(), fill=False, color=\"r\", linestyle=\"--\")\n",
"ax2.add_patch(c)\n",
"ax2.set_title(\"lensed\")\n",
"ax2.axis(\"off\")\n",
Expand Down Expand Up @@ -564,7 +566,9 @@
"# Define a cosmology for the lensing\n",
"cosmology = caustics.FlatLambdaCDM()\n",
"# Define a point mass for the lens plane\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, q=0.5, phi=0, b=1.0, z_l=z_l)\n",
"lens = caustics.SIE(\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.5, phi=0, Rein=1.0, z_l=z_l\n",
")\n",
"# Define a caustics simulator to handle the raytracing\n",
"sim = caustics.LensSource(lens, source, pixelscale=res, pixels_x=n_pix, z_s=z_s)\n",
"\n",
Expand Down Expand Up @@ -662,7 +666,7 @@
"cosmology = caustics.FlatLambdaCDM()\n",
"# Define a point mass for the lens plane\n",
"sie_lens = caustics.SIE(\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.99, phi=0, b=0.1, z_l=z_l\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.99, phi=0, Rein=0.1, z_l=z_l\n",
")\n",
"# Define a batched plane lens to combine many point masses\n",
"point_lens = caustics.BatchedPlane(\n",
Expand Down Expand Up @@ -750,7 +754,9 @@
"outputs": [],
"source": [
"cosmology = caustics.FlatLambdaCDM()\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, q=0.6, phi=0, b=1.0, z_l=z_l)\n",
"lens = caustics.SIE(\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.6, phi=0, Rein=1.0, z_l=z_l\n",
")\n",
"theta_x, theta_y = caustics.utils.meshgrid(res, n_pix)\n",
"A = lens.jacobian_lens_equation(theta_x, theta_y, z_s)"
]
Expand Down Expand Up @@ -809,7 +815,9 @@
"outputs": [],
"source": [
"cosmology = caustics.FlatLambdaCDM()\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, q=0.6, phi=0, b=1.0, z_l=z_l)\n",
"lens = caustics.SIE(\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.6, phi=0, Rein=1.0, z_l=z_l\n",
")\n",
"theta_x, theta_y = caustics.utils.meshgrid(res, n_pix)\n",
"gamma_1, gamma_2 = lens.shear(theta_x, theta_y, z_s)"
]
Expand Down Expand Up @@ -928,7 +936,9 @@
"outputs": [],
"source": [
"cosmology = caustics.FlatLambdaCDM()\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, q=0.6, phi=0, b=1.0, z_l=z_l)\n",
"lens = caustics.SIE(\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.6, phi=0, Rein=1.0, z_l=z_l\n",
")\n",
"mu = lens.magnification(theta_x, theta_y, z_s)"
]
},
Expand Down Expand Up @@ -973,7 +983,7 @@
"source": [
"F = 50\n",
"cosmology = caustics.FlatLambdaCDM()\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, phi=0, b=0.6, z_l=z_l)\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, phi=0, Rein=0.6, z_l=z_l)\n",
"q = torch.linspace(0.1, 1.0, F)\n",
"theta_x, theta_y = caustics.utils.meshgrid(res, n_pix)\n",
"A = torch.stack([lens.jacobian_lens_equation(theta_x, theta_y, z_s, [q_]) for q_ in q])\n",
Expand Down Expand Up @@ -1058,7 +1068,9 @@
") # periodic brightness\n",
"source.Ie.link(T)\n",
"cosmology = caustics.FlatLambdaCDM()\n",
"lens = caustics.SIE(cosmology=cosmology, x0=0.0, y0=0.0, q=0.5, phi=0, b=1.0, z_l=z_l)\n",
"lens = caustics.SIE(\n",
" cosmology=cosmology, x0=0.0, y0=0.0, q=0.5, phi=0, Rein=1.0, z_l=z_l\n",
")\n",
"t = torch.linspace(0, 1, F)\n",
"theta_x, theta_y = caustics.utils.meshgrid(res, n_pix)\n",
"source_images = torch.vmap(lambda t: source.brightness(theta_x, theta_y, [t]))(t)\n",
Expand Down Expand Up @@ -1234,7 +1246,7 @@
" cosmology=cosmology,\n",
" x0=0.0,\n",
" y0=0.0,\n",
" th_ein=1.0 / np.sqrt(len(z_ls)),\n",
" Rein=1.0 / np.sqrt(len(z_ls)),\n",
" z_l=z,\n",
" s=1e-3,\n",
" )\n",
Expand Down Expand Up @@ -1344,7 +1356,7 @@
"z_ls = torch.tensor([0.2, 0.4, 0.6, 0.8], dtype=torch.float32)\n",
"cosmology = caustics.FlatLambdaCDM()\n",
"lenses = [\n",
" caustics.Point(cosmology=cosmology, th_ein=1.0 / np.sqrt(len(z_ls)), z_l=z, s=1e-3)\n",
" caustics.Point(cosmology=cosmology, Rein=1.0 / np.sqrt(len(z_ls)), z_l=z, s=1e-3)\n",
" for z in z_ls\n",
"]\n",
"lens = caustics.Multiplane(cosmology=cosmology, lenses=lenses)\n",
Expand Down Expand Up @@ -1445,7 +1457,7 @@
" y0=(np.random.rand() - 0.5) * fov * 0.6,\n",
" q=np.random.rand() * 0.4 + 0.3,\n",
" phi=np.random.rand() * np.pi,\n",
" b=0.5 / np.sqrt(len(z_ls)),\n",
" Rein=0.5 / np.sqrt(len(z_ls)),\n",
" z_l=z,\n",
" s=1e-3,\n",
" )\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/source/tutorials/InterfaceIntroduction_func.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"outputs": [],
"source": [
"x = torch.tensor([\n",
"# z_s z_l x0 y0 q phi b x0 y0 q phi n Re\n",
"# z_s z_l x0 y0 q phi Rein x0 y0 q phi n Re\n",
" 1.5, 0.5, -0.2, 0.0, 0.4, 1.5708, 1.7, 0.0, 0.0, 0.5, -0.985, 1.3, 1.0, \n",
"# Ie x0 y0 q phi n Re Ie\n",
" 5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0\n",
Expand Down Expand Up @@ -217,7 +217,7 @@
" \"lens y0\",\n",
" \"lens q\",\n",
" \"lens phi\",\n",
" \"lens b\",\n",
" \"lens Rein\",\n",
" \"source x0\",\n",
" \"source y0\",\n",
" \"source q\",\n",
Expand Down Expand Up @@ -253,7 +253,7 @@
"- The next two parameters `x0` and `y0` indicate where the lens is relative to the main optical axis, which is the coordinates `(0, 0)`. \n",
"- The `q` parameter gives the axis ratio for the `SIE`, so it knows how elongated it is. \n",
"- `phi` indicates the position angle (where the ellipse is pointing). \n",
"- `b` gives the Einstein radius (in arcsec) of the lens. \n",
"- `Rein` gives the Einstein radius (in arcsec) of the lens. \n",
"- The next `x0` and `y0` provide the position relative to the main optical axis of the Sersic source, here we offset the source slightly to make for an interesting figure. \n",
"- The `q` parameter defines the axis ratio of the Sersic ellipse. \n",
"- `phi` defines the position angle of the ellipse. \n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/InterfaceIntroduction_oop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"outputs": [],
"source": [
"x = torch.tensor([\n",
"# z_s z_l x0 y0 q phi b x0 y0 q phi n Re\n",
"# z_s z_l x0 y0 q phi Rein x0 y0 q phi n Re\n",
" 1.5, 0.5, -0.2, 0.0, 0.4, 1.5708, 1.7, 0.0, 0.0, 0.5, -0.985, 1.3, 1.0, \n",
"# Ie x0 y0 q phi n Re Ie\n",
" 5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0\n",
Expand Down Expand Up @@ -282,7 +282,7 @@
"- The next two parameters `x0` and `y0` indicate where the lens is relative to the main optical axis, which is the coordinates `(0, 0)`. \n",
"- The `q` parameter gives the axis ratio for the `SIE`, so it knows how elongated it is. \n",
"- `phi` indicates the position angle (where the ellipse is pointing). \n",
"- `b` gives the Einstein radius (in arcsec) of the lens. \n",
"- `Rein` gives the Einstein radius (in arcsec) of the lens. \n",
"- The next `x0` and `y0` provide the position relative to the main optical axis of the Sersic source, here we offset the source slightly to make for an interesting figure. \n",
"- The `q` parameter defines the axis ratio of the Sersic ellipse. \n",
"- `phi` defines the position angle of the ellipse. \n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/InterfaceIntroduction_yaml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"source": [
"# Here we build a tensor with the parameters of the model\n",
"x = torch.tensor([\n",
"# z_s z_l x0 y0 q phi b x0 y0 q phi n Re\n",
"# z_s z_l x0 y0 q phi Rein x0 y0 q phi n Re\n",
" 1.5, 0.5, -0.2, 0.0, 0.4, 1.5708, 1.7, 0.0, 0.0, 0.5, -0.985, 1.3, 1.0, \n",
"# Ie x0 y0 q phi n Re Ie\n",
" 5.0, -0.2, 0.0, 0.8, 0.0, 1., 1.0, 10.0\n",
Expand Down Expand Up @@ -219,7 +219,7 @@
"- The next two parameters `x0` and `y0` indicate where the lens is relative to the main optical axis, which is the coordinates `(0, 0)`. \n",
"- The `q` parameter gives the axis ratio for the `SIE`, so it knows how elongated it is. \n",
"- `phi` indicates the position angle (where the ellipse is pointing). \n",
"- `b` gives the Einstein radius (in arcsec) of the lens. \n",
"- `Rein` gives the Einstein radius (in arcsec) of the lens. \n",
"- The next `x0` and `y0` provide the position relative to the main optical axis of the Sersic source, here we offset the source slightly to make for an interesting figure. \n",
"- The `q` parameter defines the axis ratio of the Sersic ellipse. \n",
"- `phi` defines the position angle of the ellipse. \n",
Expand Down
20 changes: 10 additions & 10 deletions docs/source/tutorials/Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
" 0.0, # y_0\n",
" 0.9, # q\n",
" 0.4, # phi\n",
" 1.0, # b (Einstein radius)\n",
" 1.0, # Rein\n",
" ]\n",
")\n",
"\n",
Expand Down Expand Up @@ -238,7 +238,7 @@
"simulator.lens.y0 = 0.0\n",
"simulator.lens.q = 0.9\n",
"simulator.lens.phi = 0.4\n",
"simulator.lens.b = None # Make sure this one stays Dynamic\n",
"simulator.lens.Rein = None # Make sure this one stays Dynamic\n",
"simulator.lens.z_l = 0.5\n",
"\n",
"simulator.source.x0 = 0.0\n",
Expand Down Expand Up @@ -278,7 +278,7 @@
"for i, ax in enumerate(axs.flatten()):\n",
" ax.axis(\"off\")\n",
" ax.imshow(ys[i], cmap=\"gray\")\n",
" ax.set_title(f\"$b = {b[i].item():.2f}$\")\n",
" ax.set_title(f\"$Rein = {b[i].item():.2f}$\")\n",
"plt.subplots_adjust(wspace=0, hspace=0)"
]
},
Expand All @@ -305,7 +305,7 @@
"source": [
"# Make some parameters dynamic for this example\n",
"simulator.source.Ie = None\n",
"simulator.lens.b = None"
"simulator.lens.Rein = None"
]
},
{
Expand All @@ -332,9 +332,9 @@
"outputs": [],
"source": [
"B = 5 # Batch dimension\n",
"b = torch.rand(B, 1)\n",
"Rein = torch.rand(B, 1)\n",
"Ie = torch.rand(B, 1)\n",
"x = torch.concat([b, Ie], dim=1) # Concat along the feature dimension\n",
"x = torch.concat([Rein, Ie], dim=1) # Concat along the feature dimension\n",
"\n",
"# Now we can use vmap to simulate multiple images at once\n",
"ys = vmap(simulator)(x)"
Expand All @@ -361,7 +361,7 @@
"source": [
"# Make some parameters dynamic for this example\n",
"simulator.source.Ie = None\n",
"simulator.lens.b = None\n",
"simulator.lens.Rein = None\n",
"simulator.lens.x0 = None\n",
"simulator.lens.cosmology.h0 = None\n",
"\n",
Expand Down Expand Up @@ -402,7 +402,7 @@
"source": [
"B = 5\n",
"x0 = torch.randn(B, 1)\n",
"b = torch.randn(B, 1)\n",
"Rein = torch.randn(B, 1)\n",
"Ie = torch.rand(B, 1)\n",
"h0 = torch.rand(B, 1)"
]
Expand All @@ -416,7 +416,7 @@
"x = {\n",
" \"lens\": {\n",
" \"x0\": x0,\n",
" \"b\": b,\n",
" \"Rein\": Rein,\n",
" },\n",
" \"source\": {\n",
" \"Ie\": Ie,\n",
Expand Down Expand Up @@ -494,7 +494,7 @@
"\n",
"titles = [\n",
" r\"$\\nabla_{x_0} f(\\mathbf{x})$\",\n",
" r\"$\\nabla_{b} f(\\mathbf{x})$\",\n",
" r\"$\\nabla_{Rein} f(\\mathbf{x})$\",\n",
" r\"$\\nabla_{h_0} f(\\mathbf{x})$\",\n",
" r\"$\\nabla_{I_e} f(\\mathbf{x})$\",\n",
"]\n",
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 @@ -61,7 +61,7 @@
" y0=0.0,\n",
" q=0.4,\n",
" phi=np.pi / 5,\n",
" b=1.0,\n",
" Rein=1.0,\n",
" s=1e-3,\n",
")"
]
Expand Down
Loading
Loading