{"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":"markdown","source":"\nLet's see length and time of \"neutrinos tracks\" for separate events.\n2 cases:\n - 'auxiliary' == False\n - 'auxiliary' == True","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport os\nimport random","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-12T19:19:56.924918Z","iopub.execute_input":"2023-02-12T19:19:56.925441Z","iopub.status.idle":"2023-02-12T19:19:56.954234Z","shell.execute_reply.started":"2023-02-12T19:19:56.925340Z","shell.execute_reply":"2023-02-12T19:19:56.952970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"To obtain lengths of trajectories let's take data of space  locations of sensors:","metadata":{}},{"cell_type":"code","source":"sg_path = '/kaggle/input/icecube-neutrinos-in-deep-ice/sensor_geometry.csv'\nsg = pd.read_csv(sg_path)\nsg.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:19:56.956357Z","iopub.execute_input":"2023-02-12T19:19:56.956698Z","iopub.status.idle":"2023-02-12T19:19:56.980924Z","shell.execute_reply.started":"2023-02-12T19:19:56.956668Z","shell.execute_reply":"2023-02-12T19:19:56.980036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Randomly choose of 10 batches:","metadata":{}},{"cell_type":"code","source":"dir_name = '/kaggle/input/icecube-neutrinos-in-deep-ice/train/'\nall_files = os.listdir(dir_name)\n\nrandom.shuffle(all_files)\n\nall_files = all_files[:10]","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:19:56.982910Z","iopub.execute_input":"2023-02-12T19:19:56.983417Z","iopub.status.idle":"2023-02-12T19:19:57.066522Z","shell.execute_reply.started":"2023-02-12T19:19:56.983377Z","shell.execute_reply":"2023-02-12T19:19:57.065302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"To simplify computation, length of \"trajectory\" let's compute approximately:\n\nl^2 = (x_max-x_min)^2 + (y_max-y_min)^2 + (z_max-z_min)^2 \n\nThis way of computation approximatelly correct on the bacis that the \"trajectory\" approximatelly matches straight line .","metadata":{}},{"cell_type":"markdown","source":"**In case 'auxiliary' == False :**","metadata":{}},{"cell_type":"code","source":"batches_false =[]\n\nfor i,f in enumerate(all_files):\n    df = pd.read_parquet(f'{dir_name}/{f}')\n    df_a_f = df[df['auxiliary'] == False]\n    df_a_f = df_a_f.reset_index()\n    \n    stat = df_a_f.merge(sg, on='sensor_id',how='inner')\n    stat = stat.pivot_table(index=['event_id'],\n                                      values=['time','x','y','z'],\n                                      aggfunc=['min','max','count']).reset_index()\n    stat.columns = ['event_id','min_time','min_x','min_y','min_z',\n                    'max_time','max_x','max_y','max_z','count','count_x','count_y','count_z']\n    stat = stat.drop(['count_x','count_y','count_z'], axis=1)\n\n    stat['time_delta'] = stat['max_time'] - stat['min_time']\n    stat['x_delta'] = stat['max_x'] - stat['min_x']\n    stat['y_delta'] = stat['max_y'] - stat['min_y']\n    stat['z_delta'] = stat['max_z'] - stat['min_z']\n    stat['length'] = (stat['x_delta']**2 + stat['y_delta']**2 + stat['z_delta'] ** 2) ** 0.5\n    stat['velocity'] = 10**9 * stat['length'] / stat['time_delta']\n\n    batches_false.append(stat)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:19:57.070158Z","iopub.execute_input":"2023-02-12T19:19:57.070918Z","iopub.status.idle":"2023-02-12T19:21:43.883657Z","shell.execute_reply.started":"2023-02-12T19:19:57.070880Z","shell.execute_reply":"2023-02-12T19:21:43.882412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results_aux_false = pd.concat(batches_false)\nresults_aux_false.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:21:43.885181Z","iopub.execute_input":"2023-02-12T19:21:43.885551Z","iopub.status.idle":"2023-02-12T19:21:43.993707Z","shell.execute_reply.started":"2023-02-12T19:21:43.885511Z","shell.execute_reply":"2023-02-12T19:21:43.992600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**In case 'auxiliary' == True**","metadata":{}},{"cell_type":"code","source":"batches_true =[]\n\nfor i,f in enumerate(all_files):\n    df = pd.read_parquet(f'{dir_name}/{f}')\n    df_a_f = df[df['auxiliary'] == True]\n    df_a_f = df_a_f.reset_index()\n    \n    stat = df_a_f.merge(sg, on='sensor_id',how='inner')\n    stat = stat.pivot_table(index=['event_id'],\n                                      values=['time','x','y','z'],\n                                      aggfunc=['min','max','count']).reset_index()\n    stat.columns = ['event_id','min_time','min_x','min_y','min_z',\n                    'max_time','max_x','max_y','max_z','count','count_x','count_y','count_z']\n    stat = stat.drop(['count_x','count_y','count_z'], axis=1)\n\n    stat['time_delta'] = stat['max_time'] - stat['min_time']\n    stat['x_delta'] = stat['max_x'] - stat['min_x']\n    stat['y_delta'] = stat['max_y'] - stat['min_y']\n    stat['z_delta'] = stat['max_z'] - stat['min_z']\n    stat['length'] = (stat['x_delta']**2 + stat['y_delta']**2 + stat['z_delta'] ** 2) ** 0.5\n    stat['velocity'] = 10**9 * stat['length'] / stat['time_delta']\n\n    batches_true.append(stat)","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:21:43.995029Z","iopub.execute_input":"2023-02-12T19:21:43.995763Z","iopub.status.idle":"2023-02-12T19:22:36.313874Z","shell.execute_reply.started":"2023-02-12T19:21:43.995725Z","shell.execute_reply":"2023-02-12T19:22:36.313193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results_aux_true = pd.concat(batches_true)\nresults_aux_true.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:22:36.314871Z","iopub.execute_input":"2023-02-12T19:22:36.315143Z","iopub.status.idle":"2023-02-12T19:22:36.402281Z","shell.execute_reply.started":"2023-02-12T19:22:36.315121Z","shell.execute_reply":"2023-02-12T19:22:36.401250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,8))\nresults_aux_false['length'].hist(bins=200)\nresults_aux_true['length'].hist(bins=200)\nplt.title('Length of \"trajectory\" of each event with auxiliary=False (blue) and auxiliary=True(orange)')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:23:01.169137Z","iopub.execute_input":"2023-02-12T19:23:01.169518Z","iopub.status.idle":"2023-02-12T19:23:02.038752Z","shell.execute_reply.started":"2023-02-12T19:23:01.169489Z","shell.execute_reply":"2023-02-12T19:23:02.037614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see that in case  auxiliary=True   trajectory the whole Icecube is often covered . In case auxiliary=False the lengths of trajectories are much shorter. Besides in that case  there are lots of short  oddly distributed trajectories.","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,8))\nresults_aux_false['time_delta'].hist(bins=200)\nresults_aux_true['time_delta'].hist(bins=200)\nplt.title('Full time of each event with auxiliary=False (blue) and auxiliary=True(orange)')\nplt.xlim(0,30000)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-12T19:23:06.084259Z","iopub.execute_input":"2023-02-12T19:23:06.085330Z","iopub.status.idle":"2023-02-12T19:23:06.776723Z","shell.execute_reply.started":"2023-02-12T19:23:06.085300Z","shell.execute_reply":"2023-02-12T19:23:06.775568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}