{"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":"# IceCube Neutrinos PCA Visualization Tool\n\nA tool used for visualizing and testing different parameters with PCA, and checking prediction results against actual true values.","metadata":{}},{"cell_type":"markdown","source":"## Imports","metadata":{}},{"cell_type":"code","source":"import os\n\nimport pandas as pd\nfrom typing import Optional\n\n# fist-party libraries\nfrom utils import seed_it_all\nfrom icecube_neutrino_utils import compose_event_df\nfrom icecube_neutrino_pca_plot import plot_pca, get_event_true_values","metadata":{"_uuid":"90704bee-8a40-4233-986e-067c87745d7c","_cell_guid":"ba5a4287-8cad-47fe-991e-5b3a1a177bf2","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-02-25T12:40:10.329068Z","iopub.execute_input":"2023-02-25T12:40:10.329590Z","iopub.status.idle":"2023-02-25T12:40:10.337727Z","shell.execute_reply.started":"2023-02-25T12:40:10.329548Z","shell.execute_reply":"2023-02-25T12:40:10.336033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Variables","metadata":{}},{"cell_type":"code","source":"EVENT: Optional[int] = None # set to None to use a random event, or change manually set to a specific event id\nEXCLUDE_AUXILIARY= False # set to True to exclude auxiliary sensor readings\nIS_TRAINING = True # set to True to use the training data, or False to use the test data\n\n# DO NOT CHANGE THESE VARIABLES\nDATA_DIR = \"/kaggle/input/icecube-neutrinos-in-deep-ice\"\nDATA_SET = 'train' if IS_TRAINING else 'test'","metadata":{"execution":{"iopub.status.busy":"2023-02-25T12:40:10.341386Z","iopub.execute_input":"2023-02-25T12:40:10.342450Z","iopub.status.idle":"2023-02-25T12:40:10.351012Z","shell.execute_reply.started":"2023-02-25T12:40:10.342357Z","shell.execute_reply":"2023-02-25T12:40:10.349473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Seed for reproducibilty","metadata":{}},{"cell_type":"code","source":"seed_it_all(10)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T12:40:10.352913Z","iopub.execute_input":"2023-02-25T12:40:10.353762Z","iopub.status.idle":"2023-02-25T12:40:10.361731Z","shell.execute_reply.started":"2023-02-25T12:40:10.353717Z","shell.execute_reply":"2023-02-25T12:40:10.360268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load Data","metadata":{}},{"cell_type":"code","source":"meta_df = pd.read_parquet(f'{DATA_DIR}/{DATA_SET}_meta.parquet')\nsensor_geometry = pd.read_csv(f'{DATA_DIR}/sensor_geometry.csv', index_col=0)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T12:40:10.362939Z","iopub.execute_input":"2023-02-25T12:40:10.363362Z","iopub.status.idle":"2023-02-25T12:40:26.093344Z","shell.execute_reply.started":"2023-02-25T12:40:10.363325Z","shell.execute_reply":"2023-02-25T12:40:26.091924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Plot the result\n\nExecute the following code to plot the predicted Neutrino path vs Actual true path.","metadata":{}},{"cell_type":"code","source":"# Get a random event_id and associated batch_id from meta_df\n# If EVENT is given, use that instead of a random event_id\nevent_id, batch_id = \\\n    meta_df[['event_id', 'batch_id']].sample(n=1).values[0] \\\n    if not EVENT \\\n    else (\n        EVENT, \n        meta_df[meta_df['event_id']==EVENT]['batch_id'].values[0]\n    )\n    \nbatch_df = pd.read_parquet(f'{DATA_DIR}/train/batch_{batch_id}.parquet').reset_index()\nevent_df = compose_event_df(batch_df, event_id, sensor_geometry)  # type: ignore\n\ntrue_values = get_event_true_values(meta_df, event_id)\nprint('Plotting event_id:', event_id)\nprint(\"Marker Color is time and marker size is relative to the charge detected. \")\n\nplot_pca(\n    event_df, \n    labels=true_values, \n    exclude_axillary=EXCLUDE_AUXILIARY, \n    marker_size=12, \n    # charge_threshold=(1, None),\n    # time_threshold=(0, 12000)\n)","metadata":{"execution":{"iopub.status.busy":"2023-02-25T12:40:26.096243Z","iopub.execute_input":"2023-02-25T12:40:26.096621Z","iopub.status.idle":"2023-02-25T12:40:37.364217Z","shell.execute_reply.started":"2023-02-25T12:40:26.096586Z","shell.execute_reply":"2023-02-25T12:40:37.362212Z"},"trusted":true},"execution_count":null,"outputs":[]}]}