Skip to content

Commit

Permalink
Add an alternative way to plot the result data
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Oct 11, 2024
1 parent ffd7a2c commit 595c258
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 1 deletion.
97 changes: 97 additions & 0 deletions notebooks/results_viz_tool.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# KBMOD Visualization Tool\n",
" \n",
"This notebook is a tool for loading and visualizing results data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from kbmod.analysis.plotting import *\n",
"from kbmod.results import Results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load the results data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Clean Data:\n",
"res_file = \"/epyc/users/dinob/public_html/kbmod_runs/results/20190402_A0b_001.results.ecsv\"\n",
"\n",
"# Noisy data:\n",
"# res_file = \"/epyc/users/dinob/public_html/kbmod_runs/results/20190601_A1b_041.results.ecsv\"\n",
"\n",
"results = Results.read_table(res_file)\n",
"print(f\"Loaded {len(results)} results.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot each result."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"num_results = len(results)\n",
"\n",
"for idx in range(num_results):\n",
" row = results[idx]\n",
" plot_result_row_summary(row)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Jeremy's KBMOD",
"language": "python",
"name": "kbmod_jk"
},
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
58 changes: 57 additions & 1 deletion src/kbmod/analysis/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"plot_multiple_images",
"plot_time_series",
"plot_result_row",
"plot_result_row_summary",
"plot_search_trajectories",
]

Expand Down Expand Up @@ -527,7 +528,7 @@ def plot_result_row(row, times=None, figure=None):
# In the top subfigure plot the coadded stamp on the left and
# the light curve on the right.
(ax_stamp, ax_lc) = fig_top.subplots(1, 2)
if row["stamp"] is not None:
if "stamp" in row and row["stamp"] is not None:
plot_image(row["stamp"], ax=ax_stamp, figure=fig_top, norm=True, title="Coadded Stamp")
else:
ax_stamp.text(0.5, 0.5, "No Stamp")
Expand Down Expand Up @@ -558,6 +559,61 @@ def plot_result_row(row, times=None, figure=None):
ax.text(0.5, 0.5, "No Individual Stamps")


def compute_lightcurve_histogram(row, min_val=0.0, max_val=1000.0, bins=20):
psi = row["psi_curve"]
phi = row["phi_curve"]
valid = (phi != 0) & np.isfinite(psi) & np.isfinite(phi)

lc = psi[valid] / phi[valid]
lc[lc < min_val] = min_val
lc[lc > max_val] = max_val

return np.histogram(lc, bins=bins)


def plot_result_row_summary(row, times=None, figure=None):
"""Plot a single row of the results table.
Parameters
----------
row : `astropy.table.row.Row`
The information from the results to plot.
times : a `list` or `numpy.ndarray` of floats
The array of the time stamps. If ``None`` then uses equally
spaced points. `None` by default.
figure : `matplotlib.pyplot.Figure` or `None`
Figure, `None` by default.
"""
if figure is None:
figure = plt.figure(layout="constrained")

figure = plt.figure()
(fig_top, fig_bot) = figure.subfigures(2, 1)

# Plot the light curves on the top
ax_curves = fig_top.subplots(1, 2)
if "psi_curve" in row.colnames and "psi_curve" in row.colnames:
psi = row["psi_curve"]
phi = row["phi_curve"]

valid = (phi != 0) & np.isfinite(psi) & np.isfinite(phi)
if "obs_valid" in row.colnames:
valid = valid & row["obs_valid"]

lc = np.full(psi.shape, 0.0)
lc[valid] = psi[valid] / phi[valid]
plot_time_series(lc, times, indices=valid, ax=ax_curves[0], figure=fig_top, title=f"Psi/Phi")

counts, bins = compute_lightcurve_histogram(row)
ax_curves[1].stairs(counts, bins)

# Plot the stamps along the bottom.
ax_stamps = fig_bot.subplots(1, 4)
for col, name in enumerate(["coadd_sum", "coadd_mean", "coadd_median", "coadd_weighted"]):
if name in row.colnames and row[name] is not None:
plot_image(row[name], ax=ax_stamps[col], figure=fig_top, norm=True, title=name, show_counts=False)


def plot_search_trajectories(gen, figure=None):
"""Plot the search trajectorys as created by a TrajectoryGenerator.
Expand Down

0 comments on commit 595c258

Please sign in to comment.