Skip to content

Commit

Permalink
Merge pull request #485 from mwcraig/fix-bjd-column
Browse files Browse the repository at this point in the history
Fix bjd column among other exoplanet fixes
  • Loading branch information
mwcraig authored Dec 1, 2024
2 parents 506c488 + 3c8b98e commit 9b546fa
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 115 deletions.
18 changes: 17 additions & 1 deletion .jp_app_launcher_stellarphot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@

- title: Initial exoplanet model
description: Do an initial fit to a transit
source: ../stellarphot/tess-intial-model-fit.ipynb
source: ../stellarphot/tess-initial-model-fit.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
catalog: Stellarphot analysis and tools

- title: Second exoplanet model fit
description: Second transit model fit
source: ../stellarphot/tess-second-model-fit.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
catalog: Stellarphot analysis and tools

- title: Exoplanet model fit with EXOTIC
description: The final exoplanet fit
source: ../stellarphot/tess-EXOTIC-fit.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
Expand Down
14 changes: 11 additions & 3 deletions stellarphot/differential_photometry/aij_rel_fluxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from astropy.coordinates import SkyCoord
from astropy.table import QTable, Table
from astropy.time import Time

from stellarphot import PhotometryData, SourceListData

Expand Down Expand Up @@ -240,13 +241,20 @@ def add_relative_flux_column(
if "bjd" not in flux_table.colnames:
if verbose:
print("Adding BJD column to photometry data")
# Add dummy BJD column so the whole table has one
flux_table["bjd"] = np.nan
# Accumulate the BJD here
bjds = []

flux_group = flux_table.group_by("file")
for group in flux_group.groups:
mean_ra = group["ra"].mean()
mean_dec = group["dec"].mean()
group.add_bjd_col(bjd_coordinates=SkyCoord(mean_ra, mean_dec))
bjds.extend(group["bjd"].jd)

# Each (ephemeral) group had a BJD, this adds the column to the
# original table.
flux_group["bjd"] = Time(bjds, scale="tdb", format="jd")

if verbose:
print("Writing photometry data with relative flux columns")
flux_table.write(output_file, overwrite=True)
flux_group.write(output_file, overwrite=True)
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"from pathlib import Path\n",
"import pickle\n",
"\n",
"import numpy as np\n",
"import numpy as np \n",
"\n",
"from astropy.table import Table\n",
"from astropy.table import Table \n",
"\n",
"#from try_json_editing_rev1 import whole_thing, generate_json_file_name, exotic_arguments, get_values_from_widget\n",
"from stellarphot.transit_fitting.gui import generate_json_file_name, exotic_arguments, get_values_from_widget, exotic_settings_widget, populate_TOI_boxes\n",
"from stellarphot.settings.fits_opener import FitsOpener\n",
"from stellarphot import PhotometryData\n",
"from stellarphot.io import TOI"
"from stellarphot.io import TOI\n",
"from stellarphot.gui_tools.photometry_widget_functions import TessAnalysisInputControls"
]
},
{
Expand All @@ -30,15 +31,49 @@
"This notebook will do a different kind of fit to your exoplanet data. It takes longer to run than the fitting we've done so far, which is why we didn't begin with this type of fit."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 0. Get some data\n",
"\n",
"+ Select photometry file with relative flux\n",
"+ Select passband\n",
"+ Select TESS info file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fits_opener = FitsOpener(title=\"Select your photometry/relative flux file\", filter_pattern=[\"*.ecsv\"])\n",
"taic = TessAnalysisInputControls()\n",
"taic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# 👉 File with photometry, including flux\n",
"photometry_file = taic.photometry_data_file\n",
"inp_photometry = taic.phot_data\n",
"\n",
"fits_opener.file_chooser"
"# 👉 File with exoplanet info in\n",
"tess_info_output_file = taic.tic_info_file\n",
"tess_info = TOI.model_validate_json(tess_info_output_file.read_text())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Get just the target star and some information about it"
]
},
{
Expand All @@ -47,10 +82,17 @@
"metadata": {},
"outputs": [],
"source": [
"input_data_file = fits_opener.path\n",
"toi_info_file = Path(\"TIC-194461202-info.json\")\n",
"\n",
"tess_info = TOI.model_validate_json(toi_info_file.read_text())"
"if np.isnan(inp_photometry['bjd']).all():\n",
" inp_photometry.add_bjd_col()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"photometry = inp_photometry.lightcurve_for(1, flux_column=\"relative_flux\", passband=taic.passband).remove_nans()"
]
},
{
Expand All @@ -70,12 +112,8 @@
"metadata": {},
"outputs": [],
"source": [
"inp_data = PhotometryData.read(input_data_file)\n",
"inp_data = inp_data[inp_data['star_id'] == 1]\n",
"inp_data.add_bjd_col()\n",
"# inp_data = inp_data[inp_data['BJD'] > 2459795.75]\n",
"\n",
"out_data = inp_data['bjd', 'relative_flux', 'relative_flux_error', 'airmass']\n",
"out_data = photometry['bjd', 'relative_flux', 'relative_flux_error', 'airmass']\n",
"out_data.write(exotic_data_file, overwrite=True)"
]
},
Expand All @@ -90,6 +128,13 @@
"populate_TOI_boxes(tess_info, settings.value_widget)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## YOU MAY NEED DATA FROM HERE: https://exofop.ipac.caltech.edu/tess/\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -145,9 +190,16 @@
"metadata": {},
"outputs": [],
"source": [
"!exotic --override --pre TIC_194461202-2024-10-08-SR.json"
"!exotic --override --pre TIC_370981403-2024-10-18-SG.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -158,7 +210,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "stelldev-pyd2",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -172,7 +224,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
"### Get just the target star and some information about it"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if np.isnan(inp_photometry['bjd']).all():\n",
" inp_photometry.add_bjd_col()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -198,7 +208,7 @@
"binned2 = aggregate_downsample(ts2, time_bin_size=model_options.bin_size * u.min, aggregate_func=add_quad)\n",
"\n",
"binned[\"normalized_flux_error\"] = binned2[\"normalized_flux_error\"]\n",
"# binned_time = BinnedTimeSeries(photometry['bjd'], time_bin_start=first_time, time_bin_end=last_time, time_bin_size=bin_size)"
"binned = binned[~np.isnan(binned[\"normalized_flux\"])]"
]
},
{
Expand Down Expand Up @@ -389,7 +399,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 9b546fa

Please sign in to comment.