Skip to content

Commit

Permalink
First draft notebook calculating Broeg weighted mags
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Oct 1, 2023
1 parent f45b78c commit 7da2beb
Showing 1 changed file with 312 additions and 0 deletions.
312 changes: 312 additions & 0 deletions stellarphot/notebooks/photometry/broeg2-trial.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "7e195b60-aa45-404b-ae1b-180a7089cac4",
"metadata": {},
"outputs": [],
"source": [
"from astropy.table import Table, join \n",
"\n",
"import numpy as np\n",
"\n",
"from matplotlib import pyplot as plt\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "05672aa4-ce5c-4be2-bf37-aa5b5f47c115",
"metadata": {},
"outputs": [],
"source": [
"from broeg_weights import broeg_weights2"
]
},
{
"cell_type": "markdown",
"id": "f9596998-0aef-4a47-87da-e54f773c7841",
"metadata": {},
"source": [
"## 👇👇 change the file name 👇👇"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc155555-0847-4a50-ac40-46d407a3b1ed",
"metadata": {},
"outputs": [],
"source": [
"use_phot = Table.read('../../Combined/TIC-81247877-combined-killer-brooks-ified.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2852b113-821b-48ff-8760-721ff71802aa",
"metadata": {},
"outputs": [],
"source": [
"star_ids = np.array(sorted(set(use_phot['star_id'])))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be327b49-65e7-4c9e-ab4f-1391d4d09f7c",
"metadata": {},
"outputs": [],
"source": [
"mags = []\n",
"errs = []\n",
"good_star_ids = []\n",
"for star_id in star_ids:\n",
" mag = use_phot[use_phot[\"star_id\"] == star_id][\"mag_inst\"]\n",
" err = use_phot[use_phot[\"star_id\"] == star_id][\"mag_error\"]\n",
" if np.isnan(mag).any():\n",
" continue\n",
" good_star_ids.append(star_id)\n",
" mags.append(mag)\n",
" errs.append(err)"
]
},
{
"cell_type": "markdown",
"id": "ed648acb-ecb8-4f7f-846d-00940a7e8c30",
"metadata": {},
"source": [
"## Number of stars input, number of stars with no NaNs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee43cf36-9fa6-4f4a-a662-fd04a1dd770a",
"metadata": {},
"outputs": [],
"source": [
"len(star_ids), len(good_star_ids)"
]
},
{
"cell_type": "markdown",
"id": "b5ae488c-a42e-4a12-9dfd-2f79eac5e89b",
"metadata": {},
"source": [
"Check for any stars that are missing data..."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cd4ba06-a0f9-4fe7-8c0e-d8eb99427e6c",
"metadata": {},
"outputs": [],
"source": [
"n_data = [len(mag) for mag in mags]\n",
"n_err = [len(err) for err in errs]\n",
"\n",
"len(mags), len(errs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cb55c400-7740-460b-abe1-1d977bbee278",
"metadata": {},
"outputs": [],
"source": [
"n_max = max(n_data)\n",
"\n",
"bad_star_id_index = []\n",
"for i, n in enumerate(n_data):\n",
" if n != n_max:\n",
" print(f\"Bad {i=} with {n=}\")\n",
" bad_star_id_index.append(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03c5bb67-30a6-4ebc-9716-7fd37e2a3eb4",
"metadata": {},
"outputs": [],
"source": [
"for idx in bad_star_id_index:\n",
" del good_star_ids[idx]\n",
" del mags[idx]\n",
" del errs[idx]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af9efa44-9bd1-481c-8fd5-d10977a51e6f",
"metadata": {},
"outputs": [],
"source": [
"mags_a = np.array(mags)\n",
"errs_a = np.array(errs)\n",
"mags_a.shape, errs_a.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d348ff35-c396-42cd-9258-64dad04a5b5d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"weights, lights = broeg_weights2(mags_a, errs_a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8e699bd-4500-43d3-8940-fdf9ca74a163",
"metadata": {},
"outputs": [],
"source": [
"len(weights)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a6116368-e66d-4f5c-a663-5094d505c26a",
"metadata": {},
"outputs": [],
"source": [
"plt.plot(weights[-1] - weights[-2])\n",
"#plt.ylim(0.002, 0.004)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b6c8a52-ea5f-4bd3-a4ac-3293a8cae483",
"metadata": {},
"outputs": [],
"source": [
"plt.plot(weights[0], label=\"0\")\n",
"plt.plot(weights[-1], label=\"-1\")\n",
"plt.legend()\n",
"plt.grid()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12483d7d-698a-4077-b354-935d250edee1",
"metadata": {},
"outputs": [],
"source": [
"lights[-1].shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c02a61e2-5bcf-4f82-8c96-24f58ce95289",
"metadata": {},
"outputs": [],
"source": [
"good_star_ids[np.argmax(weights[0])]"
]
},
{
"cell_type": "markdown",
"id": "4162f569-3855-443d-b328-7016d5f7143e",
"metadata": {},
"source": [
"## 👇👇 set which star you want to plot 👇👇"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e8435c8-c3e3-4c49-b933-39cc5c493bf5",
"metadata": {},
"outputs": [],
"source": [
"da_star = 303\n",
"da_index = np.where(np.array(good_star_ids) == da_star)[0][0]\n",
"da_index, good_star_ids[da_index]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b5cfc76-dfdb-4df2-8843-e24c4900b560",
"metadata": {},
"outputs": [],
"source": [
"plt.plot(lights[-1][da_index, :], '.')\n",
"plt.grid()\n",
"plt.ylim(reversed(plt.ylim()))\n",
"plt.xlabel('data point number')\n",
"plt.ylabel('differential magnitude')\n",
"plt.title(f'Star ID: {da_star}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "05e25851-200c-455f-8f0b-631d58651e4d",
"metadata": {},
"outputs": [],
"source": [
"just_da_star = use_phot[use_phot['star_id'] == da_star]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "671e1989-8c82-44a9-a36e-a9106800d020",
"metadata": {},
"outputs": [],
"source": [
"plt.plot(just_da_star['mag_inst_cal'], '.')\n",
"plt.grid()\n",
"plt.ylim(reversed(plt.ylim()))\n",
"plt.xlabel('data point number')\n",
"plt.ylabel('calibrated magnitude')\n",
"plt.title(f'Star ID: {da_star}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8286191d-9f08-43ab-ae7d-86351f3a3c55",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 7da2beb

Please sign in to comment.