{"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":"# Neutorinos 2D/3D Slide Show","metadata":{"papermill":{"duration":0.007973,"end_time":"2023-03-28T04:23:39.328336","exception":false,"start_time":"2023-03-28T04:23:39.320363","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import os\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport json\nimport pyarrow.parquet as pq\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom matplotlib import animation, rc","metadata":{"papermill":{"duration":0.222657,"end_time":"2023-03-28T04:23:39.557872","exception":false,"start_time":"2023-03-28T04:23:39.335215","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:24.662818Z","iopub.execute_input":"2023-03-31T12:16:24.664104Z","iopub.status.idle":"2023-03-31T12:16:24.670683Z","shell.execute_reply.started":"2023-03-31T12:16:24.664048Z","shell.execute_reply":"2023-03-31T12:16:24.669465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf 2D\n!rm -rf 3D\n!mkdir 2D\n!mkdir 3D","metadata":{"papermill":{"duration":4.356728,"end_time":"2023-03-28T04:23:44.429377","exception":false,"start_time":"2023-03-28T04:23:40.072649","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:24.778199Z","iopub.execute_input":"2023-03-31T12:16:24.779493Z","iopub.status.idle":"2023-03-31T12:16:29.147784Z","shell.execute_reply.started":"2023-03-31T12:16:24.779435Z","shell.execute_reply":"2023-03-31T12:16:29.146400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test paraquet","metadata":{"papermill":{"duration":0.00786,"end_time":"2023-03-28T04:23:44.445250","exception":false,"start_time":"2023-03-28T04:23:44.437390","status":"completed"},"tags":[]}},{"cell_type":"code","source":"batch = pq.read_table('/kaggle/input/icecube-neutrinos-in-deep-ice/test/batch_661.parquet')\nprint(batch.to_pydict().keys())\nbatchdf = pd.DataFrame.from_dict(batch.to_pydict())\ndisplay(batchdf)","metadata":{"papermill":{"duration":0.197991,"end_time":"2023-03-28T04:23:44.650551","exception":false,"start_time":"2023-03-28T04:23:44.452560","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:29.150081Z","iopub.execute_input":"2023-03-31T12:16:29.151061Z","iopub.status.idle":"2023-03-31T12:16:29.179518Z","shell.execute_reply.started":"2023-03-31T12:16:29.151018Z","shell.execute_reply":"2023-03-31T12:16:29.178348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# test_meta.parquet","metadata":{}},{"cell_type":"code","source":"test_meta = pq.read_table('/kaggle/input/icecube-neutrinos-in-deep-ice/test_meta.parquet')\nprint(test_meta.to_pydict().keys())\ntest_metadf = pd.DataFrame.from_dict(test_meta.to_pydict())\ndisplay(test_metadf)","metadata":{"execution":{"iopub.status.busy":"2023-03-31T12:16:29.181474Z","iopub.execute_input":"2023-03-31T12:16:29.181922Z","iopub.status.idle":"2023-03-31T12:16:29.197700Z","shell.execute_reply.started":"2023-03-31T12:16:29.181876Z","shell.execute_reply":"2023-03-31T12:16:29.196536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# sensor_geometry","metadata":{}},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/icecube-neutrinos-in-deep-ice/sensor_geometry.csv')\ndisplay(df)\nxmin=df['x'].min()\nxmax=df['x'].max()\nymin=df['y'].min()\nymax=df['y'].max()\nzmin=df['z'].min()\nzmax=df['z'].max()","metadata":{"execution":{"iopub.status.busy":"2023-03-31T12:16:29.199141Z","iopub.execute_input":"2023-03-31T12:16:29.199450Z","iopub.status.idle":"2023-03-31T12:16:29.224972Z","shell.execute_reply.started":"2023-03-31T12:16:29.199420Z","shell.execute_reply":"2023-03-31T12:16:29.223863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualize_2D","metadata":{"papermill":{"duration":0.007804,"end_time":"2023-03-28T04:23:44.711049","exception":false,"start_time":"2023-03-28T04:23:44.703245","status":"completed"},"tags":[]}},{"cell_type":"code","source":"def Visualize_2D(i):\n    dfi=df.iloc[i]\n    fig,ax = plt.subplots(figsize=(6,6))\n    ax.set_title('frame '+str(i).zfill(4),fontsize=8)\n    ax.set_xlim([xmin, xmax])\n    ax.set_ylim([ymin, ymax]) \n    ax.set_xlabel('x',fontsize=8)\n    ax.set_ylabel('y',fontsize=8)\n    ax.scatter(dfi['x'],dfi['y'],color='blue')\n    plt.savefig('2D/frame'+str(i).zfill(4)+'.png') \n    plt.close()","metadata":{"papermill":{"duration":0.022039,"end_time":"2023-03-28T04:23:44.741061","exception":false,"start_time":"2023-03-28T04:23:44.719022","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:29.228493Z","iopub.execute_input":"2023-03-31T12:16:29.228861Z","iopub.status.idle":"2023-03-31T12:16:29.236986Z","shell.execute_reply.started":"2023-03-31T12:16:29.228797Z","shell.execute_reply":"2023-03-31T12:16:29.235727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(0,len(df),10):\n    Visualize_2D(i)    ","metadata":{"papermill":{"duration":1.363078,"end_time":"2023-03-28T04:23:46.112375","exception":false,"start_time":"2023-03-28T04:23:44.749297","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:29.238365Z","iopub.execute_input":"2023-03-31T12:16:29.238659Z","iopub.status.idle":"2023-03-31T12:16:45.261531Z","shell.execute_reply.started":"2023-03-31T12:16:29.238629Z","shell.execute_reply":"2023-03-31T12:16:45.260180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualize_3D","metadata":{"papermill":{"duration":0.007635,"end_time":"2023-03-28T04:23:46.128031","exception":false,"start_time":"2023-03-28T04:23:46.120396","status":"completed"},"tags":[]}},{"cell_type":"code","source":"def Visualize_3D(i):\n    dfi=df.iloc[i]\n    fig,ax = plt.subplots(figsize=(6,6))\n    ax.axis('off')\n    ax = fig.add_subplot(111, projection='3d')\n    ax.set_title('frame '+str(i).zfill(4),fontsize=8)\n    ax.set_xlim([xmin, xmax])\n    ax.set_ylim([ymin, ymax]) \n    ax.set_zlim([zmin, zmax])    \n    ax.set_xlabel('x',fontsize=8)\n    ax.set_ylabel('y',fontsize=8)\n    ax.set_zlabel('z',fontsize=8)\n    ax.scatter(dfi['x'],dfi['y'],dfi['z'],color='blue')\n    plt.savefig('3D/frame'+str(i).zfill(4)+'.png') \n    plt.close()","metadata":{"papermill":{"duration":0.022412,"end_time":"2023-03-28T04:23:46.158478","exception":false,"start_time":"2023-03-28T04:23:46.136066","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:45.262942Z","iopub.execute_input":"2023-03-31T12:16:45.263285Z","iopub.status.idle":"2023-03-31T12:16:45.271621Z","shell.execute_reply.started":"2023-03-31T12:16:45.263251Z","shell.execute_reply":"2023-03-31T12:16:45.270734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(0,len(df),10):\n    Visualize_3D(i)   ","metadata":{"papermill":{"duration":1.692917,"end_time":"2023-03-28T04:23:47.859334","exception":false,"start_time":"2023-03-28T04:23:46.166417","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:16:45.272731Z","iopub.execute_input":"2023-03-31T12:16:45.273624Z","iopub.status.idle":"2023-03-31T12:17:06.903949Z","shell.execute_reply.started":"2023-03-31T12:16:45.273590Z","shell.execute_reply":"2023-03-31T12:17:06.902723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Create Slide Show","metadata":{"papermill":{"duration":0.007815,"end_time":"2023-03-28T04:23:47.875643","exception":false,"start_time":"2023-03-28T04:23:47.867828","status":"completed"},"tags":[]}},{"cell_type":"code","source":"paths=[]\nfor dirname, _, filenames in os.walk('/kaggle/working/2D'):\n    for filename in filenames:\n        if filename[-4:]=='.png':\n            paths+=[os.path.join(dirname, filename)]\npaths=sorted(paths)\nprint(paths[0:3])\n\nimages=[]\nfor path in paths:\n    images+=[cv2.imread(path)]","metadata":{"papermill":{"duration":0.05355,"end_time":"2023-03-28T04:23:47.937318","exception":false,"start_time":"2023-03-28T04:23:47.883768","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:17:06.905963Z","iopub.execute_input":"2023-03-31T12:17:06.906378Z","iopub.status.idle":"2023-03-31T12:17:07.484359Z","shell.execute_reply.started":"2023-03-31T12:17:06.906332Z","shell.execute_reply":"2023-03-31T12:17:07.483100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"paths3=[]\nfor dirname, _, filenames in os.walk('/kaggle/working/3D'):\n    for filename in filenames:\n        if filename[-4:]=='.png':\n            paths3+=[os.path.join(dirname, filename)]\npaths3=sorted(paths3)\nprint(paths3[0:3])\n\nimages3=[]\nfor path in paths3:\n    images3+=[cv2.imread(path)]","metadata":{"papermill":{"duration":0.044022,"end_time":"2023-03-28T04:23:47.989686","exception":false,"start_time":"2023-03-28T04:23:47.945664","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:17:07.485716Z","iopub.execute_input":"2023-03-31T12:17:07.486056Z","iopub.status.idle":"2023-03-31T12:17:08.269072Z","shell.execute_reply.started":"2023-03-31T12:17:07.486023Z","shell.execute_reply":"2023-03-31T12:17:08.267794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import animation, rc\nrc('animation', html='jshtml')\n\ndef create_animation(ims):\n    fig=plt.figure(figsize=(6,6))\n    plt.axis('off')\n    im=plt.imshow(cv2.cvtColor(ims[0],cv2.COLOR_BGR2RGB))\n    plt.close()\n    \n    def animate_func(i):\n        im.set_array(cv2.cvtColor(ims[i],cv2.COLOR_BGR2RGB))\n        return [im]\n\n    return animation.FuncAnimation(fig, animate_func, frames=len(ims), interval=1000/20)","metadata":{"papermill":{"duration":0.020188,"end_time":"2023-03-28T04:23:48.017971","exception":false,"start_time":"2023-03-28T04:23:47.997783","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:17:08.270682Z","iopub.execute_input":"2023-03-31T12:17:08.271036Z","iopub.status.idle":"2023-03-31T12:17:08.279508Z","shell.execute_reply.started":"2023-03-31T12:17:08.271003Z","shell.execute_reply":"2023-03-31T12:17:08.278283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2D Slide Show","metadata":{"papermill":{"duration":0.007736,"end_time":"2023-03-28T04:23:48.033909","exception":false,"start_time":"2023-03-28T04:23:48.026173","status":"completed"},"tags":[]}},{"cell_type":"code","source":"create_animation(images)","metadata":{"papermill":{"duration":0.581016,"end_time":"2023-03-28T04:23:48.622983","exception":false,"start_time":"2023-03-28T04:23:48.041967","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:17:08.281038Z","iopub.execute_input":"2023-03-31T12:17:08.281387Z","iopub.status.idle":"2023-03-31T12:17:18.550442Z","shell.execute_reply.started":"2023-03-31T12:17:08.281355Z","shell.execute_reply":"2023-03-31T12:17:18.548641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3D Slide Show","metadata":{"papermill":{"duration":0.013602,"end_time":"2023-03-28T04:23:48.651114","exception":false,"start_time":"2023-03-28T04:23:48.637512","status":"completed"},"tags":[]}},{"cell_type":"code","source":"create_animation(images3)","metadata":{"papermill":{"duration":0.646295,"end_time":"2023-03-28T04:23:49.311879","exception":false,"start_time":"2023-03-28T04:23:48.665584","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:17:18.551698Z","iopub.execute_input":"2023-03-31T12:17:18.552363Z","iopub.status.idle":"2023-03-31T12:17:30.101219Z","shell.execute_reply.started":"2023-03-31T12:17:18.552320Z","shell.execute_reply":"2023-03-31T12:17:30.098544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.030298,"end_time":"2023-03-28T04:23:49.373771","exception":false,"start_time":"2023-03-28T04:23:49.343473","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nx = [1, 2, 3, 4, 5]\ny = [5, 4, 3, 2, 1]\nz = [0, 0, 0, 0, 0]\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\nax.scatter(x, y, z)\n\nax.set_xlabel('X Label')\nax.set_ylabel('Y Label')\nax.set_zlabel('Z Label')\n\nplt.show()","metadata":{"papermill":{"duration":0.263263,"end_time":"2023-03-28T04:23:49.667739","exception":false,"start_time":"2023-03-28T04:23:49.404476","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-03-31T12:17:30.107017Z","iopub.execute_input":"2023-03-31T12:17:30.110644Z","iopub.status.idle":"2023-03-31T12:17:30.317614Z","shell.execute_reply.started":"2023-03-31T12:17:30.110581Z","shell.execute_reply":"2023-03-31T12:17:30.316766Z"},"trusted":true},"execution_count":null,"outputs":[]}]}