{ "cells": [ { "cell_type": "markdown", "id": "48eff708", "metadata": {}, "source": [ "# Blazar-neutrino connected simulation\n", "\n", "We demonstrate how to run a simulation for a population of blazars that produce neutrinos according to their gamma-ray fluxes in the 0.1 to 100 GeV range." ] }, { "cell_type": "code", "execution_count": 1, "id": "f3c55398", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:29:08.563297Z", "iopub.status.busy": "2022-07-22T12:29:08.562645Z", "iopub.status.idle": "2022-07-22T12:29:12.012395Z", "shell.execute_reply": "2022-07-22T12:29:12.011528Z" } }, "outputs": [], "source": [ "from popsynth.utils.logging import quiet_mode\n", "from icecube_tools.detector.effective_area import EffectiveArea\n", "from icecube_tools.detector.energy_resolution import EnergyResolution\n", "from icecube_tools.detector.angular_resolution import AngularResolution\n", "\n", "from nu_coincidence.blazar_nu.connected import BlazarNuConnectedSim\n", "from nu_coincidence.blazar_nu.connected import BlazarNuConnectedResults\n", "from nu_coincidence.utils.package_data import get_available_config\n", "\n", "quiet_mode() # silence popsynth logs/output" ] }, { "cell_type": "markdown", "id": "4da123ff", "metadata": {}, "source": [ "Firstly, we make sure that we have the necessary files for running an IceCube simulation by using the `icecube_tools` package" ] }, { "cell_type": "code", "execution_count": 2, "id": "802c9a5a", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:29:12.017121Z", "iopub.status.busy": "2022-07-22T12:29:12.016560Z", "iopub.status.idle": "2022-07-22T12:29:17.384208Z", "shell.execute_reply": "2022-07-22T12:29:17.383426Z" } }, "outputs": [], "source": [ "my_aeff = EffectiveArea.from_dataset(\"20181018\")\n", "my_aeff = EffectiveArea.from_dataset(\"20131121\")\n", "my_eres = EnergyResolution.from_dataset(\"20150820\")\n", "my_angres = AngularResolution.from_dataset(\"20181018\")" ] }, { "cell_type": "markdown", "id": "840ead94", "metadata": {}, "source": [ "The inputs to `BlazarNuConnectedSim` are specified by the `.yml` config files provided with the `nu_coincidence` package. We can check what is available using the helper function `get_available_config()`." ] }, { "cell_type": "code", "execution_count": 3, "id": "e8a5876c", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:29:17.388912Z", "iopub.status.busy": "2022-07-22T12:29:17.388468Z", "iopub.status.idle": "2022-07-22T12:29:17.402519Z", "shell.execute_reply": "2022-07-22T12:29:17.401779Z" } }, "outputs": [ { "data": { "text/plain": [ "['nu_connected_hese.yml',\n", " 'fsrq_high.yml',\n", " 'bllac_rbcu.yml',\n", " 'nu_diffuse_tracks.yml',\n", " 'fsrq_ref.yml',\n", " 'nu_diffuse_ehe_hard.yml',\n", " 'nu_diffuse_hese_soft.yml',\n", " 'bllac_high.yml',\n", " 'nu_connected_tracks.yml',\n", " 'bllac_low.yml',\n", " 'bllac_ref.yml',\n", " 'fsrq_gpsel.yml',\n", " 'fsrq_nobcu.yml',\n", " 'nu_diffuse_ehe_soft.yml',\n", " 'bllac_gpsel.yml',\n", " 'fsrq_low.yml',\n", " 'bllac_nobcu.yml',\n", " 'nu_diffuse_hese.yml',\n", " 'nu_diffuse_hese_hard.yml',\n", " 'nu_connected_ehe.yml',\n", " 'fsrq_rbcu.yml',\n", " 'nu_diffuse_ehe.yml']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "get_available_config()" ] }, { "cell_type": "markdown", "id": "53758d53", "metadata": {}, "source": [ "The connecting flux factor, $Y_{\\nu\\gamma}$ can be set in the `nu_connected_...` config files or specified at run time. we may want to explore different flux factors and their implications, as we show below." ] }, { "cell_type": "code", "execution_count": 4, "id": "d8cf434f", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:29:17.407057Z", "iopub.status.busy": "2022-07-22T12:29:17.406580Z", "iopub.status.idle": "2022-07-22T12:29:17.410332Z", "shell.execute_reply": "2022-07-22T12:29:17.409609Z" } }, "outputs": [], "source": [ "flux_factors = [0.001, 0.01]\n", "sub_file_names = [\"output/test_connected_sim_%.1e.h5\" % ff for ff in flux_factors]" ] }, { "cell_type": "markdown", "id": "d0c7397c", "metadata": {}, "source": [ "For this example, we use the reference blazar model (`bllac_ref.yml` and `fsrq_ref.yml`) together with the connected IceCube HESE and EHE alerts models (`nu_connected_hese.yml` and `nu_connected_ehe.yml`). This will run for a couple of mins." ] }, { "cell_type": "code", "execution_count": 5, "id": "32105a34", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:29:17.413701Z", "iopub.status.busy": "2022-07-22T12:29:17.413321Z", "iopub.status.idle": "2022-07-22T12:31:51.085554Z", "shell.execute_reply": "2022-07-22T12:31:51.084481Z" } }, "outputs": [], "source": [ "for ff, sfn in zip(flux_factors, sub_file_names):\n", " sim = BlazarNuConnectedSim(\n", " file_name=\"output/test_connected_sim_%.1e.h5\" % ff,\n", " N=2, # Number of sims to run\n", " bllac_config=\"bllac_ref.yml\",\n", " fsrq_config=\"fsrq_ref.yml\",\n", " nu_hese_config=\"nu_connected_hese.yml\",\n", " nu_ehe_config=\"nu_connected_ehe.yml\",\n", " seed=42,\n", " flux_factor=ff,\n", " flare_only=True, # only flare emission contributes\n", " det_only=True,\n", " ) # only detected blazars contribute\n", "\n", " sim.run(parallel=False) # define number of parallel jobs to run" ] }, { "cell_type": "markdown", "id": "3b453943", "metadata": {}, "source": [ "If working with different flux factors, there is a helper function to merge together the separate output files." ] }, { "cell_type": "code", "execution_count": 6, "id": "ec1f0b22", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:31:51.090030Z", "iopub.status.busy": "2022-07-22T12:31:51.089580Z", "iopub.status.idle": "2022-07-22T12:31:51.108093Z", "shell.execute_reply": "2022-07-22T12:31:51.107293Z" } }, "outputs": [], "source": [ "BlazarNuConnectedResults.merge_over_flux_factor(\n", " sub_file_names, flux_factors, write_to=\"output/test_connected_sim.h5\", delete=True\n", ")\n", "\n", "results = BlazarNuConnectedResults([\"output/test_connected_sim.h5\"])" ] }, { "cell_type": "markdown", "id": "f14c7a40", "metadata": {}, "source": [ "The results are organised to store relevant information divided into the `results.bllac` and `results.fsrq` populations. We focus on the total number of alerts, `n_alerts`, and the number of sources that produce multiple detected neutrinos, `n_multi`, from each simulated survey." ] }, { "cell_type": "code", "execution_count": 7, "id": "93f1316d", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:31:51.111950Z", "iopub.status.busy": "2022-07-22T12:31:51.111580Z", "iopub.status.idle": "2022-07-22T12:31:51.116940Z", "shell.execute_reply": "2022-07-22T12:31:51.116397Z" } }, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('n_alerts',\n", " array([[0, 0],\n", " [0, 0]])),\n", " ('n_alerts_flare',\n", " array([[0, 0],\n", " [0, 0]])),\n", " ('n_multi',\n", " array([[0, 0],\n", " [0, 0]])),\n", " ('n_multi_flare',\n", " array([[0, 0],\n", " [0, 0]]))])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.bllac" ] }, { "cell_type": "code", "execution_count": 8, "id": "648951e6", "metadata": { "execution": { "iopub.execute_input": "2022-07-22T12:31:51.120499Z", "iopub.status.busy": "2022-07-22T12:31:51.120018Z", "iopub.status.idle": "2022-07-22T12:31:51.129328Z", "shell.execute_reply": "2022-07-22T12:31:51.128748Z" } }, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('n_alerts',\n", " array([[0, 0],\n", " [1, 1]])),\n", " ('n_alerts_flare',\n", " array([[0, 0],\n", " [1, 1]])),\n", " ('n_multi',\n", " array([[0, 0],\n", " [0, 0]])),\n", " ('n_multi_flare',\n", " array([[0, 0],\n", " [0, 0]]))])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.fsrq" ] }, { "cell_type": "code", "execution_count": null, "id": "66c3e111", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "1afee808e1be44c6ab24eb33e88389de": { "model_module": "jupyter-vuetify", "model_module_version": "^1.8.2", "model_name": "ThemeColorsModel", "state": { "_model_module": "jupyter-vuetify", "_model_module_version": "^1.8.2", "_model_name": "ThemeColorsModel", "_theme_name": "light", "_view_count": null, "_view_module": null, "_view_module_version": "^1.8.2", "_view_name": null, "accent": "#82B1FF", "anchor": null, "error": "#FF5252", "info": "#2196F3", "primary": "#1976D2", "secondary": "#424242", "success": "#4CAF50", "warning": "#FB8C00" } }, "316107f28d0749d8bf142eea18ebbc0d": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "65e80ffdf79748edaef610d3d2bb9d58": { "model_module": "jupyter-vuetify", "model_module_version": "^1.8.2", "model_name": "ThemeModel", "state": { "_model_module": "jupyter-vuetify", "_model_module_version": "^1.8.2", "_model_name": "ThemeModel", "_view_count": null, "_view_module": null, "_view_module_version": "^1.8.2", "_view_name": null, "dark": null } }, "957dc8c466ce48b38accb550c4e31bd8": { "model_module": "jupyter-vuetify", "model_module_version": "^1.8.2", "model_name": "ThemeColorsModel", "state": { "_model_module": "jupyter-vuetify", "_model_module_version": "^1.8.2", "_model_name": "ThemeColorsModel", "_theme_name": "dark", "_view_count": null, "_view_module": null, "_view_module_version": "^1.8.2", "_view_name": null, "accent": "#FF4081", "anchor": null, "error": "#FF5252", "info": "#2196F3", "primary": "#2196F3", "secondary": "#424242", "success": "#4CAF50", "warning": "#FB8C00" } }, "bc746503cf7b4184879bd990f75f5eab": { "model_module": "jupyter-vue", "model_module_version": "^1.7.0", "model_name": "ForceLoadModel", "state": { "_dom_classes": [], "_model_module": "jupyter-vue", "_model_module_version": "^1.7.0", "_model_name": "ForceLoadModel", "_view_count": null, "_view_module": null, "_view_module_version": "", "_view_name": null, "layout": "IPY_MODEL_316107f28d0749d8bf142eea18ebbc0d" } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }