Skip to content

Instantly share code, notes, and snippets.

@thejevans
Last active February 15, 2022 20:01
Show Gist options
  • Save thejevans/5085ffa399ceaa67b293051a16ea7b12 to your computer and use it in GitHub Desktop.
Save thejevans/5085ffa399ceaa67b293051a16ea7b12 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "83662c1b-2936-4784-b074-68ec362acca8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/jevans96/git_repos/mla\n"
]
}
],
"source": [
"cd ~/git_repos/mla/"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0c247d67",
"metadata": {},
"outputs": [],
"source": [
"import mla\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6647506f",
"metadata": {},
"outputs": [],
"source": [
"root = '/Users/jevans96/jupyter/student_data/'\n",
"data = np.load(root + 'IC86_2012_exp.npy')\n",
"sim = np.load(root + 'IC86_2012_MC.npy')\n",
"grl = np.load(root + 'GRL/IC86_2012_exp.npy')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "23d3a8f7",
"metadata": {},
"outputs": [],
"source": [
"global_config = mla.generate_default_config([\n",
" mla.NuSourcesDataHandler,\n",
" mla.PointSource,\n",
" mla.SpatialTermFactory,\n",
" mla.SplineMapEnergyTermFactory,\n",
"])\n",
"\n",
"global_config['PointSource']['name'] = 'TXS0506+056'\n",
"global_config['PointSource']['ra'] = mla.ra_to_rad(5, 9, 25.9645434784)\n",
"global_config['PointSource']['dec'] = mla.dec_to_rad(1, 5, 41, 35.333636817)\n",
"global_config['NuSourcesDataHandler']['dec_cut_location'] = global_config['PointSource']['dec']\n",
"global_config['NuSourcesDataHandler']['dec_bandwidth (rad)'] = np.deg2rad(3)\n",
"\n",
"analysis_config = mla.SingleSourceLLHAnalysis.generate_default_config(mla.GridSearchMinimizer)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "62ad93a7-1bc4-4dff-a031-abb2ad4328d5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"NuSourcesDataHandler\": {\n",
" \"normalization_energy (GeV)\": 100000.0,\n",
" \"assumed_gamma\": -2,\n",
" \"dec_cut_location\": 0.09936418146033345,\n",
" \"dec_bandwidth (rad)\": 0.05235987755982989,\n",
" \"sin_dec_bins\": 500,\n",
" \"dec_spline_kwargs\": {\n",
" \"bbox\": [\n",
" -1,\n",
" 1\n",
" ],\n",
" \"s\": 1.5e-05,\n",
" \"ext\": 3\n",
" }\n",
" },\n",
" \"PointSource\": {\n",
" \"name\": \"TXS0506+056\",\n",
" \"ra\": 1.3501550420509332,\n",
" \"dec\": 0.09936418146033345\n",
" },\n",
" \"SpatialTermFactory\": {\n",
" \"name\": \"SpatialTerm\"\n",
" },\n",
" \"SplineMapEnergyTermFactory\": {\n",
" \"name\": \"SplineMapEnergyTerm\",\n",
" \"initial_gamma\": -2,\n",
" \"sin_dec_bins\": 50,\n",
" \"log_energy_bins\": 50,\n",
" \"log_energy_bounds\": [\n",
" 1,\n",
" 8\n",
" ],\n",
" \"gamma_bins\": 50,\n",
" \"gamma_bounds\": [\n",
" -4.25,\n",
" -0.5\n",
" ],\n",
" \"sob_spline_kwargs\": {\n",
" \"k\": 3,\n",
" \"s\": 0,\n",
" \"ext\": \"raise\"\n",
" },\n",
" \"energy_spline_kwargs\": {\n",
" \"k\": 1,\n",
" \"s\": 0,\n",
" \"ext\": 3\n",
" }\n",
" }\n",
"}\n"
]
}
],
"source": [
"import json\n",
"print(json.dumps(global_config, indent=4))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6a2e4dd3-1a4c-4843-b37f-e6655ae75ef8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"GridSearchMinimizer\": {\n",
" \"gridsearch_points\": 5,\n",
" \"scipy_minimize_method\": \"L-BFGS-B\"\n",
" },\n",
" \"SingleSourceTrialGenerator\": {\n",
" \"random_seed\": null,\n",
" \"fixed_ns\": false\n",
" },\n",
" \"LLHTestStatisticFactory\": {\n",
" \"newton_precision\": 0,\n",
" \"newton_iterations\": 20\n",
" }\n",
"}\n"
]
}
],
"source": [
"print(json.dumps(analysis_config, indent=4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10a6406b-ddca-43cd-b81b-de662195bdef",
"metadata": {},
"outputs": [],
"source": [
"source = mla.PointSource(global_config['PointSource'])\n",
"data_handler = mla.NuSourcesDataHandler(global_config['NuSourcesDataHandler'], sim, (data, grl))\n",
"spatial_term_factory = mla.SpatialTermFactory(global_config['SpatialTermFactory'], data_handler, source)\n",
"energy_term_factory = mla.SplineMapEnergyTermFactory(global_config['SplineMapEnergyTermFactory'], data_handler)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "088d8f40",
"metadata": {},
"outputs": [],
"source": [
"analysis = mla.SingleSourceLLHAnalysis(\n",
" config=analysis_config,\n",
" minimizer_class=mla.GridSearchMinimizer,\n",
" sob_term_factories=[spatial_term_factory, energy_term_factory],\n",
" data_handler_source=(data_handler, source),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "389775f1",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"params = analysis.generate_params()\n",
"\n",
"ts_dist = [analysis.produce_and_minimize(params, ['gamma'])[0] for _ in range(100)]\n",
"plt.hist(ts_dist)\n",
"plt.show()\n",
"\n",
"ts_dist = [analysis.produce_and_minimize(params, ['gamma'], n_signal=5e-11)[0] for _ in range(100)]\n",
"plt.hist(ts_dist)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a2058e8-cc2a-43dd-ae87-f15b7629127a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment