From 60f76b7841b78fd012513a0a3ab6c97b5656e508 Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Tue, 6 Dec 2022 08:17:09 -0600 Subject: [PATCH 1/3] Add import and update inline explanations --- ...5-relative-flux-calculation-template.ipynb | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/stellarphot/notebooks/photometry/05-relative-flux-calculation-template.ipynb b/stellarphot/notebooks/photometry/05-relative-flux-calculation-template.ipynb index f1219f71..4571d8ce 100755 --- a/stellarphot/notebooks/photometry/05-relative-flux-calculation-template.ipynb +++ b/stellarphot/notebooks/photometry/05-relative-flux-calculation-template.ipynb @@ -6,13 +6,15 @@ "metadata": {}, "outputs": [], "source": [ + "from astropy.coordinates import SkyCoord\n", "import astropy.units as u\n", - "import matplotlib.pyplot as plt\n", "from astropy.table import Table\n", "from astropy.time import Time\n", "\n", "import ipywidgets as ipw\n", "\n", + "import matplotlib.pyplot as plt\n", + "\n", "import numpy as np\n", "\n", "from stellarphot.differential_photometry.aij_rel_fluxes import *\n", @@ -23,7 +25,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Load photometry table " + "### Choose photometry and aperture files" ] }, { @@ -47,6 +49,13 @@ "box" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run the remaining cells" + ] + }, { "cell_type": "code", "execution_count": null, @@ -70,13 +79,6 @@ "photometry = photometry[~del_rows]" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Load comp star table" - ] - }, { "cell_type": "code", "execution_count": null, @@ -145,8 +147,15 @@ "metadata": {}, "outputs": [], "source": [ - "flux_table.write(output_file)" + "flux_table.write(output_file, overwrite=True)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From 4aea23a34446057e30c1b78ff28e0c19a8660e30 Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Tue, 6 Dec 2022 08:42:39 -0600 Subject: [PATCH 2/3] Multiple improvements to transit fit notebook --- .../photometry/06-transit-fit-template.ipynb | 102 ++++++++++++------ 1 file changed, 72 insertions(+), 30 deletions(-) diff --git a/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb b/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb index dcb5f309..ca0ee82a 100644 --- a/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb +++ b/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb @@ -19,6 +19,7 @@ "from itertools import product\n", "import pickle\n", "\n", + "import ipywidgets as ipw\n", "import numpy as np\n", "\n", "from matplotlib import pyplot as plt\n", @@ -26,6 +27,7 @@ "\n", "from stellarphot.analysis.transit_fitting import TransitModelFit\n", "from stellarphot.visualization.transit_plots import *\n", + "from stellarphot.visualization.fits_opener import FitsOpener\n", "\n", "from astropy.timeseries import BinnedTimeSeries, TimeSeries, aggregate_downsample\n", "from astropy.time import Time\n", @@ -40,6 +42,20 @@ "### 0. Get some data" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fo = FitsOpener(title=\"Select your photometry/flux file\", filter_pattern=[\"*.csv\", \"*.fits\"])\n", + "fo2 = FitsOpener(title=\"Select your TESS info file\", filter_pattern=[\"*.pickle\"])\n", + "\n", + "box = ipw.VBox()\n", + "box.children = [fo.file_chooser, fo2.file_chooser]\n", + "box" + ] + }, { "cell_type": "code", "execution_count": null, @@ -47,10 +63,10 @@ "outputs": [], "source": [ "# 👉 File with photometry, including flux\n", - "photometry_file = 'aperture_locations.csv'\n", + "photometry_file = fo.path\n", "\n", "# 👉 File with exoplanet info in\n", - "tess_info_output_file = 'tess-info.pickle'" + "tess_info_output_file = fo2.path" ] }, { @@ -66,12 +82,10 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "tess_info.tic_id" + "### You may need to alter some of the settings here" ] }, { @@ -80,24 +94,6 @@ "metadata": {}, "outputs": [], "source": [ - "# Enter your object's period here\n", - "period = tess_info.period\n", - "\n", - "# Enter the epoch here\n", - "epoch = tess_info.epoch # Time(2458761.602894, scale='tdb', format='jd')\n", - "\n", - "# Enter the duration below\n", - "duration = tess_info.duration\n", - "\n", - "# Enter the transit depth here -- get the \"ppm\" value from ExoFOP-TESS\n", - "depth = tess_info.depth\n", - "\n", - "# Enter object name\n", - "obj = 'TIC ' + tess_info.tic_id\n", - "\n", - "# Enter filter\n", - "phot_filter = 'gp'\n", - "\n", "# These affect the fitting that is done\n", "\n", "#bin size in minutes\n", @@ -105,6 +101,7 @@ "\n", "# Keep the time of transit fixed?\n", "keep_fixed_transit_time = True\n", + "transit_time_range = 60 * u.min\n", "\n", "# Keep radius of planet fixed?\n", "\n", @@ -124,6 +121,31 @@ "fit_width = False\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Enter your object's period here\n", + "period = tess_info.period\n", + "\n", + "# Enter the epoch here\n", + "epoch = tess_info.epoch # Time(2458761.602894, scale='tdb', format='jd')\n", + "\n", + "# Enter the duration below\n", + "duration = tess_info.duration\n", + "\n", + "# Enter the transit depth here -- get the \"ppm\" value from ExoFOP-TESS\n", + "depth = tess_info.depth\n", + "\n", + "# Enter object name\n", + "obj = 'TIC ' + tess_info.tic_id\n", + "\n", + "# Enter filter\n", + "phot_filter = 'ip'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -334,7 +356,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 3.5 👉👉👉 Constrain the fits if you want 👈👈👈\n", + "### 3.5 Constrain the fits if you want\n", "\n", "#### Exoplanet parameters" ] @@ -370,6 +392,26 @@ "mod.model.width_trend.fixed = not fit_width" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "detrended_by = []\n", + "if fit_airmass:\n", + " detrended_by.append('Airmass')\n", + "\n", + "if fit_spp:\n", + " detrended_by.appened('SPP')\n", + "\n", + "if fit_width:\n", + " detrended_by.append('Wdith')\n", + "\n", + "detrended_by = (\"Detrended by: \" + \",\".join(detrended_by)) if detrended_by else \"No detrending\"\n", + " " + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -500,10 +542,10 @@ "plt.plot(photometry['BJD'] - 2400000, normalized_flux, 'b.', label=f\"rel_flux_T1 (RMS={rel_flux_rms:.5f})\", ms=4)\n", "\n", "plt.plot(mod.times, flux_full_detrend - 0.04, '.', c='r', ms=4,\n", - " label=f\"rel_flux_T1 (Airmass and X(FITS) detrended)(RMS={rel_detrended_flux_rms:.5f}), (bin size={bin_size} min)\")\n", + " label=f\"rel_flux_T1 ({detrended_by})(RMS={rel_detrended_flux_rms:.5f}), (bin size={bin_size} min)\")\n", "\n", "plt.plot(mod.times, flux_full_detrend - 0.08, '.', c='g', ms=4,\n", - " label=f\"rel_flux_T1 (Airmass detrended with transit fit)(RMS={rel_model_rms:.5f}), (bin size={bin_size})\")\n", + " label=f\"rel_flux_T1 ({detrended_by} with transit fit)(RMS={rel_model_rms:.5f}), (bin size={bin_size})\")\n", "plt.plot(mod.times, flux_full_detrend_model - 0.08, c='g', ms=4,\n", " label=f\"rel_flux_T1 Transit Model ([P={mod.model.period.value:.4f}], \"\n", " f\"(Rp/R*)^2={(mod.model.rp.value)**2:.4f}, \\na/R*={mod.model.a.value:.4f}, \"\n", @@ -538,7 +580,7 @@ "ax.set_yticks(grid_y_ticks)\n", "plt.grid()\n", "\n", - "plt.savefig('TIC272758199-01_20200701_Paul-P-Feder-0.4m_gp_lightcurve.png', facecolor='w')" + "plt.savefig(f'TIC{tess_info.tic_id}-01_20200701_Paul-P-Feder-0.4m_gp_lightcurve.png', facecolor='w')" ] }, { @@ -577,12 +619,12 @@ " if fix:\n", " setattr(mod.model, f\"{param}_trend\", 0.0)\n", " trend_mod.fixed = fix\n", - " this_summary.append(f\"{param}: {fix}\")\n", + " this_summary.append(f\"{param}: {not fix}\")\n", "\n", " settings.append(', '.join(this_summary))\n", " mod.fit()\n", " BICs.append(mod.BIC)\n", - " return Table(data=[settings, BICs], names=['Detrend params', 'BIC'])" + " return Table(data=[settings, BICs], names=['Fit this param?', 'BIC'])" ] }, { From a5d775ead5d11f25f571dc7da556eb114d61b6a4 Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Tue, 6 Dec 2022 10:21:58 -0600 Subject: [PATCH 3/3] Use bounds on transit time --- stellarphot/notebooks/photometry/06-transit-fit-template.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb b/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb index ca0ee82a..285d9185 100644 --- a/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb +++ b/stellarphot/notebooks/photometry/06-transit-fit-template.ipynb @@ -367,7 +367,7 @@ "metadata": {}, "outputs": [], "source": [ - "mod.model.t0.bounds = [mid.jd - 2400000 - 0.01, mid.jd - 2400000 + 0.01]\n", + "mod.model.t0.bounds = [mid.jd - 2400000 - transit_time_range.to('day').value/2, mid.jd - 2400000 + transit_time_range.to('day').value/2]\n", "mod.model.t0.fixed = keep_fixed_transit_time\n", "mod.model.a.fixed = keep_fixed_radius_orbit\n", "mod.model.rp.fixed = keep_fixed_radius_planet\n",