{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c30b6a4f-cb8a-4da2-8939-beaa5420a8a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import math\n",
    "import json\n",
    "import statistics\n",
    "from pathlib import Path\n",
    "from matplotlib import pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c8fbf52a-76df-4d5a-a50d-0e16d4a5921c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "74lvc_mesh_new_p0.3mm\n",
      "74lvc_mesh_new_p0.4mm\n",
      "74lvc_mesh_new_p0.6mm\n",
      "74lvc_mesh_new_p1.0mm\n",
      "74lvc_mesh_p0.3mm\n",
      "74lvc_mesh_p0.3mm_flip\n",
      "74lvc_mesh_p0.3mm_term\n",
      "74lvc_mesh_p0.4mm\n",
      "74lvc_mesh_p0.6mm\n",
      "74lvc_mesh_p1.0mm\n",
      "74lvc_new2_mesh_p0.3mm\n",
      "74lvc_new2_mesh_p0.4mm\n",
      "74lvc_new2_mesh_p0.6mm\n",
      "74lvc_new2_mesh_p1.0mm\n",
      "74lvc_new2_open\n",
      "74lvc_new_mesh_p0.3mm\n",
      "74lvc_new_mesh_p0.3mm_flip\n",
      "74lvc_new_mesh_p0.3mm_term\n",
      "74lvc_new_open\n",
      "74lvc_open\n",
      "max3748_mesh_p0.3mm\n",
      "max3748_mesh_p0.3mm_flip\n",
      "max3748_mesh_p0.3mm_term\n",
      "max3748_mesh_p0.4mm\n",
      "max3748_mesh_p0.6mm\n",
      "max3748_mesh_p1.0mm\n",
      "max3748_open\n",
      "pi3hdx_clipline_offset_a_mesh_p0.3mm\n",
      "pi3hdx_clipline_offset_a_mesh_p0.3mm_flip\n",
      "pi3hdx_clipline_offset_a_mesh_p0.3mm_term\n",
      "pi3hdx_clipline_offset_a_mesh_p0.4mm\n",
      "pi3hdx_clipline_offset_a_mesh_p0.6mm\n",
      "pi3hdx_clipline_offset_a_mesh_p1.0mm\n",
      "pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_a\n",
      "pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_b\n",
      "pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_none\n",
      "pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_short\n",
      "pi3hdx_clipline_offset_a_open\n",
      "pi3hdx_clipline_offset_b_mesh_p0.3mm\n",
      "pi3hdx_clipline_offset_b_mesh_p0.3mm_flip\n",
      "pi3hdx_clipline_offset_b_mesh_p0.3mm_term\n",
      "pi3hdx_clipline_offset_b_mesh_p0.4mm\n",
      "pi3hdx_clipline_offset_b_mesh_p0.6mm\n",
      "pi3hdx_clipline_offset_b_mesh_p1.0mm\n",
      "pi3hdx_clipline_offset_b_mesh_p1.0mm_manip_short\n",
      "pi3hdx_clipline_offset_b_open\n",
      "pi3hdx_clipline_risetime\n",
      "pi3hdx_clipline_risetime_new\n",
      "pi3hdx_manip_test2_baseline\n",
      "pi3hdx_manip_test2_baseline2\n",
      "pi3hdx_manip_test2_open\n",
      "pi3hdx_manip_test2_scope_probe\n",
      "pi3hdx_manip_test2_short\n",
      "pi3hdx_manip_test_baseline\n",
      "pi3hdx_manip_test_baseline2\n",
      "pi3hdx_manip_test_baseline3\n",
      "pi3hdx_manip_test_open\n",
      "pi3hdx_manip_test_scope_probe\n",
      "pi3hdx_manip_test_scope_probe2\n",
      "pi3hdx_manip_test_short\n",
      "run2_74lvc_mesh_p0.3mm\n",
      "run2_74lvc_mesh_p0.4mm\n",
      "run2_74lvc_mesh_p0.6mm\n",
      "run2_74lvc_mesh_p1.0mm\n",
      "run2_74lvc_open\n",
      "run3_74lvc_manip_baseline1\n",
      "run3_74lvc_manip_baseline2\n",
      "run3_74lvc_manip_baseline3\n",
      "run3_74lvc_manip_baseline4\n",
      "run3_74lvc_manip_cut\n",
      "run3_74lvc_manip_probe1a\n",
      "run3_74lvc_manip_probe1b\n",
      "run3_74lvc_manip_probe2a\n",
      "run3_74lvc_manip_probe2b\n",
      "run3_74lvc_manip_probe3a\n",
      "run3_74lvc_manip_probe3b\n",
      "run3_74lvc_manip_short1\n",
      "run3_74lvc_manip_short2\n",
      "run3_74lvc_manip_short3\n",
      "run3_74lvc_mesh_p0.3mm\n",
      "run3_74lvc_mesh_p0.4mm\n",
      "run3_74lvc_mesh_p0.6mm\n",
      "run3_74lvc_mesh_p1.0mm\n",
      "run3_74lvc_open\n",
      "run3_max3748_mesh_p0.3mm\n",
      "run3_max3748_mesh_p0.4mm\n",
      "run3_max3748_mesh_p0.6mm\n",
      "run3_max3748_mesh_p1.0mm\n",
      "run3_max3748_open\n",
      "run3_pi3hdx_manip_baseline1\n",
      "run3_pi3hdx_manip_baseline2\n",
      "run3_pi3hdx_manip_baseline3\n",
      "run3_pi3hdx_manip_baseline4\n",
      "run3_pi3hdx_manip_cut\n",
      "run3_pi3hdx_manip_probe1a\n",
      "run3_pi3hdx_manip_probe1b\n",
      "run3_pi3hdx_manip_probe2a\n",
      "run3_pi3hdx_manip_probe2b\n",
      "run3_pi3hdx_manip_probe3a\n",
      "run3_pi3hdx_manip_probe3b\n",
      "run3_pi3hdx_manip_short1\n",
      "run3_pi3hdx_manip_short2\n",
      "run3_pi3hdx_manip_short3\n",
      "run3_pi3hdx_mesh_p0.3mm\n",
      "run3_pi3hdx_mesh_p0.4mm\n",
      "run3_pi3hdx_mesh_p0.6mm\n",
      "run3_pi3hdx_mesh_p04mm\n",
      "run3_pi3hdx_mesh_p1.0mm\n",
      "run3_pi3hdx_open\n",
      "run3_tdp0604_mesh_p0.3mm\n",
      "run3_tdp0604_mesh_p0.4mm\n",
      "run3_tdp0604_mesh_p0.6mm\n",
      "run3_tdp0604_mesh_p1.0mm\n",
      "run3_tdp0604_open\n",
      "run4_pi3hdx_manip_baseline1\n",
      "run4_pi3hdx_manip_baseline2\n",
      "run4_pi3hdx_manip_baseline3\n",
      "run4_pi3hdx_manip_baseline4\n",
      "run4_pi3hdx_manip_probe1a\n",
      "run4_pi3hdx_manip_probe1b\n",
      "run4_pi3hdx_manip_probe2a\n",
      "run4_pi3hdx_manip_probe2b\n",
      "run4_pi3hdx_manip_probe3a\n",
      "run4_pi3hdx_manip_probe3b\n",
      "tdp0604_mesh_p0.3mm\n",
      "tdp0604_mesh_p0.3mm_flip\n",
      "tdp0604_mesh_p0.3mm_term\n",
      "tdp0604_mesh_p0.4mm\n",
      "tdp0604_mesh_p0.6mm\n",
      "tdp0604_mesh_p1.0mm\n",
      "tdp0604_new_avg_flip_mesh_p0.3mm\n",
      "tdp0604_new_avg_flip_mesh_p0.4mm\n",
      "tdp0604_new_avg_flip_mesh_p0.6mm\n",
      "tdp0604_new_avg_flip_mesh_p1.0mm\n",
      "tdp0604_new_avg_mesh_p0.3mm\n",
      "tdp0604_new_avg_mesh_p0.4mm\n",
      "tdp0604_new_avg_mesh_p0.6mm\n",
      "tdp0604_new_avg_mesh_p1.0mm\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_open\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_open_fix\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_open_fix_finished\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_open_fix_wire\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_probe_a\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_probe_b\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_probe_no\n",
      "tdp0604_new_avg_term_flip_mesh_1.0mm_short\n",
      "tdp0604_new_avg_term_flip_mesh_p0.3mm\n",
      "tdp0604_new_avg_term_flip_mesh_p0.4mm\n",
      "tdp0604_new_avg_term_flip_mesh_p0.6mm\n",
      "tdp0604_new_avg_term_flip_mesh_p1.0mm\n",
      "tdp0604_new_avg_term_flip_open\n",
      "tdp0604_new_mesh_p0.3mm\n",
      "tdp0604_new_mesh_p0.4mm\n",
      "tdp0604_new_mesh_p0.6mm\n",
      "tdp0604_new_mesh_p1.0mm\n",
      "tdp0604_new_open\n",
      "tdp0604_open\n",
      "works\n"
     ]
    }
   ],
   "source": [
    "meas = {}\n",
    "for f in Path('../data').glob('*.json'):\n",
    "    d = json.loads(f.read_bytes())\n",
    "    d['adc1'] = np.array(d['adc1'])\n",
    "    d['adc2'] = np.array(d['adc2'])\n",
    "    d['var1'] = np.array(d['var1'])\n",
    "    d['var2'] = np.array(d['var2'])\n",
    "    meas[d['meta']] = d\n",
    "\n",
    "for n in sorted(meas):\n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f6038e2f-53b9-41a0-ab7c-e5ba72c05e4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'mesh_flip': False,\n",
       " 'mesh_flip_n': True,\n",
       " 'rf_term': False,\n",
       " 'rf_term_short': False,\n",
       " 'sampling_phase_var': '6',\n",
       " 'sampling_width': '2',\n",
       " 'stimulus_offset': '104',\n",
       " 'oversampling': '256'}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "meas['tdp0604_new_avg_mesh_p0.3mm']['settings']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d70ba947-0154-483b-ad2a-86ece294e5be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26288 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 77192 characters]",
      "text/plain": [
       "<Figure size 700x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 51464 characters]",
      "text/plain": [
       "<Figure size 700x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26784 characters]",
      "text/plain": [
       "<Figure size 700x150 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 50464 characters]",
      "text/plain": [
       "<Figure size 1383x1125 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 52504 characters]",
      "text/plain": [
       "<Figure size 1430x1208 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 290628 characters]",
      "text/plain": [
       "<Figure size 1424x1026 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 48604 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 68688 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69248 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69776 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 68688 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69776 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 48604 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69776 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 36836 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 33612 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69776 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 75508 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 75228 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 70928 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26288 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def do_plot(name, ax=None):\n",
    "    if ax is None:\n",
    "        fig, ax = plt.subplots()\n",
    "\n",
    "    d = meas[name]\n",
    "    ax.plot(d['adc1'])\n",
    "\n",
    "do_plot('pi3hdx_clipline_offset_b_mesh_p0.6mm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ab54ba7f-1e18-4373-899c-30e740399a55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 77192 characters]",
      "text/plain": [
       "<Figure size 700x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "        'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(2, 1, sharex=True, figsize=[7, 3])\n",
    "\n",
    "    for name in [\n",
    "            'pi3hdx_clipline_offset_b_mesh_p1.0mm',\n",
    "            'pi3hdx_clipline_offset_b_mesh_p0.6mm',\n",
    "            'pi3hdx_clipline_offset_b_mesh_p0.4mm',\n",
    "            'pi3hdx_clipline_offset_b_mesh_p0.3mm',\n",
    "            'pi3hdx_clipline_offset_b_mesh_p1.0mm_manip_short',\n",
    "        ]:\n",
    "        d = meas[name]\n",
    "        axs[0].plot(d['adc1'])\n",
    "        axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlim([465, 750])\n",
    "    axs[0].set_ylim([0.25, 0.45])\n",
    "    axs[1].set_ylim([0.05, 0.15])\n",
    "    fig.tight_layout()\n",
    "\n",
    "#fig.savefig('../paper/fig_edge_risetime.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "035306ff-c645-47ca-8358-87ecd626bd4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 51464 characters]",
      "text/plain": [
       "<Figure size 700x300 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "        'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(2, 1, sharex=True, figsize=[7, 3])\n",
    "\n",
    "    for name in [\n",
    "            'pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_none',\n",
    "            'pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_a',\n",
    "            'pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_b',\n",
    "            'pi3hdx_clipline_offset_b_mesh_p1.0mm_manip_short',\n",
    "        ]:\n",
    "        d = meas[name]\n",
    "        axs[0].plot(d['adc1'])\n",
    "        axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlim([465, 750])\n",
    "    axs[0].set_ylim([0.30, 0.45])\n",
    "    axs[1].set_ylim([0.05, 0.15])\n",
    "    fig.tight_layout()\n",
    "\n",
    "#fig.savefig('../paper/fig_edge_risetime.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "ad413015-63aa-4c37-aa97-aa465f2f45e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26784 characters]",
      "text/plain": [
       "<Figure size 700x150 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "        'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(1, 2, sharex=True, figsize=[7, 1.5])\n",
    "\n",
    "    for name in [\n",
    "            #'pi3hdx_clipline_offset_b_mesh_p1.0mm_manip_short',\n",
    "            'pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_none',\n",
    "            'pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_a',\n",
    "            'pi3hdx_clipline_offset_a_mesh_p1.0mm_manip_scope_probe_b',\n",
    "        ]:\n",
    "        d = meas[name]\n",
    "        axs[0].plot(d['adc2'])\n",
    "        axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlim([475, 525])\n",
    "    axs[0].set_ylim([0.40, 0.55])\n",
    "    axs[1].set_ylim([0.05, 0.15])\n",
    "    fig.tight_layout()\n",
    "\n",
    "#fig.savefig('../paper/fig_edge_risetime.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7a81769c-4734-45c5-92fa-0228cc5cf241",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 129548 characters]",
      "text/plain": [
       "<Figure size 700x500 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "        'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(4, 1, sharex=True, figsize=[7, 5])\n",
    "\n",
    "    d = meas['74lvc_new2_mesh_p1.0mm']\n",
    "    sampling_period_ns = 1000 / 168 / 32\n",
    "    t = np.linspace(0, len(d['adc1'])*sampling_period_ns, len(d['adc1']))\n",
    "\n",
    "    for ax, (chip, (chip_label, adc, shift)) in zip(axs, {\n",
    "                             'pi3hdx': ('PI3HDX12211', 'adc2', 0),\n",
    "                             '74lvc': ('74LVC1G157', 'adc1', 4),\n",
    "                             'max3748': ('MAX3748', 'adc2', 0),\n",
    "                             'tdp0604': ('TDP0604', 'adc2', 0)}.items()):\n",
    "        low, high = 1000, -1000\n",
    "        for name in [\n",
    "                'run3_{chip}_mesh_p1.0mm',\n",
    "                'run3_{chip}_mesh_p0.6mm',\n",
    "                'run3_{chip}_mesh_p0.4mm',\n",
    "                'run3_{chip}_mesh_p0.3mm',\n",
    "            ]:\n",
    "            d = meas[name.format(chip=chip)]\n",
    "            v = d[adc]\n",
    "            th = (v.min() + v.max()) / 2\n",
    "            idx = np.argmax((v[:-1] >= th) & (v[1:] < th))\n",
    "            t_off = idx*sampling_period_ns + shift\n",
    "            ax.plot(t - t_off, v)\n",
    "\n",
    "            v_slice = v[idx+10:idx+350]\n",
    "            low = min(low, v_slice.min())\n",
    "            high = max(high, v_slice.max())\n",
    "            \n",
    "        amp = high - low\n",
    "        low -= 0.3*amp\n",
    "        high += 0.3*amp\n",
    "        ax.set_ylim([low, high])\n",
    "            \n",
    "        ax.set_title(chip_label)\n",
    "        ax.grid()\n",
    "    axs[-1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[-1].set_xlim([-2, 70])\n",
    "    fig.tight_layout()\n",
    "\n",
    "fig.savefig('../paper/fig_mesh_length.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "857c241e-083d-49e9-81da-61670501d567",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 121416 characters]",
      "text/plain": [
       "<Figure size 900x1200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "    'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(1, 2, figsize=[9, 12])\n",
    "    \n",
    "    d = meas['74lvc_new2_mesh_p1.0mm']\n",
    "    sampling_period_ns = 1000 / 168 / 32\n",
    "    t = np.linspace(0, len(d['adc1'])*sampling_period_ns, len(d['adc1']))\n",
    "\n",
    "    for name in [\n",
    "            'tdp0604_new_avg_term_flip_mesh_p1.0mm',\n",
    "            'tdp0604_new_avg_term_flip_mesh_1.0mm_open',\n",
    "            #'tdp0604_new_avg_term_flip_mesh_1.0mm_open_fix_wire',\n",
    "            'tdp0604_new_avg_term_flip_mesh_1.0mm_short',\n",
    "            #'tdp0604_new_avg_term_flip_mesh_1.0mm_probe_a',\n",
    "            'tdp0604_new_avg_term_flip_mesh_1.0mm_probe_b',\n",
    "            #'tdp0604_new_avg_term_flip_mesh_1.0mm_probe_no',\n",
    "        ]:\n",
    "        d = meas[name]\n",
    "        _1, _, foo = name.rpartition('_')\n",
    "        axs[0].plot(d['adc1'], label=foo)\n",
    "        axs[1].plot(d['adc1'], label=foo)\n",
    "        #axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    axs[0].legend()\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[0].set_xlim([415, 425])\n",
    "    #axs[1].set_xlim([505, 515])\n",
    "    axs[0].set_ylim([1.75, 1.92])\n",
    "    #axs[1].set_ylim([1.80, 2.00])\n",
    "    fig.tight_layout()\n",
    "\n",
    "#fig.savefig('../paper/fig_edge_risetime.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "8c16dfd9-e0e0-4709-9a68-075489b3e3d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 30616 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "    'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(1, 2, figsize=[7, 2])\n",
    "    \n",
    "    d = meas['74lvc_new2_mesh_p1.0mm']\n",
    "    sampling_period_ns = 1000 / 168 / 32\n",
    "    t = np.linspace(0, len(d['adc1'])*sampling_period_ns, len(d['adc1']))\n",
    "\n",
    "    for name, label in {\n",
    "            'pi3hdx_manip_test2_baseline': 'Baseline',\n",
    "            'pi3hdx_manip_test2_baseline2': 'Baseline',\n",
    "            'pi3hdx_manip_test2_scope_probe': 'Probed',\n",
    "        }.items():\n",
    "        d = meas[name]\n",
    "        _1, _, foo = name.rpartition('_')\n",
    "        axs[0].plot(t[470:550], d['adc1'][470:550], label=label)\n",
    "        axs[1].plot(t[470:550], d['adc2'][470:550], label=label)\n",
    "        #axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    axs[1].legend(loc='lower right', ncol=3)\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[0].set_xlim([90, 95])\n",
    "    axs[1].set_xlim([90, 95])\n",
    "    axs[0].set_ylim([0.32, 0.38])\n",
    "    axs[1].set_ylim([0.42, 0.50])\n",
    "    axs[0].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "    fig.tight_layout()\n",
    "\n",
    "#fig.savefig('../paper/fig_probe_shape.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "964e2441-a7de-449c-bad2-5f9b37a48247",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 39632 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "    'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(1, 2, figsize=[7, 2], sharey=True)\n",
    "    \n",
    "    d = meas['74lvc_new2_mesh_p1.0mm']\n",
    "    sampling_period_ns = 1000 / 168 / 32\n",
    "    t = np.linspace(0, len(d['adc1'])*sampling_period_ns, len(d['adc1']))\n",
    "\n",
    "    for name, (label, linestyle) in {\n",
    "            'pi3hdx_manip_test2_baseline2': ('Baseline', '--'),\n",
    "            'pi3hdx_manip_test2_scope_probe': ('Probed', '-'),\n",
    "        }.items():\n",
    "        d_b = meas['pi3hdx_manip_test2_baseline']\n",
    "        d = meas[name]\n",
    "        _1, _, foo = name.rpartition('_')\n",
    "        a, b = 470, 550\n",
    "        axs[0].plot(t[a:b], (d['adc1'] - d_b['adc1'])[a:b], label=label, color='black', alpha=0.8, linestyle=linestyle)\n",
    "        axs[1].plot(t[a:b], (d['adc2'] - d_b['adc2'])[a:b], label=label, color='black', alpha=0.8, linestyle=linestyle)\n",
    "        #axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    axs[1].legend(loc='lower right', ncol=3)\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    #axs[0].set_xlim([90, 100])\n",
    "    #axs[1].set_xlim([90, 100])\n",
    "    axs[0].set_title('Positive')\n",
    "    axs[1].set_title('Negative')\n",
    "    #axs[0].set_ylim([0.32, 0.38])\n",
    "    #axs[1].set_ylim([0.42, 0.50])\n",
    "    axs[0].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "    fig.tight_layout()\n",
    "\n",
    "#fig.savefig('../paper/fig_probe_shape.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "b1744aea-18f3-4522-9be1-a73fd55e3f64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 70416 characters]",
      "text/plain": [
       "<Figure size 700x200 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "    'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(1, 2, figsize=[7, 2])\n",
    "    \n",
    "    d = meas['74lvc_new2_mesh_p1.0mm']\n",
    "    sampling_period_ns = 1000 / 168 / 32\n",
    "    t = np.linspace(0, len(d['adc1'])*sampling_period_ns, len(d['adc1']))\n",
    "\n",
    "    ivl_start, ivl_end = 530, 650\n",
    "\n",
    "    legend_names = []\n",
    "    legend_handles = []\n",
    "    for name, (label, color, linestyle) in {\n",
    "            'run3_pi3hdx_manip_baseline1': ('Baseline', 'black', '-'),\n",
    "            'run3_pi3hdx_manip_baseline2': ('', 'black', '-'),\n",
    "            'run3_pi3hdx_manip_baseline3': ('', 'black', '-'),\n",
    "            'run3_pi3hdx_manip_baseline4': ('', 'black', '-'),\n",
    "            'run3_pi3hdx_manip_short1':    ('Short @ location 1', 'red', '-'),\n",
    "            'run3_pi3hdx_manip_short2':    ('Short @ location 2', 'red', '--'),\n",
    "            'run3_pi3hdx_manip_short3':    ('Short @ location 3', 'red', '-.'),\n",
    "            'run3_pi3hdx_manip_cut':       ('Cut', 'blue', '-'),\n",
    "        }.items():\n",
    "        d = meas[name]\n",
    "        _1, _, foo = name.rpartition('_')\n",
    "        h, = axs[0].plot(t[ivl_start:ivl_end], d['adc1'][ivl_start:ivl_end], color=color, alpha=0.7, linestyle=linestyle)\n",
    "        h, = axs[1].plot(t[ivl_start:ivl_end], d['adc2'][ivl_start:ivl_end], color=color, alpha=0.7, linestyle=linestyle)\n",
    "        if label:\n",
    "            legend_handles.append(h)\n",
    "            legend_names.append(label)\n",
    "        #axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    fig.tight_layout()\n",
    "    fig.subplots_adjust(top=0.8, bottom=0.1)\n",
    "    fig.legend(legend_handles, legend_names, loc='upper center', ncol=5, bbox_to_anchor=[0.5, 0.95])\n",
    "    #axs[1].legend(loc='lower right', ncol=3)\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    #axs[0].set_xlim([87, 102])\n",
    "    #axs[1].set_xlim([87, 102])\n",
    "    axs[0].set_ylim([0.29, 0.382])\n",
    "    axs[1].set_ylim([0.00, 0.35])\n",
    "    axs[0].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "\n",
    "fig.savefig('../paper/fig_manip_shape.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "7639a590-153a-4354-a902-73c71c123df4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 154664 characters]",
      "text/plain": [
       "<Figure size 700x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with plt.rc_context({\n",
    "    'legend.fontsize': 8,\n",
    "    # RC config from ChatGPT:\n",
    "    \"font.size\": 8,  # General font size\n",
    "    \"axes.labelsize\": 8,  # Axis labels\n",
    "    \"axes.titlesize\": 8,  # Axis titles\n",
    "    \"xtick.labelsize\": 8,  # X-axis tick labels\n",
    "    \"ytick.labelsize\": 8,  # Y-axis tick labels\n",
    "    \"legend.fontsize\": 8,  # Legend font size\n",
    "    \"figure.titlesize\": 12,  # Overall figure title\n",
    "    \"mathtext.fontset\": \"cm\",  # Use Computer Modern for math\n",
    "\n",
    "    # Line and Marker settings\n",
    "    \"lines.linewidth\": 1,\n",
    "    \"lines.markersize\": 3,\n",
    "\n",
    "    # Tick settings\n",
    "    \"xtick.major.size\": 4,\n",
    "    \"xtick.minor.size\": 2,\n",
    "    \"ytick.major.size\": 4,\n",
    "    \"ytick.minor.size\": 2,\n",
    "    \"xtick.direction\": \"in\",\n",
    "    \"ytick.direction\": \"in\",\n",
    "\n",
    "    # Axes settings\n",
    "    \"axes.linewidth\": 0.8,\n",
    "    \"axes.grid\": True,\n",
    "    \"grid.linewidth\": 0.5,\n",
    "    \"grid.linestyle\": \"--\",\n",
    "\n",
    "    # Legend settings\n",
    "    \"legend.frameon\": False,\n",
    "\n",
    "    # Figure size for single-column figures in print (inches)\n",
    "#    \"figure.figsize\": (3.5, 2.5),  # Adjust based on journal specifications\n",
    "#    \"figure.dpi\": 300,  # High resolution for print\n",
    "\n",
    "    # Savefig settings for high-quality output\n",
    "    \"savefig.dpi\": 600,  # Ensures high-resolution images\n",
    "    \"savefig.bbox\": \"tight\",  # Trim extra whitespace\n",
    "    \"savefig.transparent\": True,  # Avoid background color\n",
    "}):\n",
    "    fig, axs = plt.subplots(2, 1, figsize=[7, 4])\n",
    "    \n",
    "    d = meas['run4_pi3hdx_manip_baseline1']\n",
    "    sampling_period_ns = 1000 / 168 / 32\n",
    "    t = np.linspace(0, len(d['adc1'])*sampling_period_ns, len(d['adc1']))\n",
    "\n",
    "    fig_handles, fig_labels = [], []\n",
    "    for name, (label, color, linestyle, linewidth) in {\n",
    "            'run4_pi3hdx_manip_probe1a': ('Probed @ location 1A', 'red', '-', 1),\n",
    "            'run4_pi3hdx_manip_probe1b': ('Probed @ location 1B', 'red', '--', 1),\n",
    "            'run4_pi3hdx_manip_probe2a': ('Probed @ location 2A', 'blue', '-', 1),\n",
    "            'run4_pi3hdx_manip_probe2b': ('Probed @ location 2B', 'blue', '--', 1),\n",
    "            'run4_pi3hdx_manip_probe3b': ('Probed @ location 3A', 'orange', '-', 1), # Note: Location 3 A/B labels are flipped on PCB and source data\n",
    "            'run4_pi3hdx_manip_probe3a': ('Probed @ location 3B', 'orange', '--', 1),\n",
    "            'run4_pi3hdx_manip_baseline3': ('Baseline', '#333', '-', 1),\n",
    "            'run4_pi3hdx_manip_baseline1': ('', '#333', '-', 1),\n",
    "            'run4_pi3hdx_manip_baseline4': ('', '#333', '-', 1),\n",
    "        }.items():\n",
    "        d_b = meas['run4_pi3hdx_manip_baseline2']\n",
    "        d = meas[name]\n",
    "        _1, _, foo = name.rpartition('_')\n",
    "        a, b = 540, 650\n",
    "        x = 540\n",
    "        y = x + (b - a)\n",
    "        delta1 = (d['adc1'] - d_b['adc1'])[a:b]\n",
    "        delta2 = (d['adc2'] - d_b['adc2'])[x:y]\n",
    "        delta1 -= delta1.mean()\n",
    "        delta2 -= delta2.mean()\n",
    "        h, = axs[0].plot(t[a:b], delta1, color=color, alpha=0.7, linestyle=linestyle, linewidth=linewidth)\n",
    "        h, = axs[1].plot(t[x:y], delta2, color=color, alpha=0.7, linestyle=linestyle, linewidth=linewidth)\n",
    "        if label:\n",
    "            fig_handles.append(h)\n",
    "            fig_labels.append(label)\n",
    "        #axs[1].plot(d['adc2'] - d['adc1'])\n",
    "\n",
    "    fig.tight_layout()\n",
    "    fig.subplots_adjust(top=0.8, bottom=0.1)\n",
    "    fig.legend(fig_handles, fig_labels, loc='upper center', ncol=4, bbox_to_anchor=[0.5, 0.95])\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    #axs[0].set_xlim([90, 100])\n",
    "    #axs[1].set_xlim([90, 100])\n",
    "    axs[0].set_title('Positive')\n",
    "    axs[1].set_title('Negative')\n",
    "    #axs[0].set_ylim([-0.005, 0.005])\n",
    "    #axs[1].set_ylim([-0.01, 0.02])\n",
    "    axs[0].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[1].set_xlabel(r'$t\\;[\\mathrm{ns}]$')\n",
    "    axs[0].grid()\n",
    "    axs[1].grid()\n",
    "\n",
    "fig.savefig('../paper/fig_probe_shape.pdf')"
   ]
  }
 ],
 "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.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
