{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import sklearn\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calulate_density(travel):\n",
    "    return 2710/(6293-travel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def filter_data(df):\n",
    "    # filter data\n",
    "    df['P.Zeit'] = pd.to_timedelta(df['P.Zeit'])\n",
    "\n",
    "    df=df[df['Pyrometer'] >460].copy()\n",
    "    df=df[df['AV Force'] > 55].copy()\n",
    "\n",
    "    minPistonTravel = df['Abs. Piston Trav'].min()\n",
    "    df['TravelRelative'] = ((df['Abs. Piston Trav'] - minPistonTravel)*1000).astype(int)\n",
    "    df['TravelRelativeCorrected'] = np.maximum.accumulate(df['TravelRelative'])\n",
    "    minTemperature = df['Pyrometer'].min()\n",
    "    df['TravelRelativeCorrected'] = df['TravelRelativeCorrected'].rolling(window=10).mean()\n",
    "    df.loc[pd.isnull(df['TravelRelativeCorrected']), 'TravelRelativeCorrected'] =  0\n",
    "    df['TravelRelativeTempCorrected']=df['TravelRelativeCorrected']+(df['Pyrometer']-minTemperature)*1.241\n",
    "    #df['TravelRelativeCorrected'] = df['TravelRelativeCorrected'].ewm(span=10, adjust=False).mean()\n",
    "    df.loc[pd.isnull(df['TravelRelativeCorrected']), 'TravelRelativeCorrected'] =  0\n",
    "\n",
    "    #df['TravelDelta'] = df['TravelDelta'].rolling(window=60).mean()\n",
    "    #df.loc[pd.isnull(df['TravelDelta']), 'TravelDelta'] =  0\n",
    "\n",
    "    #df.loc[(df['TravelDelta']<0), 'TravelDelta'] =  0\n",
    "    #df['TravelDelta'] = df['TravelDelta'].astype(int)\n",
    "    df['TravelDeltaOriginal'] = df['Abs. Piston Trav'] - df['Abs. Piston Trav'].shift(1)\n",
    "    #df = df.drop(columns=['Abs. Piston Trav'])\n",
    "    \n",
    "    df['seconds'] = df['P.Zeit'].dt.total_seconds()\n",
    "    df['seconds'] = df['seconds'].astype(int)\n",
    "    minSeconds = df['seconds'].min()\n",
    "    df['seconds'] = (df['seconds'] - minSeconds+1)\n",
    "    df = df.drop(columns=['P.Zeit'])\n",
    "    \n",
    "    df['Heating'] = (df['Heating power']*10).astype(int)\n",
    "    df = df.drop(columns=['Heating power'])\n",
    "    \n",
    "    #df = df.iloc[::10]\n",
    "\n",
    "    df['TravelDelta'] = df['TravelRelativeTempCorrected'] - df['TravelRelativeTempCorrected'].shift(1)\n",
    "    df['TravelDelta2'] = df['TravelRelativeCorrected'] - df['TravelRelativeCorrected'].shift(1)\n",
    "    df.loc[pd.isnull(df['TravelDelta']), 'TravelDelta'] =  0\n",
    "\n",
    "    df['TravelRelativeCorrectedShifted'] = df['TravelRelativeCorrected'].shift(-1)\n",
    "    df['TravelRelativeCorrectedShifted'] = df['TravelRelativeCorrectedShifted'].fillna(0)\n",
    "    df['TravelRelativeTempCorrectedShifted'] = df['TravelRelativeTempCorrected'].shift(-1)\n",
    "    #df['TravelRelativeTempCorrectedShifted'] = df['TravelRelativeTempCorrectedShifted'].fillna(df['TravelRelativeTempCorrectedShifted'].iloc[-2])\n",
    "    df['PyrometerShifted'] = df['Pyrometer'].shift(-1)\n",
    "    df['Density'] =  calulate_density(df['TravelRelativeTempCorrected'])\n",
    "    #df['PyrometerShifted'] = df['PyrometerShifted'].fillna(df['PyrometerShifted'].iloc[-2])\n",
    "\n",
    "    df = df.drop(df.index[-1])\n",
    "\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def filter_dataEmpty(df):\n",
    "    # filter data\n",
    "    df['seconds'] = df['No.']\n",
    "    df = df.drop(columns=['No.'])\n",
    "    df['Pyrometer'] = df['AV Pyro top']\n",
    "    df = df.drop(columns=['AV Pyro top'])\n",
    "\n",
    "    df=df[df['Pyrometer'] >460].copy()\n",
    "    df=df[df['AV Force'] >15].copy()\n",
    "\n",
    "    minPistonTravel = df['AV Abs. Piston T'].min()\n",
    "    df['TravelRelative'] = ((df['AV Abs. Piston T'] - minPistonTravel)*1000).astype(int)\n",
    "    # maxPistonTravel = df['TravelRelative'].max()\n",
    "    # df['TravelRelative'] = -(df['TravelRelative']-maxPistonTravel)\n",
    "    #df['TravelRelativeCorrected'] = np.maximum.accumulate(df['TravelRelative'])\n",
    "    df['TravelRelativeCorrected'] = df['TravelRelative']\n",
    "    df['TravelRelativeCorrected'] = df['TravelRelativeCorrected'].rolling(window=60).mean()\n",
    "    #df['TravelRelativeCorrected'] = df['TravelRelativeCorrected'].ewm(span=10, adjust=False).mean()\n",
    "    df['TravelDelta'] = df['TravelRelativeCorrected'] - df['TravelRelativeCorrected'].shift(1)\n",
    "    df.loc[pd.isnull(df['TravelDelta']), 'TravelDelta'] =  0\n",
    "\n",
    "    #df['TravelDelta'] = df['TravelDelta'].rolling(window=60).mean()\n",
    "    #df.loc[pd.isnull(df['TravelDelta']), 'TravelDelta'] =  0\n",
    "\n",
    "    #df.loc[(df['TravelDelta']<0), 'TravelDelta'] =  0\n",
    "    #df['TravelDelta'] = df['TravelDelta'].astype(int)\n",
    "    df = df.drop(columns=['AV Abs. Piston T'])\n",
    "    \n",
    "    \n",
    "    df['Heating'] = (df['AV Heating Power']*10).astype(int)\n",
    "    df = df.drop(columns=['AV Heating Power'])\n",
    "    \n",
    "\n",
    "\n",
    "\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "data1000 = pd.read_csv('data/160508-1021-1000,0min,56kN.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['P.Zeit','MTC1','MTC2','Pyrometer','AV Abs. Press. 2','yPower','AV Force','AV Speed','I RMS','Pulse Time','Pause Time','U RMS','Heating power','Rel. Piston Trav','Abs. Piston Trav']) \n",
    "                   # usecols=['P.Zeit','Pyrometer','AV Force','Heating power','Abs. Piston Trav']) \n",
    "                    #usecols=['P.Zeit','Pyrometer','Heating power','Abs. Piston Trav']) \n",
    "data900 = pd.read_csv('data/160508-1022-900,0min,56kN.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['P.Zeit','MTC1','MTC2','Pyrometer','AV Abs. Press. 2','yPower','AV Force','AV Speed','I RMS','Pulse Time','Pause Time','U RMS','Heating power','Rel. Piston Trav','Abs. Piston Trav']) \n",
    "data1350 = pd.read_csv('data/200508-1023-1350,0min,56kN.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['P.Zeit','MTC1','MTC2','Pyrometer','AV Abs. Press. 2','yPower','AV Force','AV Speed','I RMS','Pulse Time','Pause Time','U RMS','Heating power','Rel. Piston Trav','Abs. Piston Trav']) \n",
    "data1200 = pd.read_csv('data/200508-1024-1200,0min,56kN.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['P.Zeit','MTC1','MTC2','Pyrometer','AV Abs. Press. 2','yPower','AV Force','AV Speed','I RMS','Pulse Time','Pause Time','U RMS','Heating power','Rel. Piston Trav','Abs. Piston Trav']) \n",
    "dataN1200 = pd.read_csv('data/050608-1037-1200,0min,70kN.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['P.Zeit','MTC1','MTC2','Pyrometer','AV Abs. Press. 2','yPower','AV Force','AV Speed','I RMS','Pulse Time','Pause Time','U RMS','Heating power','Rel. Piston Trav','Abs. Piston Trav']) \n",
    "dataN1100 = pd.read_csv('data/290508-1033-1100,0min,70kN.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['P.Zeit','MTC1','MTC2','Pyrometer','AV Abs. Press. 2','yPower','AV Force','AV Speed','I RMS','Pulse Time','Pause Time','U RMS','Heating power','Rel. Piston Trav','Abs. Piston Trav']) \n",
    "dataEmpty1= pd.read_csv('data/fct20-082 graphite 4f 1800 (100) 16kN 5 min d20.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['No.','AV Pyro top','AV Force','AV Abs. Piston T','AV Heating Power','U RMS','I RMS']) \n",
    "dataEmpty2= pd.read_csv('data/fct20-083 graphite for fct20-075 1800 (100) 16kN 5 min d20.csv',sep = ';', skiprows=[1],decimal=',',\n",
    "                    usecols=['No.','AV Pyro top','AV Force','AV Abs. Piston T','AV Heating Power','U RMS','I RMS']) \n",
    "\n",
    "data1000 = filter_data(data1000)\n",
    "data900 = filter_data(data900)\n",
    "data1350 = filter_data(data1350)\n",
    "data1200 = filter_data(data1200)\n",
    "dataN1200 = filter_data(dataN1200)\n",
    "dataN1100 = filter_data(dataN1100)\n",
    "\n",
    "dataN1200['TravelRelativeTempCorrected'] = dataN1200['TravelRelativeTempCorrected']/2\n",
    "dataN1200['TravelRelativeTempCorrectedShifted'] = dataN1200['TravelRelativeTempCorrectedShifted']/2\n",
    "#dataN1200['TravelRelativeTempCorrected'] = dataN1200['TravelRelativeTempCorrected']/2\n",
    "#dataN1200['TravelRelativeTempCorrectedShifted'] = dataN1200['TravelRelativeTempCorrectedShifted']/2\n",
    "\n",
    "dataEmpty1 = filter_dataEmpty(dataEmpty1)\n",
    "dataEmpty2 = filter_dataEmpty(dataEmpty2)\n",
    "\n",
    "\n",
    "\n",
    "#dataEmpty1.describe()\n",
    "#dataN1200.dtypes\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "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>MTC1</th>\n",
       "      <th>MTC2</th>\n",
       "      <th>Pyrometer</th>\n",
       "      <th>AV Abs. Press. 2</th>\n",
       "      <th>yPower</th>\n",
       "      <th>AV Force</th>\n",
       "      <th>AV Speed</th>\n",
       "      <th>I RMS</th>\n",
       "      <th>Pulse Time</th>\n",
       "      <th>Pause Time</th>\n",
       "      <th>...</th>\n",
       "      <th>TravelRelativeTempCorrected</th>\n",
       "      <th>TravelDeltaOriginal</th>\n",
       "      <th>seconds</th>\n",
       "      <th>Heating</th>\n",
       "      <th>TravelDelta</th>\n",
       "      <th>TravelDelta2</th>\n",
       "      <th>TravelRelativeCorrectedShifted</th>\n",
       "      <th>TravelRelativeTempCorrectedShifted</th>\n",
       "      <th>PyrometerShifted</th>\n",
       "      <th>Density</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>432</th>\n",
       "      <td>104</td>\n",
       "      <td>84</td>\n",
       "      <td>462</td>\n",
       "      <td>853</td>\n",
       "      <td>30</td>\n",
       "      <td>56</td>\n",
       "      <td>0.03</td>\n",
       "      <td>1.47</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>68</td>\n",
       "      <td>0.000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241</td>\n",
       "      <td>463.0</td>\n",
       "      <td>0.430637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>433</th>\n",
       "      <td>105</td>\n",
       "      <td>84</td>\n",
       "      <td>463</td>\n",
       "      <td>853</td>\n",
       "      <td>31</td>\n",
       "      <td>57</td>\n",
       "      <td>0.03</td>\n",
       "      <td>1.47</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.241</td>\n",
       "      <td>0.01</td>\n",
       "      <td>2</td>\n",
       "      <td>68</td>\n",
       "      <td>1.241</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241</td>\n",
       "      <td>463.0</td>\n",
       "      <td>0.430722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>434</th>\n",
       "      <td>105</td>\n",
       "      <td>84</td>\n",
       "      <td>463</td>\n",
       "      <td>908</td>\n",
       "      <td>31</td>\n",
       "      <td>56</td>\n",
       "      <td>0.03</td>\n",
       "      <td>1.50</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>1.241</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>3</td>\n",
       "      <td>70</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.723</td>\n",
       "      <td>465.0</td>\n",
       "      <td>0.430722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>435</th>\n",
       "      <td>105</td>\n",
       "      <td>84</td>\n",
       "      <td>465</td>\n",
       "      <td>962</td>\n",
       "      <td>31</td>\n",
       "      <td>56</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1.50</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.723</td>\n",
       "      <td>0.00</td>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>2.482</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7.446</td>\n",
       "      <td>468.0</td>\n",
       "      <td>0.430892</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>436</th>\n",
       "      <td>106</td>\n",
       "      <td>85</td>\n",
       "      <td>468</td>\n",
       "      <td>962</td>\n",
       "      <td>31</td>\n",
       "      <td>56</td>\n",
       "      <td>0.00</td>\n",
       "      <td>1.48</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>7.446</td>\n",
       "      <td>0.00</td>\n",
       "      <td>5</td>\n",
       "      <td>68</td>\n",
       "      <td>3.723</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7.446</td>\n",
       "      <td>468.0</td>\n",
       "      <td>0.431147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1251</th>\n",
       "      <td>344</td>\n",
       "      <td>255</td>\n",
       "      <td>1342</td>\n",
       "      <td>1004</td>\n",
       "      <td>0</td>\n",
       "      <td>57</td>\n",
       "      <td>0.68</td>\n",
       "      <td>0.03</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5323.680</td>\n",
       "      <td>0.01</td>\n",
       "      <td>820</td>\n",
       "      <td>0</td>\n",
       "      <td>14.723</td>\n",
       "      <td>11.0</td>\n",
       "      <td>4243.5</td>\n",
       "      <td>5335.580</td>\n",
       "      <td>1342.0</td>\n",
       "      <td>2.795774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1252</th>\n",
       "      <td>342</td>\n",
       "      <td>254</td>\n",
       "      <td>1342</td>\n",
       "      <td>1001</td>\n",
       "      <td>0</td>\n",
       "      <td>57</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.03</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5335.580</td>\n",
       "      <td>0.02</td>\n",
       "      <td>821</td>\n",
       "      <td>0</td>\n",
       "      <td>11.900</td>\n",
       "      <td>11.9</td>\n",
       "      <td>4254.5</td>\n",
       "      <td>5336.652</td>\n",
       "      <td>1334.0</td>\n",
       "      <td>2.830524</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1253</th>\n",
       "      <td>342</td>\n",
       "      <td>254</td>\n",
       "      <td>1334</td>\n",
       "      <td>1008</td>\n",
       "      <td>0</td>\n",
       "      <td>56</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.03</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5336.652</td>\n",
       "      <td>0.00</td>\n",
       "      <td>822</td>\n",
       "      <td>0</td>\n",
       "      <td>1.072</td>\n",
       "      <td>11.0</td>\n",
       "      <td>4265.5</td>\n",
       "      <td>5346.411</td>\n",
       "      <td>1333.0</td>\n",
       "      <td>2.833697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1254</th>\n",
       "      <td>341</td>\n",
       "      <td>253</td>\n",
       "      <td>1333</td>\n",
       "      <td>1001</td>\n",
       "      <td>0</td>\n",
       "      <td>56</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.04</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5346.411</td>\n",
       "      <td>0.01</td>\n",
       "      <td>823</td>\n",
       "      <td>0</td>\n",
       "      <td>9.759</td>\n",
       "      <td>11.0</td>\n",
       "      <td>4275.6</td>\n",
       "      <td>5354.029</td>\n",
       "      <td>1331.0</td>\n",
       "      <td>2.862911</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1255</th>\n",
       "      <td>339</td>\n",
       "      <td>252</td>\n",
       "      <td>1331</td>\n",
       "      <td>1001</td>\n",
       "      <td>0</td>\n",
       "      <td>56</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.03</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5354.029</td>\n",
       "      <td>0.01</td>\n",
       "      <td>824</td>\n",
       "      <td>0</td>\n",
       "      <td>7.618</td>\n",
       "      <td>10.1</td>\n",
       "      <td>4284.7</td>\n",
       "      <td>5363.129</td>\n",
       "      <td>1331.0</td>\n",
       "      <td>2.886138</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>789 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      MTC1  MTC2  Pyrometer  AV Abs. Press. 2  yPower  AV Force  AV Speed  \\\n",
       "432    104    84        462               853      30        56      0.03   \n",
       "433    105    84        463               853      31        57      0.03   \n",
       "434    105    84        463               908      31        56      0.03   \n",
       "435    105    84        465               962      31        56      0.00   \n",
       "436    106    85        468               962      31        56      0.00   \n",
       "...    ...   ...        ...               ...     ...       ...       ...   \n",
       "1251   344   255       1342              1004       0        57      0.68   \n",
       "1252   342   254       1342              1001       0        57      0.66   \n",
       "1253   342   254       1334              1008       0        56      0.66   \n",
       "1254   341   253       1333              1001       0        56      0.66   \n",
       "1255   339   252       1331              1001       0        56      0.66   \n",
       "\n",
       "      I RMS  Pulse Time  Pause Time  ...  TravelRelativeTempCorrected  \\\n",
       "432    1.47        20.0         5.0  ...                        0.000   \n",
       "433    1.47        20.0         5.0  ...                        1.241   \n",
       "434    1.50        20.0         5.0  ...                        1.241   \n",
       "435    1.50        20.0         5.0  ...                        3.723   \n",
       "436    1.48        20.0         5.0  ...                        7.446   \n",
       "...     ...         ...         ...  ...                          ...   \n",
       "1251   0.03        20.0         5.0  ...                     5323.680   \n",
       "1252   0.03        20.0         5.0  ...                     5335.580   \n",
       "1253   0.03        20.0         5.0  ...                     5336.652   \n",
       "1254   0.04        20.0         5.0  ...                     5346.411   \n",
       "1255   0.03        20.0         5.0  ...                     5354.029   \n",
       "\n",
       "      TravelDeltaOriginal  seconds  Heating  TravelDelta  TravelDelta2  \\\n",
       "432                   NaN        1       68        0.000           NaN   \n",
       "433                  0.01        2       68        1.241           0.0   \n",
       "434                 -0.01        3       70        0.000           0.0   \n",
       "435                  0.00        4       70        2.482           0.0   \n",
       "436                  0.00        5       68        3.723           0.0   \n",
       "...                   ...      ...      ...          ...           ...   \n",
       "1251                 0.01      820        0       14.723          11.0   \n",
       "1252                 0.02      821        0       11.900          11.9   \n",
       "1253                 0.00      822        0        1.072          11.0   \n",
       "1254                 0.01      823        0        9.759          11.0   \n",
       "1255                 0.01      824        0        7.618          10.1   \n",
       "\n",
       "      TravelRelativeCorrectedShifted  TravelRelativeTempCorrectedShifted  \\\n",
       "432                              0.0                               1.241   \n",
       "433                              0.0                               1.241   \n",
       "434                              0.0                               3.723   \n",
       "435                              0.0                               7.446   \n",
       "436                              0.0                               7.446   \n",
       "...                              ...                                 ...   \n",
       "1251                          4243.5                            5335.580   \n",
       "1252                          4254.5                            5336.652   \n",
       "1253                          4265.5                            5346.411   \n",
       "1254                          4275.6                            5354.029   \n",
       "1255                          4284.7                            5363.129   \n",
       "\n",
       "      PyrometerShifted   Density  \n",
       "432              463.0  0.430637  \n",
       "433              463.0  0.430722  \n",
       "434              465.0  0.430722  \n",
       "435              468.0  0.430892  \n",
       "436              468.0  0.431147  \n",
       "...                ...       ...  \n",
       "1251            1342.0  2.795774  \n",
       "1252            1334.0  2.830524  \n",
       "1253            1333.0  2.833697  \n",
       "1254            1331.0  2.862911  \n",
       "1255            1331.0  2.886138  \n",
       "\n",
       "[789 rows x 25 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "#dataEmpty1.describe()\n",
    "selectedData=dataEmpty2[dataEmpty2['Pyrometer'] >1200].copy()\n",
    "selectedData=selectedData[selectedData['Pyrometer'] <1210].copy()\n",
    "dataN1100.head(10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 86672 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(10, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(10, 6))\n",
    "ax1.plot(dataEmpty1['Pyrometer'], dataEmpty1['TravelRelative'], color='orange') \n",
    "ax1.plot(dataEmpty2['Pyrometer'], dataEmpty2['TravelRelative'], color='red') \n",
    "\n",
    "minTemperature = data1000['Pyrometer'].min()\n",
    "data1000['TravelRelative2']=data1000['TravelRelative']+(data1000['Pyrometer']-minTemperature)*1.241\n",
    "sc = ax1.plot(data1000['Pyrometer'], data1000['TravelRelative'], color='green') \n",
    "sc = ax1.plot(data1000['Pyrometer'], data1000['TravelRelative2'], color='blue') \n",
    "\n",
    "\n",
    "#minTemperature = data1200['Pyrometer'].min()\n",
    "#data1200['TravelRelative2']=data1200['TravelRelative']+(data1200['Pyrometer']-minTemperature)*1.241\n",
    "#sc = ax1.plot(data1200['Pyrometer'], data1200['TravelRelative'], color='green') \n",
    "#sc = ax1.plot(data1200['Pyrometer'], data1200['TravelRelative2'], color='blue') \n",
    "\n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Pyrometer'],color='red')  \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Heating'], color='green') \n",
    "# Add color bar to show the color scale\n",
    "ax1.set_ylabel('Хід поршня, μм')\n",
    "#ax1.set_ylim(400, 1000)\n",
    "#ax1.set_xlim(300, 1400)\n",
    "ax1.set_title('Спікання без порошку, визначення коєфіцієнта термічного розширення')\n",
    "ax1.set_xlabel('Температура, °C')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 106048 characters]",
      "text/plain": [
       "<Figure size 2000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(40, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(20, 6))\n",
    "#sc = ax1.plot(data900['seconds'], data900['Pyrometer'], color='red') \n",
    "#sc = ax1.plot(data1000['seconds'], data1000['Pyrometer'], color='red') \n",
    "#sc = ax1.plot(data1000['seconds'], data1000['Density'], color='green')\n",
    "#sc = ax1.plot(data1200['seconds'], data1200['Density'], color='red')\n",
    "#sc = ax1.plot(data1000['Density'], data1000['TravelDelta'], color='green')\n",
    "#sc = ax1.plot(data900['Density'], data900['TravelDelta'], color='black')\n",
    "sc = ax1.plot(data1200['Density'], data1200['TravelDelta'], color='red')\n",
    "#sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrected'], color='blue') \n",
    "#sc = ax1.plot(data1200['seconds'], data1200['Pyrometer'], color='green') \n",
    "#sc = ax1.plot(data1350['seconds'], data1350['Pyrometer'], color='black') \n",
    "#sc = ax1.plot(dataN1200['seconds'], dataN1200['Pyrometer'], color='purple') \n",
    "#sc = ax1.plot(dataN1100['seconds'], dataN1100['Pyrometer'], color='orange') \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Pyrometer'],color='red')  \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Heating'], color='green') \n",
    "# Add color bar to show the color scale\n",
    "ax1.set_ylabel('Швидкість ущільнення')\n",
    "#ax1.set_ylim(400, 1000)\n",
    "#ax1.set_xlim(300, 1400)\n",
    "#ax1.set_title('title')\n",
    "ax1.set_xlabel('Відносна щільність')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 452060 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(40, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(40, 6))\n",
    "sc = ax1.plot(data900['seconds'], data900['AV Force'], color='red') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['AV Force'], color='blue') \n",
    "sc = ax1.plot(data1200['seconds'], data1200['AV Force'], color='green') \n",
    "sc = ax1.plot(data1350['seconds'], data1350['AV Force'], color='black') \n",
    "sc = ax1.plot(dataN1200['seconds'], dataN1200['AV Force'], color='purple') \n",
    "sc = ax1.plot(dataN1100['seconds'], dataN1100['AV Force'], color='orange') \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Pyrometer'],color='red')  \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Heating'], color='green') \n",
    "# Add color bar to show the color scale\n",
    "ax1.set_ylabel('AV Force')\n",
    "#ax1.set_ylim(400, 1000)\n",
    "#ax1.set_xlim(300, 1400)\n",
    "ax1.set_title('title')\n",
    "ax1.set_xlabel('seconds')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 2000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 142472 characters]",
      "text/plain": [
       "<Figure size 3000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.figure(figsize=(20, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(30, 6))\n",
    "#sc = ax1.plot(data900['seconds'], data900['TravelDelta'], color='red')  \n",
    "#sc = ax1.plot(data1000['seconds'], data1000['TravelDelta'], color='green') \n",
    "sc = ax1.plot(data1200['seconds'], data1200['TravelDeltaOriginal']*1000, color='gray') \n",
    "sc = ax1.plot(data1200['seconds'], data1200['TravelDelta2'], color='red') \n",
    "\n",
    "##sc = ax1.plot(data1200['seconds'], data1200['TravelDelta'], color='green') \n",
    "#sc = ax1.plot(dataN1200['seconds'], dataN1200['TravelDelta'], color='purple') \n",
    "#sc = ax1.plot(dataN1100['seconds'], dataN1100['TravelDelta'], color='orange') \n",
    "#sc = ax1.plot(data1350['seconds'], data1350['TravelDelta'], color='black') \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Pyrometer'],color='red')  \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Heating'], color='green') \n",
    "# Add color bar to show the color scale\n",
    "ax1.set_ylabel('Швидкість ходу поршня, μm/с')\n",
    "#ax1.set_ylim(400, 1000)\n",
    "#ax1.set_xlim(300, 1400)\n",
    "ax1.set_title('Швидкість ходу поршня до і після усереднення')\n",
    "ax1.set_xlabel('час, с')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_data_Travel(data, title):\n",
    "    setToPlot = data.copy()\n",
    "    #setToPlot = setToPlot[(setToPlot['seconds'] > 0) & (setToPlot['seconds'] <650)].copy()\n",
    "    #setToPlot = setToPlot[(setToPlot['Heating'] > 0)].copy()\n",
    "\n",
    "    #setToPlot = setToPlot[(setToPlot['Pyrometer'] < 900)].copy()\n",
    "    #setToPlot = setToPlot[(setToPlot['seconds'] < 850)].copy()\n",
    "    plt.figure(figsize=(40, 6))\n",
    "    fig, ax1 = plt.subplots( figsize=(40, 6))\n",
    "    sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelative'], color='red')\n",
    "    sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelative'], color='red')\n",
    "    TravelDeltaOriginal\n",
    "    #sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelativeCorrected'], color='green')\n",
    "    #sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelativeCorrectedShifted'], color='blue')\n",
    "    sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelativeTempCorrected'], color='orange')\n",
    "\n",
    "    \n",
    "    ax1.set_ylabel('TrevelRelative')\n",
    "    #ax1.set_ylim(0, 800)\n",
    "    #ax1.set_ylim(0, 4000)\n",
    "    ax1.set_title(title)\n",
    "    ax1.set_xlabel('seconds')\n",
    "    ax1.grid(True)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'TravelDeltaOriginal' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mplot_data_Travel\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata900\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43m900\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m      2\u001b[39m plot_data_Travel(data1000, \u001b[33m'\u001b[39m\u001b[33m1000\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m      3\u001b[39m plot_data_Travel(data1200, \u001b[33m'\u001b[39m\u001b[33m1200\u001b[39m\u001b[33m'\u001b[39m)\n",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 12\u001b[39m, in \u001b[36mplot_data_Travel\u001b[39m\u001b[34m(data, title)\u001b[39m\n\u001b[32m     10\u001b[39m sc2 = ax1.plot(setToPlot[\u001b[33m'\u001b[39m\u001b[33mseconds\u001b[39m\u001b[33m'\u001b[39m], setToPlot[\u001b[33m'\u001b[39m\u001b[33mTravelRelative\u001b[39m\u001b[33m'\u001b[39m], color=\u001b[33m'\u001b[39m\u001b[33mred\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m     11\u001b[39m sc2 = ax1.plot(setToPlot[\u001b[33m'\u001b[39m\u001b[33mseconds\u001b[39m\u001b[33m'\u001b[39m], setToPlot[\u001b[33m'\u001b[39m\u001b[33mTravelRelative\u001b[39m\u001b[33m'\u001b[39m], color=\u001b[33m'\u001b[39m\u001b[33mred\u001b[39m\u001b[33m'\u001b[39m)\n\u001b[32m---> \u001b[39m\u001b[32m12\u001b[39m \u001b[43mTravelDeltaOriginal\u001b[49m\n\u001b[32m     13\u001b[39m \u001b[38;5;66;03m#sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelativeCorrected'], color='green')\u001b[39;00m\n\u001b[32m     14\u001b[39m \u001b[38;5;66;03m#sc2 = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelativeCorrectedShifted'], color='blue')\u001b[39;00m\n\u001b[32m     15\u001b[39m sc2 = ax1.plot(setToPlot[\u001b[33m'\u001b[39m\u001b[33mseconds\u001b[39m\u001b[33m'\u001b[39m], setToPlot[\u001b[33m'\u001b[39m\u001b[33mTravelRelativeTempCorrected\u001b[39m\u001b[33m'\u001b[39m], color=\u001b[33m'\u001b[39m\u001b[33morange\u001b[39m\u001b[33m'\u001b[39m)\n",
      "\u001b[31mNameError\u001b[39m: name 'TravelDeltaOriginal' is not defined"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 31920 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_data_Travel(data900, '900')\n",
    "plot_data_Travel(data1000, '1000')\n",
    "plot_data_Travel(data1200, '1200')\n",
    "plot_data_Travel(dataN1200, 'N1200')\n",
    "#plot_data_Travel(dataN1100, 'N1100')\n",
    "#plot_data_Travel(data1350, '1350')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_data_TravelDelta(data, title):\n",
    "    setToPlot = data.copy()\n",
    "    #setToPlot = setToPlot[(setToPlot['seconds'] > 0) & (setToPlot['seconds'] <650)].copy()\n",
    "    #setToPlot = setToPlot[(setToPlot['Heating'] > 0)].copy()\n",
    "\n",
    "    #setToPlot = setToPlot[(setToPlot['Pyrometer'] < 900)].copy()\n",
    "    #setToPlot = setToPlot[(setToPlot['seconds'] < 850)].copy()\n",
    "\n",
    "    # setToPlot['Heating'] = (setToPlot['Heating']*10).astype(int)\n",
    "    plt.figure(figsize=(40, 6))\n",
    "    fig, ax1 = plt.subplots( figsize=(40, 6))\n",
    "    sc = ax1.plot(setToPlot['Pyrometer'], setToPlot['TravelDelta'], color='red')  \n",
    "    #sc = ax1.plot(setToPlot['seconds'], setToPlot['TravelRelativeTempCorrectedShifted'], color='red')  \n",
    "    #sc = ax1.plot(setToPlot['seconds'], setToPlot['TravelDelta'], color='green')  \n",
    "    #sc = ax1.plot(setToPlot['Pyrometer'], setToPlot['AV Force']*10, color='blue')  \n",
    "    # sc = ax1.plot(setToPlot['seconds'], setToPlot['Heating']) \n",
    "    #sc = plt.scatter(setToPlot['seconds'], setToPlot['Pyrometer'],color='red')  \n",
    "    #sc = plt.scatter(setToPlot['seconds'], setToPlot['Heating'], color='green') \n",
    "    # ax2 = ax1.twinx()\n",
    "    # sc2 = ax2.plot(setToPlot['seconds'], setToPlot['TravelDelta'], color='green')\n",
    "    # Add color bar to show the color scale\n",
    "    # ax2.set_ylim(0, 10)\n",
    "    # ax2.set_ylabel('TravelDelta')\n",
    "    ax1.set_ylabel('seconds, TravelDelta')\n",
    "    # ax1.set_ylim(400, 1000)\n",
    "    # ax1.set_xlim(300, 1400)\n",
    "    # ax2.set_xlim(300, 1400)\n",
    "    ax1.set_title(title)\n",
    "    ax1.set_xlabel('seconds')\n",
    "    ax1.grid(True)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 92104 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "setToPlot = data1000\n",
    "#setToPlot = setToPlot[(setToPlot['seconds'] > 550) & (setToPlot['seconds'] <650)].copy()\n",
    " \n",
    "\n",
    "plt.figure(figsize=(40, 6))\n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['TravelDelta'], c=setToPlot['Pyrometer'], cmap='viridis')  \n",
    "sc = plt.plot(setToPlot['seconds'], setToPlot['TravelDelta'])  \n",
    "\n",
    "# Add color bar to show the color scale\n",
    "#plt.colorbar(sc, label='Temperature')\n",
    "#plt.title('-')\n",
    "plt.xlabel('seconds')\n",
    "plt.ylabel('TravelDelta')\n",
    "plt.grid(True)\n",
    "plt.show()\n",
    "\n",
    "#setToPlot.head(50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 55696 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 57756 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 55592 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 54596 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 57676 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_data_TravelDelta(data900, '900')\n",
    "plot_data_TravelDelta(data1000, '1000')\n",
    "plot_data_TravelDelta(data1200, '1200')\n",
    "plot_data_TravelDelta(dataN1200, 'N1200')\n",
    "plot_data_TravelDelta(data1350, '1350')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 344744 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "#data1000.corr()\n",
    "selected_columns = ['Pyrometer', '', 'column3']\n",
    "new_df = data1000[selected_columns].copy()\n",
    "corr_matrix = new_df.corr()\n",
    "\n",
    "# Побудова теплової карти\n",
    "sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt=\".2f\")\n",
    "plt.title(\"Кореляційна матриця\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean Squared Error: 2893.90950167473\n",
      "Kernel parameters: 3.16**2 * RationalQuadratic(alpha=0.114, length_scale=1.28)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\kernels.py:452: ConvergenceWarning: The optimal value found for dimension 0 of parameter k1__constant_value is close to the specified upper bound 10.0. Increasing the bound and calling fit again may find a better value.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "from sklearn.gaussian_process import GaussianProcessRegressor\n",
    "from sklearn.gaussian_process.kernels import RBF, Matern, RationalQuadratic, ExpSineSquared, DotProduct, ConstantKernel as C\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import mean_squared_error\n",
    "\n",
    "\n",
    "# Select the relevant columns\n",
    "X = pd.concat( [data900,data1000,data1200], axis=0)\n",
    "y = pd.concat( [data900,data1000,data1200], axis=0)\n",
    "\n",
    "X = X[['seconds','Heating', 'Pyrometer', 'AV Force']]\n",
    "y = y['TravelRelativeCorrected']\n",
    "\n",
    "\n",
    "# Split the data into training and testing sets\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
    "\n",
    "# Define the kernel for the GPR model\n",
    "kernels = [\n",
    "    C(1.0, (1e-4, 1e1)) * RBF(length_scale=1.0),\n",
    "    C(1.0, (1e-4, 1e1)) * Matern(length_scale=1.0, nu=1.5),\n",
    "    C(1.0, (1e-4, 1e1)) * RationalQuadratic(length_scale=1.0, alpha=0.1),\n",
    "    C(1.0, (1e-4, 1e1)) * ExpSineSquared(length_scale=1.0, periodicity=3.0),\n",
    "    C(1.0, (1e-4, 1e1)) * DotProduct(sigma_0=1.0)\n",
    "]\n",
    "kernel = kernels[2]\n",
    "\n",
    "# Create and train the GPR model\n",
    "gpr = GaussianProcessRegressor(kernel=kernel, n_restarts_optimizer=10, alpha=1e-2)\n",
    "gpr.fit(X_train, y_train)\n",
    "\n",
    "# Make predictions\n",
    "y_pred = gpr.predict(X_test)\n",
    "\n",
    "# Evaluate the model\n",
    "mse = mean_squared_error(y_test, y_pred)\n",
    "print(f'Mean Squared Error: {mse}')\n",
    "\n",
    "# Print the kernel parameters\n",
    "print(f'Kernel parameters: {gpr.kernel_}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:660: ConvergenceWarning: lbfgs failed to converge (status=2):\n",
      "ABNORMAL_TERMINATION_IN_LNSRCH.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "  _check_optimize_result(\"lbfgs\", opt_res)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean Squared Error: 1.1976613823991402e-05\n",
      "Kernel parameters: 2.93e+03**2 * RationalQuadratic(alpha=9.14e-05, length_scale=1.21e+03)\n"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
      "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
      "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
      "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "from sklearn.gaussian_process import GaussianProcessRegressor\n",
    "from sklearn.gaussian_process.kernels import RBF, Matern, RationalQuadratic, ExpSineSquared, DotProduct, ConstantKernel as C\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import mean_squared_error\n",
    "\n",
    "# data1000 \n",
    "# data900 \n",
    "# data1350 -- bad data\n",
    "# data1200 \n",
    "# dataN1200 -- Different rate?\n",
    "# dataN1100 -- bad data?\n",
    "\n",
    "# data1000 = data1000.sort_values(by=['seconds'])\n",
    "# data900 = data900.sort_values(by=['seconds'])\n",
    "# data1200 = data1200.sort_values(by=['seconds'])\n",
    "# data1350 = data1350.sort_values(by=['seconds'])\n",
    "# dataN1200 = dataN1200.sort_values(by=['seconds'])\n",
    "# dataN1100 = dataN1100.sort_values(by=['seconds'])\n",
    "\n",
    "# Select the relevant columns\n",
    "#D = pd.concat( [data900, data1000, data1200, data1350,dataN1200,dataN1100], axis=0)\n",
    "D = pd.concat( [data900, data1000, data1200,dataN1200], axis=0)\n",
    "#D = pd.concat( [data900, data1000,dataN1200], axis=0)\n",
    "#D = pd.concat( [data900, data1000, data1200], axis=0)\n",
    "\n",
    "#TravelRelativeCorrectedShifted\n",
    "\n",
    "#X_train = X[['seconds','Heating', 'Pyrometer', 'AV Force']]\n",
    "X_train = D[['seconds','TravelRelativeTempCorrected', 'Pyrometer','PyrometerShifted']]\n",
    "#X_train = X[['seconds','Heating', 'Pyrometer']]\n",
    "y_train = D['TravelRelativeTempCorrectedShifted']\n",
    "\n",
    " # Define the kernel for the GPR model\n",
    "kernels = [\n",
    "    C(1.0, (1e-4, 1e9)) * RBF(length_scale=1.0),\n",
    "    C(1.0, (1e-4, 1e9)) * Matern(length_scale=1.0, nu=1.5),\n",
    "    C(1.0, (1e-4, 1e9)) * RationalQuadratic(length_scale=1.0, alpha=0.1),\n",
    "    C(1.0, (1e-4, 1e9)) * ExpSineSquared(length_scale=1.0, periodicity=3.0),\n",
    "    C(1.0, (1e-4, 1e9)) * DotProduct(sigma_0=1.0)\n",
    "]\n",
    "kernel = kernels[2]\n",
    "\n",
    "# Create and train the GPR model\n",
    "gpr = GaussianProcessRegressor(kernel=kernel, n_restarts_optimizer=100, alpha=1e-3)\n",
    "gpr.fit(X_train, y_train)\n",
    "\n",
    "# Make predictions\n",
    "\n",
    "#X_test = data1000[['seconds','Heating', 'Pyrometer', 'AV Force']]\n",
    "X_test = dataN1200[['seconds','TravelRelativeTempCorrected', 'Pyrometer','PyrometerShifted']]\n",
    "#X_test = data1000[['seconds','Heating', 'Pyrometer']]\n",
    "y_test = dataN1200['TravelRelativeTempCorrectedShifted']\n",
    "\n",
    "y_pred = gpr.predict(X_test)\n",
    "\n",
    "\n",
    "# Evaluate the model\n",
    "mse = mean_squared_error(y_test, y_pred)\n",
    "print(f'Mean Squared Error: {mse}')\n",
    "\n",
    "# Print the kernel parameters\n",
    "print(f'Kernel parameters: {gpr.kernel_}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1500x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 140204 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(15, 6))\n",
    "\n",
    "sc = ax1.plot(data1200['seconds'], data1200['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "#sc = ax1.plot(data1350['seconds'], data1350['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "#sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(data900['seconds'], data900['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(dataN1200['seconds'], dataN1200['TravelRelativeTempCorrectedShifted'], color='green') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(X_test['seconds'], y_pred, color='red') \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Pyrometer'],color='red')  \n",
    "#sc = plt.scatter(setToPlot['seconds'], setToPlot['Heating'], color='green') \n",
    "# Add color bar to show the color scale\n",
    "#ax1.set_ylabel('Pyrometer, Heating')\n",
    "#ax1.set_ylim(400, 1000)\n",
    "#ax1.set_xlim(300, 1400)\n",
    "ax1.set_title('Поріваняння передбаченого моделлю ходу поршня з реальними даними')\n",
    "ax1.set_xlabel('час, с')\n",
    "ax1.set_ylabel('хід поршня, μм')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   seconds  TravelRelativeTempCorrected  Pyrometer  PyrometerShifted\n",
      "0        1                          0.0        463             482.0\n"
     ]
    }
   ],
   "source": [
    "\n",
    "PredictionSet = data1000.head(1)\n",
    "PredictionSet = PredictionSet[['seconds','TravelRelativeTempCorrected', 'Pyrometer','PyrometerShifted']]\n",
    "PredictionSet = PredictionSet.reset_index(drop=True)\n",
    "time = PredictionSet['seconds'].iloc[0]\n",
    "\n",
    "newRegime = PredictionSet.copy()\n",
    "\n",
    "heating = 1\n",
    "\n",
    "print(PredictionSet)\n",
    "while time < 4000 and ( heating == 1 or PredictionSet['PyrometerShifted'].iloc[0] > 1000) :\n",
    "     TravelRelativeTempCorrectedPredicted = gpr.predict(PredictionSet, return_std=True); \n",
    "     #print(TravelRelativeTempCorrectedPredicted[0][0])\n",
    "     if PredictionSet['PyrometerShifted'].iloc[0] > 1200:\n",
    "           heating = 0\n",
    "     time = time + 10\n",
    "     PredictionSet.loc[0,'seconds'] = time\n",
    "     PredictionSet.loc[0,'TravelRelativeTempCorrected'] = TravelRelativeTempCorrectedPredicted[0][0]\n",
    "     PredictionSet.loc[0,'Pyrometer'] = PredictionSet['PyrometerShifted'].iloc[0]\n",
    "     if heating:\n",
    "          PredictionSet.loc[0,'PyrometerShifted'] = PredictionSet['PyrometerShifted'].iloc[0] + 8\n",
    "     else:\n",
    "          PredictionSet.loc[0,'PyrometerShifted'] = PredictionSet['PyrometerShifted'].iloc[0] -30\n",
    "     #print(PredictionSet)\n",
    "     newRegime = pd.concat([newRegime, PredictionSet], ignore_index=True)\n",
    "     newRegime.at[newRegime.index[-1],'STD'] = TravelRelativeTempCorrectedPredicted[1][0]\n",
    "#newRegime.head(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calulate_TargetDensificationRateValue(value):\n",
    "    if value < 0.40:\n",
    "        return 1\n",
    "    elif 0.40 <= value < 0.70:\n",
    "        # Лінійне зростання від 0 до 110\n",
    "        return ((value - 0.40) / (0.70 - 0.40) * 110)+1\n",
    "\n",
    "    elif 0.70 <= value < 0.85:\n",
    "        return 50\n",
    "    elif 0.85 <= value < 0.97:\n",
    "        # Лінійне зменшення від 50 до 0\n",
    "        return (0.97 - value) / (0.97 - 0.85) * 50\n",
    "    else:\n",
    "        return 0\n",
    "\n",
    "def calulate_TargetDensificationRate(column):\n",
    "    result = []\n",
    "    for value in column:\n",
    "        result.append(calulate_TargetDensificationRateValue(value))\n",
    "    return pd.Series(result, index=column.index)\n",
    "\n",
    "def find_closest_index(column, target_value):\n",
    "    squared_diff = (column - target_value) ** 2\n",
    "    return squared_diff.idxmin()\n",
    "\n",
    "#calulate_TargetDensificationRate(0.45)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:478: UserWarning: Predicted variances smaller than 0. Setting those variances to 0.\n",
      "  warnings.warn(\n",
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:478: UserWarning: Predicted variances smaller than 0. Setting those variances to 0.\n",
      "  warnings.warn(\n",
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:478: UserWarning: Predicted variances smaller than 0. Setting those variances to 0.\n",
      "  warnings.warn(\n",
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:478: UserWarning: Predicted variances smaller than 0. Setting those variances to 0.\n",
      "  warnings.warn(\n",
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:478: UserWarning: Predicted variances smaller than 0. Setting those variances to 0.\n",
      "  warnings.warn(\n",
      "c:\\Users\\arros\\miniconda3\\Lib\\site-packages\\sklearn\\gaussian_process\\_gpr.py:478: UserWarning: Predicted variances smaller than 0. Setting those variances to 0.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "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>seconds</th>\n",
       "      <th>TravelRelativeTempCorrected</th>\n",
       "      <th>Pyrometer</th>\n",
       "      <th>PyrometerShifted</th>\n",
       "      <th>STD</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>463.0</td>\n",
       "      <td>463.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>21.0</td>\n",
       "      <td>12.1875</td>\n",
       "      <td>492.0</td>\n",
       "      <td>506.0</td>\n",
       "      <td>0.006659</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>31.0</td>\n",
       "      <td>23.4375</td>\n",
       "      <td>506.0</td>\n",
       "      <td>520.0</td>\n",
       "      <td>0.003967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>41.0</td>\n",
       "      <td>36.0000</td>\n",
       "      <td>518.0</td>\n",
       "      <td>530.0</td>\n",
       "      <td>0.004734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>51.0</td>\n",
       "      <td>48.7500</td>\n",
       "      <td>527.0</td>\n",
       "      <td>536.0</td>\n",
       "      <td>0.005167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>61.0</td>\n",
       "      <td>62.2500</td>\n",
       "      <td>535.0</td>\n",
       "      <td>543.0</td>\n",
       "      <td>0.004931</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>71.0</td>\n",
       "      <td>76.5000</td>\n",
       "      <td>543.0</td>\n",
       "      <td>551.0</td>\n",
       "      <td>0.004734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>81.0</td>\n",
       "      <td>90.8750</td>\n",
       "      <td>550.0</td>\n",
       "      <td>557.0</td>\n",
       "      <td>0.004632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>91.0</td>\n",
       "      <td>105.3750</td>\n",
       "      <td>557.0</td>\n",
       "      <td>564.0</td>\n",
       "      <td>0.005074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>101.0</td>\n",
       "      <td>120.2500</td>\n",
       "      <td>564.0</td>\n",
       "      <td>571.0</td>\n",
       "      <td>0.004834</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   seconds  TravelRelativeTempCorrected  Pyrometer  PyrometerShifted       STD\n",
       "0      1.0                       0.0000      463.0             463.0       NaN\n",
       "1     21.0                      12.1875      492.0             506.0  0.006659\n",
       "2     31.0                      23.4375      506.0             520.0  0.003967\n",
       "3     41.0                      36.0000      518.0             530.0  0.004734\n",
       "4     51.0                      48.7500      527.0             536.0  0.005167\n",
       "5     61.0                      62.2500      535.0             543.0  0.004931\n",
       "6     71.0                      76.5000      543.0             551.0  0.004734\n",
       "7     81.0                      90.8750      550.0             557.0  0.004632\n",
       "8     91.0                     105.3750      557.0             564.0  0.005074\n",
       "9    101.0                     120.2500      564.0             571.0  0.004834"
      ]
     },
     "execution_count": 437,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "PredictionSet = data1000.head(1)\n",
    "PredictionSet = PredictionSet[['seconds','TravelRelativeTempCorrected', 'Pyrometer','PyrometerShifted']]\n",
    "PredictionSet = PredictionSet.reset_index(drop=True)\n",
    "time = PredictionSet['seconds'].iloc[0]\n",
    "numberOfOptions = 60\n",
    "newRegime = PredictionSet.copy()\n",
    "for i in range(0, numberOfOptions):\n",
    "     PredictionSet = pd.concat([newRegime]*numberOfOptions, ignore_index=True)\n",
    "heating = 1\n",
    "#print(newRegime)\n",
    "\n",
    "density=0\n",
    "time = time + 10\n",
    "for i in range(0, numberOfOptions):\n",
    "     PredictionSet.loc[i,'seconds'] = time\n",
    "     PredictionSet.loc[i,'PyrometerShifted'] = PredictionSet['PyrometerShifted'].iloc[i] + i-5\n",
    "\n",
    "#print(PredictionSet)\n",
    "while time < 1000 and (density<0.96 ) :\n",
    "     \n",
    "     TravelRelativeTempCorrectedPredicted = gpr.predict(PredictionSet, return_std=True); \n",
    "     #print(TravelRelativeTempCorrectedPredicted[0][0])\n",
    "     #select best prediction\n",
    "     \n",
    "     densificationRate = ( TravelRelativeTempCorrectedPredicted[0]-PredictionSet['TravelRelativeTempCorrected'])/10/1000\n",
    "     density = calulate_density(PredictionSet['TravelRelativeTempCorrected'].iloc[0])\n",
    "     targetRate = calulate_TargetDensificationRateValue(density)\n",
    "     predictedRates = pd.Series(TravelRelativeTempCorrectedPredicted[0]-PredictionSet.loc[0,'TravelRelativeTempCorrected'])\n",
    "     #print(predictedRates)\n",
    "     bestIndex = find_closest_index(predictedRates, targetRate)\n",
    "     #print(targetRate)\n",
    "     #print(bestIndex)\n",
    "     time = time + 10\n",
    "     for i in range(0, numberOfOptions):\n",
    "          PredictionSet.loc[i,'seconds'] = time\n",
    "          PredictionSet.loc[i,'TravelRelativeTempCorrected'] = TravelRelativeTempCorrectedPredicted[0][bestIndex]\n",
    "          PredictionSet.loc[i,'Pyrometer'] = PredictionSet['PyrometerShifted'].iloc[bestIndex]\n",
    "          if heating:\n",
    "               PredictionSet.loc[i,'PyrometerShifted'] = PredictionSet['PyrometerShifted'].iloc[bestIndex] + i-20\n",
    "          else:\n",
    "               PredictionSet.loc[i,'PyrometerShifted'] = PredictionSet['PyrometerShifted'].iloc[bestIndex] -30\n",
    "     #print(PredictionSet)\n",
    "     bestPrediction = PredictionSet.iloc[bestIndex]\n",
    "     bestPrediction = pd.DataFrame([bestPrediction])\n",
    "     #print(bestPrediction)\n",
    "     newRegime = pd.concat([newRegime, bestPrediction], ignore_index=True)\n",
    "     #print(newRegime)\n",
    "     newRegime.at[newRegime.index[-1],'STD'] = TravelRelativeTempCorrectedPredicted[1][bestIndex]\n",
    "newRegime.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-20.0, 40.0)"
      ]
     },
     "execution_count": 438,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 1500x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 112952 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(15, 6))\n",
    "#heating rate\n",
    "sc = ax1.plot(data1200['seconds'], data1200['PyrometerShifted'] - data1200['Pyrometer'], color='gray') \n",
    "sc = ax1.plot(data900['seconds'], data900['PyrometerShifted'] - data900['Pyrometer'], color='gray') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['PyrometerShifted'] - data1000['Pyrometer'], color='gray') \n",
    "sc = ax1.plot(dataN1200['seconds'], dataN1200['PyrometerShifted'] - dataN1200['Pyrometer'], color='gray') \n",
    "sc = ax1.plot(newRegime['seconds'], newRegime['PyrometerShifted'] - newRegime['Pyrometer'], color='red') \n",
    "ax1.set_title('Швидкість нагріву в віртуальному експерименті в порівнянні з реальним даними')\n",
    "ax1.set_xlabel('час в секундах')\n",
    "ax1.set_ylabel('Швидкість °C/c')\n",
    "ax1.set_ylim(-20, 40 )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1500x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 119496 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(15, 6))\n",
    "\n",
    "#densification rate\n",
    "sc = ax1.plot( calulate_density(data1200['TravelRelativeTempCorrected']), data1200['TravelRelativeTempCorrected'] - data1200['TravelRelativeTempCorrected'].shift(1), color='grey')\n",
    "sc = ax1.plot( calulate_density(data1000['TravelRelativeTempCorrected']), data1000['TravelRelativeTempCorrected'] - data1000['TravelRelativeTempCorrected'].shift(1), color='grey')\n",
    "sc = ax1.plot( calulate_density(data900['TravelRelativeTempCorrected']), data900['TravelRelativeTempCorrected'] - data900['TravelRelativeTempCorrected'].shift(1), color='grey')\n",
    "sc = ax1.plot( calulate_density(dataN1200['TravelRelativeTempCorrected']), dataN1200['TravelRelativeTempCorrected'] - dataN1200['TravelRelativeTempCorrected'].shift(1), color='grey')\n",
    "sc = ax1.plot( calulate_density(newRegime['TravelRelativeTempCorrected']), newRegime['TravelRelativeTempCorrected'] - newRegime['TravelRelativeTempCorrected'].shift(1), color='red')\n",
    "sc = ax1.plot( calulate_density(newRegime['TravelRelativeTempCorrected']), calulate_TargetDensificationRate(calulate_density(newRegime['TravelRelativeTempCorrected'])), color='green')\n",
    "# sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrected'], color='grey') \n",
    "# sc = ax1.plot(newRegime['seconds'], newRegime['TravelRelativeTempCorrected'], color='green') \n",
    "#sc = ax1.plot(newRegime['seconds'], newRegime['STD'], color='green') \n",
    "\n",
    "#densification rate\n",
    "#sc = ax1.plot(data1200['seconds'], data1200['TravelRelativeTempCorrectedShifted']-data1200['TravelRelativeTempCorrected'], color='grey') \n",
    "#sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrectedShifted']-data1000['TravelRelativeTempCorrected'], color='grey') \n",
    "#sc = ax1.plot(newRegime['seconds'], newRegime['TravelRelativeTempCorrected'] - newRegime['TravelRelativeTempCorrected'].shift(1), color='green') \n",
    "\n",
    "\n",
    "#sc = ax1.plot(data1200['seconds'], data1200['PyrometerShifted'] - data1200['Pyrometer'].shift(1), color='orange') \n",
    "#sc = ax1.plot(data1350['seconds'], data1350['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "#sc = ax1.plot(data900['seconds'], data900['TravelRelativeTempCorrectedShifted']-data900['TravelRelativeTempCorrected'], color='grey') \n",
    "#sc = ax1.plot(dataN1200['seconds'], dataN1200['TravelRelativeTempCorrectedShifted']-dataN1200['TravelRelativeTempCorrected'], color='grey') \n",
    "#sc = ax1.plot(dataN1100['seconds'], dataN1100['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "#sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrectedShifted']-data1000['TravelRelativeTempCorrected'], color='grey') \n",
    "#sc = ax1.plot(newRegime['seconds'], newRegime['PyrometerShifted'] - newRegime['Pyrometer'].shift(1), color='red') \n",
    "# df['TravelDelta'] = df['TravelRelativeTempCorrected'] - df['TravelRelativeTempCorrected'].shift(1)\n",
    " \n",
    "\n",
    "#ax1.set_title('title')\n",
    "ax1.set_xlabel('Щільність')\n",
    "ax1.set_ylabel('Швидкість ущільнення')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1500x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 81632 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(15, 6))\n",
    "\n",
    "#Temperature\n",
    "sc = ax1.plot(data1200['seconds'], data1200['Pyrometer'], color='grey')\n",
    "sc = ax1.plot(data1000['seconds'], data1000['Pyrometer'], color='grey')\n",
    "sc = ax1.plot(data900['seconds'], data900['Pyrometer'], color='grey')\n",
    "sc = ax1.plot(dataN1200['seconds'], dataN1200['Pyrometer'], color='grey')\n",
    "sc = ax1.plot(newRegime['seconds'], newRegime['Pyrometer'], color='red')\n",
    "\n",
    "ax1.set_title('Порівняння температури з єксперементальними даними')\n",
    "ax1.set_xlabel('Час, с')\n",
    "ax1.set_ylabel('Температура °C')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 1500x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 85536 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(15, 6))\n",
    "\n",
    "sc = ax1.plot(data1200['seconds'], data1200['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "#sc = ax1.plot(data1350['seconds'], data1350['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(data900['seconds'], data900['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(dataN1200['seconds'], dataN1200['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "#sc = ax1.plot(dataN1100['seconds'], dataN1100['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['TravelRelativeTempCorrectedShifted'], color='grey') \n",
    "sc = ax1.plot(newRegime['seconds'], newRegime['TravelRelativeTempCorrected'], color='red') \n",
    " \n",
    "ax1.set_title('Порівняння ходу поршня з єкспериментальними даними')\n",
    "ax1.set_xlabel('час, с')\n",
    "ax1.set_ylabel('хід поршня, μм')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 125032 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(40, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(40, 6))\n",
    "\n",
    "sc = ax1.plot(data1200['TravelRelativeTempCorrectedShifted'], data1200['Pyrometer'], color='grey') \n",
    "#sc = ax1.plot(data1350['Pyrometer'], data1350['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(data1000['TravelRelativeTempCorrectedShifted'], data1000['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(data900['TravelRelativeTempCorrectedShifted'], data900['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(dataN1200['TravelRelativeTempCorrectedShifted'], dataN1200['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(data1000['TravelRelativeTempCorrectedShifted'], data1000['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(newRegime['TravelRelativeTempCorrected'], newRegime['Pyrometer'], color='red') \n",
    " \n",
    "\n",
    "ax1.set_title('title')\n",
    "ax1.set_xlabel('Microns')\n",
    "ax1.set_ylabel('Pyrometer')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 4000x600 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 147412 characters]",
      "text/plain": [
       "<Figure size 4000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(40, 6))\n",
    "fig, ax1 = plt.subplots( figsize=(40, 6))\n",
    "\n",
    "sc = ax1.plot(data1200['seconds'], data1200['Pyrometer'], color='grey') \n",
    "#sc = ax1.plot(data1350['seconds'], data1350['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(data900['seconds'], data900['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(dataN1200['seconds'], dataN1200['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(data1000['seconds'], data1000['Pyrometer'], color='grey') \n",
    "#sc = ax1.plot(dataN1100['seconds'], dataN1100['Pyrometer'], color='grey') \n",
    "sc = ax1.plot(newRegime['seconds'], newRegime['Pyrometer'], color='red') \n",
    " \n",
    "\n",
    "ax1.set_title('title')\n",
    "ax1.set_xlabel('seconds')\n",
    "ax1.set_ylabel('Pyrometer')\n",
    "ax1.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 36292 characters]",
      "text/plain": [
       "<Figure size 1000x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
