Skip to content

Commit

Permalink
Merge pull request #89 from mwcraig/notebook-tweaks
Browse files Browse the repository at this point in the history
Notebook tweaks
  • Loading branch information
mwcraig authored Dec 6, 2022
2 parents 8d3fab9 + a5d775e commit 2472305
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,7 +25,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load photometry table "
"### Choose photometry and aperture files"
]
},
{
Expand All @@ -47,6 +49,13 @@
"box"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run the remaining cells"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -70,13 +79,6 @@
"photometry = photometry[~del_rows]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load comp star table"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -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": {
Expand Down
104 changes: 73 additions & 31 deletions stellarphot/notebooks/photometry/06-transit-fit-template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"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",
"from astropy.table import Table\n",
"\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",
Expand All @@ -40,17 +42,31 @@
"### 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,
"metadata": {},
"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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -80,31 +94,14 @@
"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",
"bin_size = 5 * u.min\n",
"\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",
Expand All @@ -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,
Expand Down Expand Up @@ -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"
]
Expand All @@ -345,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",
Expand All @@ -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": {},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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')"
]
},
{
Expand Down Expand Up @@ -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'])"
]
},
{
Expand Down

0 comments on commit 2472305

Please sign in to comment.