Skip to content

Commit

Permalink
Merge pull request #9 from JoranAngevaare/add_ci
Browse files Browse the repository at this point in the history
Continuous integration
  • Loading branch information
JelleAalbers authored Aug 17, 2022
2 parents fa7699a + 1ae5151 commit 247a50b
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 54 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Test package

on:
workflow_dispatch:
release:
types: [ created ]
pull_request:
push:
branches:
- master

jobs:
update:
name: "${{ matrix.test }}_py${{ matrix.python-version }}"
runs-on: ubuntu-latest
strategy:
fail-fast: False
matrix:
python-version: [3.7, 3.8, 3.9, "3.10" ]
# Test coveralls (with numba disabled) and normal pytest
test: [ 'coveralls', 'pytest', ]
exclude:
- python-version: 3.7
test: pytest
- python-version: 3.9
test: pytest
- python-version: "3.10"
test: pytest
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Checkout repo
uses: actions/checkout@v3
- name: Install requirements for tests and latest strax
run: |
# Requirements for running the notebooks as a pytest
pip install cython ipython
pip install nbconvert==6.4.3 nbmake pytest-xdist pytest coverage coveralls pytest-cov pytest-notebook ipython_genutils
# Several optional packages that are imported in the notebooks
pip install git+https://github.com/XENON1T/laidbax
python setup.py develop
- name: Test package
if: matrix.test == 'pytest'
run:
pytest --cov wimprates -v --nbmake notebooks/*.ipynb --durations 0 --nb-coverage
- name: Coveralls
env:
NUMBA_DISABLE_JIT: 1
if: matrix.test == 'coveralls'
run:
pytest --cov wimprates -v --nbmake notebooks/*.ipynb --durations 0 --nb-coverage
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
- name: goodbye
run: echo "tests done, bye bye"
62 changes: 41 additions & 21 deletions notebooks/Checks, plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"source": [
"try:\n",
" plt.style.use('latex_thesis')\n",
" _latex_thesis=True\n",
"except (FileNotFoundError, OSError):\n",
" print(\"Can't use my favourite plotting style... oh well\")"
" print(\"Can't use my favourite plotting style... oh well\")\n",
" _latex_thesis=False"
]
},
{
Expand All @@ -48,7 +50,8 @@
"source": [
"kms = nu.km/nu.s\n",
"\n",
"from wimprates import v_0, v_earth, v_esc \n",
"from wimprates import StandardHaloModel, v_earth\n",
"v_0, v_esc = StandardHaloModel().v_0, StandardHaloModel().v_esc\n",
"\n",
"def galactic_v_dist(v):\n",
" # Maxwell Boltzmann distribution with\n",
Expand Down Expand Up @@ -393,10 +396,16 @@
],
"source": [
"# Get mean energies and energy spectra\n",
"from laidbax import wimps\n",
"from s2only import wimprates as wr\n",
"\n",
"es = np.logspace(-2, 3.5, 500)\n",
"try:\n",
" from laidbax import wimps\n",
" from s2only import wimprates as wr\n",
"except ImportError:\n",
" import wimprates as wr\n",
" wimps = None\n",
"\n",
"es = np.logspace(-2, 3.5, 100)\n",
"# Reduce the number a bit to get the results quicker\n",
"mchi = mchi[::5]\n",
"ms = mchi / gevcsq\n",
"rates = []\n",
"rates_bs = []\n",
Expand All @@ -407,7 +416,10 @@
"means_bs = np.zeros(len(ms), dtype=np.float)\n",
"\n",
"for i, mw in enumerate(tqdm(ms)):\n",
" r = wimps.wimp_recoil_spectrum(es, mass=mw, sigma=1e-45)\n",
" if wimps is not None:\n",
" r = wimps.wimp_recoil_spectrum(es, mass=mw, sigma=1e-45)\n",
" else:\n",
" r = wr.rate_wimp_std(es, mw, 1e-45)\n",
" rates.append(r)\n",
" rate_per_bin = (r[1:] + r[:-1])/2 * widths\n",
" if rate_per_bin.sum() != 0:\n",
Expand Down Expand Up @@ -435,9 +447,13 @@
"metadata": {},
"outputs": [],
"source": [
"from s2only.utils import load_pickle, dump_pickle\n",
"dump_pickle(dict(means=means, means_bs=means_bs, rates=rates, rates_bs=rates_bs, ms=ms),\n",
" 'dm_mean_energies.pickle')"
"try:\n",
" from s2only.utils import load_pickle, dump_pickle\n",
"except ModuleNotFoundError:\n",
" pass\n",
"else:\n",
" dump_pickle(dict(means=means, means_bs=means_bs, rates=rates, rates_bs=rates_bs, ms=ms),\n",
" 'dm_mean_energies.pickle')"
]
},
{
Expand All @@ -461,7 +477,7 @@
" ax.set_ylabel(label, color=color)\n",
" ax.tick_params('y', colors=color)\n",
"\n",
"v = v_earth + v_esc\n",
"v = v_earth() + v_esc\n",
"plt.plot(mchi / gevcsq, \n",
" 4 * mchi * mn / (mchi + mn)**2 * (mchi * v**2 /2) / nu.keV,\n",
" linestyle=':', c='b'\n",
Expand Down Expand Up @@ -574,13 +590,13 @@
"tyear = 1e3 * 365\n",
"\n",
"plt.plot(ms, [tyear * total_rate(m, threshold=5) for m in ms], \n",
" label='NR, $E_T =\\SI{5}{keV}$', \n",
" label='NR, $E_T =\\SI{5}{keV}$' if _latex_thesis else 'NR, $E_T =5$ keV', \n",
" c='blue', linewidth=1)\n",
"plt.plot(ms, [tyear * total_rate(m, threshold=1) for m in ms], \n",
" label='NR, $E_T = \\SI{1}{keV}$', \n",
" label='NR, $E_T = \\SI{1}{keV}$' if _latex_thesis else 'NR, $E_T = 1$ keV', \n",
" c='g', linewidth=1)\n",
"plt.plot(ms, [tyear * total_rate(m, bs=True, threshold=0.18) * 1e-10 for m in ms], \n",
" label='BS, $E_T =\\SI{180}{eV}$',\n",
" label='BS, $E_T =\\SI{180}{eV}$' if _latex_thesis else 'BS, $E_T =180$ eV',\n",
" c='r', linewidth=1)\n",
"plt.yscale('log')\n",
"plt.ylim(None, 1e4)\n",
Expand All @@ -589,8 +605,12 @@
"leg = plt.legend(loc='upper right')\n",
"leg.get_frame().set_linewidth(0.0)\n",
"leg.get_frame().set_alpha(0.85)\n",
"plt.ylabel('Rate (\\si{events/(ton\\;year)})')\n",
"plt.xlabel('$m_\\chi$ (\\si{GeV/c^2})')\n",
"if _latex_thesis:\n",
" plt.ylabel('Rate (\\si{events/(ton\\;year)})')\n",
" plt.xlabel('$m_\\chi$ (\\si{GeV/c^2})')\n",
"else:\n",
" plt.ylabel('Rate')\n",
" plt.xlabel('$m_\\chi$')\n",
"plt.gca().invert_yaxis()\n",
"#plt.plot(es, total_rate(, c='b', label='$\\SI{1}{GeV/c^2}$')\n",
"plt.xlim(1e-1, 1e4)\n",
Expand All @@ -615,10 +635,10 @@
}
],
"source": [
"plt.plot(es, nearest_rate(1), c='b', label='$\\SI{1}{GeV/c^2}$')\n",
"plt.plot(es, nearest_rate(100), label='$\\SI{100}{GeV/c^2}$', c='g')\n",
"plt.plot(es, nearest_rate(1), c='b', label='$\\SI{1}{GeV/c^2}$' if _latex_thesis else None)\n",
"plt.plot(es, nearest_rate(100), label='$\\SI{100}{GeV/c^2}$' if _latex_thesis else None, c='g')\n",
"plt.plot(es, nearest_rate(1, bs=True) * 1e-10, c='b', linestyle=':',\n",
" label='$\\SI{1}{GeV/c^2}$, Bremsstrahlung' # $\\\\times 10^{10}$'\n",
" label='$\\SI{1}{GeV/c^2}$, Bremsstrahlung' if _latex_thesis else None # $\\\\times 10^{10}$'\n",
" )\n",
"leg = plt.legend(loc='upper right', frameon=False)\n",
"#leg.get_frame().set_linewidth(0.0)\n",
Expand Down Expand Up @@ -695,7 +715,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -709,7 +729,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
10 changes: 6 additions & 4 deletions notebooks/DM-electron scattering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@
" \n",
" for shell, rn in drsn.items():\n",
" rn *= (1000 * nu.kg * nu.year)\n",
" plt.plot(n_el, rn, linestyle='steps-mid', label=shell)\n",
" plt.plot(n_el, rn, drawstyle='steps-mid', label=shell)\n",
"\n",
" plt.plot(n_el, np.sum(list(drsn.values()), axis=0),\n",
" label='Total',\n",
" drawstyle='steps-mid', linestyle='--', c='k')\n",
" drawstyle='steps-mid', \n",
" linestyle='--', \n",
" c='k')\n",
"\n",
" plt.title(title + (' -- SWAP 4s<->4p' if do_swap else ''))\n",
" plt.legend(loc='upper right', ncol=2)\n",
Expand All @@ -355,7 +357,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -369,7 +371,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
27 changes: 8 additions & 19 deletions notebooks/Spin-dependent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
Expand All @@ -32,9 +30,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stderr",
Expand All @@ -48,16 +44,14 @@
"source": [
"try:\n",
" plt.style.use('latex_thesis')\n",
"except FileNotFoundError:\n",
"except (FileNotFoundError, OSError):\n",
" print(\"Can't use my favourite plotting style... oh well\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -76,7 +70,6 @@
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
Expand Down Expand Up @@ -122,9 +115,7 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -184,9 +175,7 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -265,7 +254,7 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -279,7 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.5"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 247a50b

Please sign in to comment.