Skip to content

Commit

Permalink
Initial changes to two broken notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcraig committed Oct 28, 2023
1 parent 6839799 commit 7e5bf1b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 63 deletions.
73 changes: 53 additions & 20 deletions stellarphot/notebooks/photometry/04-transform-pared-back.ipynb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 1,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from pathlib import Path\n",
Expand Down Expand Up @@ -54,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {
"tags": [
"parameters"
Expand All @@ -67,14 +69,15 @@
"c_min = -0.5\n",
"d_min = -1e-6\n",
"\n",
"our_filters = ['B', 'V', 'rp']\n",
"our_filters = ['SI']\n",
"\n",
"aavso_band_names = dict(\n",
" B='B', \n",
" V='V',\n",
" gp='SG',\n",
" rp='SR',\n",
" ip='SI'\n",
" ip='SI',\n",
" SI='SI'\n",
")\n",
"\n",
"cat_color_colums = dict(\n",
Expand All @@ -83,30 +86,34 @@
" gp=('g_mag', 'r_mag'),\n",
" rp=('r_mag', 'i_mag'),\n",
" ip=('r_mag', 'i_mag'),\n",
" \n",
" SI=('r_mag', 'i_mag'),\n",
")\n",
"\n",
"cat_filter = dict(\n",
" B='Bmag', \n",
" V='Vmag',\n",
" gp='g_mag',\n",
" rp='r_mag',\n",
" ip='i_mag')\n",
" ip='i_mag',\n",
" SI='i_mag',\n",
")\n",
"\n",
"input_photometry_file = 'm13-2021-09-28.csv'\n",
"output_photometry_file = 'some_name.csv'"
"input_photometry_file = 'TIC-402828941-2021-09-28.ecsv'\n",
"output_photometry_file = 'some_name.ecsv'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 9,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"all_mags = Table.read(input_photometry_file)\n",
"\n",
"# Ensure we have the right table ordering later\n",
"all_mags.sort(['filter', 'BJD'])"
"all_mags.sort(['passband', 'bjd'])"
]
},
{
Expand All @@ -118,11 +125,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 13,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"filter_groups = all_mags.group_by('filter')\n",
"filter_groups = all_mags.group_by('passband')\n",
"\n",
"\n",
"# Check: do we have any unexpected filters?\n",
Expand All @@ -139,15 +148,39 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 19,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transforming band SI\n"
]
},
{
"ename": "KeyError",
"evalue": "'RA'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[19], line 7\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTransforming band \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mk\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 5\u001b[0m by_bjd \u001b[38;5;241m=\u001b[39m group\u001b[38;5;241m.\u001b[39mgroup_by(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbjd\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 7\u001b[0m \u001b[43mtransform_to_catalog\u001b[49m\u001b[43m(\u001b[49m\u001b[43mby_bjd\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmag_inst\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maavso_band_names\u001b[49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43mobs_error_column\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmag_error\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[43m \u001b[49m\u001b[43mzero_point_range\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m12\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m25\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[43m \u001b[49m\u001b[43mc_delta\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# b_delta=0.1, \u001b[39;49;00m\n\u001b[1;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mcat_filter\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcat_filter\u001b[49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcat_color\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcat_color_colums\u001b[49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[43min_place\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m;\n\u001b[1;32m 13\u001b[0m output_table\u001b[38;5;241m.\u001b[39mappend(by_bjd\u001b[38;5;241m.\u001b[39mcopy())\n\u001b[1;32m 15\u001b[0m output_table \u001b[38;5;241m=\u001b[39m vstack(output_table, join_type\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mouter\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"File \u001b[0;32m~/Development/astronomy/stellarphot/stellarphot/utils/magnitude_transforms.py:609\u001b[0m, in \u001b[0;36mtransform_to_catalog\u001b[0;34m(observed_mags_grouped, obs_mag_col, obs_filter, obs_error_column, cat_filter, cat_color, a_delta, a_cen, b_delta, c_delta, d_delta, zero_point_range, in_place, fit_diff, verbose)\u001b[0m\n\u001b[1;32m 606\u001b[0m cat_coords \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 608\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m file, one_image \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(observed_mags_grouped\u001b[38;5;241m.\u001b[39mgroups\u001b[38;5;241m.\u001b[39mkeys, observed_mags_grouped\u001b[38;5;241m.\u001b[39mgroups):\n\u001b[0;32m--> 609\u001b[0m our_coords \u001b[38;5;241m=\u001b[39m SkyCoord(\u001b[43mone_image\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mRA\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m, one_image[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDec\u001b[39m\u001b[38;5;124m'\u001b[39m], unit\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdegree\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 610\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cat \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m cat_coords \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 611\u001b[0m cat, cat_coords \u001b[38;5;241m=\u001b[39m get_cat(one_image)\n",
"File \u001b[0;32m~/miniconda3/envs/stell2-dev/lib/python3.11/site-packages/astropy/table/table.py:2055\u001b[0m, in \u001b[0;36mTable.__getitem__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 2053\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getitem__\u001b[39m(\u001b[38;5;28mself\u001b[39m, item):\n\u001b[1;32m 2054\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(item, \u001b[38;5;28mstr\u001b[39m):\n\u001b[0;32m-> 2055\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[43m[\u001b[49m\u001b[43mitem\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 2056\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(item, (\u001b[38;5;28mint\u001b[39m, np\u001b[38;5;241m.\u001b[39minteger)):\n\u001b[1;32m 2057\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mRow(\u001b[38;5;28mself\u001b[39m, item)\n",
"File \u001b[0;32m~/miniconda3/envs/stell2-dev/lib/python3.11/site-packages/astropy/table/table.py:264\u001b[0m, in \u001b[0;36mTableColumns.__getitem__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Get items from a TableColumns object.\u001b[39;00m\n\u001b[1;32m 254\u001b[0m \n\u001b[1;32m 255\u001b[0m \u001b[38;5;124;03m::\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 261\u001b[0m \u001b[38;5;124;03m tc[1:3] # <TableColumns names=('b', 'c')>\u001b[39;00m\n\u001b[1;32m 262\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 263\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(item, \u001b[38;5;28mstr\u001b[39m):\n\u001b[0;32m--> 264\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mOrderedDict\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__getitem__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mitem\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 265\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(item, (\u001b[38;5;28mint\u001b[39m, np\u001b[38;5;241m.\u001b[39minteger)):\n\u001b[1;32m 266\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalues())[item]\n",
"\u001b[0;31mKeyError\u001b[0m: 'RA'"
]
}
],
"source": [
"output_table = [] \n",
"\n",
"for k, group in zip(our_filters, filter_groups.groups):\n",
" print(f'Transforming band {k}')\n",
" by_bjd = group.group_by('BJD')\n",
" by_bjd = group.group_by('bjd')\n",
" \n",
" transform_to_catalog(by_bjd, f'mag_inst', aavso_band_names[k], \n",
" obs_error_column='mag_error', \n",
Expand Down Expand Up @@ -213,7 +246,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 7e5bf1b

Please sign in to comment.