-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from lincc-frameworks/issue/6/bandpass
Passband integration
- Loading branch information
Showing
3 changed files
with
810 additions
and
0 deletions.
There are no files selected for viewing
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,278 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Passband Demo" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"A demonstartion of using the `Passbands` class to calculate normalized in-band flux densities.\n", | ||
"\n", | ||
"This code and notebook reference equations in *\"On the Choice of LSST Flux Units\"* by Željko Ivezić and the LSST Project Science Team, which may be found [here](https://docushare.lsst.org/docushare/dsweb/Get/Document-27758)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"import numpy as np\n", | ||
"from tdastro.astro_utils.passbands import Passbands\n", | ||
"from tdastro.sources.spline_model import SplineModel" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set up LSST passbands\n", | ||
"\n", | ||
"These values are unnormalized; we'll need to apply phi from eq 8 of the LSST Flux paper." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"passbands = Passbands()\n", | ||
"passbands.load_all_transmission_tables()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_single_transmission_table(band_name: str) -> None:\n", | ||
" \"\"\"Plot a single transmission table.\"\"\"\n", | ||
" plt.title(f\"{band_name}-band Transmission Table\")\n", | ||
" plt.xlabel(\"Wavelength (Angstrom)\")\n", | ||
" plt.ylabel(\"Transmission\")\n", | ||
" plt.plot(passbands.transmission_tables[band_name][:, 0], passbands.transmission_tables[band_name][:, 1])\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"plot_single_transmission_table(\"u\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_transmission_tables() -> None:\n", | ||
" \"\"\"Plot all transmission tables.\"\"\"\n", | ||
" plt.title(\"Transmission Tables\")\n", | ||
" plt.xlabel(\"Wavelength (Angstrom)\")\n", | ||
" plt.ylabel(\"Transmission\")\n", | ||
" plt.legend(passbands.bands)\n", | ||
" for band_id in passbands.bands:\n", | ||
" plt.plot(passbands.transmission_tables[band_id][:, 0], passbands.transmission_tables[band_id][:, 1])\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"plot_transmission_tables()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Get normalized passband" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"passbands.calculate_normalized_system_response_tables()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_single_normalized_system_response_table(band_name: str) -> None:\n", | ||
" \"\"\"Plot a single normalized system response table.\"\"\"\n", | ||
" plt.title(f\"{band_name}-band Normalized System Response Table\")\n", | ||
" plt.xlabel(\"Wavelength (Angstrom)\")\n", | ||
" plt.ylabel(\"Normalized System Response (Angstrom⁻¹)\")\n", | ||
" plt.plot(\n", | ||
" passbands.normalized_system_response_tables[band_name][:, 0],\n", | ||
" passbands.normalized_system_response_tables[band_name][:, 1],\n", | ||
" )\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"plot_single_normalized_system_response_table(\"u\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_normalized_system_response_tables() -> None:\n", | ||
" \"\"\"Plot all normalized system response tables.\"\"\"\n", | ||
" plt.title(\"Normalized System Response Tables\")\n", | ||
" plt.xlabel(\"Wavelength (Angstrom)\")\n", | ||
" plt.ylabel(\"Normalized System Response (Angstrom⁻¹)\")\n", | ||
" plt.legend(passbands.bands)\n", | ||
" for band_id in passbands.bands:\n", | ||
" plt.plot(\n", | ||
" passbands.normalized_system_response_tables[band_id][:, 0],\n", | ||
" passbands.normalized_system_response_tables[band_id][:, 1],\n", | ||
" )\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"plot_normalized_system_response_tables()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Set up a source\n", | ||
"\n", | ||
"Note that our transmission tables are to the closest integer; eg, in 'u', all integers in [3200, 4085].\n", | ||
"\n", | ||
"Models that follow a different grid might need to be put through a SplineModel to match this grid." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"input_times = np.array([1001.0, 1002.0, 1003.0])\n", | ||
"input_wavelengths = np.linspace(2000.0, 6000.0, 3)\n", | ||
"input_fluxes = np.array([[1.0, 5.0, 1.0], [5.0, 10.0, 5.0], [1.0, 5.0, 1.0]])\n", | ||
"\n", | ||
"spline_model = SplineModel(input_times, input_wavelengths, input_fluxes, time_degree=2, wave_degree=2)\n", | ||
"\n", | ||
"times = np.linspace(1000.0, 1006.0, 48)\n", | ||
"wavelengths = np.linspace(2000.0, 8000.0, 16)\n", | ||
"fluxes = spline_model.evaluate(times, wavelengths)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_flux_spectrogram():\n", | ||
" \"\"\"Plot a spectrogram to visualize the fluxes.\"\"\"\n", | ||
" plt.figure(figsize=(12, 3))\n", | ||
" plt.imshow(fluxes.T, cmap=\"plasma\", interpolation=\"nearest\")\n", | ||
"\n", | ||
" # Add title, axis labels, and correct ticks\n", | ||
" plt.title(\"Flux Spectrogram\")\n", | ||
" plt.xlabel(\"Time (days)\")\n", | ||
" plt.ylabel(\"Wavelength (Angstrom)\")\n", | ||
" plt.xticks(np.arange(len(times))[::4], [f\"{round(time)}\" for time in times][::4])\n", | ||
" plt.yticks(np.arange(len(wavelengths))[::2], [f\"{round(wave)}\" for wave in wavelengths][::2])\n", | ||
"\n", | ||
" # Add flux labels\n", | ||
" for (j, i), label in np.ndenumerate(fluxes.T):\n", | ||
" if i % 2 == 1:\n", | ||
" plt.text(i, j, round(label, 1), ha=\"center\", va=\"center\", size=8)\n", | ||
"\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"plot_flux_spectrogram()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Calculate in-band flux densities" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"per_passband_normalized_fluxes = passbands.get_all_in_band_fluxes(spline_model, times)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Print in-band normalized fluxes (abridged--we only print every 4th value, for space)\n", | ||
"np.set_printoptions(precision=2)\n", | ||
"print(per_passband_normalized_fluxes[::4])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_passband_normalized_lightcurve():\n", | ||
" \"\"\"Plot the passband-normalized lightcurve.\"\"\"\n", | ||
" fig, ax = plt.subplots()\n", | ||
" ax.set_title(\"Passband-Normalized Lightcurve\")\n", | ||
" ax.set_xlabel(\"Time (days)\")\n", | ||
" ax.set_ylabel(\"Flux\")\n", | ||
"\n", | ||
" offset = 0.015 # Optionally add a small offset for the overlapping bandss\n", | ||
" for i, band in enumerate(passbands.bands):\n", | ||
" ax.plot(times + offset * i, per_passband_normalized_fluxes[:, i] + offset * i, marker=\"o\", label=band)\n", | ||
"\n", | ||
" ax.legend()\n", | ||
" plt.show()\n", | ||
"\n", | ||
"\n", | ||
"plot_passband_normalized_lightcurve()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "tda", | ||
"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.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.