{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "imports",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from pyprojroot import here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "load",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(here() / 'data/base/data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "plot",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots(figsize=(10, 6))\n",
    "\n",
    "# Color by detector type\n",
    "colors = {'APD': 'steelblue', 'SNSPD': 'coral', 'PMT': 'green', 'SPAD': 'purple'}\n",
    "for detector in data['Detector Type'].unique():\n",
    "    mask = data['Detector Type'] == detector\n",
    "    ax.scatter(data[mask]['Distance (m)'], data[mask]['Visibility (%)'],\n",
    "              label=detector, alpha=0.7, s=100, color=colors.get(detector, 'gray'),\n",
    "              edgecolors='black', linewidth=1)\n",
    "\n",
    "# Fit and plot trend line\n",
    "z = np.polyfit(data['Distance (m)'], data['Visibility (%)'], 1)\n",
    "p = np.poly1d(z)\n",
    "x_trend = np.linspace(data['Distance (m)'].min(), data['Distance (m)'].max(), 100)\n",
    "ax.plot(x_trend, p(x_trend), 'r--', linewidth=2, alpha=0.5, label=f'Trend (slope={z[0]:.2f})')\n",
    "\n",
    "ax.set_xlabel('Photon Pair Distance (m)', fontsize=12)\n",
    "ax.set_ylabel('Visibility (%)', fontsize=12)\n",
    "ax.set_title('Visibility vs. Photon Pair Distance', fontsize=14)\n",
    "ax.legend(loc='best')\n",
    "ax.grid(True, alpha=0.3)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig(here() / 'output/plots/visibility_distance.png', dpi=300, bbox_inches='tight')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
