{"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":"import numpy as np \nimport pandas as pd \n\nimport math\n\nimport plotly.express as px\nimport plotly.graph_objects as go\nimport matplotlib.pyplot as plt\n\nimport plotly.offline as pyo\n# Set notebook mode to work in offline\npyo.init_notebook_mode()\n\nBASE_DIR = '/kaggle/input/icecube-neutrinos-in-deep-ice/'","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-27T16:51:46.605566Z","iopub.execute_input":"2023-01-27T16:51:46.605971Z","iopub.status.idle":"2023-01-27T16:51:46.674511Z","shell.execute_reply.started":"2023-01-27T16:51:46.605938Z","shell.execute_reply":"2023-01-27T16:51:46.672468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analyzing the preferred direction of the detector\n\nWe will analyze all of the events in the test set to see if there is a more probable direction.  We do this as a color density plot on a sphere.\n\nThe events are fairly uniformly distributed, but there is a preference for events originating from above the detector rather than below.  We assume this is probably some cosmic ray background, since we would expect events originating from below to be a 'cleaner' signal since the earth would shield many background functions.\n\nThere is also some extra density at the equator, which is interesting.  Along the equator is where the most sensor produce `auxiliary = True` signals.","metadata":{}},{"cell_type":"code","source":"train_meta = pd.read_parquet(BASE_DIR + 'train_meta.parquet')\n\nprint(f'Total number of events: {len(train_meta)}')\nprint(f'Total number of batches: {train_meta.batch_id.nunique()}')","metadata":{"execution":{"iopub.status.busy":"2023-01-27T16:54:49.653857Z","iopub.execute_input":"2023-01-27T16:54:49.654804Z","iopub.status.idle":"2023-01-27T16:55:05.750864Z","shell.execute_reply.started":"2023-01-27T16:54:49.654746Z","shell.execute_reply":"2023-01-27T16:55:05.749518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We cannot use a linear space when binning, since we want each bin to have the same solid angle on the sphere.  This will give equal solid angle size chunks for the bins.","metadata":{}},{"cell_type":"code","source":"def solid_angle_space(bins):\n    phis = np.zeros(bins+1)\n    phi_last = 0\n    gap = 2 / bins\n    for i in range(bins-1):\n        x = math.cos(phi_last) - gap\n        phi = np.arccos(x)\n        phis[i+1] = phi\n        phi_last = phi\n    phis[-1] = math.pi\n    return phis\n\nn = 1000\nthetas, phis = np.linspace(0,2*math.pi,n+1), solid_angle_space(n)","metadata":{"execution":{"iopub.status.busy":"2023-01-27T16:46:42.507889Z","iopub.execute_input":"2023-01-27T16:46:42.508298Z","iopub.status.idle":"2023-01-27T16:46:42.521588Z","shell.execute_reply.started":"2023-01-27T16:46:42.508266Z","shell.execute_reply":"2023-01-27T16:46:42.519898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"npts = len(train_meta)\n# npts = 100000\ntheta = train_meta.azimuth.values[:npts]\nphi = train_meta.zenith.values[:npts]\n\nhist, __, __ = np.histogram2d(theta, phi, bins=[thetas, phis])\nhist /= hist.max()\n\nprint(f'Minimum density value = {hist.min()}, max = {hist.max()}')","metadata":{"execution":{"iopub.status.busy":"2023-01-27T16:46:50.410620Z","iopub.execute_input":"2023-01-27T16:46:50.411078Z","iopub.status.idle":"2023-01-27T16:47:18.841785Z","shell.execute_reply.started":"2023-01-27T16:46:50.411037Z","shell.execute_reply":"2023-01-27T16:47:18.840434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def coord(azimuth, zenith):\n    x = math.cos(azimuth) * math.sin(zenith)\n    y = math.sin(azimuth) * math.sin(zenith)\n    z = math.cos(zenith)\n    return x, y, z\n\ndef make_sphere(hist, thetas, phis):\n    X = np.zeros(hist.shape)\n    Y = np.zeros(hist.shape)\n    Z = np.zeros(hist.shape)\n    C = np.zeros(hist.shape)\n    for i in range(n):\n        for j in range(n):\n            theta = 0.5*(thetas[i] + thetas[i+1])\n            phi = 0.5*(phis[j] + phis[j+1])\n            v = hist[i, j]\n            x, y, z = coord(azimuth=theta, zenith=phi)\n            X[i,j] = x\n            Y[i,j] = y\n            Z[i,j] = z\n            C[i,j] = v\n            \n    return X, Y, Z, C\n\nX, Y, Z, C = make_sphere(hist, thetas, phis)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-27T16:48:28.107768Z","iopub.execute_input":"2023-01-27T16:48:28.108195Z","iopub.status.idle":"2023-01-27T16:48:30.496880Z","shell.execute_reply.started":"2023-01-27T16:48:28.108156Z","shell.execute_reply":"2023-01-27T16:48:30.495641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"s1 = go.Surface(x = X, y=Y, z=Z, surfacecolor=C)\nfig = go.Figure(data = [s1])\nfig.update_layout(height=600, width=600, title_text='Detector incidence direction from Training data')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T16:54:42.478650Z","iopub.execute_input":"2023-01-27T16:54:42.479098Z","iopub.status.idle":"2023-01-27T16:54:49.650791Z","shell.execute_reply.started":"2023-01-27T16:54:42.479061Z","shell.execute_reply":"2023-01-27T16:54:49.649104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}