[d395cf]: / WESAD / WESAD_Extract.ipynb

Download this file

128 lines (127 with data), 3.9 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-17T19:14:54.249772Z",
     "start_time": "2019-06-17T19:14:54.237352Z"
    },
    "code_folding": []
   },
   "outputs": [],
   "source": [
    "def pickle_to_csv_chest(ID):\n",
    "    import pickle as pkl\n",
    "    import pandas as pd\n",
    "    with open('S' + str(ID) + '/S'+str(ID) + '.pkl', 'rb') as f:\n",
    "        u = pkl._Unpickler(f)\n",
    "        u.encoding = 'latin1'\n",
    "        p = u.load()\n",
    "        df = pd.DataFrame()\n",
    "        df['chestACCx'] = [item[0] for item in p['signal']['chest']['ACC']]\n",
    "        df['chestACCy'] = [item[1] for item in p['signal']['chest']['ACC']]\n",
    "        df['chestACCz'] = [item[2] for item in p['signal']['chest']['ACC']]\n",
    "        df['chestECG'] = [item for sublist in p['signal']['chest']['ECG'] for item in sublist]\n",
    "        df['chestEMG'] = [item for sublist in p['signal']['chest']['EMG'] for item in sublist]\n",
    "        df['chestEDA'] = [item for sublist in p['signal']['chest']['EDA'] for item in sublist]\n",
    "        df['chestTemp'] = [item for sublist in p['signal']['chest']['Temp'] for item in sublist]\n",
    "        df['chestResp'] = [item for sublist in p['signal']['chest']['Resp'] for item in sublist]\n",
    "        df['ID'] = ID\n",
    "        df['label'] = p['label']\n",
    "        df = df[['ID','chestACCx','chestACCy','chestACCz','chestECG','chestEMG','chestEDA','chestTemp','chestResp','label']]\n",
    "        df.to_csv('S' + str(ID) + 'chest.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-17T19:40:19.352229Z",
     "start_time": "2019-06-17T19:14:57.985458Z"
    }
   },
   "outputs": [],
   "source": [
    "for i in range(1,18):\n",
    "    if i != 1 and i != 12:\n",
    "        pickle_to_csv_chest(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-17T19:43:12.702035Z",
     "start_time": "2019-06-17T19:40:19.354185Z"
    }
   },
   "outputs": [],
   "source": [
    "!cat *chest.csv > allchest.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-06-17T20:08:30.037790Z",
     "start_time": "2019-06-17T19:43:52.786621Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The following options are in effect for this COMPRESSION.\n",
      "Threading is ENABLED. Number of CPUs detected: 16\n",
      "Detected 33628700672 bytes ram\n",
      "Compression level 7\n",
      "Nice Value: 19\n",
      "Show Progress\n",
      "Verbose\n",
      "Remove input files on completion\n",
      "Temporary Directory set as: ./\n",
      "Compression mode is: LZMA. LZO Compressibility testing enabled\n",
      "Heuristically Computed Compression Window: 213 = 21300MB\n",
      "Output filename is: allchest.csv.lrz\n",
      "File size: 9488548771\n",
      "Will take 1 pass\n",
      "Beginning rzip pre-processing phase\n",
      "allchest.csv - Compression Ratio: 7.274. Average Compression Speed:  6.130MB/s.\n",
      "Total time: 00:24:37.12\n"
     ]
    }
   ],
   "source": [
    "!lrzip -v -D allchest.csv"
   ]
  }
 ],
 "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}