{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\nimport_path = \"../input/\"\n\n# Any results you write to the current directory are saved as output.","execution_count":5,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"detectors_df = pd.read_csv(import_path + 'detectors.csv')\ndetectors_df.head()","execution_count":9,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"93d96e4ee024fd94aefb138742c29a8c4a5926f2"},"cell_type":"code","source":"train_1_files = os.listdir(import_path + 'train_1')\n# Get files names by blocks of 4: cells/hits/particles/truth\nsorted(train_1_files)[:4]","execution_count":16,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"0d60592e416725174473c618e1dfa67ee69071fb"},"cell_type":"code","source":"cells_df = pd.read_csv(import_path + 'train_1/' + 'event000001000-{}.csv'.format('cells'))\nhits_df = pd.read_csv(import_path + 'train_1/' + 'event000001000-{}.csv'.format('hits'))\nparticles_df = pd.read_csv(import_path + 'train_1/' + 'event000001000-{}.csv'.format('particles'))\ntruth_df = pd.read_csv(import_path + 'train_1/' + 'event000001000-{}.csv'.format('truth'))","execution_count":19,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"906ddd8f420944445c92610d785556b01ef3984f"},"cell_type":"code","source":"cells_df.head()","execution_count":21,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ab5e817282e253423d6309f3c7d976dd1119ef8e"},"cell_type":"code","source":"particles_df.head()","execution_count":22,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8a1f65c2e793f88c32dce651f7635c2f42aba0f1"},"cell_type":"code","source":"truth_df.head()","execution_count":23,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"deddb69481b7df5f026e5be82b30f43f74b113ef"},"cell_type":"code","source":"hits_df.head()","execution_count":24,"outputs":[]},{"metadata":{"_uuid":"0c703a96c212540c78da256d715be3aeefba7c20"},"cell_type":"markdown","source":"# Understand the hits repartition by 3D Plotting\n<br>https://matplotlib.org/gallery/mplot3d/scatter3d.html#sphx-glr-gallery-mplot3d-scatter3d-py\n<br>https://www.kaggle.com/drgilermo/dynamics-of-new-york-city-animation/code"},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"7398724e9e15bb9b184a59b398e17523cd931ba4"},"cell_type":"code","source":"import io\nimport base64\nfrom IPython.display import HTML\nfrom mpl_toolkits.mplot3d import Axes3D\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib import animation\nfrom matplotlib import cm","execution_count":51,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a0f8b14e9c71771ad11eaffb83db90001392d29b"},"cell_type":"code","source":"# https://www.kaggle.com/drgilermo/dynamics-of-new-york-city-animation/code\nfig = plt.figure(figsize=(15, 10))\nax = fig.add_subplot(111, projection='3d')\n\nN = 200\n\nbounds = []\naxes_labels = ['x', 'y', 'z']\nfor label_ in axes_labels:\n    bounds += [np.min(hits_df[label_][:N]), np.max(hits_df[label_][:N])]\n\ndef animate(hits_id):\n    ax.clear()\n    ax.set_title('LHC Particles Hits')    \n    ax.scatter(hits_df['x'][:hits_id], hits_df['y'][:hits_id], hits_df['z'][:hits_id], s=np.ones(hits_id)*50, c='red', marker='o', edgecolor='black', alpha=0.5)\n    ax.set_xlim(bounds[0], bounds[1])\n    ax.set_ylim(bounds[2], bounds[3])\n    ax.set_zlim(bounds[4], bounds[5])\n    \nani = animation.FuncAnimation(fig,animate, np.arange(0, N), interval = 5)\nplt.close()\nani.save('animation.gif', writer='imagemagick', fps=2)\nfilename = 'animation.gif'\n\nvideo = io.open(filename, 'r+b').read()\nencoded = base64.b64encode(video)\nHTML(data='''<img src=\"data:image/gif;base64,{0}\" type=\"gif\" />'''.format(encoded.decode('ascii')))","execution_count":72,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.5","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}