diff --git a/notebooks/TrajectoryExplorer.ipynb b/notebooks/TrajectoryExplorer.ipynb index 98ec62866..68dd72c91 100644 --- a/notebooks/TrajectoryExplorer.ipynb +++ b/notebooks/TrajectoryExplorer.ipynb @@ -160,6 +160,45 @@ " axs[i, j].imshow(result.all_stamps[ind], cmap=\"gray\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using (RA, dec)\n", + "\n", + "You can also use the `TrajectoryExplorer` with a WCS and (RA, dec) coordinates. Both RA and dec are specified in degrees and the corresponding velocities are expressed as degrees per day.\n", + "\n", + "We start by creating a fake WCS to match our fake images. Then we evaluate the trajectory based on this WCS." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from astropy.wcs import WCS\n", + "\n", + "my_wcs = WCS(naxis=2)\n", + "my_wcs.wcs.crpix = [201.0, 251.0] # Reference point on the image (center of the image 1-indexed)\n", + "my_wcs.wcs.crval = [45.0, -15.0] # Reference pointing on the sky\n", + "my_wcs.wcs.cdelt = [0.1, 0.1] # Pixel step size\n", + "my_wcs.wcs.ctype = [\"RA---TAN-SIP\", \"DEC--TAN-SIP\"]\n", + "\n", + "# Use the WCS to compute the angular coordinates of the inserted object at two times.\n", + "sky_pos0 = my_wcs.pixel_to_world(50, 60)\n", + "sky_pos1 = my_wcs.pixel_to_world(55, 58)\n", + "\n", + "ra0 = sky_pos0.ra.deg\n", + "dec0 = sky_pos0.dec.deg\n", + "v_ra = sky_pos1.ra.deg - ra0\n", + "v_dec = sky_pos1.dec.deg - dec0\n", + "print(f\"Object starts at ({ra0}, {dec0}) with velocity ({v_ra}, {v_dec}).\")\n", + "\n", + "result = explorer.evaluate_angle_trajectory(ra0, dec0, v_ra, v_dec, my_wcs)\n", + "print(result.trajectory)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -178,13 +217,20 @@ "explorer.apply_sigma_g(result)\n", "print(f\"Valid time steps={result.valid_indices}\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python (.conda-kbmod)", + "display_name": "Jeremy's KBMOD", "language": "python", - "name": "conda-env-.conda-kbmod-py" + "name": "kbmod_jk" }, "language_info": { "codemirror_mode": { @@ -196,7 +242,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.1" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/src/kbmod/trajectory_utils.py b/src/kbmod/trajectory_utils.py index 347c675f4..2604f2567 100644 --- a/src/kbmod/trajectory_utils.py +++ b/src/kbmod/trajectory_utils.py @@ -13,6 +13,7 @@ import numpy as np +from astropy.coordinates import SkyCoord from astropy.wcs import WCS from yaml import dump, safe_load