Skip to content

Commit

Permalink
Move time filtering to a function and out of notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Nov 25, 2024
1 parent bf086ee commit 305678a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 74 deletions.
47 changes: 47 additions & 0 deletions stellarphot/gui_tools/photometry_widget_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,53 @@ def passband(self):
return self._passband.value


def filter_by_dates(
phot_times=None,
use_no_data_before=None,
use_no_data_between=None,
use_no_data_after=None,
):
n_dropped = 0

bad_data = phot_times < use_no_data_before

n_dropped = bad_data.sum()

if n_dropped > 0:
print(
f"πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰ Dropping {n_dropped} data points before "
f"BJD {use_no_data_before}"
)

bad_data = bad_data | (
(use_no_data_between[0][0] < phot_times)
& (phot_times < use_no_data_between[0][1])
)

new_dropped = bad_data.sum() - n_dropped

if new_dropped:
print(
f"πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰ Dropping {new_dropped} data points between "
f"BJD {use_no_data_between[0][0]} and {use_no_data_between[0][1]}"
)

n_dropped += new_dropped

bad_data = bad_data | (phot_times > use_no_data_after)

new_dropped = bad_data.sum() - n_dropped

if new_dropped:
print(
f"πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰ Dropping {new_dropped} data points after "
f"BJD {use_no_data_after}"
)

n_dropped += new_dropped
return bad_data


class PhotometrySettingsOLDBAD:
"""
A class to hold the widgets for photometry settings.
Expand Down
105 changes: 31 additions & 74 deletions stellarphot/notebooks/photometry/06-transit-fit-template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"from stellarphot.transit_fitting import TransitModelFit, TransitModelOptions\n",
"from stellarphot.io import TOI\n",
"from stellarphot.plotting import plot_transit_lightcurve\n",
"from stellarphot.gui_tools.photometry_widget_functions import TessAnalysisInputControls\n"
"from stellarphot.gui_tools.photometry_widget_functions import TessAnalysisInputControls, filter_by_dates\n"
]
},
{
Expand Down Expand Up @@ -78,79 +78,6 @@
"photometry = inp_photometry.lightcurve_for(1, flux_column=\"relative_flux\", passband=taic.passband).remove_nans()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### πŸ‘‡πŸ‘‡πŸ‘‡ use this to exclude some data (only if needed!) πŸ‘‡πŸ‘‡πŸ‘‡\n",
"\n",
"Option to filter by date..even though you do not know yet what the data looks like"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"use_no_data_before = Time(2400000, format=\"jd\", scale=\"tdb\")\n",
"\n",
"use_no_data_between = [\n",
" [Time(2400000, format=\"jd\", scale=\"tdb\"), Time(2400000, format=\"jd\", scale=\"tdb\")]\n",
"]\n",
"\n",
"use_no_data_after = Time(2499999, format=\"jd\", scale=\"tdb\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Actually filter out data by date"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"phot_times = Time(photometry[\"bjd\"], format=\"jd\", scale=\"tdb\")\n",
"\n",
"n_dropped = 0\n",
"\n",
"bad_data = phot_times < use_no_data_before\n",
"\n",
"n_dropped = bad_data.sum()\n",
"\n",
"if n_dropped > 0:\n",
" print(f\"πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰ Dropping {n_dropped} data points before BJD {use_no_data_before}\")\n",
"\n",
"bad_data = bad_data | (\n",
" (use_no_data_between[0][0] < phot_times) & (phot_times < use_no_data_between[0][1])\n",
")\n",
"\n",
"new_dropped = bad_data.sum() - n_dropped\n",
"\n",
"if new_dropped:\n",
" print(\n",
" f\"πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰ Dropping {new_dropped} data points between BJD {use_no_data_between[0][0]} and {use_no_data_between[0][1]}\"\n",
" )\n",
"\n",
"n_dropped += new_dropped\n",
"\n",
"bad_data = bad_data | (phot_times > use_no_data_after)\n",
"\n",
"new_dropped = bad_data.sum() - n_dropped\n",
"\n",
"if new_dropped:\n",
" print(f\"πŸ‘‰πŸ‘‰πŸ‘‰πŸ‘‰ Dropping {new_dropped} data points after BJD {use_no_data_after}\")\n",
"\n",
"n_dropped += new_dropped\n",
"\n",
"photometry = photometry[~bad_data]"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -352,6 +279,36 @@
"plt.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### πŸ‘‡πŸ‘‡πŸ‘‡ use this to exclude some data (only if needed!) πŸ‘‡πŸ‘‡πŸ‘‡\n",
"\n",
"Option to filter by date..even though you do not know yet what the data looks like"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bad_time = filter_by_dates(\n",
" phot_times=photometry[\"bjd\"],\n",
" use_no_data_before=Time(2400000, format=\"jd\", scale=\"tdb\"),\n",
" use_no_data_between=[\n",
" [\n",
" Time(2400000, format=\"jd\", scale=\"tdb\"),\n",
" Time(2400000, format=\"jd\", scale=\"tdb\"),\n",
" ]\n",
" ],\n",
" use_no_data_after=Time(2499999, format=\"jd\", scale=\"tdb\"),\n",
")\n",
"\n",
"photometry = photometry[~bad_time]"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 305678a

Please sign in to comment.