From b1dbf9adf2f930e153048239d8f4d236051c1e55 Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Wed, 2 Nov 2022 09:51:55 -0500 Subject: [PATCH] Draft transform notebook --- .../photometry/transform-pared-back.ipynb | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 stellarphot/notebooks/photometry/transform-pared-back.ipynb diff --git a/stellarphot/notebooks/photometry/transform-pared-back.ipynb b/stellarphot/notebooks/photometry/transform-pared-back.ipynb new file mode 100644 index 00000000..b9aa31b0 --- /dev/null +++ b/stellarphot/notebooks/photometry/transform-pared-back.ipynb @@ -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 +}