Skip to content

Commit

Permalink
Search for gammapy data directory automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
moralejo committed Oct 30, 2024
1 parent dfc9adb commit c7fcca9
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions notebooks/LST1_observation_simulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
"import numpy as np\n",
"import astropy.units as u\n",
"import matplotlib.pyplot as plt\n",
"import gammapy\n",
"from gammapy.modeling.models import EBLAbsorptionNormSpectralModel\n",
"import subprocess\n",
"from pyirf.spectral import CRAB_MAGIC_JHEAP2015, PowerLaw, LogParabola\n",
"from pyirf.statistics import li_ma_significance\n",
"from scipy.stats import moyal, norm, skewnorm\n",
"from gammapy.modeling.models import EBLAbsorptionNormSpectralModel"
"from pathlib import Path"
]
},
{
Expand Down Expand Up @@ -172,7 +175,7 @@
},
{
"cell_type": "markdown",
"id": "9798d5c3",
"id": "ba8de510",
"metadata": {},
"source": [
"## Pulsar mode\n",
Expand All @@ -182,7 +185,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8d8cff5b",
"id": "8e3139e8",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -223,7 +226,7 @@
},
{
"cell_type": "markdown",
"id": "f243b138",
"id": "4ccf4294",
"metadata": {},
"source": [
"## Source extension\n",
Expand All @@ -235,7 +238,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2ab033a7",
"id": "cb352dca",
"metadata": {
"scrolled": false
},
Expand Down Expand Up @@ -278,12 +281,20 @@
"# We will apply the Dominguez EBL model to simulate the absorption\n",
"\n",
"\n",
"# Make sure we have the necessary EBL absorption data:\n",
"try:\n",
" os.environ['GAMMAPY_DATA']\n",
"except:\n",
" # SET HERE THE GAMMAPY_DATA ENV VARIABLE IN CASE IT IS NOT SET\n",
" # YOU MUST SET THE PATH TO THE CORRESPONDING DIRECTORY IN THE CONDA ENVIRONMENT YOU ARE USING:\n",
" os.environ['GAMMAPY_DATA'] = '/fefs/aswg/workspace/abelardo.moralejo/miniconda3/envs/lst-dev/lib/python3.11/site-packages/gammapy/gammapy-datasets/1.1'\n",
" # WE SET HERE THE GAMMAPY_DATA ENV VARIABLE IN CASE IT IS NOT SET\n",
" gammapy_dir = Path(gammapy.__file__).parent\n",
" gammapy_dir\n",
"\n",
" ebl_file = subprocess.run(['find', str(gammapy_dir), '-name', 'ebl_dominguez11.fits.gz'], \n",
" stdout=subprocess.PIPE).stdout.decode()\n",
" gammapy_data = ebl_file[:ebl_file.find('/ebl/')]\n",
" os.environ['GAMMAPY_DATA'] = gammapy_data\n",
" print('Set GAMMAPY_DATA to', gammapy_data)\n",
"\n",
"\n",
"dominguez = EBLAbsorptionNormSpectralModel.read_builtin(\"dominguez\", redshift=redshift)"
]
Expand Down Expand Up @@ -664,7 +675,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7295189b",
"id": "e91f0070",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -721,7 +732,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "bfdf90f7",
"id": "5113ba34",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -939,7 +950,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1ca87a15",
"id": "f9c2b653",
"metadata": {},
"outputs": [],
"source": []
Expand Down

0 comments on commit c7fcca9

Please sign in to comment.