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

Migdal cox model #17

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3c0fa9c
Add halo_model param description to docstring
lorenzomag Jul 14, 2024
b0fe5f2
Add basic file
lorenzomag Jul 22, 2024
a40921d
Moved Ibe's model
lorenzomag Jul 22, 2024
9ce21df
Added Cox model package at tag
lorenzomag Jul 22, 2024
b851471
Moving submodule
lorenzomag Aug 6, 2024
328478a
Updating import statements
lorenzomag Aug 6, 2024
5ad10fc
Add utility function to preformat data for Cox's interpolators
lorenzomag Aug 6, 2024
ef27b65
Wrapper module to include Cox's package
lorenzomag Aug 6, 2024
28ba5d8
Add docstring to cox_wrapper.py
lorenzomag Aug 6, 2024
6fc1f86
Implemented Peter Cox et al. Migdal model
lorenzomag Aug 6, 2024
e4a5802
Remove debug print statement
lorenzomag Aug 6, 2024
502fa08
Add dockstrings
lorenzomag Aug 6, 2024
6128b40
Update tutorial notebook for Migdal
lorenzomag Aug 6, 2024
8bde989
Remove typing.Self for python3.9
lorenzomag Aug 6, 2024
e0d51d4
Require seaborn
lorenzomag Aug 6, 2024
f8e8684
Add output to notebook
lorenzomag Aug 6, 2024
9e6db2f
Revert "Remove typing.Self for python3.9"
lorenzomag Aug 6, 2024
5b608a5
Revert "Require seaborn"
lorenzomag Aug 6, 2024
e6d05cc
Require Python3.11
lorenzomag Aug 6, 2024
ea47279
Require importlib package for Cox model
lorenzomag Aug 6, 2024
1eed196
Add __init__.py in tests to fix module structure
lorenzomag Aug 6, 2024
853c4f0
Add all content of data/ for build
lorenzomag Aug 6, 2024
c95fdbe
Add deprecation warning for old func
lorenzomag Aug 6, 2024
986937d
Fix typing
lorenzomag Aug 7, 2024
176bf94
Reduce required python3 version to 3.9
lorenzomag Aug 7, 2024
fd9c56e
Update notebook output
lorenzomag Aug 7, 2024
df7d904
Update pytest.yml
lorenzomag Aug 7, 2024
c1d26c0
Update pytest.yml + fix test
lorenzomag Aug 7, 2024
a7c2e0d
Downgrade jinja for pytest.yml
lorenzomag Aug 7, 2024
d2b44da
Update pytest.yml
lorenzomag Aug 7, 2024
180e391
Update pytest.yml
lorenzomag Aug 7, 2024
1679466
Update pytest.yml
lorenzomag Aug 7, 2024
97fcd25
Update pytest.yml + fix test
lorenzomag Aug 7, 2024
03f61dd
Downgrade jinja for pytest.yml
lorenzomag Aug 7, 2024
f5db5f7
Update pytest.yml
lorenzomag Aug 7, 2024
8866e90
Update pytest.yml
lorenzomag Aug 7, 2024
e5d38ef
Revert "Update pytest.yml"
lorenzomag Aug 8, 2024
c9d9d42
Revert "Update pytest.yml"
lorenzomag Aug 8, 2024
e579c2f
Revert "Downgrade jinja for pytest.yml"
lorenzomag Aug 8, 2024
7859f3e
Revert "Update pytest.yml + fix test"
lorenzomag Aug 8, 2024
687bc5e
Revert "Update pytest.yml"
lorenzomag Aug 8, 2024
020d015
Add halo_model param description to docstring
lorenzomag Jul 14, 2024
3e4ad01
Add basic file
lorenzomag Jul 22, 2024
393ef75
Moved Ibe's model
lorenzomag Jul 22, 2024
6af8458
Added Cox model package at tag
lorenzomag Jul 22, 2024
453eb5b
Moving submodule
lorenzomag Aug 6, 2024
6254779
Updating import statements
lorenzomag Aug 6, 2024
5dc19ac
Add utility function to preformat data for Cox's interpolators
lorenzomag Aug 6, 2024
c9a703a
Wrapper module to include Cox's package
lorenzomag Aug 6, 2024
331f4b8
Add docstring to cox_wrapper.py
lorenzomag Aug 6, 2024
2050efc
Implemented Peter Cox et al. Migdal model
lorenzomag Aug 6, 2024
0978c49
Remove debug print statement
lorenzomag Aug 6, 2024
d4b33d2
Add dockstrings
lorenzomag Aug 6, 2024
4fcb1bd
Update tutorial notebook for Migdal
lorenzomag Aug 6, 2024
0380e5a
Remove typing.Self for python3.9
lorenzomag Aug 6, 2024
381a30d
Require seaborn
lorenzomag Aug 6, 2024
1113870
Add output to notebook
lorenzomag Aug 6, 2024
28e67a3
Revert "Remove typing.Self for python3.9"
lorenzomag Aug 6, 2024
cc39206
Revert "Require seaborn"
lorenzomag Aug 6, 2024
0b79d66
Require Python3.11
lorenzomag Aug 6, 2024
a0ada21
Require importlib package for Cox model
lorenzomag Aug 6, 2024
426a0ed
Add __init__.py in tests to fix module structure
lorenzomag Aug 6, 2024
7b3fbc9
Add all content of data/ for build
lorenzomag Aug 6, 2024
f59cc33
Add deprecation warning for old func
lorenzomag Aug 6, 2024
fa79a1a
Fix typing
lorenzomag Aug 7, 2024
e69cc84
Reduce required python3 version to 3.9
lorenzomag Aug 7, 2024
65430fa
Update notebook output
lorenzomag Aug 7, 2024
c71e0c6
Revert "Update pytest.yml"
lorenzomag Aug 8, 2024
1714627
Revert "Update pytest.yml"
lorenzomag Aug 8, 2024
07ca8ba
Revert "Downgrade jinja for pytest.yml"
lorenzomag Aug 8, 2024
5955350
Revert "Update pytest.yml + fix test"
lorenzomag Aug 8, 2024
3033247
Revert "Update pytest.yml"
lorenzomag Aug 8, 2024
86d8f2c
Merge branch 'migdal_cox_model' of github.com:lorenzomag/wimprates in…
lorenzomag Aug 9, 2024
5286f6c
Rebase on update_cicd
lorenzomag Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,36 @@ jobs:
# Test coveralls (with numba disabled) and normal pytest
test: [ 'coveralls', 'pytest', ]
# Only do coveralls once; pytest on all python versions
python-version: [3.8, 3.9, "3.10"]
python-version: [3.9, "3.10", "3.11", "3.12"]
exclude:
- python-version: 3.8
- python-version: 3.10
test: coveralls
- python-version: 3.9
- python-version: 3.11
test: coveralls
- python-version: 3.12
test: coveralls
steps:
- name: Setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Install requirements for tests
run: |
pip install --upgrade pip
# Require setuptools for python3.12 as well
pip install setuptools
# Requirements for running the notebooks as a pytest
pip install cython ipython
pip install jinja2==3.0.3
pip install nbconvert 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
pip install -e .
pip install seaborn matplotlib
- name: Test package
if: matrix.test == 'pytest'
run:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "wimprates/data/migdal/Cox"]
path = wimprates/data/migdal/Cox/cox_submodule
url = https://github.com/petercox/Migdal.git
1,378 changes: 931 additions & 447 deletions notebooks/Migdal.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pandas
tqdm
boltons
numericalunits
importlib_metadata
53 changes: 31 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
import setuptools

