-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
196 additions
and
0 deletions.
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
stellarphot/notebooks/photometry/transform-pared-back.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"import numpy as np\n", | ||
"from scipy.optimize import curve_fit\n", | ||
"\n", | ||
"from astropy.table import Table, vstack\n", | ||
"from astropy.coordinates import SkyCoord\n", | ||
"\n", | ||
"%matplotlib inline\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"from fit_functions import get_cat, f, opts_to_str, calc_residual\n", | ||
"from calib_function import transform_to_catalog" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Parameters\n", | ||
"\n", | ||
"The magnitudes in each image are fit using this model:\n", | ||
"\n", | ||
"$$\n", | ||
"r_{p, c} = a r_{p, inst} + b r_{p, inst}^2 + c (B_c - V_c) + d (B_c - V_c)^2 + z\n", | ||
"$$\n", | ||
"\n", | ||
"The parameters in the cell below set the range of values the fit is constrained to. The way to fix a parameter is to give it a very, very small range for the constraint.\n", | ||
"\n", | ||
"More specifically, each of the fit values is subject to these constraints:\n", | ||
"\n", | ||
"+ $1 - a_{delta} < a < 1 + a_{delta}$\n", | ||
"+ $b_{min} < b < -b_{min}$\n", | ||
"+ $c_{min} < c < -c_{min}$\n", | ||
"+ $d_{min} < d < -d_{min}$\n", | ||
"+ The range for the zero point is $18 < z < 22$.\n", | ||
"\n", | ||
"\n", | ||
"`output_dir` is where the PNG and FITS files generated by this notebook are stored. `run_name` is a descriptive name for the settings you have chosen that gets included in the output file names.\n", | ||
"\n", | ||
"### *Recommendation:*\n", | ||
"\n", | ||
"+ Keep $b$ essentially fixed. \n", | ||
"+ Fixing $d$ is ok for now too, I think.\n", | ||
"\n", | ||
"In both cases, setting a min of `1e-6` or something should do the trick.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"tags": [ | ||
"parameters" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"a_delta = 0.5\n", | ||
"b_min = -0.1\n", | ||
"c_min = -0.5\n", | ||
"d_min = -1e-6\n", | ||
"\n", | ||
"our_filters = ['B', 'ip']\n", | ||
"\n", | ||
"aavso_band_names = dict(B='B', ip='SI')\n", | ||
"\n", | ||
"cat_color_colums = dict(\n", | ||
" B=('Bmag', 'Vmag'),\n", | ||
" ip=('r_mag', 'i_mag')\n", | ||
")\n", | ||
"\n", | ||
"cat_filter = dict(B='Bmag', ip='i_mag')\n", | ||
"\n", | ||
"input_photometry_file = 'combined_photometry.csv'\n", | ||
"output_photometry_file = 'some_name.csv'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"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'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Get ready for the transform" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"filter_groups = all_mags.group_by('filter')\n", | ||
"\n", | ||
"\n", | ||
"# Check: do we have any unexpected filters?\n", | ||
"\n", | ||
"assert set(k[0] for k in filter_groups.groups.keys) == set(our_filters)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Do the transforms, one filter at a time" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"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", | ||
" \n", | ||
" transform_to_catalog(by_bjd, f'mag_inst', aavso_band_names[k], \n", | ||
" obs_error_column='mag_error', \n", | ||
" zero_point_range=[12, 25],\n", | ||
" c_delta=0.5, # b_delta=0.1, \n", | ||
" cat_filter=cat_filter[k], cat_color=cat_color_colums[k],\n", | ||
" in_place=True);\n", | ||
" output_table.append(by_bjd.copy())\n", | ||
"\n", | ||
"output_table = vstack(output_table, join_type='outer')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"output_table.colnames" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"output_table.write(output_photometry_file)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"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.10.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |