Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DarkElf + test notebooks #215

Merged
merged 14 commits into from
May 28, 2022
5 changes: 4 additions & 1 deletion .github/scripts/install_on_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ echo "in that folder is:"
ls $LD_LIBRARY_PATH ; echo $LD_LIBRARY_PATH
echo "go back to installation; ls ; pwd "

cd dddm

echo "Doing other conda and pip:"
# We need the data files from this
git clone https://github.com/joranangevaare/verne ../verne
pip install -e ../verne
git clone https://github.com/JoranAngevaare/DarkELF ../darkelf
pip install -e ../darkelf
cd dddm
echo "done"
6 changes: 5 additions & 1 deletion .github/workflows/test_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
pip install git+https://github.com/jorana/wimprates
git clone https://github.com/jorana/verne
pip install -e verne
git clone https://github.com/JoranAngevaare/DarkELF
pip install -e DarkELF
- name: Install other stuff
run: |
pip install -r extra_requirements/requirements-tests.txt
Expand All @@ -68,6 +70,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coverage run --source=dddm -m pytest -vsx --durations 0
coverage run --append --source=dddm -m pytest --nbmake -n=auto ./notebooks
coveralls --service=github
- name: Test package (linux)
if: matrix.os == 'ubuntu-latest' && matrix.test == 'pytest'
Expand All @@ -77,6 +80,7 @@ jobs:
export LD_LIBRARY_PATH=/home/runner/work/dddm/dddm/MultiNest/lib
export RUN_TEST_EXTENDED=1
coverage run --source=dddm -m pytest -vsx --durations 0
coverage run --append --source=dddm -m pytest --nbmake -n=auto ./notebooks
coveralls --service=github
- name: Test package - fail fast (linux)
if: matrix.os == 'ubuntu-latest' && matrix.test == 'fail-fast'
Expand All @@ -86,7 +90,6 @@ jobs:
run: |
export LD_LIBRARY_PATH=/home/runner/work/dddm/dddm/MultiNest/lib
coverage run --source=dddm -m pytest -vsx --durations 0
coveralls --service=github
- name: Coveralls
if: matrix.test == 'coveralls'
env:
Expand All @@ -96,6 +99,7 @@ jobs:
export LD_LIBRARY_PATH=/home/runner/work/dddm/dddm/MultiNest/lib
export RUN_TEST_EXTENDED=1
coverage run --source=dddm setup.py test -v
coverage run --append --source=dddm -m pytest --nbmake -n=auto ./notebooks
coveralls --service=github
- name: goodbye
run: echo goodbye
12 changes: 10 additions & 2 deletions extra_requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ corner==2.2.1
coveralls==3.3.1
emcee==3.1.1
gitpython==3.1.27
gvar==11.9.7
hypothesis==6.21.1
immutabledict==2.2.1
matplotlib==3.5.1
matplotlib-label-lines==0.5.1
multihist==0.6.5
nestle==0.2.0
numba==0.55.1
nbmake==1.3.0
numba==0.55.2
numericalunits==1.25
numpy==1.21.6
numpy==1.22.4
pandas==1.4.2
psutil==5.9.0
pytest==7.1.2
pytest-runner==6.0.0
pytest-xdist==2.5.0
PyYAML==6.0
scipy==1.8.0
seaborn==0.11.2
tqdm==4.64.0
vegas==5.1.1


# These two packages require metadata not shipped via pip+git
git+https://github.com/jorana/wimprates
# git+https://github.com/JoranAngevaare/DarkELF
# git+https://github.com/jorana/verne

34 changes: 0 additions & 34 deletions notebooks/common_init.py

This file was deleted.

109 changes: 77 additions & 32 deletions notebooks/summary.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,39 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2022-05-23T15:23:57.392218Z",
"start_time": "2022-05-23T15:23:54.106785Z"
}
},
"outputs": [],
"source": [
"import DirectDmTargets as dddm"
"import dddm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2022-05-23T15:23:57.405372Z",
"start_time": "2022-05-23T15:23:57.395851Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"'0.3.2'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import wimprates as wr\n",
"wr.__version__"
Expand Down Expand Up @@ -214,13 +235,16 @@
"metadata": {},
"outputs": [],
"source": [
"def get_gal_spec(det):\n",
" spec_class = dddm.GenSpectrum(50, 1e-45, use_SHM, dddm.experiment[det])\n",
" spec_class.set_config(\n",
" dict(E_max = 200,\n",
" n_energy_bins = 200\n",
" ))\n",
" return spec_class.get_data(poisson = False)"
"experiments = {'Xe_simple': dddm.examples.XenonSimple,\n",
" 'Ge_simple': dddm.examples.GermaniumSimple,\n",
" 'Ar_simple': dddm.examples.ArgonSimple,\n",
"}\n",
"def get_gal_spec(det, mw =50):\n",
" spec_class = dddm.GenSpectrum(\n",
" dark_matter_model=use_SHM,\n",
" experiment=experiments[det](n_energy_bins=200, e_min_kev=0, e_max_kev=200)\n",
" )\n",
" return spec_class.get_data(wimp_mass=mw, cross_section=1e-45, poisson = False)"
]
},
{
Expand All @@ -247,12 +271,11 @@
"outputs": [],
"source": [
"def get_det_spec(det, mw =50):\n",
" spec_class = dddm.DetectorSpectrum(mw, 1e-45, use_SHM, dddm.experiment[det])\n",
" spec_class.set_config(\n",
" dict(E_max = 200,\n",
" n_energy_bins = 200\n",
" ))\n",
" return spec_class.get_data(poisson = False)"
" spec_class = dddm.DetectorSpectrum(\n",
" dark_matter_model=use_SHM,\n",
" experiment=experiments[det](n_energy_bins=200, e_min_kev=0, e_max_kev=200)\n",
" )\n",
" return spec_class.get_data(wimp_mass=mw, cross_section=1e-45, poisson = False)"
]
},
{
Expand Down Expand Up @@ -316,8 +339,19 @@
"metadata": {},
"outputs": [],
"source": [
"fit_class = dddm.NestedSamplerStatModel('Xe_simple')\n",
"fit_class.config['sampler'] = 'nestle'\n",
"context = dddm.base_context()\n",
"fit_class = context.get_sampler_for_detector(\n",
" wimp_mass=50,\n",
" cross_section=1e-45,\n",
" sampler_name='nestle',\n",
" detector_name='Xe_simple',\n",
" prior=\"Pato_2010\",\n",
" halo_name='shm',\n",
" detector_kwargs=None,\n",
" halo_kwargs=None,\n",
" sampler_kwargs=dict(nlive=100, tol=0.1, verbose=1),\n",
" fit_parameters=('log_mass', 'log_cross_section',),\n",
")\n",
"print(f\"Fitting for parameters:\\n{fit_class.config['fit_parameters']}\")"
]
},
Expand All @@ -327,8 +361,9 @@
"metadata": {},
"outputs": [],
"source": [
"fit_class.run_nestle()\n",
"fit_class.get_summary()"
"fit_class.run()\n",
"results = fit_class.get_summary()\n",
"print(results)"
]
},
{
Expand All @@ -346,9 +381,18 @@
"metadata": {},
"outputs": [],
"source": [
"fit_unconstrained = dddm.NestedSamplerStatModel('Xe_simple')\n",
"fit_unconstrained.set_fit_parameters(fit_unconstrained.known_parameters)\n",
"print(f\"Fitting for parameters:\\n{fit_unconstrained.fit_class.config['fit_parameters']}\")"
"fit_unconstrained = context.get_sampler_for_detector(\n",
" wimp_mass=50,\n",
" cross_section=1e-45,\n",
" sampler_name='nestle',\n",
" detector_name='Xe_simple',\n",
" prior=\"Pato_2010\",\n",
" halo_name='shm',\n",
" detector_kwargs=None,\n",
" halo_kwargs=None,\n",
" sampler_kwargs=dict(nlive=100, tol=0.1, verbose=1),\n",
" fit_parameters=dddm.statistics.get_param_list(),\n",
")"
]
},
{
Expand All @@ -357,8 +401,9 @@
"metadata": {},
"outputs": [],
"source": [
"fit_unconstrained.run_nestle()\n",
"fit_unconstrained.get_summary()"
"fit_unconstrained.run()\n",
"results = fit_unconstrained.get_summary()\n",
"print(results)"
]
},
{
Expand All @@ -367,7 +412,7 @@
"metadata": {},
"outputs": [],
"source": [
"fit_unconstrained.show_corner()"
"fit_unconstrained.show_corner()\n"
]
},
{
Expand All @@ -387,7 +432,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -401,9 +446,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.1"
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading