Skip to content

Commit

Permalink
Simplify relative flux notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Nov 20, 2024
1 parent 865b6e2 commit 8c8f550
Showing 1 changed file with 26 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"\n",
"import numpy as np\n",
"\n",
"from stellarphot.differential_photometry.aij_rel_fluxes import calc_aij_relative_flux\n",
"from stellarphot.differential_photometry.aij_rel_fluxes import add_relative_flux_column\n",
"from stellarphot.settings.fits_opener import FitsOpener\n",
"from stellarphot import PhotometryData, SourceListData"
"from stellarphot.settings.custom_widgets import Spinner"
]
},
{
Expand All @@ -42,7 +42,28 @@
"fits_openr = FitsOpener(title=\"Select your photometry file\", filter_pattern=[\"*.csv\", \"*.ecsv\"])\n",
"fits_openr2 = FitsOpener(\n",
" title=\"Select your aperture file\", filter_pattern=[\"*.csv\", \"*.fits\", \"*.ecsv\"]\n",
")"
")\n",
"go = ipw.Button(description=\"Add flux column\", disabled=True)\n",
"prog_box = ipw.HBox()\n",
"progress_output = ipw.Output()\n",
"spinner = Spinner()\n",
"prog_box.children = [spinner, progress_output]\n",
"\n",
"def on_click(button):\n",
" aperture_file = fits_openr2.path\n",
" photometry_file = fits_openr.path\n",
" spinner.start()\n",
" with progress_output:\n",
" add_relative_flux_column(photometry_file, aperture_file, verbose=True)\n",
" spinner.stop()\n",
"\n",
"def enable_go(change):\n",
" if fits_openr.file_chooser.selected_filename and fits_openr2.file_chooser.selected_filename:\n",
" go.disabled = False\n",
"\n",
"fits_openr.file_chooser.observe(enable_go, names=\"_value\")\n",
"fits_openr2.file_chooser.observe(enable_go, names=\"_value\")\n",
"go.on_click(on_click)"
]
},
{
Expand All @@ -54,121 +75,9 @@
"outputs": [],
"source": [
"box = ipw.VBox()\n",
"box.children = [fits_openr.file_chooser, fits_openr2.file_chooser]\n",
"box.children = [fits_openr.file_chooser, fits_openr2.file_chooser, go, prog_box]\n",
"box"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run the remaining cells"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"aperture_file = fits_openr2.path\n",
"photometry_file = fits_openr.path\n",
"\n",
"output_file = photometry_file.stem + \"-relative-flux\" + photometry_file.suffix"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"photometry = PhotometryData.read(photometry_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"comp_table = SourceListData.read(aperture_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"comp_table[\"coord\"] = SkyCoord(\n",
" ra=comp_table[\"ra\"], dec=comp_table[\"dec\"], frame=\"icrs\"\n",
")\n",
"comp_bool = comp_table[\"marker name\"] == [\"APASS comparison\"]\n",
"only_comp_stars = comp_table[comp_bool]\n",
"coords = only_comp_stars[\"coord\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Calculate flux"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# calculate flux\n",
"flux_table = calc_aij_relative_flux(photometry, only_comp_stars)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if \"bjd\" not in flux_table.colnames:\n",
" flux_group = flux_table.group_by(\"file\")\n",
" # Add dummy BJD column so the whole table has one\n",
" flux[\"bjd\"] = np.nan\n",
" for group in flux_group.groups:\n",
" mean_ra = group[\"ra\"].mean()\n",
" mean_dec = group[\"dec\"].mean()\n",
" group.add_bjd_col(bjd_coordinates=SkyCoord(mean_ra, mean_dec))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"flux_table.write(output_file, overwrite=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -187,7 +96,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8c8f550

Please sign in to comment.