{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install /kaggle/input/librosa/librosa-0.9.1-py3-none-any.whl","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:07:27.326118Z","iopub.execute_input":"2023-06-18T19:07:27.327349Z","iopub.status.idle":"2023-06-18T19:07:36.476632Z","shell.execute_reply.started":"2023-06-18T19:07:27.327246Z","shell.execute_reply":"2023-06-18T19:07:36.474512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport librosa\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport librosa\nimport os","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:07:36.479175Z","iopub.execute_input":"2023-06-18T19:07:36.480108Z","iopub.status.idle":"2023-06-18T19:07:36.487141Z","shell.execute_reply.started":"2023-06-18T19:07:36.480065Z","shell.execute_reply":"2023-06-18T19:07:36.485608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"INPUT_PATH = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/'","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:07:36.488581Z","iopub.execute_input":"2023-06-18T19:07:36.488884Z","iopub.status.idle":"2023-06-18T19:07:36.498506Z","shell.execute_reply.started":"2023-06-18T19:07:36.488857Z","shell.execute_reply":"2023-06-18T19:07:36.497493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs(f'./defog_np')\nos.makedirs(f'./tdcsfog_np')","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:22.491060Z","iopub.execute_input":"2023-06-18T19:08:22.491452Z","iopub.status.idle":"2023-06-18T19:08:22.530672Z","shell.execute_reply.started":"2023-06-18T19:08:22.491396Z","shell.execute_reply":"2023-06-18T19:08:22.528856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"events = pd.read_csv(f'{INPUT_PATH}/events.csv')\nevents = events[~events.Type.isnull()]","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:37.216460Z","iopub.execute_input":"2023-06-18T19:08:37.216941Z","iopub.status.idle":"2023-06-18T19:08:37.232692Z","shell.execute_reply.started":"2023-06-18T19:08:37.216906Z","shell.execute_reply":"2023-06-18T19:08:37.231274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog = pd.read_csv(f'{INPUT_PATH}/defog_metadata.csv')\ndefog = defog[defog.Id.isin(events.Id)]","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:39.075286Z","iopub.execute_input":"2023-06-18T19:08:39.076370Z","iopub.status.idle":"2023-06-18T19:08:39.088118Z","shell.execute_reply.started":"2023-06-18T19:08:39.076295Z","shell.execute_reply":"2023-06-18T19:08:39.085812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"g0=9.80665","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:44.018715Z","iopub.execute_input":"2023-06-18T19:08:44.019221Z","iopub.status.idle":"2023-06-18T19:08:44.025144Z","shell.execute_reply.started":"2023-06-18T19:08:44.019181Z","shell.execute_reply":"2023-06-18T19:08:44.023198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sigs = []","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:46.563441Z","iopub.execute_input":"2023-06-18T19:08:46.563781Z","iopub.status.idle":"2023-06-18T19:08:46.568913Z","shell.execute_reply.started":"2023-06-18T19:08:46.563754Z","shell.execute_reply":"2023-06-18T19:08:46.568044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i,r in defog.iterrows():\n    data = pd.read_csv(f'{INPUT_PATH}/train/defog/{r.Id}.csv')\n    sig = data[[ 'AccV', 'AccML', 'AccAP']].values\n    target = data[['StartHesitation', 'Turn', 'Walking']].values\n    \n    sig = sig*g0\n    np.save(f'./defog_np/{r.Id}_sig.npy',sig)\n    np.save(f'./defog_np/{r.Id}_tgt.npy',target)\n    sigs.append(sig)","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:48.131728Z","iopub.execute_input":"2023-06-18T19:08:48.132114Z","iopub.status.idle":"2023-06-18T19:08:57.186869Z","shell.execute_reply.started":"2023-06-18T19:08:48.132086Z","shell.execute_reply":"2023-06-18T19:08:57.185932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog = pd.read_csv(f'{INPUT_PATH}/tdcsfog_metadata.csv')\ntdcsfog = tdcsfog[tdcsfog.Id.isin(events.Id)]","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:08:57.188557Z","iopub.execute_input":"2023-06-18T19:08:57.188825Z","iopub.status.idle":"2023-06-18T19:08:57.198959Z","shell.execute_reply.started":"2023-06-18T19:08:57.188803Z","shell.execute_reply":"2023-06-18T19:08:57.197349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i,r in tdcsfog.iterrows():\n    data = pd.read_csv(f'{INPUT_PATH}/train/tdcsfog/{r.Id}.csv')\n    sig = data[[ 'AccV', 'AccML', 'AccAP']].values\n    target = data[['StartHesitation', 'Turn', 'Walking']].astype(np.float32).values\n    \n    sig = sig\n    sig_resample = []\n    \n    for i in range(3):\n        sig_resample.append(librosa.resample(sig[:,i],orig_sr=128,target_sr=100))\n    sig = np.stack(sig_resample,axis=1)\n    \n        \n    target_resample = []\n    for i in range(3):\n        target_resample.append(librosa.resample(target[:,i],orig_sr=128,target_sr=100))\n        \n    target = np.stack(target_resample,axis=1)  \n    np.save(f'.//tdcsfog_np/{r.Id}_sig.npy',sig)\n    np.save(f'.//tdcsfog_np/{r.Id}_tgt.npy',target)\n    #print('sig',r.Id,sig)\n    sigs.append(sig)\n    #print('target',target)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:09:27.730108Z","iopub.execute_input":"2023-06-18T19:09:27.730586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.concatenate(sigs).max(),np.concatenate(sigs).min()","metadata":{"execution":{"iopub.status.busy":"2023-06-18T19:07:36.890508Z","iopub.status.idle":"2023-06-18T19:07:36.890766Z","shell.execute_reply.started":"2023-06-18T19:07:36.890639Z","shell.execute_reply":"2023-06-18T19:07:36.890650Z"},"trusted":true},"execution_count":null,"outputs":[]}]}