readme = open('README.md').read()
history = open('HISTORY.md').read().replace('.. :changelog:', '')
requirements = open('requirements.txt').read().splitlines()
readme = open("README.md").read()
history = open("HISTORY.md").read().replace(".. :changelog:", "")
requirements = open("requirements.txt").read().splitlines()

setuptools.setup(
name='wimprates',
version='0.5.0',
description='Differential rates of WIMP-nucleus scattering',
long_description=readme + '\n\n' + history,
long_description_content_type='text/markdown',
author='Jelle Aalbers',
url='https://github.com/jelleaalbers/wimprates',
license='MIT',
name="wimprates",
version="0.5.0",
description="Differential rates of WIMP-nucleus scattering",
long_description=readme + "\n\n" + history,
long_description_content_type="text/markdown",
author="Jelle Aalbers",
url="https://github.com/jelleaalbers/wimprates",
license="MIT",
packages=setuptools.find_packages(),
setup_requires=['pytest-runner'],
setup_requires=["pytest-runner"],
install_requires=requirements,
package_dir={'wimprates': 'wimprates'},
package_data={'wimprates': [
'data/bs/*', 'data/migdal/*', 'data/sd/*', 'data/dme/*']},
tests_require=requirements + ['pytest', 'unittest'],
keywords='wimp,spin-dependent,spin-independent,bremsstrahlung,migdal',
classifiers=['Intended Audience :: Science/Research',
'Development Status :: 3 - Alpha',
'Programming Language :: Python',
'Programming Language :: Python :: 3'],
zip_safe=False)
package_dir={"wimprates": "wimprates"},
package_data={
"wimprates": ["data/bs/*", "data/migdal/**", "data/sd/*", "data/dme/*"]
},
tests_require=requirements + ["pytest", "unittest"],
keywords="wimp,spin-dependent,spin-independent,bremsstrahlung,migdal",
classifiers=[
"Intended Audience :: Science/Research",
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
python_requires=">=3.9",
zip_safe=False,
)
Empty file added tests/__init__.py
Empty file.
17 changes: 15 additions & 2 deletions tests/test_wimprates.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,19 @@ def test_spindependent(self):
0.00019944698779638946)


