{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "afd9cde8-c7b3-4c87-85d4-fdb3246a2424",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from scipy.optimize import curve_fit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "6f36ba20-5efd-4afb-98f4-ff87eac8a1e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def line(x, k, b):\n",
    "    return x*k + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "17d7c03e-5547-4505-85d6-733678982f80",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(r\"raw-data/data.csv\")\n",
    "\n",
    "rev_nu_0 = df['rev_nu_0']\n",
    "tau = df['tau']\n",
    "\n",
    "delta_rev_nu_0 = df['Delta_rev_nu_0']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "ec64aa59-2e42-4311-9b3b-f4daa99b8071",
   "metadata": {},
   "outputs": [],
   "source": [
    "opt, cov = curve_fit(line, tau, rev_nu_0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "6922d03a-70b0-450e-be7a-626e92ecc348",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 143420 characters]\n",
      "text/plain": [
       "<Figure size 1600x900 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(8, 4.5), dpi=200)\n",
    "\n",
    "plt.minorticks_on()\n",
    "plt.grid(which='minor', linestyle=':', color='0.9')\n",
    "plt.grid(which='major', linestyle='-', color='0.8', linewidth=0.3)\n",
    "\n",
    "plt.errorbar(tau, rev_nu_0, yerr=delta_rev_nu_0, linestyle='', marker='.', markersize=10, label=\"Experiment\", color=\"tab:blue\", alpha=0.3)\n",
    "plt.plot(tau, line(tau, opt[0], opt[1]), label=r\"Fitting\", color=\"tab:blue\", linestyle='-')\n",
    "\n",
    "plt.ylabel(r\"$1/\\nu_0$, мкс\", fontsize=14)\n",
    "plt.xlabel(r\"$\\tau$, мкс\", fontsize=14)\n",
    "\n",
    "plt.legend()\n",
    "plt.savefig(r\"images\\data.png\", facecolor=\"white\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59d3e6e3-0861-4ded-a70b-9e85890e7168",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "df2005d7-8ad7-441a-83c0-8ebda7901ce2",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(r\"raw-data/plot2.csv\")\n",
    "\n",
    "m = df['m']\n",
    "k = df['k']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "c52f43da-bb84-446a-b81a-b465d37290ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "opt, cov = curve_fit(line, m, k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "15b4a580-5da3-4c54-b918-414f50268e5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 105168 characters]\n",
      "text/plain": [
       "<Figure size 1600x900 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(8, 4.5), dpi=200)\n",
    "\n",
    "plt.minorticks_on()\n",
    "plt.grid(which='minor', linestyle=':', color='0.9')\n",
    "plt.grid(which='major', linestyle='-', color='0.8', linewidth=0.3)\n",
    "\n",
    "plt.errorbar(m, k, linestyle='', marker='.', markersize=10, label=\"Experiment\", color=\"tab:blue\", alpha=0.3)\n",
    "plt.plot(m, line(m, opt[0], opt[1]), label=r\"Fitting\", color=\"tab:blue\", linestyle='-')\n",
    "\n",
    "plt.ylabel(r\"$k$\", fontsize=18)\n",
    "plt.xlabel(r\"$m$\", fontsize=18)\n",
    "\n",
    "plt.legend()\n",
    "plt.savefig(r\"images\\plot2.png\", facecolor=\"white\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fac6d1b6-3b03-42c1-8911-12b2f7279f41",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
