{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "713c24ce-2114-445c-9c0e-dcded05fdf60",
   "metadata": {},
   "source": [
    "# Photobleaching at three temperatures\n",
    "\n",
    "This notebook plots the supplied synthetic dye concentrations against time at 25, 35 and 45 °C. It fits a separate first-order decay to each series and exports a one-column figure and an Origin-ready workbook. The input CSV is kept unchanged."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5a650114-3631-4a8b-8f6e-c6ad5ab61b31",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Points</th>\n",
       "      <th>First time (min)</th>\n",
       "      <th>Last time (min)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Temperature (°C)</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Points  First time (min)  Last time (min)\n",
       "Temperature (°C)                                           \n",
       "25                    13                 0               60\n",
       "35                    13                 0               60\n",
       "45                    13                 0               60"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from pathlib import Path\n",
    "import pandas as pd\n",
    "from IPython.display import display\n",
    "\n",
    "project = Path(\"/root/Photobleaching\")\n",
    "data = pd.read_csv(project / \"Data\" / \"bleaching.csv\", comment=\"#\")\n",
    "summary = data.groupby(\"temperature_C\").agg(\n",
    "    Points=(\"time_min\", \"size\"), start=(\"time_min\", \"min\"), end=(\"time_min\", \"max\")\n",
    ")\n",
    "summary.index.name = \"Temperature (°C)\"\n",
    "display(summary.rename(columns={\"start\": \"First time (min)\", \"end\": \"Last time (min)\"}))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8188df09-5e36-41b2-b1b5-4edadc538735",
   "metadata": {},
   "source": [
    "Each temperature has 13 recorded values at distinct times from 0 to 60 min. The CSV provides neither replicates nor measurement uncertainties, so no measurement error bars can be calculated. The recorded −0.0013 mM value at 45 °C and 60 min will be kept in both the fit and figure."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa3e3385-4e75-453c-9af4-95f803e66102",
   "metadata": {},
   "source": [
    "## First-order fits\n",
    "\n",
    "For each temperature, fit C(t) = C₀ exp(−kt), where C₀ is the fitted starting concentration and k is the decay rate constant. Fit on the original concentration scale by unweighted nonlinear least squares: this keeps every value, including the negative reading, and avoids assuming measurement weights that the CSV does not provide. The model has no fitted background and approaches zero at long times."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9363204b-3054-4c7b-8d03-72059d7c66f9",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "</style>\n",
       "<table id=\"T_02693\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th id=\"T_02693_level0_col0\" class=\"col_heading level0 col0\" >Temperature</th>\n",
       "      <th id=\"T_02693_level0_col1\" class=\"col_heading level0 col1\" >Quantity</th>\n",
       "      <th id=\"T_02693_level0_col2\" class=\"col_heading level0 col2\" >Estimate</th>\n",
       "      <th id=\"T_02693_level0_col3\" class=\"col_heading level0 col3\" >Standard uncertainty</th>\n",
       "      <th id=\"T_02693_level0_col4\" class=\"col_heading level0 col4\" >Unit</th>\n",
       "      <th id=\"T_02693_level0_col5\" class=\"col_heading level0 col5\" >How set</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td id=\"T_02693_row0_col0\" class=\"data row0 col0\" >25 °C</td>\n",
       "      <td id=\"T_02693_row0_col1\" class=\"data row0 col1\" >Starting concentration, C₀</td>\n",
       "      <td id=\"T_02693_row0_col2\" class=\"data row0 col2\" >0.5054</td>\n",
       "      <td id=\"T_02693_row0_col3\" class=\"data row0 col3\" >0.0058</td>\n",
       "      <td id=\"T_02693_row0_col4\" class=\"data row0 col4\" >mM</td>\n",
       "      <td id=\"T_02693_row0_col5\" class=\"data row0 col5\" >Fitted</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_02693_row1_col0\" class=\"data row1 col0\" >25 °C</td>\n",
       "      <td id=\"T_02693_row1_col1\" class=\"data row1 col1\" >Decay rate constant, k</td>\n",
       "      <td id=\"T_02693_row1_col2\" class=\"data row1 col2\" >0.0206</td>\n",
       "      <td id=\"T_02693_row1_col3\" class=\"data row1 col3\" >0.0005</td>\n",
       "      <td id=\"T_02693_row1_col4\" class=\"data row1 col4\" >min⁻¹</td>\n",
       "      <td id=\"T_02693_row1_col5\" class=\"data row1 col5\" >Fitted</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_02693_row2_col0\" class=\"data row2 col0\" >35 °C</td>\n",
       "      <td id=\"T_02693_row2_col1\" class=\"data row2 col1\" >Starting concentration, C₀</td>\n",
       "      <td id=\"T_02693_row2_col2\" class=\"data row2 col2\" >0.5019</td>\n",
       "      <td id=\"T_02693_row2_col3\" class=\"data row2 col3\" >0.0028</td>\n",
       "      <td id=\"T_02693_row2_col4\" class=\"data row2 col4\" >mM</td>\n",
       "      <td id=\"T_02693_row2_col5\" class=\"data row2 col5\" >Fitted</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_02693_row3_col0\" class=\"data row3 col0\" >35 °C</td>\n",
       "      <td id=\"T_02693_row3_col1\" class=\"data row3 col1\" >Decay rate constant, k</td>\n",
       "      <td id=\"T_02693_row3_col2\" class=\"data row3 col2\" >0.0413</td>\n",
       "      <td id=\"T_02693_row3_col3\" class=\"data row3 col3\" >0.0004</td>\n",
       "      <td id=\"T_02693_row3_col4\" class=\"data row3 col4\" >min⁻¹</td>\n",
       "      <td id=\"T_02693_row3_col5\" class=\"data row3 col5\" >Fitted</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_02693_row4_col0\" class=\"data row4 col0\" >45 °C</td>\n",
       "      <td id=\"T_02693_row4_col1\" class=\"data row4 col1\" >Starting concentration, C₀</td>\n",
       "      <td id=\"T_02693_row4_col2\" class=\"data row4 col2\" >0.4863</td>\n",
       "      <td id=\"T_02693_row4_col3\" class=\"data row4 col3\" >0.0053</td>\n",
       "      <td id=\"T_02693_row4_col4\" class=\"data row4 col4\" >mM</td>\n",
       "      <td id=\"T_02693_row4_col5\" class=\"data row4 col5\" >Fitted</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_02693_row5_col0\" class=\"data row5 col0\" >45 °C</td>\n",
       "      <td id=\"T_02693_row5_col1\" class=\"data row5 col1\" >Decay rate constant, k</td>\n",
       "      <td id=\"T_02693_row5_col2\" class=\"data row5 col2\" >0.0775</td>\n",
       "      <td id=\"T_02693_row5_col3\" class=\"data row5 col3\" >0.0014</td>\n",
       "      <td id=\"T_02693_row5_col4\" class=\"data row5 col4\" >min⁻¹</td>\n",
       "      <td id=\"T_02693_row5_col5\" class=\"data row5 col5\" >Fitted</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0xffff3c2aca10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import scipy\n",
    "from scipy.optimize import curve_fit\n",
    "\n",
    "def first_order(time, initial, rate):\n",
    "    return initial * np.exp(-rate * time)\n",
    "\n",
    "fits = {}\n",
    "parameters = []\n",
    "for temperature, group in data.groupby(\"temperature_C\", sort=True):\n",
    "    time = group[\"time_min\"].to_numpy()\n",
    "    concentration = group[\"concentration_mM\"].to_numpy()\n",
    "    estimate, covariance = curve_fit(\n",
    "        first_order, time, concentration, p0=(concentration[0], 0.04),\n",
    "        bounds=(0, np.inf), method=\"trf\", absolute_sigma=False,\n",
    "    )\n",
    "    uncertainty = np.sqrt(np.diag(covariance))\n",
    "    fit_time = np.linspace(time.min(), time.max(), 241)\n",
    "    predicted = first_order(time, *estimate)\n",
    "    fits[temperature] = dict(\n",
    "        time=time, concentration=concentration, predicted=predicted,\n",
    "        residual=concentration - predicted, fit_time=fit_time,\n",
    "        fit_concentration=first_order(fit_time, *estimate),\n",
    "    )\n",
    "    for quantity, unit, value, u in zip(\n",
    "        (\"Starting concentration, C₀\", \"Decay rate constant, k\"),\n",
    "        (\"mM\", \"min⁻¹\"), estimate, uncertainty,\n",
    "    ):\n",
    "        parameters.append(dict(dataset=f\"{temperature} °C\", quantity=quantity,\n",
    "                               value=value, uncertainty=u, unit=unit, how=\"Fitted\"))\n",
    "\n",
    "parameter_table = pd.DataFrame(parameters).rename(columns={\n",
    "    \"dataset\": \"Temperature\", \"quantity\": \"Quantity\", \"value\": \"Estimate\",\n",
    "    \"uncertainty\": \"Standard uncertainty\", \"unit\": \"Unit\", \"how\": \"How set\",\n",
    "})\n",
    "display(parameter_table.style.hide(axis=\"index\").format({\n",
    "    \"Estimate\": \"{:.4f}\", \"Standard uncertainty\": \"{:.4f}\",\n",
    "}))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9396421a-9566-4d05-ad20-38ab9bd2e842",
   "metadata": {},
   "source": [
    "The fitted decay rate increases with temperature: 0.02057, 0.04128 and 0.07745 min⁻¹ at 25, 35 and 45 °C, respectively. The standard uncertainties in the table come from the fit covariance scaled by the residual variance; they are not uncertainties on individual readings or estimates of repeatability. These synthetic data illustrate the temperature trend but do not establish a mechanism. Independent time courses would allow repeatability to be assessed.\n",
    "\n",
    "## Figure\n",
    "\n",
    "The chart uses the journal style at 88 mm wide, the one-column width listed in the [Nature Communications submission guidance](https://www.nature.com/ncomms/submit/how-to-submit#figures). Lettering follows the [artwork guidelines](https://www.nature.com/documents/aj-artworkguidelines.pdf). Each temperature has a distinct marker and line style so the series can be distinguished without color."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dfcdaccb-57d3-415b-9731-d630718a1060",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "displaylogo": false,
        "showSendToCloud": false
       },
       "data": [
        {
         "hovertemplate": "Time: %{x:.2f} min<br>Fit: %{y:.4f} mM<extra>%{fullData.name}</extra>",
         "legendgroup": "25 °C",
         "line": {
          "color": "#0754C6",
          "dash": "solid",
          "simplify": false,
          "width": 1.15
         },
         "mode": "lines",
         "name": "25 °C fit",
         "showlegend": false,
         "type": "scatter",
         "uid": "25-c-fit",
         "x": [
          0,
          0.25,
          0.5,
          0.75,
          1,
          1.25,
          1.5,
          1.75,
          2,
          2.25,
          2.5,
          2.75,
          3,
          3.25,
          3.5,
          3.75,
          4,
          4.25,
          4.5,
          4.75,
          5,
          5.25,
          5.5,
          5.75,
          6,
          6.25,
          6.5,
          6.75,
          7,
          7.25,
          7.5,
          7.75,
          8,
          8.25,
          8.5,
          8.75,
          9,
          9.25,
          9.5,
          9.75,
          10,
          10.25,
          10.5,
          10.75,
          11,
          11.25,
          11.5,
          11.75,
          12,
          12.25,
          12.5,
          12.75,
          13,
          13.25,
          13.5,
          13.75,
          14,
          14.25,
          14.5,
          14.75,
          15,
          15.25,
          15.5,
          15.75,
          16,
          16.25,
          16.5,
          16.75,
          17,
          17.25,
          17.5,
          17.75,
          18,
          18.25,
          18.5,
          18.75,
          19,
          19.25,
          19.5,
          19.75,
          20,
          20.25,
          20.5,
          20.75,
          21,
          21.25,
          21.5,
          21.75,
          22,
          22.25,
          22.5,
          22.75,
          23,
          23.25,
          23.5,
          23.75,
          24,
          24.25,
          24.5,
          24.75,
          25,
          25.25,
          25.5,
          25.75,
          26,
          26.25,
          26.5,
          26.75,
          27,
          27.25,
          27.5,
          27.75,
          28,
          28.25,
          28.5,
          28.75,
          29,
          29.25,
          29.5,
          29.75,
          30,
          30.25,
          30.5,
          30.75,
          31,
          31.25,
          31.5,
          31.75,
          32,
          32.25,
          32.5,
          32.75,
          33,
          33.25,
          33.5,
          33.75,
          34,
          34.25,
          34.5,
          34.75,
          35,
          35.25,
          35.5,
          35.75,
          36,
          36.25,
          36.5,
          36.75,
          37,
          37.25,
          37.5,
          37.75,
          38,
          38.25,
          38.5,
          38.75,
          39,
          39.25,
          39.5,
          39.75,
          40,
          40.25,
          40.5,
          40.75,
          41,
          41.25,
          41.5,
          41.75,
          42,
          42.25,
          42.5,
          42.75,
          43,
          43.25,
          43.5,
          43.75,
          44,
          44.25,
          44.5,
          44.75,
          45,
          45.25,
          45.5,
          45.75,
          46,
          46.25,
          46.5,
          46.75,
          47,
          47.25,
          47.5,
          47.75,
          48,
          48.25,
          48.5,
          48.75,
          49,
          49.25,
          49.5,
          49.75,
          50,
          50.25,
          50.5,
          50.75,
          51,
          51.25,
          51.5,
          51.75,
          52,
          52.25,
          52.5,
          52.75,
          53,
          53.25,
          53.5,
          53.75,
          54,
          54.25,
          54.5,
          54.75,
          55,
          55.25,
          55.5,
          55.75,
          56,
          56.25,
          56.5,
          56.75,
          57,
          57.25,
          57.5,
          57.75,
          58,
          58.25,
          58.5,
          58.75,
          59,
          59.25,
          59.5,
          59.75,
          60
         ],
         "y": [
          0.5054014607460307,
          0.5028087350872631,
          0.5002293101940527,
          0.4976631178330468,
          0.4951100901209319,
          0.492570159522638,
          0.49004325884955247,
          0.4875293212577421,
          0.48502828024618544,
          0.4825400696550132,
          0.4800646236637585,
          0.4776018767896155,
          0.4751517638857072,
          0.47271422013936215,
          0.47028918107040013,
          0.4678765825294261,
          0.4654763606961337,
          0.46308845207761656,
          0.4607127935066891,
          0.4583493221402153,
          0.4559979754574465,
          0.45365869125836766,
          0.4513314076620515,
          0.449016063105022,
          0.4467125963396258,
          0.44442094643241187,
          0.44214105276251986,
          0.43987285502007617,
          0.437616293204599,
          0.43537130762341075,
          0.43313783889005936,
          0.43091582792274696,
          0.4287052159427674,
          0.4265059444729509,
          0.4243179553361178,
          0.42214119065353894,
          0.41997559284340497,
          0.4178211046193031,
          0.4156776689887017,
          0.4135452292514425,
          0.411423728998241,
          0.409313112109194,
          0.40721332275229544,
          0.405124305381959,
          0.4030460047375491,
          0.400978365841919,
          0.39892133399995633,
          0.39687485479713663,
          0.39483887409808344,
          0.3928133380451368,
          0.39079819305692803,
          0.38879338582696266,
          0.3867988633222103,
          0.3848145727817016,
          0.3828404617151328,
          0.380876477901477,
          0.37892256938760266,
          0.37697868448689986,
          0.3750447717779123,
          0.3731207801029776,
          0.3712066585668737,
          0.36930235653547266,
          0.36740782363440144,
          0.3655230097477088,
          0.36364786501654023,
          0.36178233983781855,
          0.35992638486293216,
          0.3580799509964291,
          0.356242989394719,
          0.35441545146478043,
          0.3525972888628757,
          0.35078845349327237,
          0.3489888975069701,
          0.347198573300436,
          0.3454174335143445,
          0.343645431032325,
          0.3418825189797152,
          0.3401286507223217,
          0.33838377986518564,
          0.33664786025135596,
          0.3349208459606681,
          0.3332026913085297,
          0.3314933508447115,
          0.3297927793521455,
          0.3281009318457287,
          0.32641776357113317,
          0.32474323000362204,
          0.32307728684687176,
          0.32141989003180044,
          0.3197709957154018,
          0.3181305602795858,
          0.31649854033002445,
          0.31487489269500407,
          0.3132595744242833,
          0.31165254278795695,
          0.31005375527532536,
          0.3084631695937705,
          0.30688074366763646,
          0.305306435637117,
          0.30374020385714795,
          0.30218200689630564,
          0.30063180353571106,
          0.2990895527679392,
          0.29755521379593447,
          0.2960287460319316,
          0.29451010909638176,
          0.2929992628168845,
          0.29149616722712507,
          0.29000078256581735,
          0.28851306927565157,
          0.28703298800224847,
          0.285560499593118,
          0.28409556509662354,
          0.28263814576095164,
          0.28118820303308695,
          0.27974569855779224,
          0.278310594176594,
          0.2768828519267727,
          0.27546243404035897,
          0.2740493029431343,
          0.27264342125363705,
          0.2712447517821736,
          0.26985325752983497,
          0.2684689016875174,
          0.26709164763494914,
          0.26572145893972177,
          0.264358299356326,
          0.2630021328251934,
          0.2616529234717421,
          0.2603106356054283,
          0.25897523371880127,
          0.2576466824865652,
          0.25632494676464385,
          0.25500999158925136,
          0.2537017821759671,
          0.2524002839188158,
          0.25110546238935183,
          0.24981728333574849,
          0.24853571268189223,
          0.247260716526481,
          0.24599226114212744,
          0.24473031297446685,
          0.24347483864126945,
          0.24222580493155738,
          0.2409831788047262,
          0.2397469273896707,
          0.2385170179839157,
          0.23729341805275053,
          0.23607609522836878,
          0.23486501730901188,
          0.23366015225811732,
          0.23246146820347113,
          0.23126893343636493,
          0.23008251641075683,
          0.22890218574243745,
          0.22772791020819907,
          0.22655965874501027,
          0.22539740044919387,
          0.22424110457560953,
          0.22309074053684055,
          0.22194627790238453,
          0.22080768639784865,
          0.21967493590414858,
          0.2185479964567119,
          0.2174268382446855,
          0.2163114316101468,
          0.21520174704731923,
          0.21409775520179194,
          0.21299942686974316,
          0.21190673299716753,
          0.21081964467910774,
          0.20973813315888987,
          0.20866216982736258,
          0.20759172622214042,
          0.20652677402685093,
          0.20546728507038556,
          0.20441323132615433,
          0.20336458491134463,
          0.20232131808618362,
          0.2012834032532043,
          0.20025081295651562,
          0.19922351988107612,
          0.1982014968519713,
          0.19718471683369493,
          0.1961731529294338,
          0.19516677838035615,
          0.1941655665649039,
          0.19316949099808844,
          0.19217852533079,
          0.19119264334906058,
          0.1902118189734306,
          0.18923602625821903,
          0.18826523939084697,
          0.18729943269115495,
          0.18633858061072342,
          0.18538265773219711,
          0.1844316387686126,
          0.18348549856272936,
          0.1825442120863644,
          0.18160775443972998,
          0.18067610085077518,
          0.1797492266745304,
          0.17882710739245564,
          0.17790971861179164,
          0.17699703606491493,
          0.17608903560869557,
          0.17518569322385885,
          0.1742869850143495,
          0.17339288720669987,
          0.172503376149401,
          0.17161842831227683,
          0.17073802028586202,
          0.16986212878078227,
          0.16899073062713882,
          0.16812380277389496,
          0.16726132228826676,
          0.16640326635511601,
          0.16554961227634704,
          0.16470033747030607,
          0.16385541947118396,
          0.16301483592842184,
          0.16217856460611993,
          0.16134658338244937,
          0.16051887024906691,
          0.15969540331053295,
          0.158876160783732,
          0.1580611209972969,
          0.15725026239103498,
          0.15644356351535832,
          0.15564100303071596,
          0.15484255970702948,
          0.15404821242313158,
          0.153257940166207,
          0.15247172203123718,
          0.15168953722044667,
          0.15091136504275357,
          0.15013718491322164,
          0.14936697635251617,
          0.1486007189863621,
          0.14783839254500486,
          0.14707997686267468
         ]
        },
        {
         "hovertemplate": "Time: %{x:.2f} min<br>Fit: %{y:.4f} mM<extra>%{fullData.name}</extra>",
         "legendgroup": "35 °C",
         "line": {
          "color": "#AF6015",
          "dash": "dash",
          "simplify": false,
          "width": 1.15
         },
         "mode": "lines",
         "name": "35 °C fit",
         "showlegend": false,
         "type": "scatter",
         "uid": "35-c-fit",
         "x": [
          0,
          0.25,
          0.5,
          0.75,
          1,
          1.25,
          1.5,
          1.75,
          2,
          2.25,
          2.5,
          2.75,
          3,
          3.25,
          3.5,
          3.75,
          4,
          4.25,
          4.5,
          4.75,
          5,
          5.25,
          5.5,
          5.75,
          6,
          6.25,
          6.5,
          6.75,
          7,
          7.25,
          7.5,
          7.75,
          8,
          8.25,
          8.5,
          8.75,
          9,
          9.25,
          9.5,
          9.75,
          10,
          10.25,
          10.5,
          10.75,
          11,
          11.25,
          11.5,
          11.75,
          12,
          12.25,
          12.5,
          12.75,
          13,
          13.25,
          13.5,
          13.75,
          14,
          14.25,
          14.5,
          14.75,
          15,
          15.25,
          15.5,
          15.75,
          16,
          16.25,
          16.5,
          16.75,
          17,
          17.25,
          17.5,
          17.75,
          18,
          18.25,
          18.5,
          18.75,
          19,
          19.25,
          19.5,
          19.75,
          20,
          20.25,
          20.5,
          20.75,
          21,
          21.25,
          21.5,
          21.75,
          22,
          22.25,
          22.5,
          22.75,
          23,
          23.25,
          23.5,
          23.75,
          24,
          24.25,
          24.5,
          24.75,
          25,
          25.25,
          25.5,
          25.75,
          26,
          26.25,
          26.5,
          26.75,
          27,
          27.25,
          27.5,
          27.75,
          28,
          28.25,
          28.5,
          28.75,
          29,
          29.25,
          29.5,
          29.75,
          30,
          30.25,
          30.5,
          30.75,
          31,
          31.25,
          31.5,
          31.75,
          32,
          32.25,
          32.5,
          32.75,
          33,
          33.25,
          33.5,
          33.75,
          34,
          34.25,
          34.5,
          34.75,
          35,
          35.25,
          35.5,
          35.75,
          36,
          36.25,
          36.5,
          36.75,
          37,
          37.25,
          37.5,
          37.75,
          38,
          38.25,
          38.5,
          38.75,
          39,
          39.25,
          39.5,
          39.75,
          40,
          40.25,
          40.5,
          40.75,
          41,
          41.25,
          41.5,
          41.75,
          42,
          42.25,
          42.5,
          42.75,
          43,
          43.25,
          43.5,
          43.75,
          44,
          44.25,
          44.5,
          44.75,
          45,
          45.25,
          45.5,
          45.75,
          46,
          46.25,
          46.5,
          46.75,
          47,
          47.25,
          47.5,
          47.75,
          48,
          48.25,
          48.5,
          48.75,
          49,
          49.25,
          49.5,
          49.75,
          50,
          50.25,
          50.5,
          50.75,
          51,
          51.25,
          51.5,
          51.75,
          52,
          52.25,
          52.5,
          52.75,
          53,
          53.25,
          53.5,
          53.75,
          54,
          54.25,
          54.5,
          54.75,
          55,
          55.25,
          55.5,
          55.75,
          56,
          56.25,
          56.5,
          56.75,
          57,
          57.25,
          57.5,
          57.75,
          58,
          58.25,
          58.5,
          58.75,
          59,
          59.25,
          59.5,
          59.75,
          60
         ],
         "y": [
          0.5019228027996684,
          0.4967696115509966,
          0.4916693276018084,
          0.4866214077581482,
          0.4816253144029784,
          0.4766805154389217,
          0.47178648423159153,
          0.4669426995535038,
          0.46214864552856505,
          0.45740381157713,
          0.4527076923616235,
          0.4480597877327209,
          0.44345960267608076,
          0.4389066472596241,
          0.4344004365813559,
          0.42994049071772134,
          0.42552633467249273,
          0.4211574983261814,
          0.41683351638596816,
          0.41255392833614885,
          0.4083182783890881,
          0.4041261154366764,
          0.3999769930022864,
          0.3958704691932215,
          0.39180610665365323,
          0.38778347251804157,
          0.3838021383650342,
          0.37986168017183747,
          0.3759616782690577,
          0.3721017172960048,
          0.3682813861564552,
          0.3645002779748697,
          0.36075799005305914,
          0.35705412382729634,
          0.3533882848258686,
          0.34976008262706415,
          0.34616913081759265,
          0.34261504695142975,
          0.3390974525090866,
          0.33561597285729616,
          0.3321702372091132,
          0.3287598785844256,
          0.325384533770869,
          0.3220438432851442,
          0.318737451334731,
          0.31546500577999564,
          0.31222615809668663,
          0.30902056333881617,
          0.3058478801019225,
          0.30270777048670916,
          0.29959990006305826,
          0.2965239378344123,
          0.2934795562025225,
          0.2904664309325582,
          0.287484241118576,
          0.2845326691493411,
          0.2816114006745019,
          0.2787201245711103,
          0.27585853291048623,
          0.273026320925423,
          0.27022318697772807,
          0.26744883252609813,
          0.26470296209432365,
          0.2619852832398198,
          0.2592955065224805,
          0.2566333454738523,
          0.25399851656662475,
          0.25139073918443405,
          0.2488097355919764,
          0.2462552309054287,
          0.24372695306317255,
          0.24122463279681897,
          0.23874800360253076,
          0.23629680171263878,
          0.2338707660675503,
          0.23146963828794534,
          0.2290931626472585,
          0.2267410860444436,
          0.22441315797701739,
          0.2221091305143808,
          0.2198287582714133,
          0.21757179838233898,
          0.2153380104748604,
          0.2131271566445586,
          0.21093900142955557,
          0.2087733117854367,
          0.20662985706043122,
          0.204508408970847,
          0.20240874157675773,
          0.2003306312579398,
          0.19827385669005596,
          0.19623819882108404,
          0.19422344084798682,
          0.19222936819362238,
          0.1902557684838908,
          0.18830243152511586,
          0.1863691492816587,
          0.1844557158537617,
          0.18256192745561933,
          0.18068758239367474,
          0.1788324810451385,
          0.17699642583672853,
          0.17517922122362775,
          0.17338067366865834,
          0.17160059162166924,
          0.1698387854991356,
          0.1680950676639678,
          0.1663692524055274,
          0.16466115591984845,
          0.16297059629006208,
          0.16129739346702165,
          0.15964136925012712,
          0.1580023472683462,
          0.15638015296143043,
          0.15477461356132383,
          0.15318555807376288,
          0.15161281726006512,
          0.1500562236191046,
          0.14851561136947275,
          0.14699081643182224,
          0.1454816764113918,
          0.14398803058071113,
          0.1425097198624827,
          0.1410465868126397,
          0.1395984756035779,
          0.1381652320075594,
          0.13674670338028713,
          0.13534273864464774,
          0.13395318827462152,
          0.13257790427935748,
          0.1312167401874118,
          0.12986955103114847,
          0.12853619333129965,
          0.12721652508168474,
          0.12591040573408652,
          0.12461769618328218,
          0.1233382587522284,
          0.1220719571773982,
          0.12081865659426874,
          0.11957822352295763,
          0.11835052585400718,
          0.1171354328343143,
          0.11593281505320484,
          0.11474254442865121,
          0.11356449419363121,
          0.11239853888262685,
          0.11124455431826222,
          0.11010241759807805,
          0.10897200708144233,
          0.10785320237659526,
          0.10674588432782726,
          0.10564993500278844,
          0.10456523767992858,
          0.10349167683606599,
          0.10242913813408386,
          0.10137750841075321,
          0.10033667566468062,
          0.09930652904437967,
          0.09828695883646522,
          0.09727785645396836,
          0.09627911442477184,
          0.09529062638016386,
          0.09431228704350952,
          0.09334399221903865,
          0.09238563878074861,
          0.09143712466142112,
          0.09049834884175187,
          0.08956921133959161,
          0.08864961319929782,
          0.0877394564811957,
          0.0868386442511473,
          0.08594708057022774,
          0.08506467048450751,
          0.08419132001493965,
          0.0833269361473506,
          0.08247142682253408,
          0.08162470092644646,
          0.08078666828050289,
          0.07995723963197306,
          0.07913632664447547,
          0.07832384188856946,
          0.07751969883244371,
          0.07672381183270033,
          0.0759360961252336,
          0.07515646781620251,
          0.07438484387309563,
          0.07362114211588806,
          0.07286528120828902,
          0.07211718064907925,
          0.07137676076353751,
          0.07064394269495494,
          0.06991864839623664,
          0.0692008006215894,
          0.06849032291829488,
          0.06778713961856714,
          0.06709117583149386,
          0.06640235743506019,
          0.06572061106825468,
          0.06504586412325591,
          0.06437804473769983,
          0.06371708178702605,
          0.06306290487690297,
          0.06241544433573051,
          0.06177463120721994,
          0.061140397243049885,
          0.06051267489559767,
          0.05989139731074529,
          0.059276498320759284,
          0.05866791243724374,
          0.058065574844165475,
          0.05746942139095111,
          0.05687938858565478,
          0.056295413588196085,
          0.05571743420366742,
          0.05514538887571013,
          0.05457921667995848,
          0.05401885731755114,
          0.05346425110870918,
          0.05291533898637996,
          0.0523720624899464,
          0.05183436375900074,
          0.05130218552718215,
          0.050775471116077914,
          0.05025416442918687,
          0.04973820994594503,
          0.04922755271581249,
          0.04872213835242102,
          0.04822191302778184,
          0.047726823466552715,
          0.047236816940364044,
          0.04675184126220313,
          0.04627184478085612,
          0.04579677637540697,
          0.045326585449793004,
          0.04486122192741629,
          0.044400636245810275,
          0.04394477935136132,
          0.04349360269408436,
          0.04304705822245209,
          0.042605098378277514,
          0.042167676091648766
         ]
        },
        {
         "hovertemplate": "Time: %{x:.2f} min<br>Fit: %{y:.4f} mM<extra>%{fullData.name}</extra>",
         "legendgroup": "45 °C",
         "line": {
          "color": "#2C965D",
          "dash": "dot",
          "simplify": false,
          "width": 1.15
         },
         "mode": "lines",
         "name": "45 °C fit",
         "showlegend": false,
         "type": "scatter",
         "uid": "45-c-fit",
         "x": [
          0,
          0.25,
          0.5,
          0.75,
          1,
          1.25,
          1.5,
          1.75,
          2,
          2.25,
          2.5,
          2.75,
          3,
          3.25,
          3.5,
          3.75,
          4,
          4.25,
          4.5,
          4.75,
          5,
          5.25,
          5.5,
          5.75,
          6,
          6.25,
          6.5,
          6.75,
          7,
          7.25,
          7.5,
          7.75,
          8,
          8.25,
          8.5,
          8.75,
          9,
          9.25,
          9.5,
          9.75,
          10,
          10.25,
          10.5,
          10.75,
          11,
          11.25,
          11.5,
          11.75,
          12,
          12.25,
          12.5,
          12.75,
          13,
          13.25,
          13.5,
          13.75,
          14,
          14.25,
          14.5,
          14.75,
          15,
          15.25,
          15.5,
          15.75,
          16,
          16.25,
          16.5,
          16.75,
          17,
          17.25,
          17.5,
          17.75,
          18,
          18.25,
          18.5,
          18.75,
          19,
          19.25,
          19.5,
          19.75,
          20,
          20.25,
          20.5,
          20.75,
          21,
          21.25,
          21.5,
          21.75,
          22,
          22.25,
          22.5,
          22.75,
          23,
          23.25,
          23.5,
          23.75,
          24,
          24.25,
          24.5,
          24.75,
          25,
          25.25,
          25.5,
          25.75,
          26,
          26.25,
          26.5,
          26.75,
          27,
          27.25,
          27.5,
          27.75,
          28,
          28.25,
          28.5,
          28.75,
          29,
          29.25,
          29.5,
          29.75,
          30,
          30.25,
          30.5,
          30.75,
          31,
          31.25,
          31.5,
          31.75,
          32,
          32.25,
          32.5,
          32.75,
          33,
          33.25,
          33.5,
          33.75,
          34,
          34.25,
          34.5,
          34.75,
          35,
          35.25,
          35.5,
          35.75,
          36,
          36.25,
          36.5,
          36.75,
          37,
          37.25,
          37.5,
          37.75,
          38,
          38.25,
          38.5,
          38.75,
          39,
          39.25,
          39.5,
          39.75,
          40,
          40.25,
          40.5,
          40.75,
          41,
          41.25,
          41.5,
          41.75,
          42,
          42.25,
          42.5,
          42.75,
          43,
          43.25,
          43.5,
          43.75,
          44,
          44.25,
          44.5,
          44.75,
          45,
          45.25,
          45.5,
          45.75,
          46,
          46.25,
          46.5,
          46.75,
          47,
          47.25,
          47.5,
          47.75,
          48,
          48.25,
          48.5,
          48.75,
          49,
          49.25,
          49.5,
          49.75,
          50,
          50.25,
          50.5,
          50.75,
          51,
          51.25,
          51.5,
          51.75,
          52,
          52.25,
          52.5,
          52.75,
          53,
          53.25,
          53.5,
          53.75,
          54,
          54.25,
          54.5,
          54.75,
          55,
          55.25,
          55.5,
          55.75,
          56,
          56.25,
          56.5,
          56.75,
          57,
          57.25,
          57.5,
          57.75,
          58,
          58.25,
          58.5,
          58.75,
          59,
          59.25,
          59.5,
          59.75,
          60
         ],
         "y": [
          0.4862720729653345,
          0.47694694571498814,
          0.46780064427650636,
          0.4588297393485908,
          0.4500308673928618,
          0.4414007293727387,
          0.4329360895165035,
          0.42463377410408504,
          0.41649067027710934,
          0.40850372487176834,
          0.4006699432740715,
          0.3929863882970491,
          0.38545017907948775,
          0.3780584900057842,
          0.3708085496465132,
          0.3636976397193116,
          0.3567230940696892,
          0.3498822976713851,
          0.34317268564589287,
          0.33659174230078903,
          0.33013700018650266,
          0.3238060391711737,
          0.31759648553325154,
          0.31150601107149584,
          0.30553233223204374,
          0.29967320925221747,
          0.2939264453207511,
          0.2882898857541206,
          0.2827614171886707,
          0.27733896678823283,
          0.2720205014669389,
          0.2668040271269389,
          0.2616875879107371,
          0.2566692654678651,
          0.2517471782356185,
          0.24691948073358627,
          0.24218436287170916,
          0.23754004927160705,
          0.2329847986009209,
          0.22851690292042026,
          0.22413468704363088,
          0.21983650790874268,
          0.21562075396256253,
          0.21148584455628072,
          0.20743022935282468,
          0.20345238774557795,
          0.19955082828824597,
          0.19572408813565534,
          0.19197073249527682,
          0.18828935408926606,
          0.18467857262682105,
          0.18113703428665773,
          0.17766341120941004,
          0.17425640099976455,
          0.1709147262381419,
          0.167637134001743,
          0.1644223953947799,
          0.16126930508771553,
          0.15817668086533893,
          0.1551433631835072,
          0.15216821473438777,
          0.14925012002003768,
          0.14638798493416047,
          0.14358073635188345,
          0.1408273217274018,
          0.1381267086993386,
          0.13547788470367253,
          0.13287985659408874,
          0.13033165026961,
          0.12783231030936848,
          0.12538089961438165,
          0.12297649905619791,
          0.12061820713227964,
          0.11830513962799519,
          0.11603642928509277,
          0.11381122547653177,
          0.11162869388754995,
          0.10948801620284654,
          0.10738838979976432,
          0.1053290274473555,
          0.10330915701121832,
          0.10132802116399416,
          0.09938487710141625,
          0.09747899626380374,
          0.0956096640628965,
          0.0937761796139285,
          0.09197785547283895,
          0.0902140173785231,
          0.0884840040000257,
          0.08678716668858252,
          0.08512286923441688,
          0.08349048762820006,
          0.08188940982708617,
          0.08031903552523359,
          0.07877877592872722,
          0.07726805353481694,
          0.07578630191538945,
          0.07433296550459262,
          0.07290749939053232,
          0.07150936911096405,
          0.07013805045290229,
          0.06879302925607295,
          0.06747380122013469,
          0.06617987171559744,
          0.0649107555983666,
          0.0636659770278439,
          0.06244506928851627,
          0.061247574614966244,
          0.060073044020238144,
          0.05892103712749536,
          0.05779112200490628,
          0.056682875003696176,
          0.055595880599305154,
          0.05452973123559177,
          0.053484027172024586,
          0.0524583763338041,
          0.051452394164858604,
          0.05046570348365947,
          0.049497934341801046,
          0.04854872388529291,
          0.04761771621851177,
          0.04670456227076251,
          0.045808919665398184,
          0.04493045259144966,
          0.04406883167771731,
          0.043223733869276824,
          0.04239484230635369,
          0.041581846205520016,
          0.040784440743170045,
          0.04000232694122983,
          0.039235211555058915,
          0.038482806963501655,
          0.03774483106104683,
          0.037021007152055495,
          0.03631106384701705,
          0.03561473496079491,
          0.03493175941282333,
          0.03426188112921834,
          0.03360484894676566,
          0.03296041651874999,
          0.03232834222259013,
          0.031708389069245266,
          0.031100324614358753,
          0.03050392087110563,
          0.02991895422471171,
          0.029345205348611614,
          0.028782459122214894,
          0.028230504550249006,
          0.02768913468364899,
          0.02715814654196434,
          0.02663734103725375,
          0.02612652289943943,
          0.025625500603092734,
          0.02513408629562395,
          0.024652095726849114,
          0.024179348179907467,
          0.02371566640350379,
          0.02326087654544997,
          0.022814808087481216,
          0.02237729378132207,
          0.02194816958597868,
          0.021527274606233417,
          0.021114451032319088,
          0.020709544080749983,
          0.020312401936287534,
          0.019922875695018966,
          0.019540819308527423,
          0.01916608952913285,
          0.01879854585618283,
          0.018438050483373557,
          0.018084468247080866,
          0.01773766657568218,
          0.017397515439850367,
          0.017063887303800616,
          0.016736657077472454,
          0.01641570206962859,
          0.016100901941853263,
          0.01579213866343272,
          0.015489296467100943,
          0.015192261805634065,
          0.014900923309277074,
          0.01461517174398707,
          0.01433489997047713,
          0.014060002904045736,
          0.013790377475176387,
          0.013525922590892915,
          0.01326653909685582,
          0.013012129740185448,
          0.012762599132998195,
          0.012517853716641837,
          0.012277801726616846,
          0.012042353158170292,
          0.011811419732549625,
          0.011584914863903532,
          0.011362753626817575,
          0.011144852724472395,
          0.01093113045741248,
          0.010721506692913928,
          0.010515902834939564,
          0.010314241794670284,
          0.010116447961601447,
          0.009922447175193617,
          0.009732166697066889,
          0.009545535183728464,
          0.009362482659823246,
          0.009182940491897353,
          0.009006841362664808,
          0.008834119245767666,
          0.008664709381020218,
          0.008498548250127882,
          0.008335573552871718,
          0.008175724183749726,
          0.008018940209066005,
          0.007865162844459274,
          0.007714334432862401,
          0.007566398422884505,
          0.007421299347607678,
          0.007278982803790266,
          0.007139395431469036,
          0.00700248489395245,
          0.006868199858197598,
          0.006736489975563499,
          0.006607305862933425,
          0.006480599084199281,
          0.006356322132101016,
          0.006234428410414347,
          0.006114872216480028,
          0.005997608724068138,
          0.00588259396657103,
          0.005769784820518536,
          0.00565913898940932,
          0.005550614987852272,
          0.005444172126012059,
          0.005339770494352926,
          0.005237370948675055,
          0.005136935095437922,
          0.005038425277365058,
          0.004941804559324895,
          0.004847036714482338,
          0.004754086210715959,
          0.004662918197295614
         ]
        },
        {
         "hovertemplate": "Time: %{x:g} min<br>Concentration: %{y:.4f} mM<extra>%{fullData.name}</extra>",
         "legendgroup": "25 °C",
         "marker": {
          "color": "#0754C6",
          "line": {
           "color": "#0754C6",
           "width": 0
          },
          "size": 4.2,
          "symbol": "circle"
         },
         "mode": "markers",
         "name": "25 °C",
         "type": "scatter",
         "uid": "25-c",
         "x": [
          0,
          5,
          10,
          15,
          20,
          25,
          30,
          35,
          40,
          45,
          50,
          55,
          60
         ],
         "y": [
          0.5016,
          0.4578,
          0.4276,
          0.3736,
          0.3194,
          0.2957,
          0.2718,
          0.241,
          0.2176,
          0.2111,
          0.175,
          0.1733,
          0.1492
         ]
        },
        {
         "hovertemplate": "Time: %{x:g} min<br>Concentration: %{y:.4f} mM<extra>%{fullData.name}</extra>",
         "legendgroup": "35 °C",
         "marker": {
          "color": "#AF6015",
          "line": {
           "color": "#AF6015",
           "width": 1.15
          },
          "size": 5.4,
          "symbol": "square-open"
         },
         "mode": "markers",
         "name": "35 °C",
         "type": "scatter",
         "uid": "35-c",
         "x": [
          0,
          5,
          10,
          15,
          20,
          25,
          30,
          35,
          40,
          45,
          50,
          55,
          60
         ],
         "y": [
          0.4999,
          0.4145,
          0.3294,
          0.2682,
          0.2205,
          0.1796,
          0.1402,
          0.1153,
          0.1023,
          0.0807,
          0.0643,
          0.0492,
          0.0454
         ]
        },
        {
         "hovertemplate": "Time: %{x:g} min<br>Concentration: %{y:.4f} mM<extra>%{fullData.name}</extra>",
         "legendgroup": "45 °C",
         "marker": {
          "color": "#2C965D",
          "line": {
           "color": "#2C965D",
           "width": 1.15
          },
          "size": 5.4,
          "symbol": "triangle-up-open"
         },
         "mode": "markers",
         "name": "45 °C",
         "type": "scatter",
         "uid": "45-c",
         "x": [
          0,
          5,
          10,
          15,
          20,
          25,
          30,
          35,
          40,
          45,
          50,
          55,
          60
         ],
         "y": [
          0.4789,
          0.3431,
          0.2251,
          0.1502,
          0.105,
          0.0644,
          0.0429,
          0.0258,
          0.0237,
          0.0176,
          0.0123,
          0.0038,
          -0.0013
         ]
        }
       ],
       "layout": {
        "font": {
         "color": "#000000",
         "family": "Arial, Helvetica, Liberation Sans, sans-serif",
         "size": 9
        },
        "height": 245.67,
        "legend": {
         "bgcolor": "rgba(0,0,0,0)",
         "itemsizing": "trace",
         "itemwidth": 30,
         "traceorder": "normal",
         "x": 0.96,
         "xanchor": "right",
         "y": 0.96,
         "yanchor": "top"
        },
        "margin": {
         "b": 43,
         "l": 54,
         "pad": 0,
         "r": 13,
         "t": 12
        },
        "paper_bgcolor": "#ffffff",
        "plot_bgcolor": "#ffffff",
        "template": {
         "data": {
          "scatter": [
           {
            "type": "scatter"
           }
          ]
         }
        },
        "title": {
         "automargin": true,
         "font": {
          "size": 10.33
         }
        },
        "width": 332.6,
        "xaxis": {
         "automargin": true,
         "dtick": 10,
         "linecolor": "#000000",
         "linewidth": 1,
         "minor": {
          "showgrid": false,
          "tickcolor": "#000000",
          "ticklen": 2.27,
          "ticks": "",
          "tickwidth": 1
         },
         "mirror": false,
         "range": [
          -2,
          62
         ],
         "showgrid": false,
         "showline": true,
         "tick0": 0,
         "tickcolor": "#000000",
         "ticklen": 3,
         "ticks": "outside",
         "tickwidth": 1,
         "title": {
          "font": {
           "size": 9
          },
          "standoff": 8,
          "text": "Time (min)"
         },
         "zeroline": false
        },
        "yaxis": {
         "automargin": true,
         "dtick": 0.1,
         "linecolor": "#000000",
         "linewidth": 1,
         "minor": {
          "showgrid": false,
          "tickcolor": "#000000",
          "ticklen": 2.27,
          "ticks": "",
          "tickwidth": 1
         },
         "mirror": false,
         "range": [
          -0.025,
          0.535
         ],
         "showgrid": false,
         "showline": true,
         "tick0": 0,
         "tickcolor": "#000000",
         "tickformat": ".1f",
         "ticklen": 3,
         "ticks": "outside",
         "tickwidth": 1,
         "title": {
          "font": {
           "size": 9
          },
          "standoff": 7,
          "text": "Concentration (mM)"
         },
         "zeroline": false
        }
       }
      },
      "text/plain": [
       "<Chart: /root/Photobleaching/charts/Photobleaching.chart.json>"
      ]
     },
     "metadata": {
      "vicena": {
       "file": "/root/Photobleaching/charts/Photobleaching.chart.json",
       "modified": 1796324092898
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.insert(0, \"/root/.library/apps/chart-editor/chartkit/src\")\n",
    "import chartkit\n",
    "import plotly\n",
    "import plotly.graph_objects as go\n",
    "\n",
    "fig = go.Figure(layout=dict(template=\"none\"))\n",
    "styles = {\n",
    "    25: (\"#0754C6\", \"circle\", \"solid\"),\n",
    "    35: (\"#AF6015\", \"square-open\", \"dash\"),\n",
    "    45: (\"#2C965D\", \"triangle-up-open\", \"dot\"),\n",
    "}\n",
    "for temperature, result in fits.items():\n",
    "    color, symbol, dash = styles[temperature]\n",
    "    label = f\"{temperature} °C\"\n",
    "    fig.add_scatter(\n",
    "        x=result[\"fit_time\"].tolist(), y=result[\"fit_concentration\"].tolist(),\n",
    "        mode=\"lines\", name=f\"{label} fit\", legendgroup=label, showlegend=False,\n",
    "        line=dict(color=color, width=1.15, dash=dash, simplify=False),\n",
    "        hovertemplate=\"Time: %{x:.2f} min<br>Fit: %{y:.4f} mM<extra>%{fullData.name}</extra>\",\n",
    "    )\n",
    "for temperature, result in fits.items():\n",
    "    color, symbol, dash = styles[temperature]\n",
    "    label = f\"{temperature} °C\"\n",
    "    fig.add_scatter(\n",
    "        x=result[\"time\"].tolist(), y=result[\"concentration\"].tolist(),\n",
    "        mode=\"markers\", name=label, legendgroup=label,\n",
    "        marker=dict(color=color, symbol=symbol, size=4.2 if temperature == 25 else 5.4,\n",
    "                    line=dict(color=color, width=0 if temperature == 25 else 1.15)),\n",
    "        hovertemplate=\"Time: %{x:g} min<br>Concentration: %{y:.4f} mM<extra>%{fullData.name}</extra>\",\n",
    "    )\n",
    "\n",
    "size = dict(width_mm=88, height_mm=65, font_pt=6.75)\n",
    "fig = chartkit.journal_style(fig, size)\n",
    "fig.update_layout(\n",
    "    font_family=\"Arial, Helvetica, Liberation Sans, sans-serif\",\n",
    "    margin=dict(l=54, r=13, b=43, t=12, pad=0),\n",
    "    legend=dict(x=0.96, y=0.96, xanchor=\"right\", yanchor=\"top\",\n",
    "                traceorder=\"normal\", itemsizing=\"trace\", itemwidth=30),\n",
    ")\n",
    "fig.update_xaxes(title=dict(text=\"Time (min)\", standoff=8, font=dict(size=9)),\n",
    "                 range=[-2, 62], tick0=0, dtick=10)\n",
    "fig.update_yaxes(title=dict(text=\"Concentration (mM)\", standoff=7, font=dict(size=9)),\n",
    "                 range=[-0.025, 0.535], tick0=0, dtick=0.1, tickformat=\".1f\")\n",
    "fig.update_xaxes(mirror=False, ticks=\"outside\", ticklen=3, minor_ticks=\"\")\n",
    "fig.update_yaxes(mirror=False, ticks=\"outside\", ticklen=3, minor_ticks=\"\")\n",
    "chart = chartkit.show(fig, str(project / \"charts\" / \"Photobleaching.chart.json\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70a537d2-f04e-44f6-9b64-e9aaf27df283",
   "metadata": {},
   "source": [
    "**Suggested caption. Photobleaching of a dye at three temperatures (synthetic data).** Markers show the supplied concentrations at 25 °C (blue circles), 35 °C (orange squares) and 45 °C (green triangles), with 13 time points per temperature. The solid, dashed and dotted lines, respectively, show separate first-order fits on the original concentration scale. No measurement error bars are shown because the dataset supplied neither replicates nor measurement uncertainties.\n",
    "\n",
    "Use the chart’s **Edit** button to restyle it, or right-click the part you want changed and ask me to change it. Chart Editor keeps your edits when the notebook reruns."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af5a2412-af68-4cb5-b7b4-b7d058a8c1ab",
   "metadata": {},
   "source": [
    "## Submission files and source data\n",
    "\n",
    "Export the saved chart as a vector PDF for the journal and a 600 dpi PNG for preview. Save one workbook sheet per temperature, with the original readings, fitted values, residuals and the exact points used to draw the fit line. Each data column has quantity, unit and sample condition in rows 1–3."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "21a31451-2fe2-41a7-894d-07ac79da5853",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "charts/Photobleaching.chart.json\n",
      "results/Photobleaching.pdf\n",
      "results/Photobleaching.png\n",
      "results/Photobleaching source data.xlsx\n",
      "Decay rate constants:\n",
      "25 °C: 0.02057 ± 0.00050 min⁻¹ (fit standard uncertainty)\n",
      "35 °C: 0.04128 ± 0.00039 min⁻¹ (fit standard uncertainty)\n",
      "45 °C: 0.07745 ± 0.00143 min⁻¹ (fit standard uncertainty)\n",
      "Checked: all 39 source values match the chart and workbook. All 723 fit-line points match the workbook.\n"
     ]
    }
   ],
   "source": [
    "import importlib.util\n",
    "import platform\n",
    "from importlib.metadata import version\n",
    "\n",
    "results_dir = project / \"results\"\n",
    "pdf = chartkit.export(chart, results_dir / \"Photobleaching.pdf\")\n",
    "png = chartkit.export(chart, results_dir / \"Photobleaching.png\", dpi=600)\n",
    "\n",
    "spec = importlib.util.spec_from_file_location(\n",
    "    \"workbook\", \"/root/.library/notebooks/scripts/workbook.py\"\n",
    ")\n",
    "workbook = importlib.util.module_from_spec(spec)\n",
    "spec.loader.exec_module(workbook)\n",
    "sheets = {}\n",
    "for temperature, result in fits.items():\n",
    "    sample = f\"Synthetic dye, {temperature} °C\"\n",
    "    sheets[f\"{temperature} °C\"] = [\n",
    "        (\"Time at data points\", \"min\", sample, result[\"time\"]),\n",
    "        (\"Concentration (supplied)\", \"mM\", sample, result[\"concentration\"]),\n",
    "        (\"Fitted concentration at data points\", \"mM\", sample, result[\"predicted\"]),\n",
    "        (\"Residual (supplied minus fitted)\", \"mM\", sample, result[\"residual\"]),\n",
    "        (\"Time for fit line\", \"min\", sample, result[\"fit_time\"]),\n",
    "        (\"Concentration for fit line\", \"mM\", sample, result[\"fit_concentration\"]),\n",
    "    ]\n",
    "book = workbook.write(\n",
    "    results_dir / \"Photobleaching source data.xlsx\", sheets, parameters=parameters,\n",
    "    method=[\n",
    "        \"Source: Data/bleaching.csv (synthetic photobleaching of a dye). All 39 values retained.\",\n",
    "        \"Model: C(t) = C₀ exp(−kt). No offset or background fitted; first-order decay to zero.\",\n",
    "        \"Fit each temperature separately using all 13 observations on the original concentration scale.\",\n",
    "        \"Unweighted scipy.optimize.curve_fit with method='trf', nonnegative C₀ and k, and no upper bounds.\",\n",
    "        \"Starting values: supplied concentration at t=0 and k=0.04 min⁻¹. Other solver settings are defaults.\",\n",
    "        \"Standard uncertainties: square roots of covariance diagonal with absolute_sigma=False (11 residual degrees of freedom).\",\n",
    "        \"Measurement error bars are not available; the CSV supplied no replicates or measurement uncertainties.\",\n",
    "        \"Plotted first-order curves use 241 equally spaced times from 0 to 60 min inclusive.\",\n",
    "        f\"Python {platform.python_version()}; NumPy {np.__version__}; SciPy {scipy.__version__}; pandas {pd.__version__}.\",\n",
    "        f\"Plotly {plotly.__version__}; Kaleido {version('kaleido')}; openpyxl {version('openpyxl')}.\",\n",
    "    ],\n",
    ")\n",
    "for artifact in (chart, pdf, png, book):\n",
    "    print(artifact.relative_to(project))\n",
    "print(\"Decay rate constants:\")\n",
    "for row in parameters[1::2]:\n",
    "    print(f\"{row['dataset']}: {row['value']:.5f} ± {row['uncertainty']:.5f} {row['unit']} (fit standard uncertainty)\")\n",
    "\n",
    "from openpyxl import load_workbook\n",
    "saved_book = load_workbook(book, read_only=True, data_only=True)\n",
    "saved_chart = chartkit.load(chart)\n",
    "for temperature, result in fits.items():\n",
    "    label = f\"{temperature} °C\"\n",
    "    sheet = saved_book[label]\n",
    "    supplied = list(sheet.iter_rows(min_row=4, max_row=16, max_col=2, values_only=True))\n",
    "    assert supplied == list(zip(result[\"time\"], result[\"concentration\"]))\n",
    "    markers = next(trace for trace in saved_chart.data if trace.name == label)\n",
    "    assert list(zip(markers.x, markers.y)) == supplied\n",
    "    line = next(trace for trace in saved_chart.data if trace.name == f\"{label} fit\")\n",
    "    saved_line = list(sheet.iter_rows(min_row=4, max_row=244, min_col=5,\n",
    "                                     max_col=6, values_only=True))\n",
    "    np.testing.assert_allclose(saved_line, list(zip(line.x, line.y)), rtol=1e-14, atol=0)\n",
    "saved_book.close()\n",
    "print(\"Checked: all 39 source values match the chart and workbook. All 723 fit-line points match the workbook.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a900b8e4-943d-4609-b477-7d6e45326c82",
   "metadata": {},
   "source": [
    "Submit the PDF as the figure; the PNG is a preview. In Origin 2021b or later, drag the workbook onto the workspace or use **Data → Connect to File → Excel**. For each temperature sheet, assign rows 1, 2 and 3 to **Long Name**, **Units** and **Comments**, respectively, if Origin does not recognize them. The first time column is the X column for the supplied points; use the second time column as X for the smooth fit. The Parameters and Method sheets document the estimates and fitting settings."
   ]
  }
 ],
 "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.10"
  },
  "vicena": {
   "changed_at": 1796324092835,
   "changed_cells": [
    "9396421a-9566-4d05-ad20-38ab9bd2e842",
    "dfcdaccb-57d3-415b-9731-d630718a1060",
    "21a31451-2fe2-41a7-894d-07ac79da5853"
   ]
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
