Skip to content

Instantly share code, notes, and snippets.

@bmorris3
Created November 13, 2025 19:43
Show Gist options
  • Select an option

  • Save bmorris3/7221058c30c0e14bc84dfe823d680d49 to your computer and use it in GitHub Desktop.

Select an option

Save bmorris3/7221058c30c0e14bc84dfe823d680d49 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "b3dc3efb-3938-40f3-8e20-dddb285cd32c",
"metadata": {},
"source": [
"# Notebook level metrics from `jdaviz_profiler`\n",
"\n",
"Read the metrics table:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "646b6274-1f8b-493f-afda-41250989b262",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from astropy.table import Table\n",
"\n",
"nb_path = '/Users/bmmorris/Downloads/metrics/2025_11_04/notebook_metrics_105948596227666.csv'\n",
"notebook_metrics = Table.read(nb_path, delimiter=',', format='csv')"
]
},
{
"cell_type": "markdown",
"id": "6e4ec367-7731-43fd-b2a4-ad6a3d67fda6",
"metadata": {},
"source": [
"Gather column names of metrics and parameters:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3290905c-965f-4fbc-bb43-484a8ba7f9c5",
"metadata": {},
"outputs": [],
"source": [
"metrics = [name for name in notebook_metrics.colnames if name.endswith('metric')]\n",
"params = [name for name in notebook_metrics.colnames if name.endswith('param')]"
]
},
{
"cell_type": "markdown",
"id": "c0f89f0a-1aec-455b-b9e2-eaed8affe7ea",
"metadata": {},
"source": [
"Exclude runs that did not complete:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e5e9a86-6172-4a68-a667-cc3316712b15",
"metadata": {},
"outputs": [],
"source": [
"timed_out = notebook_metrics['total_execution_time_metric'] > 300\n",
"not_completed = notebook_metrics['total_cells'] != notebook_metrics['executed_cells']\n",
"completed_runs = ~(timed_out | not_completed)"
]
},
{
"cell_type": "markdown",
"id": "a2ed7fb6-6876-4eda-941b-a771e25e5c92",
"metadata": {},
"source": [
"Make pairwise plots for these parameters, over each of the metrics:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b386962-7657-4efc-a61f-97cc314ba0e6",
"metadata": {},
"outputs": [],
"source": [
"pair_params = [\n",
" 'image_pixel_side_param',\n",
" 'viewport_pixel_size_param',\n",
" 'n_images_param',\n",
" 'image_compression_param',\n",
"]"
]
},
{
"cell_type": "markdown",
"id": "3eaa7915-04a5-412a-ac09-ad0f891bc499",
"metadata": {},
"source": [
"Make pairwise plots for all metrics _except_ the \"min\" metrics:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "295d3b45-a8f4-4b82-b881-9769a7ffc7e8",
"metadata": {},
"outputs": [],
"source": [
"for metric in metrics:\n",
" if '_min_' in metric:\n",
" continue\n",
"\n",
" fig, ax = plt.subplots(\n",
" len(pair_params), len(pair_params), figsize=(12, 12),\n",
" sharex='col', sharey='row', layout='constrained'\n",
" )\n",
" \n",
" vmin, vmax = np.percentile(np.array(notebook_metrics[metric]), [15, 85])\n",
" cbar_limits = dict(\n",
" vmin=vmin,\n",
" vmax=vmax\n",
" )\n",
" for i, param_i in enumerate(pair_params):\n",
" for j, param_j in enumerate(pair_params):\n",
" \n",
" x = np.sort(list(set(notebook_metrics[completed_runs][param_i])))\n",
" y = np.sort(list(set(notebook_metrics[completed_runs][param_j])))\n",
"\n",
" grid = np.zeros((len(x), len(y)))\n",
" for k in range(len(x)):\n",
" for ell in range(len(y)):\n",
" condition = (\n",
" (x[k] == notebook_metrics[param_i]) & \n",
" (y[ell] == notebook_metrics[param_j])\n",
" )\n",
" grid[k, ell] = np.median(notebook_metrics[metric][condition])\n",
" \n",
" if i != j:\n",
" cax = ax[i, j].pcolormesh(\n",
" y, x, grid, shading='nearest',\n",
" alpha=0.1 if i == j else 1,\n",
" **cbar_limits\n",
" )\n",
" if not isinstance(x[0], str):\n",
" ax[i, j].set(\n",
" ylim=[x.min(), x.max()],\n",
" )\n",
" \n",
" if not isinstance(y[0], str):\n",
" ax[i, j].set(\n",
" xlim=[y.min(), y.max()]\n",
" )\n",
" \n",
" if j == 0: \n",
" ax[i, j].set(\n",
" ylabel=param_i,\n",
" )\n",
" \n",
" if i == len(pair_params) - 1:\n",
" ax[i, j].set(\n",
" xlabel=param_j,\n",
" )\n",
" \n",
" if 'image_compression_param' not in [param_i, param_j]:\n",
" ax[i, j].set(\n",
" xscale='log',\n",
" yscale='log'\n",
" )\n",
" \n",
" fig.colorbar(cax, ax=ax[0, -1], label=metric)\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8746ca8d-be93-4ade-a16e-9c815a1f3364",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment