{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","collapsed":true,"trusted":true},"cell_type":"code","source":"\n","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"trusted":true},"cell_type":"code","source":"import trackml","execution_count":30,"outputs":[]},{"metadata":{"_cell_guid":"74aa8424-f0ca-42ee-b882-9a340582a65f","_uuid":"82ba4ba370c7a4ec67c2897890b5197f60721313","collapsed":true,"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom matplotlib import cm\nfrom mpl_toolkits.mplot3d import Axes3D\n\n","execution_count":31,"outputs":[]},{"metadata":{"_cell_guid":"5c4ddb8d-9603-4168-8403-4c252859dd92","_uuid":"2e63da34095e63902dc19ef12180f397029ccede","collapsed":true,"trusted":true},"cell_type":"code","source":"\ndef plot_volumes(title, df):\n    \"\"\" Plot each volume in a subplot, each layer with different color.\n    \"\"\"\n    figsize = (36, 5)\n    fig = plt.figure(figsize=figsize)    \n    \n    volume_ids = [7, 8,  9, 12, 13, 14, 16, 17, 18]\n    for volume_idx, volume_id in enumerate(volume_ids):\n        ax = fig.add_subplot('1{}{}'.format(len(volume_ids), volume_idx+1), projection='3d')\n        df_volume = df[df.volume_id==volume_id]\n        ax.scatter(df_volume.x, df_volume.y, df_volume.z, c=df_volume.layer_id)\n        ax.set_xlabel(\"X\")\n        ax.set_ylabel(\"Y\")\n        ax.set_zlabel(\"Z\")\n        ax.set_xlim(-1000, 1000)\n        ax.set_ylim(-1000, 1000)\n        ax.set_zlim(-3000, 3000)\n        ax.set_title('event {} - volume {}'.format(title, volume_id))\n        #ax.view_init(0, 0)\n    return ax\n\n","execution_count":32,"outputs":[]},{"metadata":{"collapsed":true,"trusted":true,"_uuid":"2c380e5549058cc0364dde6409bbdd22b0237a76"},"cell_type":"code","source":"def plot_xz(df, color_by='layer_id'):\n    figsize = (10, 10)\n    fig, axes = plt.subplots(nrows=1, ncols=2)\n    \n    axes[0].scatter(df.x, df.z, c=df[color_by])\n    axes[0].set_xlabel(\"x\")\n    axes[0].set_ylabel(\"z\")\n    \n    axes[1].scatter(df.x, df.y, c=df[color_by])\n    axes[1].set_xlabel(\"x\")\n    axes[1].set_ylabel(\"y\")\n    ","execution_count":33,"outputs":[]},{"metadata":{"_cell_guid":"b1866bca-52b6-4aa0-9ebc-8c39cf91632d","_uuid":"cbe25a7811d87579a8036ab64b76a41b3f5ce19c","collapsed":true,"trusted":true},"cell_type":"code","source":"from trackml.dataset import load_dataset\n\nidx = 0\nfor event_id, hits, cells, particles, truth in load_dataset('../input/train_1'):\n    break\n","execution_count":34,"outputs":[]},{"metadata":{"_cell_guid":"41a9f164-438d-49ac-b993-986e5dfba4b1","_uuid":"8faa40529130651f949d04ed88a5128bb89833c9","trusted":true},"cell_type":"code","source":"plot_volumes(event_id, hits)\n","execution_count":20,"outputs":[]},{"metadata":{"_cell_guid":"9eae7f01-da0c-4990-9070-8840023e5adf","_uuid":"c611695fb1f92818637c440de26a9463dabc17ed","trusted":true},"cell_type":"code","source":"plot_xz(hits[hits.volume_id.isin([7,8,9])])","execution_count":21,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"21e893cb61081c965cfb4c844eec0cde62efdc75"},"cell_type":"code","source":"plot_xz(hits[hits.volume_id.isin([12,13,14])])","execution_count":22,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"80f544fb5f1c2d30d153772221697ec8169f0c6e"},"cell_type":"code","source":"plot_xz(hits[hits.volume_id.isin([16,17,18])])","execution_count":24,"outputs":[]},{"metadata":{"collapsed":true,"trusted":true,"_uuid":"f445f7d9df495000f85d1b8622547976ec184c03"},"cell_type":"code","source":"# join hits with truth so we can color by particle :-)\ndf = hits.merge(truth, on='hit_id', how='inner')","execution_count":35,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6b69f0f6e0ca6e8b10df1f4a78d873b748394f92"},"cell_type":"code","source":"# Plot on the left is xz projection\n# Plot on the right is xy projection\n\nparticle_ids = list(set(df.particle_id))\nsample = df[df.particle_id.isin(particle_ids[1:50])]\nplot_xz(sample, 'particle_id')","execution_count":36,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cb487d4ad3f2faed94026f5593555d1ad70acb5a"},"cell_type":"code","source":"figsize = (10, 10)\nfig, axes = plt.subplots(nrows=1, ncols=2)\n    \nfor track_id in range(100):\n    track = df[df.particle_id==particle_ids[1+track_id]]\n    axes[0].scatter(track.x, track.z)\n    axes[1].plot(track.x, track.y)\n    \naxes[0].set_xlabel(\"x\")\naxes[0].set_ylabel(\"z\")\naxes[1].set_xlabel(\"x\")\naxes[1].set_ylabel(\"y\")","execution_count":37,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"36ca5ac14c9a767ddcb56620d3236e2d03277214"},"cell_type":"code","source":"","execution_count":null,"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}