From 28de82f5534b98ca59bd84e74470e5a99c76b7ac Mon Sep 17 00:00:00 2001 From: Konstantin Malanchev Date: Fri, 15 Sep 2023 16:49:14 -0400 Subject: [PATCH 1/2] S82 RRLyr notebook --- docs/tutorials/rrlyr-period.ipynb | 136 ++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 docs/tutorials/rrlyr-period.ipynb diff --git a/docs/tutorials/rrlyr-period.ipynb b/docs/tutorials/rrlyr-period.ipynb new file mode 100644 index 00000000..5e8f9742 --- /dev/null +++ b/docs/tutorials/rrlyr-period.ipynb @@ -0,0 +1,136 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "7bc777c97b317198", + "metadata": { + "collapsed": false + }, + "source": [ + "# Explore SDSS Stripe 82 RR Lyrae catalog with period-folding\n", + "\n", + "This short example notebook demonstrates how to use TAPE to explore the SDSS Stripe 82 RR Lyrae catalog. We will use a Lomb–Scargle periodogram to extract periods from r-band light curves and select the RR Lyrae star with the most confident period determination. Then, we will plot the period-folded light curve for this RR Lyrae star." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "initial_id", + "metadata": { + "ExecuteTime": { + "end_time": "2023-09-20T13:16:49.339804Z", + "start_time": "2023-09-20T13:16:48.655140Z" + } + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "from light_curve import Periodogram\n", + "from tape import Ensemble" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fecf2313f49ad1ac", + "metadata": { + "ExecuteTime": { + "end_time": "2023-09-20T13:16:53.703300Z", + "start_time": "2023-09-20T13:16:49.340873Z" + } + }, + "outputs": [], + "source": [ + "# Load SDSS Stripe 82 RR Lyrae catalog\n", + "ens = Ensemble(client=False).from_dataset('s82_rrlyrae')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c2dd5a5fd58ce00", + "metadata": { + "ExecuteTime": { + "end_time": "2023-09-20T13:17:00.548389Z", + "start_time": "2023-09-20T13:16:53.706738Z" + } + }, + "outputs": [], + "source": [ + "%%time\n", + "\n", + "# Filter out invalid detections, \"flux\" denotes magnitude column\n", + "ens = ens.query(\"10 < flux < 25\", table=\"source\")\n", + "\n", + "# Find periods using Lomb-Scargle periodogram\n", + "periodogram = Periodogram(peaks=1, nyquist=0.1, max_freq_factor=10, fast=False)\n", + "\n", + "# Use r band only\n", + "df = ens.batch(periodogram, band_to_calc='r')\n", + "display(df)\n", + "\n", + "# Find RR Lyr with the most confient period\n", + "id = df.index[df['period_s_to_n_0'].argmax()]\n", + "period = df['period_0'].loc[id]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f79ad1eb83d0d125", + "metadata": { + "ExecuteTime": { + "end_time": "2023-09-20T13:17:00.655691Z", + "start_time": "2023-09-20T13:17:00.548017Z" + } + }, + "outputs": [], + "source": [ + "# Plot folded light curve\n", + "ts = ens.to_timeseries(id)\n", + "COLORS = {'u': 'blue', 'g': 'green', 'r': 'orange', 'i': 'red', 'z': 'purple'}\n", + "color = [COLORS[band] for band in ts.band]\n", + "plt.title(f'{id} P={period:.3f} d')\n", + "plt.gca().invert_yaxis()\n", + "plt.scatter(ts.time % period / period, ts.flux, c=color, s=7)\n", + "plt.xlim([0, 1])\n", + "plt.xlabel('Phase')\n", + "plt.ylabel('Magnitude')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cf157e25e291651a", + "metadata": { + "ExecuteTime": { + "end_time": "2023-09-20T13:17:00.655819Z", + "start_time": "2023-09-20T13:17:00.647036Z" + } + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 7b747be048f83dd56185370c2405c9b86139e3dd Mon Sep 17 00:00:00 2001 From: Konstantin Malanchev Date: Fri, 15 Sep 2023 17:06:08 -0400 Subject: [PATCH 2/2] Move rrlyr nb to examples --- docs/examples.rst | 8 ++++++++ docs/{tutorials => examples}/rrlyr-period.ipynb | 0 docs/index.rst | 1 + 3 files changed, 9 insertions(+) create mode 100644 docs/examples.rst rename docs/{tutorials => examples}/rrlyr-period.ipynb (100%) diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 00000000..2088c92b --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,8 @@ +Examples +======================================================================================== + +Some examples of how to use the TAPE package are provided in these notebooks. + +.. toctree:: + + Use Lomb–Scargle Periodograms for SDSS Stripe 82 RR Lyrae diff --git a/docs/tutorials/rrlyr-period.ipynb b/docs/examples/rrlyr-period.ipynb similarity index 100% rename from docs/tutorials/rrlyr-period.ipynb rename to docs/examples/rrlyr-period.ipynb diff --git a/docs/index.rst b/docs/index.rst index 10eb10b0..60c4d4dc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,5 +32,6 @@ API Reference section. Home page Getting Started Tutorials + Examples API Reference