diff --git a/.coveragerc b/.coveragerc index 6f5f2ad..6644afb 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,3 +1,5 @@ [report] exclude_also = - # pragma: no cover \ No newline at end of file + # pragma: no cover + +omit = src/adler/adler.py \ No newline at end of file diff --git a/README.md b/README.md index 9b06b93..fa333aa 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ You can then test that everything works by running: ``` adler -s 8268570668335894776 ``` -This currently prints a friendly message to the terminal. +This will currently print some phase curve information to the terminal. Notes: 1) The single quotes around `'[dev]'` may not be required for your operating system. diff --git a/notebooks/adler_examples.ipynb b/notebooks/adler_examples.ipynb index e594f29..6c4d4f1 100644 --- a/notebooks/adler_examples.ipynb +++ b/notebooks/adler_examples.ipynb @@ -4,15 +4,7 @@ "cell_type": "code", "execution_count": null, "id": "d591f5d8-9148-46ff-a62b-0f2a29eb806c", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:11.533501Z", - "iopub.status.busy": "2024-02-29T16:09:11.533247Z", - "iopub.status.idle": "2024-02-29T16:09:13.062886Z", - "shell.execute_reply": "2024-02-29T16:09:13.061510Z", - "shell.execute_reply.started": "2024-02-29T16:09:11.533477Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from adler.dataclasses.AdlerPlanetoid import AdlerPlanetoid\n", @@ -28,15 +20,7 @@ "cell_type": "code", "execution_count": null, "id": "645efb98-567d-481e-a79c-b1cfdc828726", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:13.065333Z", - "iopub.status.busy": "2024-02-29T16:09:13.064482Z", - "iopub.status.idle": "2024-02-29T16:09:13.070452Z", - "shell.execute_reply": "2024-02-29T16:09:13.069235Z", - "shell.execute_reply.started": "2024-02-29T16:09:13.065297Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# ssObjectId of object to analyse\n", @@ -47,53 +31,35 @@ "cell_type": "code", "execution_count": null, "id": "10b36aab-b322-49b8-8ff3-49bef68d7416", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:13.072314Z", - "iopub.status.busy": "2024-02-29T16:09:13.071967Z", - "iopub.status.idle": "2024-02-29T16:09:14.279820Z", - "shell.execute_reply": "2024-02-29T16:09:14.278772Z", - "shell.execute_reply.started": "2024-02-29T16:09:13.072275Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# retrieve the object data via adler\n", - "planetoid = AdlerPlanetoid(ssoid)" + "\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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.281553Z", - "iopub.status.busy": "2024-02-29T16:09:14.281143Z", - "iopub.status.idle": "2024-02-29T16:09:14.287399Z", - "shell.execute_reply": "2024-02-29T16:09:14.286612Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.281511Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# inspect the object\n", - "planetoid.__dict__" + "# planetoid.__dict__" ] }, { "cell_type": "code", "execution_count": null, "id": "1d360360-025b-4a77-acf5-325b2f2d1873", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.290960Z", - "iopub.status.busy": "2024-02-29T16:09:14.290631Z", - "iopub.status.idle": "2024-02-29T16:09:14.307210Z", - "shell.execute_reply": "2024-02-29T16:09:14.306215Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.290937Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "planetoid.SSObject.__dict__" @@ -102,62 +68,37 @@ { "cell_type": "code", "execution_count": null, - "id": "e0bcad0b-32ea-4c0f-b489-00d7491ff3b6", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.308956Z", - "iopub.status.busy": "2024-02-29T16:09:14.308489Z", - "iopub.status.idle": "2024-02-29T16:09:14.333001Z", - "shell.execute_reply": "2024-02-29T16:09:14.332167Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.308917Z" - } - }, + "id": "be8f8d63", + "metadata": {}, "outputs": [], "source": [ - "# dir(planetoid.Observations)\n", - "planetoid.Observations.__dict__" + "obs_r = planetoid.observations_in_filter(\"r\")" ] }, { "cell_type": "code", "execution_count": null, - "id": "b226fefa-a252-40d2-925e-549eee16858e", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.334599Z", - "iopub.status.busy": "2024-02-29T16:09:14.334226Z", - "iopub.status.idle": "2024-02-29T16:09:14.351732Z", - "shell.execute_reply": "2024-02-29T16:09:14.350910Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.334562Z" - } - }, + "id": "da1e483d", + "metadata": {}, "outputs": [], "source": [ - "getattr(planetoid.Observations, \"phaseAngle\")" + "obs_r.__dict__" ] }, { "cell_type": "code", "execution_count": null, "id": "9d7dc125-06c1-49ad-8854-17d8c8b6954f", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.353538Z", - "iopub.status.busy": "2024-02-29T16:09:14.352944Z", - "iopub.status.idle": "2024-02-29T16:09:14.544075Z", - "shell.execute_reply": "2024-02-29T16:09:14.543137Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.353500Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# plot the observations\n", "x_plot = \"phaseAngle\"\n", "y_plot = \"reduced_mag\"\n", "\n", - "x = getattr(planetoid.Observations, x_plot)\n", - "y = getattr(planetoid.Observations, y_plot)\n", - "xerr = planetoid.Observations.magErr\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", @@ -176,36 +117,24 @@ "cell_type": "code", "execution_count": null, "id": "6efe3b5a-09dd-4d5e-9f41-20ea6e1b43df", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.545627Z", - "iopub.status.busy": "2024-02-29T16:09:14.545342Z", - "iopub.status.idle": "2024-02-29T16:09:14.553323Z", - "shell.execute_reply": "2024-02-29T16:09:14.552540Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.545603Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# define the phase curve\n", - "pc = PhaseCurve(\n", - " abs_mag=planetoid.SSObject.r_H * u.mag, phase_param=planetoid.SSObject.r_G12, model_name=\"HG12_Pen16\"\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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.554644Z", - "iopub.status.busy": "2024-02-29T16:09:14.554319Z", - "iopub.status.idle": "2024-02-29T16:09:14.571588Z", - "shell.execute_reply": "2024-02-29T16:09:14.570921Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.554620Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "pc.model_function" @@ -215,18 +144,10 @@ "cell_type": "code", "execution_count": null, "id": "24c1955e-95cd-4d77-ad05-aa5b8d18620a", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.572987Z", - "iopub.status.busy": "2024-02-29T16:09:14.572491Z", - "iopub.status.idle": "2024-02-29T16:09:14.593610Z", - "shell.execute_reply": "2024-02-29T16:09:14.592732Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.572960Z" - } - }, + "metadata": {}, "outputs": [], "source": [ - "alpha = np.linspace(0, np.amax(planetoid.Observations.phaseAngle)) * u.deg\n", + "alpha = np.linspace(0, np.amax(obs_r.phaseAngle)) * u.deg\n", "alpha" ] }, @@ -234,15 +155,7 @@ "cell_type": "code", "execution_count": null, "id": "c3f30fe0-0d89-4ffa-8237-9c71181d44ee", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.594977Z", - "iopub.status.busy": "2024-02-29T16:09:14.594621Z", - "iopub.status.idle": "2024-02-29T16:09:14.614140Z", - "shell.execute_reply": "2024-02-29T16:09:14.613401Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.594943Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "red_mag = pc.ReducedMag(alpha)\n", @@ -253,15 +166,7 @@ "cell_type": "code", "execution_count": null, "id": "04be98a1-e4dc-4216-bcd9-ef777f6053fb", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.615656Z", - "iopub.status.busy": "2024-02-29T16:09:14.615050Z", - "iopub.status.idle": "2024-02-29T16:09:14.783515Z", - "shell.execute_reply": "2024-02-29T16:09:14.782664Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.615623Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# %matplotlib widget\n", @@ -270,9 +175,9 @@ "x_plot = \"phaseAngle\"\n", "y_plot = \"reduced_mag\"\n", "\n", - "x = getattr(planetoid.Observations, x_plot)\n", - "y = getattr(planetoid.Observations, y_plot)\n", - "xerr = planetoid.Observations.magErr\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", @@ -293,24 +198,16 @@ "cell_type": "code", "execution_count": null, "id": "9815543d-6140-4bdb-8bad-8296994723f4", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.784754Z", - "iopub.status.busy": "2024-02-29T16:09:14.784498Z", - "iopub.status.idle": "2024-02-29T16:09:14.953022Z", - "shell.execute_reply": "2024-02-29T16:09:14.952237Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.784731Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# plot the observations\n", - "x_plot = \"mjd\"\n", + "x_plot = \"midpointMjdTai\"\n", "y_plot = \"reduced_mag\"\n", "\n", - "x = getattr(planetoid.Observations, x_plot)\n", - "y = getattr(planetoid.Observations, y_plot)\n", - "xerr = planetoid.Observations.magErr\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", @@ -329,15 +226,7 @@ "cell_type": "code", "execution_count": null, "id": "de462b92-3914-4091-b0af-bddd9e9c1ef1", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.954181Z", - "iopub.status.busy": "2024-02-29T16:09:14.953935Z", - "iopub.status.idle": "2024-02-29T16:09:14.957556Z", - "shell.execute_reply": "2024-02-29T16:09:14.956913Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.954159Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# do a different phase curve fit to the data\n", @@ -348,15 +237,7 @@ "cell_type": "code", "execution_count": null, "id": "f92891c9-6ccf-4dac-8887-9545f633ba90", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.963464Z", - "iopub.status.busy": "2024-02-29T16:09:14.958584Z", - "iopub.status.idle": "2024-02-29T16:09:14.975015Z", - "shell.execute_reply": "2024-02-29T16:09:14.974187Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.963434Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "pc_fit = PhaseCurve(abs_mag=pc.abs_mag, model_name=\"HG\")" @@ -366,15 +247,7 @@ "cell_type": "code", "execution_count": null, "id": "db24432b-6d05-4ff2-9d98-e52d8c2e4342", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.976283Z", - "iopub.status.busy": "2024-02-29T16:09:14.975943Z", - "iopub.status.idle": "2024-02-29T16:09:14.992854Z", - "shell.execute_reply": "2024-02-29T16:09:14.992071Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.976260Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "pc_fit.model_function" @@ -384,21 +257,13 @@ "cell_type": "code", "execution_count": null, "id": "9039e2e2-27d9-4d21-b2f6-9504a5b85ce4", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.994511Z", - "iopub.status.busy": "2024-02-29T16:09:14.993863Z", - "iopub.status.idle": "2024-02-29T16:09:15.023285Z", - "shell.execute_reply": "2024-02-29T16:09:15.022583Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.994486Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "pc_fit.FitModel(\n", - " phase_angle=planetoid.Observations.phaseAngle * u.deg,\n", - " reduced_mag=planetoid.Observations.reduced_mag * u.mag,\n", - " mag_err=planetoid.Observations.magErr * u.mag,\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", ")" ] }, @@ -406,15 +271,7 @@ "cell_type": "code", "execution_count": null, "id": "5d4b7144-ee72-45e0-9606-c40f83c443c6", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:15.024555Z", - "iopub.status.busy": "2024-02-29T16:09:15.024229Z", - "iopub.status.idle": "2024-02-29T16:09:15.217263Z", - "shell.execute_reply": "2024-02-29T16:09:15.216519Z", - "shell.execute_reply.started": "2024-02-29T16:09:15.024533Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# %matplotlib widget\n", @@ -423,9 +280,9 @@ "x_plot = \"phaseAngle\"\n", "y_plot = \"reduced_mag\"\n", "\n", - "x = getattr(planetoid.Observations, x_plot)\n", - "y = getattr(planetoid.Observations, y_plot)\n", - "xerr = planetoid.Observations.magErr\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", @@ -448,21 +305,21 @@ "cell_type": "code", "execution_count": null, "id": "b7f39ed4-8334-4e10-a97c-a9471105225b", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:15.221317Z", - "iopub.status.busy": "2024-02-29T16:09:15.220742Z", - "iopub.status.idle": "2024-02-29T16:09:15.224414Z", - "shell.execute_reply": "2024-02-29T16:09:15.223697Z", - "shell.execute_reply.started": "2024-02-29T16:09:15.221290Z" - } - }, + "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": { diff --git a/notebooks/adler_examples_local_db.ipynb b/notebooks/adler_examples_local_db.ipynb deleted file mode 100644 index f959401..0000000 --- a/notebooks/adler_examples_local_db.ipynb +++ /dev/null @@ -1,476 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "d591f5d8-9148-46ff-a62b-0f2a29eb806c", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:11.533501Z", - "iopub.status.busy": "2024-02-29T16:09:11.533247Z", - "iopub.status.idle": "2024-02-29T16:09:13.062886Z", - "shell.execute_reply": "2024-02-29T16:09:13.061510Z", - "shell.execute_reply.started": "2024-02-29T16:09:11.533477Z" - } - }, - "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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:13.065333Z", - "iopub.status.busy": "2024-02-29T16:09:13.064482Z", - "iopub.status.idle": "2024-02-29T16:09:13.070452Z", - "shell.execute_reply": "2024-02-29T16:09:13.069235Z", - "shell.execute_reply.started": "2024-02-29T16:09:13.065297Z" - } - }, - "outputs": [], - "source": [ - "# ssObjectId of object to analyse\n", - "ssoid = \"8268570668335894776\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "10b36aab-b322-49b8-8ff3-49bef68d7416", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:13.072314Z", - "iopub.status.busy": "2024-02-29T16:09:13.071967Z", - "iopub.status.idle": "2024-02-29T16:09:14.279820Z", - "shell.execute_reply": "2024-02-29T16:09:14.278772Z", - "shell.execute_reply.started": "2024-02-29T16:09:13.072275Z" - } - }, - "outputs": [], - "source": [ - "# retrieve the object data via adler\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)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d9a0623d-0dc7-49c1-99dd-a76ef970a3ff", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.281553Z", - "iopub.status.busy": "2024-02-29T16:09:14.281143Z", - "iopub.status.idle": "2024-02-29T16:09:14.287399Z", - "shell.execute_reply": "2024-02-29T16:09:14.286612Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.281511Z" - } - }, - "outputs": [], - "source": [ - "# inspect the object\n", - "# planetoid.__dict__" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1d360360-025b-4a77-acf5-325b2f2d1873", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.290960Z", - "iopub.status.busy": "2024-02-29T16:09:14.290631Z", - "iopub.status.idle": "2024-02-29T16:09:14.307210Z", - "shell.execute_reply": "2024-02-29T16:09:14.306215Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.290937Z" - } - }, - "outputs": [], - "source": [ - "planetoid.SSObject.__dict__" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "be8f8d63", - "metadata": {}, - "outputs": [], - "source": [ - "obs_r = planetoid.observations_in_filter(\"r\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "da1e483d", - "metadata": {}, - "outputs": [], - "source": [ - "obs_r.__dict__" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9d7dc125-06c1-49ad-8854-17d8c8b6954f", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.353538Z", - "iopub.status.busy": "2024-02-29T16:09:14.352944Z", - "iopub.status.idle": "2024-02-29T16:09:14.544075Z", - "shell.execute_reply": "2024-02-29T16:09:14.543137Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.353500Z" - } - }, - "outputs": [], - "source": [ - "# plot the observations\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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.545627Z", - "iopub.status.busy": "2024-02-29T16:09:14.545342Z", - "iopub.status.idle": "2024-02-29T16:09:14.553323Z", - "shell.execute_reply": "2024-02-29T16:09:14.552540Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.545603Z" - } - }, - "outputs": [], - "source": [ - "# define the phase curve\n", - "\n", - "r_H = planetoid.SSObject.H[2]\n", - "r_G12 = planetoid.SSObject.G12[2]\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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.554644Z", - "iopub.status.busy": "2024-02-29T16:09:14.554319Z", - "iopub.status.idle": "2024-02-29T16:09:14.571588Z", - "shell.execute_reply": "2024-02-29T16:09:14.570921Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.554620Z" - } - }, - "outputs": [], - "source": [ - "pc.model_function" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "24c1955e-95cd-4d77-ad05-aa5b8d18620a", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.572987Z", - "iopub.status.busy": "2024-02-29T16:09:14.572491Z", - "iopub.status.idle": "2024-02-29T16:09:14.593610Z", - "shell.execute_reply": "2024-02-29T16:09:14.592732Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.572960Z" - } - }, - "outputs": [], - "source": [ - "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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.594977Z", - "iopub.status.busy": "2024-02-29T16:09:14.594621Z", - "iopub.status.idle": "2024-02-29T16:09:14.614140Z", - "shell.execute_reply": "2024-02-29T16:09:14.613401Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.594943Z" - } - }, - "outputs": [], - "source": [ - "red_mag = pc.ReducedMag(alpha)\n", - "red_mag" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "04be98a1-e4dc-4216-bcd9-ef777f6053fb", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.615656Z", - "iopub.status.busy": "2024-02-29T16:09:14.615050Z", - "iopub.status.idle": "2024-02-29T16:09:14.783515Z", - "shell.execute_reply": "2024-02-29T16:09:14.782664Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.615623Z" - } - }, - "outputs": [], - "source": [ - "# %matplotlib widget\n", - "\n", - "# plot the observations with the LSST 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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.784754Z", - "iopub.status.busy": "2024-02-29T16:09:14.784498Z", - "iopub.status.idle": "2024-02-29T16:09:14.953022Z", - "shell.execute_reply": "2024-02-29T16:09:14.952237Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.784731Z" - } - }, - "outputs": [], - "source": [ - "# plot the observations\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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.954181Z", - "iopub.status.busy": "2024-02-29T16:09:14.953935Z", - "iopub.status.idle": "2024-02-29T16:09:14.957556Z", - "shell.execute_reply": "2024-02-29T16:09:14.956913Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.954159Z" - } - }, - "outputs": [], - "source": [ - "# do a different phase curve fit to the data\n", - "# adler should be able to fit different models, and perform more sophisticated fits" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f92891c9-6ccf-4dac-8887-9545f633ba90", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.963464Z", - "iopub.status.busy": "2024-02-29T16:09:14.958584Z", - "iopub.status.idle": "2024-02-29T16:09:14.975015Z", - "shell.execute_reply": "2024-02-29T16:09:14.974187Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.963434Z" - } - }, - "outputs": [], - "source": [ - "pc_fit = PhaseCurve(abs_mag=pc.abs_mag, model_name=\"HG\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "db24432b-6d05-4ff2-9d98-e52d8c2e4342", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.976283Z", - "iopub.status.busy": "2024-02-29T16:09:14.975943Z", - "iopub.status.idle": "2024-02-29T16:09:14.992854Z", - "shell.execute_reply": "2024-02-29T16:09:14.992071Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.976260Z" - } - }, - "outputs": [], - "source": [ - "pc_fit.model_function" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9039e2e2-27d9-4d21-b2f6-9504a5b85ce4", - "metadata": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:14.994511Z", - "iopub.status.busy": "2024-02-29T16:09:14.993863Z", - "iopub.status.idle": "2024-02-29T16:09:15.023285Z", - "shell.execute_reply": "2024-02-29T16:09:15.022583Z", - "shell.execute_reply.started": "2024-02-29T16:09:14.994486Z" - } - }, - "outputs": [], - "source": [ - "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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:15.024555Z", - "iopub.status.busy": "2024-02-29T16:09:15.024229Z", - "iopub.status.idle": "2024-02-29T16:09:15.217263Z", - "shell.execute_reply": "2024-02-29T16:09:15.216519Z", - "shell.execute_reply.started": "2024-02-29T16:09:15.024533Z" - } - }, - "outputs": [], - "source": [ - "# %matplotlib widget\n", - "\n", - "# plot the observations with the LSST 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, 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": { - "execution": { - "iopub.execute_input": "2024-02-29T16:09:15.221317Z", - "iopub.status.busy": "2024-02-29T16:09:15.220742Z", - "iopub.status.idle": "2024-02-29T16:09:15.224414Z", - "shell.execute_reply": "2024-02-29T16:09:15.223697Z", - "shell.execute_reply.started": "2024-02-29T16:09:15.221290Z" - } - }, - "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" - ] - } - ], - "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.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/src/adler/adler.py b/src/adler/adler.py index c327aa3..bc24b29 100644 --- a/src/adler/adler.py +++ b/src/adler/adler.py @@ -8,8 +8,6 @@ def runAdler(args): planetoid = AdlerPlanetoid.construct_from_RSP(args.ssoid, args.filter_list, args.date_range) - planetoid.do_pretend_science() - # now let's do some phase curves! # get the RSP r filter model diff --git a/src/adler/dataclasses/AdlerPlanetoid.py b/src/adler/dataclasses/AdlerPlanetoid.py index 060b0de..3002ac2 100644 --- a/src/adler/dataclasses/AdlerPlanetoid.py +++ b/src/adler/dataclasses/AdlerPlanetoid.py @@ -1,11 +1,11 @@ from lsst.rsp import get_tap_service +import pandas as pd from adler.dataclasses.Observations import Observations from adler.dataclasses.MPCORB import MPCORB from adler.dataclasses.SSObject import SSObject from adler.dataclasses.AdlerData import AdlerData from adler.dataclasses.dataclass_utilities import get_data_table -from adler.science.DummyScience import DummyScience class AdlerPlanetoid: @@ -80,7 +80,7 @@ def construct_from_SQL( """ if len(date_range) != 2: - raise Exception("date_range argument must be of length 2.") + raise ValueError("date_range attribute must be of length 2.") observations_by_filter = cls.populate_observations( cls, ssObjectId, filter_list, date_range, sql_filename=sql_filename, schema=schema @@ -163,7 +163,7 @@ def populate_observations( """ - if schema: + if schema: # pragma: no cover schema = schema + "." else: schema = "" @@ -211,7 +211,7 @@ def populate_MPCORB(self, ssObjectId, service=None, sql_filename=None, schema="d """ - if schema: + if schema: # pragma: no cover schema = schema + "." else: schema = "" @@ -255,7 +255,7 @@ def populate_SSObject( """ - if schema: + if schema: # pragma: no cover schema = schema + "." else: schema = "" @@ -306,7 +306,24 @@ def observations_in_filter(self, filter_name): return self.observations_by_filter[filter_index] - def do_pretend_science(self): - self.DummyScienceResult = DummyScience().science_result + def SSObject_in_filter(self, filter_name): + """User-friendly helper function. Returns the filter-dependent values from SSObject for a given filter. + + Parameters + ----------- + filter_name : str + The desired filter. + + Returns + ----------- + ssobject_in_filter : SSObject + + + """ + + try: + filter_index = self.filter_list.index(filter_name) + except ValueError: + raise ValueError("Filter {} is not in AdlerPlanetoid.filter_list.".format(filter_name)) - print(self.DummyScienceResult) + return self.SSObject.filter_dependent_values[filter_index] diff --git a/src/adler/dataclasses/SSObject.py b/src/adler/dataclasses/SSObject.py index d86414c..2207c51 100644 --- a/src/adler/dataclasses/SSObject.py +++ b/src/adler/dataclasses/SSObject.py @@ -29,20 +29,9 @@ class SSObject: numObs: int Number of LSST observations of this object - H: array_like of floats - Best fit absolute magnitudes per-filter, in same order as filter_list. - - G12: array_like of floats - Best fit G12 slope parameters per-filter, in same order as filter_list. - - Herr : array_like of floats - Uncertainty of H per-filter, in same order as filter_list. - - G12Err : array_like of floats - Uncertainty of G12 per-filter, in same order as filter_list. - - nData: array_like of ints - The number of data points used to fit the phase curve per-filter, in same order as filter_list. + filter_dependent_values: list of FilterDependentSSO objects + A list of FilterDependentSSO objects storing the filter-dependent values H, Herr, G12, G12err and nData, + in same order as filter_list. See documentation for FilterDependentSSO object for descriptions of these variables. maxExtendedness: float maximum `extendedness` value from the DIASource @@ -61,11 +50,7 @@ class SSObject: firstObservationDate: float = 0.0 arc: float = 0.0 numObs: int = 0 - H: np.ndarray = field(default_factory=lambda: np.zeros(0)) - G12: np.ndarray = field(default_factory=lambda: np.zeros(0)) - Herr: np.ndarray = field(default_factory=lambda: np.zeros(0)) - G12err: np.ndarray = field(default_factory=lambda: np.zeros(0)) - nData: np.ndarray = field(default_factory=lambda: np.zeros(0)) + filter_dependent_values: list = field(default_factory=list) maxExtendedness: float = 0.0 minExtendedness: float = 0.0 medianExtendedness: float = 0.0 @@ -83,12 +68,19 @@ def construct_from_data_table(cls, ssObjectId, filter_list, data_table): G12err = np.zeros(len(filter_list)) nData = np.zeros(len(filter_list)) - for i, filter in enumerate(filter_list): - H[i] = get_from_table(data_table, filter + "_H", "float") - G12[i] = get_from_table(data_table, filter + "_G12", "float") - Herr[i] = get_from_table(data_table, filter + "_HErr", "float") - G12err[i] = get_from_table(data_table, filter + "_G12Err", "float") - nData[i] = get_from_table(data_table, filter + "_Ndata", "int") + filter_dependent_values = [] + + for i, filter_name in enumerate(filter_list): + filter_dept_object = FilterDependentSSO( + filter_name=filter_name, + H=get_from_table(data_table, filter_name + "_H", "float"), + G12=get_from_table(data_table, filter_name + "_G12", "float"), + Herr=get_from_table(data_table, filter_name + "_HErr", "float"), + G12err=get_from_table(data_table, filter_name + "_G12Err", "float"), + nData=get_from_table(data_table, filter_name + "_Ndata", "int"), + ) + + filter_dependent_values.append(filter_dept_object) maxExtendedness = get_from_table(data_table, "maxExtendedness", "float") minExtendedness = get_from_table(data_table, "minExtendedness", "float") @@ -101,12 +93,41 @@ def construct_from_data_table(cls, ssObjectId, filter_list, data_table): firstObservationDate, arc, numObs, - H, - G12, - Herr, - G12err, - nData, + filter_dependent_values, maxExtendedness, minExtendedness, medianExtendedness, ) + + +@dataclass +class FilterDependentSSO: + """Filter-dependent object information from SSObject. All attributes carry the same names as the column names from the SSObject table. + + Attributes: + ----------- + filter_name : str + Single-letter name of the filter for which these values are relevant. + + H : float + Best fit absolute magnitude in filter. + + G12: float + Best fit G12 slope parameters in filter. + + Herr : float + Uncertainty of H. + + G12Err : float + Uncertainty of G12. + + nData: int + The number of data points used to fit the phase curve in this filter. + """ + + filter_name: str + H: float + G12: float + Herr: float + G12err: float + nData: int = 0 diff --git a/src/adler/dataclasses/dataclass_utilities.py b/src/adler/dataclasses/dataclass_utilities.py index 9cbf89b..ebba3d8 100644 --- a/src/adler/dataclasses/dataclass_utilities.py +++ b/src/adler/dataclasses/dataclass_utilities.py @@ -28,7 +28,7 @@ def get_data_table(sql_query, service=None, sql_filename=None): """ - if service: + if service: # pragma: no cover data_table = service.search(sql_query) elif sql_filename: cnx = sqlite3.connect(sql_filename) diff --git a/src/adler/science/DummyScience.py b/src/adler/science/DummyScience.py deleted file mode 100644 index d76be0d..0000000 --- a/src/adler/science/DummyScience.py +++ /dev/null @@ -1,3 +0,0 @@ -class DummyScience: - def __init__(self): - self.science_result = "look, science!" diff --git a/tests/adler/dataclasses/test_AdlerPlanetoid.py b/tests/adler/dataclasses/test_AdlerPlanetoid.py index a92b777..288c5cc 100644 --- a/tests/adler/dataclasses/test_AdlerPlanetoid.py +++ b/tests/adler/dataclasses/test_AdlerPlanetoid.py @@ -1,3 +1,4 @@ +import pytest import numpy as np from numpy.testing import assert_almost_equal @@ -32,7 +33,7 @@ def test_construct_from_SQL(): # did we pick up all the filters? assert len(test_planetoid.observations_by_filter) == 6 - assert len(test_planetoid.SSObject.H) == 6 + assert len(test_planetoid.SSObject.filter_dependent_values) == 6 assert test_planetoid.filter_list == ["u", "g", "r", "i", "z", "y"] # checking the date range to ensure it's the default @@ -44,7 +45,7 @@ def test_construct_with_single_filter(): # should only be one filter in here now assert len(test_planetoid.observations_by_filter) == 1 - assert len(test_planetoid.SSObject.H) == 1 + assert len(test_planetoid.SSObject.filter_dependent_values) == 1 assert test_planetoid.filter_list == ["g"] assert_almost_equal( @@ -87,21 +88,42 @@ def test_construct_with_date_range(): assert_almost_equal(test_planetoid.observations_by_filter[0].midpointMjdTai, expected_dates) + with pytest.raises(ValueError) as error_info_1: + test_planetoid = AdlerPlanetoid.construct_from_SQL( + ssoid, test_db_path, date_range=[61000.0, 62000.0, 63000.0] + ) + + assert error_info_1.value.args[0] == "date_range attribute must be of length 2." + def test_observations_in_filter(): test_planetoid = AdlerPlanetoid.construct_from_SQL(ssoid, test_db_path) - assert_almost_equal( - test_planetoid.observations_in_filter("g").mag, - [ - 21.33099937, - 22.67099953, - 23.5359993, - 22.85000038, - 22.97599983, - 22.94499969, - 23.13599968, - 23.19400024, - 23.1609993, - ], - ) + # Python dataclasses create an __eq__ for you so object-to-object comparison just works, isn't that nice? + assert test_planetoid.observations_in_filter("u") == test_planetoid.observations_by_filter[0] + assert test_planetoid.observations_in_filter("g") == test_planetoid.observations_by_filter[1] + assert test_planetoid.observations_in_filter("r") == test_planetoid.observations_by_filter[2] + assert test_planetoid.observations_in_filter("i") == test_planetoid.observations_by_filter[3] + assert test_planetoid.observations_in_filter("z") == test_planetoid.observations_by_filter[4] + assert test_planetoid.observations_in_filter("y") == test_planetoid.observations_by_filter[5] + + with pytest.raises(ValueError) as error_info_1: + test_planetoid.observations_in_filter("f") + + assert error_info_1.value.args[0] == "Filter f is not in AdlerPlanetoid.filter_list." + + +def test_SSObject_in_filter(): + test_planetoid = AdlerPlanetoid.construct_from_SQL(ssoid, test_db_path) + + assert test_planetoid.SSObject_in_filter("u") == test_planetoid.SSObject.filter_dependent_values[0] + assert test_planetoid.SSObject_in_filter("g") == test_planetoid.SSObject.filter_dependent_values[1] + assert test_planetoid.SSObject_in_filter("r") == test_planetoid.SSObject.filter_dependent_values[2] + assert test_planetoid.SSObject_in_filter("i") == test_planetoid.SSObject.filter_dependent_values[3] + assert test_planetoid.SSObject_in_filter("z") == test_planetoid.SSObject.filter_dependent_values[4] + assert test_planetoid.SSObject_in_filter("y") == test_planetoid.SSObject.filter_dependent_values[5] + + with pytest.raises(ValueError) as error_info_1: + test_planetoid.SSObject_in_filter("f") + + assert error_info_1.value.args[0] == "Filter f is not in AdlerPlanetoid.filter_list." diff --git a/tests/adler/test_MPCORB.py b/tests/adler/dataclasses/test_MPCORB.py similarity index 100% rename from tests/adler/test_MPCORB.py rename to tests/adler/dataclasses/test_MPCORB.py diff --git a/tests/adler/dataclasses/test_SSObject.py b/tests/adler/dataclasses/test_SSObject.py index f4121e4..b6cb05b 100644 --- a/tests/adler/dataclasses/test_SSObject.py +++ b/tests/adler/dataclasses/test_SSObject.py @@ -36,17 +36,35 @@ def test_construct_SSObject_from_data_table(): data_table = get_data_table(test_query, sql_filename=test_db_path) test_SSObject = SSObject.construct_from_data_table(ssoid, filter_list, data_table) + test_values_r = [ + test_SSObject.filter_dependent_values[0].H, + test_SSObject.filter_dependent_values[0].G12, + test_SSObject.filter_dependent_values[0].Herr, + test_SSObject.filter_dependent_values[0].G12err, + test_SSObject.filter_dependent_values[0].nData, + ] + + test_values_g = [ + test_SSObject.filter_dependent_values[1].H, + test_SSObject.filter_dependent_values[1].G12, + test_SSObject.filter_dependent_values[1].Herr, + test_SSObject.filter_dependent_values[1].G12err, + test_SSObject.filter_dependent_values[1].nData, + ] + + expected_values_g = [20.292325973510742, 1.7233933210372925, 0.030210301280021667, 0.0404973067343235, 9] + + expected_values_r = [19.805892944335938, 1.52932608127594, 0.01974303089082241, 0.05071713775396347, 38] + assert test_SSObject.ssObjectId == 8268570668335894776 assert test_SSObject.filter_list == filter_list assert_almost_equal(test_SSObject.discoverySubmissionDate, 60218.0, decimal=6) assert_almost_equal(test_SSObject.firstObservationDate, 60220.01958, decimal=6) assert_almost_equal(test_SSObject.arc, 3342.05859375, decimal=6) assert test_SSObject.numObs == 94 - assert_almost_equal(test_SSObject.H, [19.80589294, 20.29232597], decimal=6) - assert_almost_equal(test_SSObject.G12, [1.52932608, 1.72339332], decimal=6) - assert_almost_equal(test_SSObject.Herr, [0.01974303, 0.0302103], decimal=6) - assert_almost_equal(test_SSObject.G12err, [0.05071714, 0.04049731], decimal=6) - assert_equal(test_SSObject.nData, [38.0, 9.0]) assert_equal(test_SSObject.maxExtendedness, 0.0) assert_equal(test_SSObject.minExtendedness, 0.0) assert_equal(test_SSObject.medianExtendedness, 0.0) + + assert_almost_equal(test_values_r, expected_values_r) + assert_almost_equal(test_values_g, expected_values_g)