def test_migdal(self):
self.assertAlmostEqual(wr.rate_wimp_std(1, detection_mechanism='migdal', **self.opts),
def test_migdal_Ibe(self):
self.assertAlmostEqual(wr.rate_wimp_std(1, detection_mechanism='migdal', migdal_model="Ibe", **self.opts),
0.27459766238555017)


def test_migdal_Cox(self):
self.assertAlmostEqual(wr.rate_wimp_std(1, detection_mechanism='migdal', migdal_model="Cox", **self.opts),
0.2843514286729741)


def test_migdal_Cox_dipole(self):
self.assertAlmostEqual(wr.rate_wimp_std(1, detection_mechanism='migdal', migdal_model="Cox", dipole=True, **self.opts),
0.30438231874513705)


def test_brems(self):
Expand Down Expand Up @@ -104,3 +114,6 @@ def test_average_v_earth(self):
# places=1 means that we get the same results at the first decimal (fine for 500.0<?>)
places=1
)

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion wimprates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
from .migdal import *
from .electron import *
from .summary import *

from .data.migdal.Cox.cox_wrapper import *
1 change: 1 addition & 0 deletions wimprates/data/migdal/Cox/cox_submodule
Submodule cox_submodule added at 99bb84
51 changes: 51 additions & 0 deletions wimprates/data/migdal/Cox/cox_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
The paths in the code in Peter Cox's package assume the working directory to be
the root of its package. With this wrapper we change the working dir when computing
the interpolators, then returning the Migdal class instance once they've been instantiated.
The working directory is then reset.
"""

import os
import sys

import wimprates as wr

from .cox_submodule.Migdal import Migdal

export, __all__ = wr.exporter()


@export
def cox_migdal_model(element: str, **kwargs) -> Migdal:
"""
This function creates a Cox Migdal model for a given element.

Parameters:
- element (str): The element for which the Cox Migdal model is created.
- **kwargs: Additional keyword arguments for loading probabilities and total probabilities.

Returns:
- material: The Cox Migdal material object.

Example usage:
cox_migdal_model("carbon", arg1=value1, arg2=value2)

Note: The Cox's model assumes that the main process is running in its root directory and uses
relative paths. Therefore, we need to switch the working directory to the root of the package
when computing the interpolators.
This wrapper function changes the working directory temporarily, instantiates the Migdal class,
and then resets the working directory back to its original state.
"""
original_cwd = os.getcwd()

try:
migdal_directory = os.path.join(os.path.dirname(__file__), "cox_submodule")
os.chdir(migdal_directory)

material = Migdal(element)
material.load_probabilities(**kwargs)
material.load_total_probabilities(**kwargs)
finally:
os.chdir(original_cwd)

return material
File renamed without changes.
File renamed without changes.
Loading
Loading