From f47a33945e90249c55b3cbc5da73d9b50c5854bf Mon Sep 17 00:00:00 2001 From: jrob93 Date: Tue, 28 May 2024 17:23:39 +0100 Subject: [PATCH 1/9] add some missing docs --- src/adler/science/PhaseCurve.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/adler/science/PhaseCurve.py b/src/adler/science/PhaseCurve.py index dc53468..715c0cc 100644 --- a/src/adler/science/PhaseCurve.py +++ b/src/adler/science/PhaseCurve.py @@ -49,6 +49,16 @@ def __init__(self, abs_mag=18, phase_param=0.2, phase_param2=None, model_name="H print("no model selected") def SetModelBounds(self, param, bound_vals=(None, None)): + """By default the sbpy model uses "physical" boundaries for the phase parameter(s). + Use this function to change the boundaries of a parameter when fitting, or remove them by setting to None. + + Parameters + ----------- + param : str + Adler PhaseCurve parameter to adjust boundaries of: abs_mag, phase_param, phase_param2 + bound_vals: tuple + The (lower, upper) boundaries to use when fitting - set (None, None) for no bounds + """ model_sbpy = self.model_function param_names = model_sbpy.param_names x = getattr(model_sbpy, param) From ec47db16d88201fa2aec763319d992b878f02b00 Mon Sep 17 00:00:00 2001 From: jrob93 Date: Tue, 28 May 2024 17:34:15 +0100 Subject: [PATCH 2/9] add an example nb --- docs/notebooks/adler_phasecurve_example.ipynb | 350 ++++++++++++++++++ docs/requirements.txt | 1 + 2 files changed, 351 insertions(+) create mode 100644 docs/notebooks/adler_phasecurve_example.ipynb diff --git a/docs/notebooks/adler_phasecurve_example.ipynb b/docs/notebooks/adler_phasecurve_example.ipynb new file mode 100644 index 0000000..9098084 --- /dev/null +++ b/docs/notebooks/adler_phasecurve_example.ipynb @@ -0,0 +1,350 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d591f5d8-9148-46ff-a62b-0f2a29eb806c", + "metadata": {}, + "outputs": [], + "source": [ + "from adler.dataclasses.AdlerPlanetoid import AdlerPlanetoid\n", + "from adler.science.PhaseCurve import PhaseCurve\n", + "\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib.gridspec as gridspec\n", + "import astropy.units as u" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "645efb98-567d-481e-a79c-b1cfdc828726", + "metadata": {}, + "outputs": [], + "source": [ + "# ssObjectId of object to analyse\n", + "ssoid = \"8268570668335894776\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10b36aab-b322-49b8-8ff3-49bef68d7416", + "metadata": {}, + "outputs": [], + "source": [ + "# retrieve the object data via adler\n", + "\n", + "# # here we use an offline SQL database which contains the observations of the sso\n", + "fname = \"../../tests/data/testing_database.db\"\n", + "planetoid = AdlerPlanetoid.construct_from_SQL(ssoid, sql_filename=fname)\n", + "\n", + "# alternatively we can retrieve the object data directly from the RSP\n", + "# planetoid = AdlerPlanetoid.construct_from_RSP(ssoid)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d9a0623d-0dc7-49c1-99dd-a76ef970a3ff", + "metadata": {}, + "outputs": [], + "source": [ + "# inspect the whole object\n", + "planetoid.__dict__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d360360-025b-4a77-acf5-325b2f2d1873", + "metadata": {}, + "outputs": [], + "source": [ + "# inspect just the ssObject table\n", + "planetoid.SSObject.__dict__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "be8f8d63", + "metadata": {}, + "outputs": [], + "source": [ + "# retrieve all observations in the r filter\n", + "obs_r = planetoid.observations_in_filter(\"r\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da1e483d", + "metadata": {}, + "outputs": [], + "source": [ + "# inspect the fields available in the observations table\n", + "obs_r.__dict__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d7dc125-06c1-49ad-8854-17d8c8b6954f", + "metadata": {}, + "outputs": [], + "source": [ + "# plot the observations as a phasecurve\n", + "x_plot = \"phaseAngle\"\n", + "y_plot = \"reduced_mag\"\n", + "\n", + "x = getattr(obs_r, x_plot)\n", + "y = getattr(obs_r, y_plot)\n", + "xerr = obs_r.magErr\n", + "\n", + "fig = plt.figure()\n", + "gs = gridspec.GridSpec(1, 1)\n", + "ax1 = plt.subplot(gs[0, 0])\n", + "\n", + "ax1.errorbar(x, y, xerr, fmt=\"o\")\n", + "\n", + "ax1.invert_yaxis()\n", + "ax1.set_xlabel(x_plot)\n", + "ax1.set_ylabel(y_plot)\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6efe3b5a-09dd-4d5e-9f41-20ea6e1b43df", + "metadata": {}, + "outputs": [], + "source": [ + "# retrieve the phase curve model parameters provided in the ssObject table\n", + "\n", + "sso_r = planetoid.SSObject_in_filter(\"r\")\n", + "\n", + "r_H = sso_r.H\n", + "r_G12 = sso_r.G12\n", + "\n", + "pc = PhaseCurve(abs_mag=r_H * u.mag, phase_param=r_G12, model_name=\"HG12_Pen16\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "80f552f1-8907-4cc9-b57c-2e667eab459c", + "metadata": {}, + "outputs": [], + "source": [ + "# what sbpy model is being used?\n", + "pc.model_function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24c1955e-95cd-4d77-ad05-aa5b8d18620a", + "metadata": {}, + "outputs": [], + "source": [ + "# set up an array of phase angles to plot the model\n", + "alpha = np.linspace(0, np.amax(obs_r.phaseAngle)) * u.deg\n", + "alpha" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c3f30fe0-0d89-4ffa-8237-9c71181d44ee", + "metadata": {}, + "outputs": [], + "source": [ + "# calculate the model reduced magnitude over these phase angles\n", + "red_mag = pc.ReducedMag(alpha)\n", + "red_mag" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "04be98a1-e4dc-4216-bcd9-ef777f6053fb", + "metadata": {}, + "outputs": [], + "source": [ + "# plot the observations with the model phase curve\n", + "x_plot = \"phaseAngle\"\n", + "y_plot = \"reduced_mag\"\n", + "\n", + "x = getattr(obs_r, x_plot)\n", + "y = getattr(obs_r, y_plot)\n", + "xerr = obs_r.magErr\n", + "\n", + "fig = plt.figure()\n", + "gs = gridspec.GridSpec(1, 1)\n", + "ax1 = plt.subplot(gs[0, 0])\n", + "\n", + "ax1.errorbar(x, y, xerr, fmt=\"o\")\n", + "\n", + "ax1.plot(alpha.value, red_mag.value)\n", + "\n", + "ax1.invert_yaxis()\n", + "ax1.set_xlabel(x_plot)\n", + "ax1.set_ylabel(y_plot)\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9815543d-6140-4bdb-8bad-8296994723f4", + "metadata": {}, + "outputs": [], + "source": [ + "# plot the observations as a lightcurve\n", + "x_plot = \"midPointMjdTai\"\n", + "y_plot = \"reduced_mag\"\n", + "\n", + "x = getattr(obs_r, x_plot)\n", + "y = getattr(obs_r, y_plot)\n", + "xerr = obs_r.magErr\n", + "\n", + "fig = plt.figure()\n", + "gs = gridspec.GridSpec(1, 1)\n", + "ax1 = plt.subplot(gs[0, 0])\n", + "\n", + "ax1.errorbar(x, y, xerr, fmt=\"o\")\n", + "\n", + "ax1.invert_yaxis()\n", + "ax1.set_xlabel(x_plot)\n", + "ax1.set_ylabel(y_plot)\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de462b92-3914-4091-b0af-bddd9e9c1ef1", + "metadata": {}, + "outputs": [], + "source": [ + "# do a different phase curve fit to the data\n", + "# adler is able to fit different models, and perform more sophisticated fits" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f92891c9-6ccf-4dac-8887-9545f633ba90", + "metadata": {}, + "outputs": [], + "source": [ + "# create a new PhaseCurve object with a different sbpy model\n", + "pc_fit = PhaseCurve(abs_mag=pc.abs_mag, model_name=\"HG\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db24432b-6d05-4ff2-9d98-e52d8c2e4342", + "metadata": {}, + "outputs": [], + "source": [ + "pc_fit.model_function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9039e2e2-27d9-4d21-b2f6-9504a5b85ce4", + "metadata": {}, + "outputs": [], + "source": [ + "# use adler to fit this new phase curve model to the data\n", + "pc_fit.FitModel(\n", + " phase_angle=obs_r.phaseAngle * u.deg,\n", + " reduced_mag=obs_r.reduced_mag * u.mag,\n", + " mag_err=obs_r.magErr * u.mag,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d4b7144-ee72-45e0-9606-c40f83c443c6", + "metadata": {}, + "outputs": [], + "source": [ + "# plot the observations with both\n", + "x_plot = \"phaseAngle\"\n", + "y_plot = \"reduced_mag\"\n", + "\n", + "x = getattr(obs_r, x_plot)\n", + "y = getattr(obs_r, y_plot)\n", + "xerr = obs_r.magErr\n", + "\n", + "fig = plt.figure()\n", + "gs = gridspec.GridSpec(1, 1)\n", + "ax1 = plt.subplot(gs[0, 0])\n", + "\n", + "ax1.errorbar(x, y, xerr, fmt=\"o\")\n", + "\n", + "ax1.plot(alpha.value, pc.ReducedMag(alpha).value, label=pc.model_name)\n", + "ax1.plot(alpha.value, pc_fit.ReducedMag(alpha).value, label=pc_fit.model_name)\n", + "\n", + "ax1.invert_yaxis()\n", + "ax1.set_xlabel(x_plot)\n", + "ax1.set_ylabel(y_plot)\n", + "ax1.legend()\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b7f39ed4-8334-4e10-a97c-a9471105225b", + "metadata": {}, + "outputs": [], + "source": [ + "# # now we would add our calculated values back into planetoid\n", + "# planetoid.AdlerSchema.r_H = pc_fit.abs_mag\n", + "# planetoid.AdlerSchema.r_G = pc_fit.phase_param" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ca4bbfd-1954-469f-8608-40c52838d300", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "adler-dev", + "language": "python", + "name": "adler-dev" + }, + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/requirements.txt b/docs/requirements.txt index 3979f83..5f633ff 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -8,3 +8,4 @@ jupyter astropy sbpy matplotlib +numpy \ No newline at end of file From c093c78db8f80b8ccc30af55d2a0d5065f436a55 Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 12:06:57 +0100 Subject: [PATCH 3/9] update param names --- docs/notebooks/adler_phasecurve_example.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/notebooks/adler_phasecurve_example.ipynb b/docs/notebooks/adler_phasecurve_example.ipynb index 9098084..9e380a3 100644 --- a/docs/notebooks/adler_phasecurve_example.ipynb +++ b/docs/notebooks/adler_phasecurve_example.ipynb @@ -130,7 +130,7 @@ "r_H = sso_r.H\n", "r_G12 = sso_r.G12\n", "\n", - "pc = PhaseCurve(abs_mag=r_H * u.mag, phase_param=r_G12, model_name=\"HG12_Pen16\")" + "pc = PhaseCurve(H=r_H * u.mag, phase_parameter_1=r_G12, model_name=\"HG12_Pen16\")" ] }, { @@ -245,7 +245,7 @@ "outputs": [], "source": [ "# create a new PhaseCurve object with a different sbpy model\n", - "pc_fit = PhaseCurve(abs_mag=pc.abs_mag, model_name=\"HG\")" + "pc_fit = PhaseCurve(H=pc.H, model_name=\"HG\")" ] }, { From 0fff0b82f92553f6b0d28e0d0e8f6a739d499ab7 Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 12:12:54 +0100 Subject: [PATCH 4/9] add title to nb --- docs/notebooks/adler_phasecurve_example.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/notebooks/adler_phasecurve_example.ipynb b/docs/notebooks/adler_phasecurve_example.ipynb index 9e380a3..ecef8d7 100644 --- a/docs/notebooks/adler_phasecurve_example.ipynb +++ b/docs/notebooks/adler_phasecurve_example.ipynb @@ -1,5 +1,14 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "8738000d", + "metadata": {}, + "source": [ + "# Adler phasecurve models\n", + "This notebook demonstrates how Adler implements phasecurve models. An example object with photometric observations is loaded. We can create a phasecurve model object from the SSObject parameters associated with this object. We can also fit a phasecurve model of our choice to the observations." + ] + }, { "cell_type": "code", "execution_count": null, From ce7866dc164247b0115a2d64f9fc2a5fa975690c Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 12:19:42 +0100 Subject: [PATCH 5/9] add phasecurve nb to toctree --- docs/notebooks.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/notebooks.rst b/docs/notebooks.rst index 7f7e544..61e3308 100644 --- a/docs/notebooks.rst +++ b/docs/notebooks.rst @@ -4,3 +4,4 @@ Notebooks .. toctree:: Introducing Jupyter Notebooks + Adler phasecurve models From 98bfcad0f578af855b3c113b70052a8b292e717f Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 12:33:41 +0100 Subject: [PATCH 6/9] add ipykernel --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 5f633ff..eefb0fc 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -8,4 +8,5 @@ jupyter astropy sbpy matplotlib -numpy \ No newline at end of file +numpy +ipykernel \ No newline at end of file From 878fce4dd60ce9baaa7147fc91dca60c03927da4 Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 12:38:20 +0100 Subject: [PATCH 7/9] change nb kernel to python3 ipykernel --- docs/notebooks/adler_phasecurve_example.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/notebooks/adler_phasecurve_example.ipynb b/docs/notebooks/adler_phasecurve_example.ipynb index ecef8d7..6e64763 100644 --- a/docs/notebooks/adler_phasecurve_example.ipynb +++ b/docs/notebooks/adler_phasecurve_example.ipynb @@ -337,9 +337,9 @@ ], "metadata": { "kernelspec": { - "display_name": "adler-dev", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "adler-dev" + "name": "python3" }, "language_info": { "codemirror_mode": { From 4b10c32a53fced34d89167ab8912e855d1024ace Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 12:43:50 +0100 Subject: [PATCH 8/9] add scipy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index eefb0fc..a02ca08 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -9,4 +9,5 @@ astropy sbpy matplotlib numpy -ipykernel \ No newline at end of file +ipykernel +scipy \ No newline at end of file From 6bc9f046ba174147ce44e1a7107788681d98d616 Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 29 Aug 2024 13:15:43 +0100 Subject: [PATCH 9/9] update requirements, scipy --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 7482ed1..7874b80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ dependencies = [ "sbpy", "matplotlib", # for plotting "pandas", + "scipy", ] [project.urls]