From 7f99a8d96d54242452ffb2d557a2f2286246c8dd Mon Sep 17 00:00:00 2001 From: Drew Oldag Date: Wed, 12 Jun 2024 21:16:41 -0700 Subject: [PATCH] Adding comparison notebook and updating pyproject.toml. --- docs/notebooks/mbls-comparison.ipynb | 111 +++++++++++++++++++++++++++ pyproject.toml | 5 +- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 docs/notebooks/mbls-comparison.ipynb diff --git a/docs/notebooks/mbls-comparison.ipynb b/docs/notebooks/mbls-comparison.ipynb new file mode 100644 index 0000000..8567bc3 --- /dev/null +++ b/docs/notebooks/mbls-comparison.ipynb @@ -0,0 +1,111 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create some artificial data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "t = []\n", + "y = []\n", + "bands = []\n", + "dy = []\n", + "N = 60\n", + "for i, band in enumerate([\"u\", \"g\", \"r\", \"i\", \"z\"]):\n", + " rng = np.random.default_rng(i)\n", + " t_band = 300 * rng.random(N)\n", + " y_band = 3 + 2 * np.sin(2 * np.pi * t_band)\n", + " dy_band = 0.01 * (0.5 + rng.random(N)) # uncertainties\n", + " y_band += dy_band * rng.standard_normal(N)\n", + " t += list(t_band)\n", + " y += list(y_band)\n", + " dy += list(dy_band)\n", + " bands += [band] * N" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Example using astropy.timeseries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from astropy.timeseries import LombScargleMultiband" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model = LombScargleMultiband(t, y, bands, dy, nterms_base=1, nterms_band=1)\n", + "frequency, power = model.autopower(method=\"flexible\")\n", + "freq_maxpower = frequency[np.argmax(power)]\n", + "t_phase = np.linspace(0, 1 / freq_maxpower, 100)\n", + "y_fit = model.model(t_phase, freq_maxpower)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.plot(frequency, power)\n", + "print(f\"Frequency with peak power: {frequency[np.argmax(power)]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "mapals", + "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.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/pyproject.toml b/pyproject.toml index 411d6b9..ec056d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dynamic = ["version"] requires-python = ">=3.9" dependencies = [ "cuda-python", + "numpy", ] [project.urls] @@ -28,8 +29,10 @@ dev = [ "black", # Used for static linting of files "jupyter", # Clears output from Jupyter notebooks "pre-commit", # Used to run checks before finalizing a git commit - "pytest", + "pytest", # Used to run tests "pytest-cov", # Used to report total code coverage + "matplotlib", # Used to plot data + "astropy", # Used as the LS baseline for comparison ] [build-system]