├── .github ├── scripts │ └── setup-osx.sh └── workflows │ ├── pypi_install.yml │ └── test_package.yml ├── .gitignore ├── .gitmodules ├── AUTHORS.md ├── CMakeLists.txt ├── HISTORY.md ├── LICENSE ├── README.md ├── conda.recipe └── meta.yaml ├── pyproject.toml ├── requirements.txt ├── setup.py ├── src └── nestpy │ ├── __init__.py │ ├── bindings.cpp │ └── helpers.py ├── tests ├── core_nest_tests.py └── example_tests.py ├── travis.yml └── tutorials ├── InstallAndBasicUsage.ipynb └── arxiv ├── benchmark_plots.py ├── how_to_maintain.ipynb ├── nestpy_tutorial.ipynb └── setup_notebook.py /.github/scripts/setup-osx.sh: -------------------------------------------------------------------------------- 1 | wget -q https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh 2 | 3 | # Install 4 | chmod +x miniconda.sh 5 | ./miniconda.sh -b -p $HOME/miniconda 6 | 7 | # Setup miniconda and environment 8 | export PATH=$HOME/miniconda/bin:$PATH 9 | conda config --set always_yes yes --set changeps1 no 10 | conda create -q -n nestpy python=${PYTHON} numpy 11 | source activate nestpy 12 | -------------------------------------------------------------------------------- /.github/workflows/pypi_install.yml: -------------------------------------------------------------------------------- 1 | # Let's upload nestpy to PyPi to make it pip installable 2 | # Mostly based on https://github.com/marketplace/actions/pypi-publish 3 | # Some of this is a bit clunky, we have both Linux and MacOS build. 4 | # We apply the following strategy: 5 | # - For Mac, run both MacOS-latest (11.xx) and MacOS-10.15. The latter 6 | # seems to be required for to properly build the wheels commonly used. 7 | # For each python version and MacOS version, we run a separate action 8 | # to complete all the required wheels. 9 | # - For linux, use a nice pre-defined docker image from 10 | # "RalfG/python-wheels-manylinux-build@v0.4.2-manylinux2014_x86_64" 11 | # to build the wheels. This allows us to build several wheels in one 12 | # go. We build newer python versions explicitly with numpy 1.21 13 | # (though this is probably not strictly required). 14 | 15 | name: Pipy 16 | on: 17 | workflow_dispatch: 18 | release: 19 | types: [ published ] 20 | 21 | jobs: 22 | build: 23 | runs-on: ${{ matrix.os }} 24 | strategy: 25 | fail-fast: False 26 | matrix: 27 | python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"] 28 | os: [ "ubuntu-latest" , "macos-latest", "macos-10.15"] 29 | exclude: 30 | - python-version: 3.6 31 | os: "ubuntu-latest" 32 | - python-version: 3.7 33 | os: "ubuntu-latest" 34 | - python-version: 3.6 35 | os: "macos-latest" 36 | - python-version: 3.7 37 | os: "macos-latest" 38 | - python-version: 3.9 39 | os: "ubuntu-latest" 40 | - python-version: "3.10" 41 | os: "ubuntu-latest" 42 | steps: 43 | # Setup steps 44 | - name: Setup python 45 | uses: actions/setup-python@v3 46 | with: 47 | python-version: ${{ matrix.python-version }} 48 | - name: Checkout repo 49 | uses: actions/checkout@v3 50 | with: 51 | submodules: recursive 52 | 53 | - name: Install dependencies 54 | run: pip install wheel twine 55 | 56 | # -- Linux -- 57 | - name: Build weels (linux) python 3.8, 3.9, 3.10, 3.11 58 | if: matrix.os == 'ubuntu-latest' 59 | uses: RalfG/python-wheels-manylinux-build@v0.4.2-manylinux2014_x86_64 60 | with: 61 | python-versions: 'cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311' 62 | build-requirements: 'numpy==1.21.6' 63 | - name: Build legacy weels (linux) python 3.6, 3.7 64 | if: matrix.os == 'ubuntu-latest' 65 | uses: RalfG/python-wheels-manylinux-build@v0.4.2-manylinux2014_x86_64 66 | with: 67 | python-versions: 'cp36-cp36m cp37-cp37m' 68 | build-requirements: 'numpy' 69 | - name: Publish wheels to PyPI (linux) 70 | if: matrix.os == 'ubuntu-latest' 71 | env: 72 | TWINE_USERNAME: __token__ 73 | TWINE_PASSWORD: ${{ secrets.pypi_password }} 74 | run: | 75 | twine upload dist/*-manylinux*.whl 76 | 77 | # -- MacOS -- 78 | - name: Build package (MAC) 79 | if: matrix.os != 'ubuntu-latest' 80 | env: 81 | TWINE_USERNAME: __token__ 82 | TWINE_PASSWORD: ${{ secrets.pypi_password }} 83 | run: 84 | | 85 | python setup.py bdist_wheel 86 | python -m twine upload -u "${TWINE_USERNAME}" -p "${TWINE_PASSWORD}" dist/*; 87 | -------------------------------------------------------------------------------- /.github/workflows/test_package.yml: -------------------------------------------------------------------------------- 1 | # Test package every time 2 | name: Pytest 3 | 4 | on: 5 | workflow_dispatch: 6 | release: 7 | types: [ created ] 8 | pull_request: 9 | push: 10 | branches: 11 | - master 12 | 13 | jobs: 14 | update: 15 | name: "(${{ matrix.os }}, ${{ matrix.python-version }}, ${{ matrix.test }})" 16 | runs-on: ${{ matrix.os }} 17 | strategy: 18 | fail-fast: False 19 | matrix: 20 | os: [ "ubuntu-latest" , "macos-latest" ] 21 | python-version: [ 3.6, 3.7, 3.8, 3.9, "3.10", "3.11" ] 22 | exclude: 23 | - python-version: 3.6 24 | os: "ubuntu-latest" 25 | - python-version: 3.6 26 | os: "macos-latest" 27 | - python-version: 3.7 28 | os: "macos-latest" 29 | steps: 30 | - name: Setup python 31 | uses: actions/setup-python@v2.3.1 32 | with: 33 | python-version: ${{ matrix.python-version }} 34 | - name: Checkout repo 35 | uses: actions/checkout@v2.4.0 36 | with: 37 | submodules: recursive 38 | - name: macos pre-install 39 | if: matrix.os == 'macos-latest' 40 | run: source .github/scripts/setup-osx.sh 41 | - name: pre install numpy 42 | if: matrix.python-version == 3.6 43 | run: pip install numpy==1.13 44 | - name: test install 45 | run: | 46 | pip install wheel 47 | pip install . 48 | python tests/core_nest_tests.py 49 | python tests/example_tests.py 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | dist/* 3 | .DS_store 4 | .idea/* 5 | nestpy/.DS_Store 6 | nestpy/nestpy.egg-info/ 7 | nestpy/__pycache__/ 8 | nestpy/nestpy.cpython-38-darwin.so 9 | tests/__pycache__/ 10 | venv/ 11 | *.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/nest"] 2 | path = lib/nest 3 | url = https://github.com/NESTCollaboration/nest # change this to any custom fork of NEST if you want to use your own code! 4 | [submodule "lib/gcem"] 5 | path = lib/gcem 6 | url = https://github.com/kthohr/gcem.git 7 | [submodule "lib/pybind11"] 8 | path = lib/pybind11 9 | url = https://github.com/pybind/pybind11.git 10 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Authors 2 | 3 | ## Python bindings 4 | 5 | * Greg Rischbieter @grischbieter 6 | * Nicholas Carrara @infophysics 7 | * Sophia Andaloro @sophiaandaloro 8 | * Christopher Tunnell @tunnell 9 | 10 | ## NEST 11 | 12 | For the NEST library that this wraps, this was made by the NEST Collaboration (http://nest.physics.ucdavis.edu) 13 | 14 | ## Other 15 | 16 | For indirect help: 17 | 18 | * Henry Shreiner @henryiii 19 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (CMAKE_CXX_STANDARD 17) 2 | cmake_minimum_required(VERSION 2.8.12) 3 | project(nestpy) 4 | 5 | # Set source directory 6 | set(SOURCE_DIR "lib/nest/src") 7 | # Tell CMake that headers are also in SOURCE_DIR 8 | include_directories( 9 | "lib/nest/include/NEST/" 10 | "lib/nest/include/Detectors" 11 | "lib/gcem/include" 12 | ) 13 | 14 | ############### Get NEST version from git ##################### 15 | execute_process(COMMAND git describe --tag 16 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/nest/ 17 | OUTPUT_VARIABLE NEST_VERSION 18 | OUTPUT_STRIP_TRAILING_WHITESPACE) 19 | 20 | function(get_versions versionString version) 21 | if ("${versionString}" STREQUAL "") 22 | set(version "0.0.0" PARENT_SCOPE) 23 | return() 24 | endif () 25 | 26 | string(REGEX REPLACE "v([0-9]*)([.][0-9]*[.][0-9]*-?.*)$" "\\1" numbers ${versionString}) 27 | set(major ${numbers}) 28 | string(REGEX REPLACE "v([0-9]*[.])([0-9]*)([.][0-9]*-?.*)$" "\\2" numbers ${versionString}) 29 | set(minor ${numbers}) 30 | string(REGEX REPLACE "v([0-9]*[.][0-9]*[.])([0-9]*)(-?.*)$" "\\2" numbers ${versionString}) 31 | set(patch ${numbers}) 32 | set(version "${major}.${minor}.${patch}" PARENT_SCOPE) 33 | endfunction() 34 | 35 | get_versions("${NEST_VERSION}" version) 36 | set(NEST_VERSION ${version}) 37 | 38 | set(SOURCES "${SOURCE_DIR}/NEST.cpp" "${SOURCE_DIR}/LArNEST.cpp" "${SOURCE_DIR}/RandomGen.cpp" "${SOURCE_DIR}/VDetector.cpp" "${SOURCE_DIR}/execNEST.cpp" "${SOURCE_DIR}/TestSpectra.cpp" "${SOURCE_DIR}/GammaHandler.cpp" "${SOURCE_DIR}/ValidityTests.cpp") 39 | 40 | # Generate Python module 41 | add_subdirectory(lib/pybind11) 42 | pybind11_add_module(nestpy ${SOURCES} "src/nestpy/bindings.cpp") 43 | 44 | target_compile_definitions(nestpy 45 | PRIVATE NESTPY_VERSION=${NESTPY_VERSION_INFO} NEST_VERSION=${NEST_VERSION}) 46 | 47 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | 2 | History 3 | ======= 4 | 5 | Patch releases mean (the Z number in X.Y.Z version) that the underlying physics has not changed. Changes to the NEST version will always trigger a minor or major release. If this library changes such that end users have to change their code, this may also trigger a minor or major release. 6 | 7 | 2.0.4 (2024-07-18) 8 | ----------------- 9 | Minor Changes: 10 | * Updated workflows for github and pypi tests; restores the ability to upload tagged nestpy releases to PyPi servers. 11 | * Updated author contact information 12 | * Added Python 3.11 compatibility 13 | 14 | 2.0.3 (2024-05-23) 15 | ----------------- 16 | Minor Changes: 17 | * Added the ability to lock and unlock the random seed 18 | * Removed Constraints in helpers.py that prevented vectorized yield equations from return high-energy yields. 19 | 20 | 2.0.2 (2024-01-29) 21 | ----------------- 22 | Synced with NEST v2.4.0 23 | 24 | 2.0.1 (2023-01-18) 25 | ----------------- 26 | Updated python bindings to sync with NEST v2.3.12 27 | * GetYields has been updated to allow for the beta ER model parameters to be user-controllable parameters 28 | ** Introduced the new default vector `ERYieldsParam` for use with GetYields 29 | 30 | * Default parameter vectors have been moved from NESTcalc declarations to globally available vectors from NEST.hh 31 | 32 | 2.0.0 (2022-09-08) 33 | ----------------- 34 | Update to nestpy internals, adding in basic LArNEST bindings 35 | * The copy/paste method for the NEST bindings have been replaced with adding NEST and other modules (such as gcem and pybind11) as git submodules which are downloaded at compile time. LXe notebooks and python scripts have been moved to tutorials/arxiv, and new notebooks will be placed in the tutorials folder as they are created in the future. LAr functionality through LArNEST has been added and will be expanded upon in future releases. 36 | 37 | * Suggestions/issues/errors should be added as github issues. 38 | 39 | * Users may have to do before installing: 40 | ** `pip uninstall nestpy` 41 | 42 | 43 | 1.5.5 (2022-07-08) 44 | ----------------- 45 | Synced with NEST v2.3.9 46 | * New Physics Modeling: 47 | ** Skewness can be turned off and on now for ER just like for NR. For on -> old model or fixed (Quentin Riffard, LZ/LBNL) 48 | ** Older beta model is default for gaseous Xenon, a better fit to old world data at the keV scale (Eric Church, DUNE/PNNL) 49 | ** New dark matter halo model defaults, bringing NEST up to date on WIMP and Sun v (Baxter et al., arXiv:2105.00599) 50 | 51 | * Miscellaneous Bug Fixes: 52 | ** Fluctuations adjust for difference in width from truncated Gaussians for PE not just mean 53 | ** Complaint that position resolution too poor does not activate until above S2 (top) of 40 PE 54 | ** In the dE/dx-based model the minimum LET is now 1.0 MeV/cm not 0 to avoid weirdness 55 | 56 | * Updated binding for GetQuanta to allow for nestpy control over ER skewness. 57 | 58 | 59 | 1.5.4 (2022-04-16) 60 | ----------------- 61 | nestpy specific code quality: 62 | * Thanks to the great help of Joran Angevaare, we now use GitHub workflows and no longer use Travis for releases and testing. 63 | * `pip install nestpy` works again. 64 | * Should one want to recompile from source, you will still need to use `git clone` (for now). 65 | 66 | 67 | 1.5.3 (2022-04-15) 68 | ----------------- 69 | **Development version, not installable** 70 | * No new physics or implementation beyond developing a stable release workflow. 71 | * There will not be a release associated with this version since we wanted to test the entire workflow. The stable release one should use to incorporate changes from 2022-02-09 (`NEST v2.3.5`) is `nestpy v1.5.4.` 72 | 73 | 1.5.2 (2022-04-11) 74 | ----------------- 75 | New Physics: 76 | * Perfectly vertical MIP tracks now work, and use latest beta model (Greg Rischbieter, LZ/UAlbany) 77 | * Field in G4 in any direction not just vertical but e.g. radial OK, ala (n)EXO and PETALO (Paola Ferrario) 78 | 79 | Code Quality: 80 | * NEST: Geant4.9.11 & C++17 compatibility achieved (Paola Ferrario, PETALO/Basque Foundation for Science) 81 | * Multiple scatter code warning addressed: unused variable (Greg Rischbieter, LZ/UAlbany) 82 | 83 | nestpy Specific: 84 | * N/A 85 | 86 | 1.5.1 (2022-02-09) 87 | ----------------- 88 | New Physics: 89 | * dE/dx-based yield code moved (execNEST->NEST.cpp) for accessibility. Muons, MIPs, LIPs; random positions 90 | * Initial or average dE/dx allowed, and use of ESTAR or custom power law, with variation around a mean dE/dx 91 | * loopNEST for ER restored, with 1st-principles mod TIB model of recombination parameters for sustainability 92 | * New multiple scatter tool allows for creation of 2+ ER-like/NR-like scatters, or mixed for inelastic, Migdal, etc. 93 | 94 | Code Quality and/or Miscellaneous Bug Fixes: 95 | * random exponential smarter sampling for small ranges especially for Kr83m times (Scott Kravitz, LZ/LBNL) 96 | * D-D energy spectrum user-settable, serving as example for any NR calibrations (Greg Rischbieter, LZ/UAlbany) 97 | * New truncated Gauss option, w/ truncation at 0 in 1st usage to solve S2 corner case (Scott Kravitz, LZ/LBNL) 98 | 99 | nestpy Specific: 100 | * N/A 101 | 102 | 1.5.0 (2021-11-11) 103 | ----------------- 104 | New Physics: 105 | * Carried over from v2.3 beta: A new binomial random number generator (C++ default library), e- EE models, beta model with new yields and fluctuations, non-beta-ER (XELDA). 106 | * New beta model is default regardless of E-field, but old one is still accessible 107 | * ER model (betas and gammas weighted) is its own function, callable 108 | * Pb-206 ion coming off wall from alpha decay has correct Ly and Qy versus field (Thomas-Imel box model for recomb) 109 | * The electron extraction efficiency model now includes “optimistic” high e- EE Aprile/PandaX fits (activatable with EPS_GAS negative) 110 | 111 | Code Quality and/or Miscellaneous Bug Fixes: 112 | * C++11 -> 17 default, README updated with all new versioning requirements, but old gcc and cmake versions requested to allow backwards-compatibility with nestpy. std::clamp still doesn’t work, so similar function written by hand 113 | * 1.1 -> 1.08 for increasing Qy to match new Zurich W-value measurement, but with new more logical variable names both deep in code and in detector file for user, and with one factor universal in NEST.cpp; general variable renaming for greater clarity 114 | * Numerous cosmetic and aesthetic changes to code, including unused variable removal, while spacing and tabbing made Google clang-format (with shell script for that now included with NEST), if/else Mac dangle warning addressed 115 | * Kr83m yields same but code overhauled to allow min versus max time separation flexibility and easier data comparison, with bug squashed where wrong error message got replayed 116 | * NEST is now 30% faster, cf. v2.2.4, at least when using gcc 7+, despite the new binomial fluctuation function! 117 | 118 | nestpy Specific: 119 | * Bindings to energy spectra generators from TestSpectra.cpp, including: tritium and C14 beta sources; AmBe, DD, Cf252 neutron sources; Spin-Independent WIMP Generators. 120 | 121 | 1.4.12 (2021-11-02) 122 | ----------------- 123 | Sync with [NEST v2.3.0beta](https://github.com/NESTCollaboration/nest/releases/tag/v2.3.0beta) 124 | 125 | * Beta model updated to work with LUX C-14 (medium E-fields) in addition to XENON1T Rn-220 calibration, < 100 V/cm (Greg Rischbieter, Matthew Szydagis, Vetri Velan, and Quentin Riffard of LZ) 126 | * Non-beta (L-shell and M-shell) ER data now matched, from the XELDA experiment, with weighting of beta and gamma models (Sophia Farrell, Rice/XENON and Greg R. UAlbany/LZ) 127 | * Work function of 11.5 eV (EXO-200, Zurich) can now be more accurately reproduced with the "remove quanta" flag set to false, matching the EXO and Baudis (new) data sets (Kirsten McMichael, RPI/nEXO and Matthew Szydagis, UAlbany/LZ) 128 | * Systematic error taken into account for 3D XYZ position reconstruction with S2, per LUX Mercury paper (Claudio Silva, Coimbra/LZ). 129 | * Made the default S1 calculation mode hybrid instead of full, for faster simulation of large-energy (e.g., MeV-scale) events 130 | * Tweaked the default detector example (LUX Run03) to work with the latest models and reproduce D-D and 3H bands perfectly still, while also adding units to this LUX detector header file (Szydagis) 131 | * Binomial random number generator now uses default C++ library (Robert James, LZ). Code is a bit slower now (only by ~10%) but is more precise, and matches python, Flamedisx 132 | * The e- ext eff from liquid to gas is now based on both E-field (in liquid) and temperature, not field alone, combining dozen data sets spanning decades, to address concern raised by Sergey Pereverzev, LLNL. So, it's NOT just PIXeY or LLNL, etc. 133 | 134 | 1.4.11 (2021-08-09) 135 | ----------------- 136 | Sync with [NEST v2.2.3](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.3) 137 | 138 | * Replaced useTiming variable by an enum and made the GetS1 result a class member. Separated the S1 and S2 calculation modes. 139 | * Made GetS1 return a ref to avoid vector copy 140 | * Made the GetS2 results a private member returned by reference, while also making GetS1 and GetS2 results "const" 141 | * Removed useless, unused variables that caused a lot of memory allocation/deallocation; result of all this and the above: +~1-5% faster 142 | * Updated the parametric S1 calc to account for the truncated-Gaussian SPE and DPE distributions, making it more consistent with "full" 143 | * Changed hybrid-mode transition to be 100 keV, ~500 photon hits in modern TPCs, instead of hits directly, creating a smooth transition 144 | * Efficiency adjustment in the S1 parametric mode that further makes the parametric and full modes (previously useTiming -1,0) closer. 145 | * Changes driven by Quentin Riffard (LZ/LBNL) & Greg Rischbieter (LZ/UA), with ideas from Matthew (UA) & Luke Kreczko (Bristol) 146 | 147 | 1.4.10 (2021-07-08) 148 | ----------------- 149 | Sync with [NEST v2.2.2](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.2) 150 | 151 | Code Quality and/or Misc Bug Fixes: 152 | * Added default density argument for LXe case, forcing an argument re-ordering (Sophia) 153 | * Moved position of "delete detector" in execNEST to solve python problem (Albert Baker, Greg R.) 154 | * Approx eff func for single phe made simpler, for FlameDisx (Robert James, Sophia, Matthew) 155 | * More robust rule used for when to approximate binomial as Gaussian (Sophia, Greg R.) 156 | * Warn that you are in a region of too-low time between S1a and S1b for Kr83m only 1x (Sophia) 157 | * Bad-order if-statements simplified with a min within a max for <0, >1 checks (Luke K., Matthew) 158 | New Physics: 159 | * Liquid Ar model for ER fits all the data better now, in both energy and dE/dx bases (Kate K.) 160 | 161 | Code Quality and/or Miscellaneous Bug Fixes: 162 | * Deleted unused redundant line in GetS1 that re-calculated the drift time (Quentin Riffard, LBNL/LZ) 163 | * Only print most error and warning messages if verbosity on (Quentin Riffard, LBNL/LZ) 164 | * Updated TravisCI link in README and added note about OSX builds (Chris Tunnell, Rice/XENON) 165 | * Use of abs value func standardized, lines broken up, multi-line string for cerr (Matthew at behest of Luke Kreczko, Bristol/LZ) 166 | New Physics: 167 | * Liquid Xe model for NR is now better behaved at few hundred keV and few hundred in S1: no odd increase in band width caused by Nex/Ni zeroing out and kinking the recombination probability. Mean yields model unchanged, nor recombination fluctuations / skewness. (Matthew and Greg R., UAlbany/LZ) 168 | 169 | 1.4.9 (2021-06-01) 170 | ----------------- 171 | Sync with [NEST v2.2.1patch2](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.1patch2) 172 | 173 | Code Quality and/or Misc Bug Fixes: 174 | * Added default density argument for LXe case, forcing an argument re-ordering (Sophia) 175 | * Moved position of "delete detector" in execNEST to solve python problem (Albert Baker, Greg R.) 176 | * Approx eff func for single phe made simpler, for FlameDisx (Robert James, Sophia, Matthew) 177 | * More robust rule used for when to approximate binomial as Gaussian (Sophia, Greg R.) 178 | * Warn that you are in a region of too-low time between S1a and S1b for Kr83m only 1x (Sophia) 179 | * Bad-order if-statements simplified with a min within a max for <0, >1 checks (Luke K., Matthew) 180 | New Physics: 181 | * Liquid Ar model for ER fits all the data better now, in both energy and dE/dx bases (Kate K.) 182 | 183 | 1.4.8 (2021-04-09) 184 | ----------------- 185 | Sync with [NEST v2.2.1patch1](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.1patch1) 186 | 187 | 1.4.7 (2021-03-03) 188 | ----------------- 189 | Sync with [NEST v2.2.1](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.1) 190 | * Cleaned up MANIFEST so pypi dist packages are less bulky 191 | [#56](https://github.com/NESTCollaboration/nestpy/pull/56) 192 | * Added floating point comparison method for equality checks 193 | [#54](https://github.com/NESTCollaboration/nestpy/pull/54) 194 | * Random Number Generation in bindings.cpp to ensure quanta are truly randomized. 195 | [#54](https://github.com/NESTCollaboration/nestpy/pull/54) 196 | * Binding to Kr83m yields model directly so users can specify explicity deltaT_ns between decay modes. 197 | [#55](https://github.com/NESTCollaboration/nestpy/pull/55) 198 | 199 | 1.4.5-1.4.6 (2021-03-01) 200 | ----------------- 201 | (Pre-releases, see version 1.4.7 for distributions) 202 |
203 | Sync with [NEST v2.2.1](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.1) 204 | 205 | 1.4.4 (2021-02-10) 206 | ----------------- 207 | NEST v2.2.0 (no NEST changes) 208 | * PyPi calls improved to compile for linux 209 | 210 | 1.4.3 (2021-02-08) 211 | ----------------- 212 | NEST v2.2.0 (no NEST changes) 213 | * Attempted bug fix (fixed properly in 1.4.4) 214 | * New tutorials directory 215 | 216 | 1.4.2 (2021-02-01) 217 | ----------------- 218 | * Bind with LUX detector file 219 | * Fix interaction key interpretation in helpers 220 | 221 | 1.4.1 (2020-12-15) 222 | ----------------- 223 | Sync with v2.2.0 NEST. 224 | Includes all files in MANIFEST.in, so that pip install will work. 225 | 226 | 1.4.0 (2020-11-19) 227 | ----------------- 228 | Minor changes all are to fix software bugs, no physics changes. 229 | 230 | * MANIFEST.in include requirements 231 | * Make sure to include all dependencies. 232 | * Fix travis builds. 233 | 234 | 1.4.0beta (2020-11-14) 235 | ----------------- 236 | 237 | NESTv2.2.0beta 238 | 239 | 1.3.2 (2020-11-11) 240 | ----------------- 241 | 242 | NESTv2.1.2 243 | * New free parameters registered 244 | * Cases of void initialization in tests fixed 245 | * Introduced files for debugging tests as we improve code 246 | * Prepared for NEST v.2.2 which is imminent 247 | * Solved half of GetS1 and GetS2 issues opened in #37 248 | 249 | 250 | 1.3.1 (2020-08-26) 251 | ----------------- 252 | 253 | NESTv2.1.1 254 | 255 | 1.3.0 (2020-07-06) 256 | ------------------ 257 | 258 | NESTv2.1.0 259 | 260 | 1.2.1 (2020-06-20) 261 | ------------------ 262 | 263 | NESTv2.1.0beta 264 | 265 | 1.1.4 (2020-06-20) 266 | ------------------ 267 | 268 | * Update pybind11 2.5.0 269 | * Fix manylinux build 270 | * Add Python 3.8 support 271 | 272 | 1.1.3 (2019-08-05) 273 | ------------------ 274 | 275 | Default arguments for GetYields and GetQuanta (see PR #25) 276 | 277 | 278 | 1.1.2 (2019-08-02) 279 | ------------------ 280 | 281 | NESTv2.0.1 282 | 283 | * execNEST included in nestpy 284 | * Extensive bug fixes and testing improvements 285 | 286 | 1.1.1 (2018-08-29) 287 | ------------------ 288 | 289 | NESTv2.0.0 290 | 291 | * Fix source installation (See #16). 292 | 293 | 1.1.0 (2018-08-18) 294 | ------------------ 295 | 296 | NESTv2.0.0 297 | 298 | * Release to world. 299 | * Cleanup (#15) 300 | 301 | 1.0.3 (2018-08-18) 302 | ------------------ 303 | 304 | NESTv2.0.0 305 | 306 | * README broken links fixed 307 | 308 | 1.0.2 (2018-08-18) 309 | ------------------ 310 | 311 | NESTv2.0.0 312 | 313 | * Metadata (classifier in setup.py, badges, chat) (#14) 314 | 315 | 1.0.1 (2018-08-18) 316 | ------------------ 317 | 318 | NESTv2.0.0 319 | 320 | * Retrigger release for PyPI deployment 321 | 322 | 1.0.0 (2018-08-18) 323 | ------------------ 324 | 325 | NESTv2.0.0 326 | 327 | * First release intended for general public. 328 | * Mac OSX support (#10) 329 | * Complete tests and various bug fixes (#13) 330 | * Documentation, citation, and technical detail writing 331 | 332 | 333 | 0.2.3 (2018-08-14) 334 | ------------------ 335 | 336 | NESTv2.0.0 337 | 338 | * Still working on PyPI 339 | 340 | 0.2.2 (2018-08-14) 341 | ------------------ 342 | 343 | NESTv2.0.0 344 | 345 | * Fix lack of deploy of release to PyPI 346 | 347 | 0.2.1 (2018-08-14) 348 | ------------------ 349 | 350 | NESTv2.0.0 351 | 352 | * Fix tests that were breaking only in deploys 353 | 354 | 0.2.0 (2018-08-14) 355 | ------------------ 356 | 357 | NESTv2.0.0 358 | 359 | * Fully wrapped NEST (PR #5) 360 | 361 | 0.1.1 (2018-08-14) 362 | ------------------ 363 | 364 | NESTv2.0.0 365 | 366 | * First release that deploys on PyPI. Limited functionality. (PR #2) 367 | 368 | 0.1.0 (2018-08-14) 369 | ------------------ 370 | 371 | NESTv2.0.0 372 | 373 | * Initial release 374 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nestpy 2 | 3 | [![Join the chat at https://gitter.im/NESTCollaboration/nestpy](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/NESTCollaboration/nestpy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![Pytest](https://github.com/NESTCollaboration/nestpy/actions/workflows/test_package.yml/badge.svg?branch=master)](https://github.com/NESTCollaboration/nestpy/actions/workflows/test_package.yml) 5 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1345595.svg)](https://doi.org/10.5281/zenodo.1345595) 6 | [![PyPi version](https://pypip.in/v/nestpy/badge.png)](https://pypi.org/project/nestpy/) 7 | [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 8 | [![Python Versions](https://img.shields.io/pypi/pyversions/nestpy.svg)](https://pypi.python.org/pypi/nestpy) 9 | [![PyPI downloads](https://img.shields.io/pypi/dm/nestpy.svg)](https://pypistats.org/packages/nestpy) 10 | 11 | Visit the tutorials directory for tutorials on the nestpy calls, maintenance, and benchmark plots. 12 | 13 | These are the Python bindings for the [NEST library](https://github.com/NESTCollaboration/nest), which provides a direct wrapping of functionality. The library is now pythonic, so be weary of the separate naming conventions for functions/variables from the C++ library. 14 | 15 | You do *not* have to have NEST already installed to use this package. 16 | 17 | ## Installing from PyPI 18 | 19 | For 64-bit Linux or Mac systems, instally 'nestpy' should just require running: 20 | 21 | ``` 22 | pip install nestpy 23 | ``` 24 | 25 | You can then test that it works by running the example above. 26 | 27 | ## Installing from source 28 | 29 | Requirements: You must have CMake>=3.6 and a C++17 compatible compiler (GCC>=4.8) to build. 30 | 31 | First, you must check out this repository then simply run the installer: 32 | 33 | ``` 34 | git clone https://github.com/NESTCollaboration/nestpy 35 | cd nestpy 36 | git submodule update --init --recursive 37 | pip install . 38 | ``` 39 | 40 | ## Installing with custom NEST code 41 | 42 | Almost all NEST users will want to incorporate some custom code into their workflow, such as custom Detector files or TestSpectra. In order to incorporate that custom code into the nestpy installation, you'll have to copy the files you've edited into the lib/nest/ directory and rerun: 43 | ``` 44 | pip install . 45 | ``` 46 | 47 | In order to create a more efficient workflow, we suggest the user takes the following steps: 48 | 49 | 1. Fork the official NEST repository into your own public/private one. 50 | 2. Make whatever changes to your fork and maintain them with commits. 51 | 3. Download or fork nestpy and change the NEST entry in the .gitmodules files to point to your custom fork of NEST. 52 | 53 | ``` 54 | [submodule "lib/nest"] 55 | path = lib/nest 56 | url = https://github.com/NESTCollaboration/nest # change this to any custom fork of NEST if you want to use your own code! 57 | [submodule "lib/gcem"] 58 | path = lib/gcem 59 | url = https://github.com/kthohr/gcem.git 60 | [submodule "lib/pybind11"] 61 | path = lib/pybind11 62 | url = https://github.com/pybind/pybind11.git 63 | ``` 64 | 65 | ## Usage 66 | 67 | Python bindings to the NEST library: 68 | 69 | ``` 70 | import nestpy 71 | 72 | # This is same as C++ NEST with naming 73 | nc = nestpy.NESTcalc(nestpy.VDetector()) 74 | 75 | interaction = nestpy.INTERACTION_TYPE(0) # NR 76 | 77 | E = 10 # keV 78 | print('For an %s keV %s' % (E, interaction)) 79 | 80 | # Get particle yields 81 | y = nc.GetYields(interaction, 82 | E) 83 | 84 | print('The photon yield is:', y.PhotonYield) 85 | print('With statistical fluctuations', 86 | nc.GetQuanta(y).photons) 87 | ``` 88 | 89 | For more examples on possible calls, please see the tests and tutorials folders. 90 | 91 | ### Support 92 | 93 | * Bugs: Please report bugs to the [issue tracker on Github](https://github.com/NESTCollaboration/nestpy/issues) such that we can keep track of them and eventually fix them. Please explain how to reproduce the issue (including code) and which system you are running on. 94 | * Help: Help can be provided also via the issue tracker by tagging your issue with 'question' 95 | * Contributing: Please fork this repository then make a pull request. In this pull request, explain the details of your change and include tests. 96 | 97 | ## Technical implementation 98 | 99 | This package is a [pybind11](https://pybind11.readthedocs.io/en/stable/intro.html) wrapper of [NEST](https://github.com/NESTCollaboration/nest) that uses [GitHub Workflows](https://docs.github.com/en/actions/using-workflows) to build binaries using the [manylinux](https://github.com/pypa/python-manylinux-demo) [Docker image](https://www.docker.com) from [this page](https://github.com/RalfG/python-wheels-manylinux-build). 100 | 101 | * Help from Henry Schreiner, which included a great [binding tutorial](https://indico.cern.ch/event/694818/contributions/2985778/attachments/1682465/2703470/PyHEPTalk.pdf) 102 | * Implementation also based on [this](http://www.benjack.io/2018/02/02/python-cpp-revisited.html) 103 | * Implementation of GitHub test and build actions was made possible by [Joran Angevaare](https://github.com/joranangevaare). 104 | 105 | See AUTHORS.md for information on the developers. 106 | 107 | ## Citation 108 | 109 | When you use `nestpy`, please say so in your slides or publications (for publications, see Zenodo link above). You can mention this in addition to how you cite NEST. This is important for us being able to get funding to support this project. 110 | -------------------------------------------------------------------------------- /conda.recipe/meta.yaml: -------------------------------------------------------------------------------- 1 | package: 2 | name: cmake_example 3 | version: 0.0.1 4 | 5 | source: 6 | path: .. 7 | 8 | build: 9 | number: 0 10 | script: python -m pip install . -vvv 11 | 12 | requirements: 13 | build: 14 | - "{{ compiler('cxx') }}" 15 | - cmake 16 | - ninja 17 | 18 | host: 19 | - python 20 | - pip !=22.1.0 21 | 22 | run: 23 | - python 24 | 25 | 26 | test: 27 | requires: 28 | - pytest 29 | imports: 30 | - cmake_example 31 | source_files: 32 | - tests 33 | commands: 34 | - python -m pytest 35 | 36 | about: 37 | summary: Python bindings for NEST. 38 | license_file: LICENSE -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel", 5 | "ninja", 6 | "cmake>=3.12", 7 | ] 8 | build-backend = "setuptools.build_meta" 9 | 10 | [tool.isort] 11 | profile = "black" 12 | 13 | [tool.pytest.ini_options] 14 | minversion = "6.0" 15 | addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] 16 | xfail_strict = true 17 | filterwarnings = ["error"] 18 | testpaths = ["tests"] 19 | 20 | [tool.cibuildwheel] 21 | test-command = "pytest {project}/tests" 22 | test-extras = ["test"] 23 | test-skip = ["*universal2:arm64"] 24 | # Setuptools bug causes collision between pypy and cpython artifacts 25 | before-build = "rm -rf {project}/build" -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import subprocess 4 | import sys 5 | 6 | from setuptools import Extension, setup, find_packages 7 | from setuptools.command.build_ext import build_ext 8 | 9 | # Convert distutils Windows platform specifiers to CMake -A arguments 10 | PLAT_TO_CMAKE = { 11 | "win32": "Win32", 12 | "win-amd64": "x64", 13 | "win-arm32": "ARM", 14 | "win-arm64": "ARM64", 15 | } 16 | 17 | 18 | # A CMakeExtension needs a sourcedir instead of a file list. 19 | # The name must be the _single_ output extension from the CMake build. 20 | # If you need multiple extensions, see scikit-build. 21 | class CMakeExtension(Extension): 22 | def __init__(self, name, sourcedir=""): 23 | Extension.__init__(self, name, sources=[]) 24 | self.sourcedir = os.path.abspath(sourcedir) 25 | 26 | 27 | class CMakeBuild(build_ext): 28 | def build_extension(self, ext): 29 | extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) 30 | 31 | # required for auto-detection & inclusion of auxiliary "native" libs 32 | if not extdir.endswith(os.path.sep): 33 | extdir += os.path.sep 34 | 35 | debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug 36 | cfg = "Debug" if debug else "Release" 37 | 38 | # CMake lets you override the generator - we need to check this. 39 | # Can be set with Conda-Build, for example. 40 | cmake_generator = os.environ.get("CMAKE_GENERATOR", "") 41 | 42 | # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON 43 | # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code 44 | # from Python. 45 | cmake_args = [ 46 | f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}", 47 | f"-DPYTHON_EXECUTABLE={sys.executable}", 48 | f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm 49 | ] 50 | build_args = [] 51 | # Adding CMake arguments set as environment variable 52 | # (needed e.g. to build for ARM OSx on conda-forge) 53 | if "CMAKE_ARGS" in os.environ: 54 | cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] 55 | 56 | # In this example, we pass in the version to C++. You might not need to. 57 | cmake_args += [f"-DNESTPY_VERSION_INFO={self.distribution.get_version()}"] 58 | 59 | if self.compiler.compiler_type != "msvc": 60 | # Using Ninja-build since it a) is available as a wheel and b) 61 | # multithreads automatically. MSVC would require all variables be 62 | # exported for Ninja to pick it up, which is a little tricky to do. 63 | # Users can override the generator with CMAKE_GENERATOR in CMake 64 | # 3.15+. 65 | if not cmake_generator or cmake_generator == "Ninja": 66 | try: 67 | import ninja # noqa: F401 68 | 69 | ninja_executable_path = os.path.join(ninja.BIN_DIR, "ninja") 70 | cmake_args += [ 71 | "-GNinja", 72 | f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", 73 | ] 74 | except ImportError: 75 | pass 76 | 77 | else: 78 | 79 | # Single config generators are handled "normally" 80 | single_config = any(x in cmake_generator for x in {"NMake", "Ninja"}) 81 | 82 | # CMake allows an arch-in-generator style for backward compatibility 83 | contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"}) 84 | 85 | # Specify the arch if using MSVC generator, but only if it doesn't 86 | # contain a backward-compatibility arch spec already in the 87 | # generator name. 88 | if not single_config and not contains_arch: 89 | cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]] 90 | 91 | # Multi-config generators have a different way to specify configs 92 | if not single_config: 93 | cmake_args += [ 94 | f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}" 95 | ] 96 | build_args += ["--config", cfg] 97 | 98 | if sys.platform.startswith("darwin"): 99 | # Cross-compile support for macOS - respect ARCHFLAGS if set 100 | archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", "")) 101 | if archs: 102 | cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))] 103 | 104 | # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level 105 | # across all generators. 106 | if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: 107 | # self.parallel is a Python 3 only way to set parallel jobs by hand 108 | # using -j in the build_ext call, not supported by pip or PyPA-build. 109 | if hasattr(self, "parallel") and self.parallel: 110 | # CMake 3.12+ only. 111 | build_args += [f"-j{self.parallel}"] 112 | 113 | build_temp = os.path.join(self.build_temp, ext.name) 114 | if not os.path.exists(build_temp): 115 | os.makedirs(build_temp) 116 | 117 | subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp) 118 | subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_temp) 119 | 120 | readme = open('README.md').read() 121 | history = open('HISTORY.md').read().replace('.. :changelog:', '') 122 | requirements = open('requirements.txt').read().splitlines() 123 | 124 | setup( 125 | name='nestpy', 126 | version='2.0.4', 127 | author='Greg Rischbieter', 128 | author_email='grischbieter@gmail.com', 129 | description='Python bindings for the NEST noble element simulations', 130 | long_description=readme + '\n\n' + history, 131 | long_description_content_type="text/markdown", 132 | # Include lib such that recompilation under e.g. different numpy versions works 133 | packages=find_packages('src'), 134 | install_requires=requirements, 135 | package_dir={'': 'src', 'lib': 'lib'}, 136 | package_data={'': ['*', ], 'lib': ['lib/*',]}, 137 | ext_modules=[CMakeExtension('nestpy/nestpy')], 138 | cmdclass=dict(build_ext=CMakeBuild), 139 | test_suite='tests', 140 | zip_safe=True, 141 | include_package_data=True, 142 | project_urls={ 143 | 'nestpy source': 'https://github.com/NESTCollaboration/nestpy', 144 | 'NEST library': 'https://github.com/NESTCollaboration/nest', 145 | 'NEST collaboration' : 'http://nest.physics.ucdavis.edu/' 146 | }, 147 | classifiers = [ 148 | 'Development Status :: 5 - Production/Stable', 149 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 150 | 'Natural Language :: English', 151 | 'Programming Language :: Python :: 3.6', 152 | 'Programming Language :: Python :: 3.7', 153 | 'Programming Language :: Python :: 3.8', 154 | 'Programming Language :: Python :: 3.9', 155 | 'Programming Language :: Python :: 3.10', 156 | 'Programming Language :: Python :: 3.11', 157 | 'Programming Language :: C++', 158 | 'Intended Audience :: Science/Research', 159 | 'Programming Language :: Python :: Implementation :: CPython', 160 | 'Topic :: Scientific/Engineering :: Physics', 161 | 'Operating System :: MacOS :: MacOS X', 162 | 'Operating System :: POSIX :: Linux' 163 | ] 164 | ) 165 | -------------------------------------------------------------------------------- /src/nestpy/__init__.py: -------------------------------------------------------------------------------- 1 | from .nestpy import * 2 | from .nestpy import __version__ 3 | from .nestpy import __nest_version__ 4 | 5 | from .helpers import Yield, PhotonYield, ElectronYield, GetYieldsVectorized, GetInteractionObject, ListInteractionTypes 6 | 7 | # Populate namespace with interaction types to allow e.g. nestpy.NR 8 | for interaction_type in ListInteractionTypes(): # interaction_type is string 9 | vars()[interaction_type] = GetInteractionObject(interaction_type) 10 | 11 | # for compatibility with older definitions 12 | -------------------------------------------------------------------------------- /src/nestpy/bindings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NEST.hh" 3 | #include "LArNEST.hh" 4 | #include "VDetector.hh" 5 | #include "execNEST.hh" 6 | #include "TestSpectra.hh" 7 | #include "LUX_Run03.hh" 8 | #include "DetectorExample_XENON10.hh" 9 | #include "RandomGen.hh" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define STRINGIFY(x) #x 16 | #define MACRO_STRINGIFY(x) STRINGIFY(x) 17 | 18 | namespace py = pybind11; 19 | 20 | PYBIND11_MODULE(nestpy, m) 21 | { 22 | // versioning 23 | #ifdef NESTPY_VERSION 24 | m.attr("__version__") = MACRO_STRINGIFY(NESTPY_VERSION); 25 | #else 26 | m.attr("__version__") = "dev"; 27 | #endif 28 | #ifdef NEST_VERSION 29 | m.attr("__nest_version__") = MACRO_STRINGIFY(NEST_VERSION); 30 | #else 31 | m.attr("__nest_version__") = ""; 32 | #endif 33 | //----------------------------------------------------------------------- 34 | // LXe NEST bindings 35 | 36 | // Init random seed 37 | RandomGen::rndm()->SetSeed( time(nullptr) ); 38 | // Binding for RandomGen class 39 | py::class_(m, "RandomGen") 40 | .def("rndm", &RandomGen::rndm) 41 | .def("set_seed", &RandomGen::SetSeed) 42 | .def("lock_seed", &RandomGen::LockSeed) 43 | .def("unlock_seed", &RandomGen::UnlockSeed); 44 | 45 | // Binding for YieldResult struct 46 | 47 | py::class_(m, "YieldResult", py::dynamic_attr()) 48 | .def(py::init<>()) 49 | .def_readwrite("PhotonYield", &NEST::YieldResult::PhotonYield) 50 | .def_readwrite("ElectronYield", &NEST::YieldResult::ElectronYield) 51 | .def_readwrite("ExcitonRatio", &NEST::YieldResult::ExcitonRatio) 52 | .def_readwrite("Lindhard", &NEST::YieldResult::Lindhard) 53 | .def_readwrite("ElectricField", &NEST::YieldResult::ElectricField) 54 | .def_readwrite("DeltaT_Scint", &NEST::YieldResult::DeltaT_Scint); 55 | 56 | // Binding for QuantaResult struct 57 | py::class_(m, "QuantaResult", py::dynamic_attr()) 58 | .def(py::init<>()) 59 | .def_readwrite("photons", &NEST::QuantaResult::photons) 60 | .def_readwrite("electrons", &NEST::QuantaResult::electrons) 61 | .def_readwrite("ions", &NEST::QuantaResult::ions) 62 | .def_readwrite("excitons", &NEST::QuantaResult::excitons); 63 | 64 | // Binding for NESTresult struct 65 | py::class_(m, "NESTresult", py::dynamic_attr()) 66 | .def(py::init<>()) 67 | .def_readwrite("yields", &NEST::NESTresult::yields) 68 | .def_readwrite("quanta", &NEST::NESTresult::quanta) 69 | .def_readwrite("photon_times", &NEST::NESTresult::photon_times); 70 | 71 | // Binding for Wvalue struct... 72 | py::class_(m, "Wvalue", py::dynamic_attr()) 73 | .def(py::init<>()) 74 | .def_readwrite("Wq_eV", &NEST::NESTcalc::Wvalue::Wq_eV) 75 | .def_readwrite("alpha", &NEST::NESTcalc::Wvalue::alpha); 76 | 77 | // Binding for the WIMP Spectrum Prep struct 78 | py::class_(m, "WIMP_spectrum_prep", py::dynamic_attr()) 79 | .def(py::init<>()); 80 | 81 | // Binding for the enumeration INTERACTION_TYPE 82 | py::enum_(m, "INTERACTION_TYPE", py::arithmetic()) 83 | .value("NR", NEST::INTERACTION_TYPE::NR) 84 | .value("WIMP", NEST::INTERACTION_TYPE::WIMP) 85 | .value("B8", NEST::INTERACTION_TYPE::B8) 86 | .value("DD", NEST::INTERACTION_TYPE::DD) 87 | .value("AmBe", NEST::INTERACTION_TYPE::AmBe) 88 | .value("Cf", NEST::INTERACTION_TYPE::Cf) 89 | .value("ion", NEST::INTERACTION_TYPE::ion) 90 | .value("gammaRay", NEST::INTERACTION_TYPE::gammaRay) 91 | .value("beta", NEST::INTERACTION_TYPE::beta) 92 | .value("CH3T", NEST::INTERACTION_TYPE::CH3T) 93 | .value("C14", NEST::INTERACTION_TYPE::C14) 94 | .value("Kr83m", NEST::INTERACTION_TYPE::Kr83m) 95 | .value("NoneType", NEST::INTERACTION_TYPE::NoneType) 96 | .export_values(); 97 | 98 | py::enum_(m, "S1CalculationMode", py::arithmetic()) 99 | .value("Full", NEST::S1CalculationMode::Full) 100 | .value("Parametric", NEST::S1CalculationMode::Parametric) 101 | .value("Hybrid", NEST::S1CalculationMode::Hybrid) 102 | .value("Waveform", NEST::S1CalculationMode::Waveform) 103 | .export_values(); 104 | 105 | py::enum_(m, "S2CalculationMode", py::arithmetic()) 106 | .value("Full", NEST::S2CalculationMode::Full) 107 | .value("Waveform", NEST::S2CalculationMode::Waveform) 108 | .value("WaveformWithEtrain", NEST::S2CalculationMode::WaveformWithEtrain) 109 | .export_values(); 110 | 111 | // Binding for the VDetector class 112 | // py::nodelete added so that NESTcalc() deconstructor does 113 | // not delete instance of VDetector() 114 | py::class_>(m, "VDetector") 115 | .def(py::init<>()) 116 | .def("Initialization", &VDetector::Initialization) 117 | .def("get_g1", &VDetector::get_g1) 118 | .def("get_sPEres", &VDetector::get_sPEres) 119 | .def("get_sPEthr", &VDetector::get_sPEthr) 120 | .def("get_sPEeff", &VDetector::get_sPEeff) 121 | .def("get_P_dphe", &VDetector::get_P_dphe) 122 | 123 | .def("get_noiseBaseline", &VDetector::get_noiseBaseline) 124 | .def("get_noiseLinear", &VDetector::get_noiseLinear) 125 | .def("get_noiseQuadratic", &VDetector::get_noiseQuadratic) 126 | .def("get_coinWind", &VDetector::get_coinWind) 127 | .def("get_coinLevel", &VDetector::get_coinLevel) 128 | .def("get_numPMTs", &VDetector::get_numPMTs) 129 | 130 | .def("get_g1_gas", &VDetector::get_g1_gas) 131 | .def("get_s2Fano", &VDetector::get_s2Fano) 132 | .def("get_s2_thr", &VDetector::get_s2_thr) 133 | //.def("get_S2botTotRatio", &VDetector::get_S2botTotRatio) 134 | .def("get_E_gas", &VDetector::get_E_gas) 135 | .def("get_eLife_us", &VDetector::get_eLife_us) 136 | 137 | .def("get_inGas", &VDetector::get_inGas) 138 | .def("get_T_Kelvin", &VDetector::get_T_Kelvin) 139 | .def("get_p_bar", &VDetector::get_p_bar) 140 | 141 | .def("get_dtCntr", &VDetector::get_dtCntr) 142 | .def("get_dt_min", &VDetector::get_dt_min) 143 | .def("get_dt_max", &VDetector::get_dt_max) 144 | .def("get_radius", &VDetector::get_radius) 145 | .def("get_radmax", &VDetector::get_radmax) 146 | .def("get_TopDrift", &VDetector::get_TopDrift) 147 | .def("get_anode", &VDetector::get_anode) 148 | .def("get_cathode", &VDetector::get_cathode) 149 | .def("get_gate", &VDetector::get_gate) 150 | 151 | .def("get_molarMass", &VDetector::get_molarMass ) 152 | 153 | .def("get_PosResExp", &VDetector::get_PosResExp) 154 | .def("get_PosResBase", &VDetector::get_PosResBase) 155 | 156 | .def("set_g1", &VDetector::set_g1) 157 | .def("set_sPEres", &VDetector::set_sPEres) 158 | .def("set_sPEthr", &VDetector::set_sPEthr) 159 | .def("set_sPEeff", &VDetector::set_sPEeff) 160 | .def("set_P_dphe", &VDetector::set_P_dphe) 161 | 162 | .def("set_noiseBaseline", &VDetector::set_noiseBaseline) 163 | .def("set_noiseLinear", &VDetector::set_noiseLinear) 164 | .def("set_noiseQuadratic", &VDetector::set_noiseQuadratic) 165 | .def("set_coinWind", &VDetector::set_coinWind) 166 | .def("set_coinLevel", &VDetector::set_coinLevel) 167 | .def("set_numPMTs", &VDetector::set_numPMTs) 168 | 169 | .def("set_g1_gas", &VDetector::set_g1_gas) 170 | .def("set_s2Fano", &VDetector::set_s2Fano) 171 | .def("set_s2_thr", &VDetector::set_s2_thr) 172 | //.def("set_S2botTotRatio", &VDetector::set_S2botTotRatio) 173 | .def("set_E_gas", &VDetector::set_E_gas) 174 | .def("set_eLife_us", &VDetector::set_eLife_us) 175 | 176 | .def("set_inGas", &VDetector::set_inGas) 177 | .def("set_T_Kelvin", &VDetector::set_T_Kelvin) 178 | .def("set_p_bar", &VDetector::set_p_bar) 179 | 180 | .def("set_dtCntr", &VDetector::set_dtCntr) 181 | .def("set_dt_min", &VDetector::set_dt_min) 182 | .def("set_dt_max", &VDetector::set_dt_max) 183 | .def("set_radius", &VDetector::set_radius) 184 | .def("set_radmax", &VDetector::set_radmax) 185 | .def("set_TopDrift", &VDetector::set_TopDrift) 186 | .def("set_anode", &VDetector::set_anode) 187 | .def("set_cathode", &VDetector::set_cathode) 188 | .def("set_gate", &VDetector::set_gate) 189 | 190 | .def("set_molarMarr", &VDetector::set_molarMass) 191 | 192 | .def("set_PosResExp", &VDetector::set_PosResExp) 193 | .def("set_PosResBase", &VDetector::set_PosResBase) 194 | 195 | .def("FitS1", &VDetector::FitS1) 196 | .def("FitS2", &VDetector::FitS1) 197 | .def("FitEF", &VDetector::FitEF) 198 | .def("FitTBA", &VDetector::FitTBA) 199 | // .def("FitS1", &VDetector::FitS1, 200 | // py::arg("xpos_mm") = 0., 201 | // py::arg("ypos_mm") = 0., 202 | // py::arg("zpos_mm") = 0., 203 | // py::arg("LCE") = VDetector::LCE::unfold) 204 | // .def("FitS2", &VDetector::FitS2, 205 | // py::arg("xpos_mm") = 0., 206 | // py::arg("ypos_mm") = 0., 207 | // py::arg("LCE") = VDetector::LCE::unfold) 208 | 209 | .def("OptTrans", &VDetector::OptTrans) 210 | .def("SinglePEWaveForm", &VDetector::SinglePEWaveForm); 211 | 212 | // Binding for example XENON10 213 | py::class_>(m, "DetectorExample_XENON10") 214 | .def(py::init<>()) 215 | .def("Initialization", &DetectorExample_XENON10::Initialization) 216 | .def("FitTBA", &DetectorExample_XENON10::FitTBA) 217 | .def("OptTrans", &DetectorExample_XENON10::OptTrans) 218 | .def("SinglePEWaveForm", &DetectorExample_XENON10::SinglePEWaveForm); 219 | 220 | // Binding for example LUX_Run03 221 | py::class_>(m, "LUX_Run03") 222 | .def(py::init<>()) 223 | .def("Initialization", &DetectorExample_LUX_RUN03::Initialization) 224 | .def("FitTBA", &DetectorExample_LUX_RUN03::FitTBA) 225 | .def("OptTrans", &DetectorExample_LUX_RUN03::OptTrans) 226 | .def("SinglePEWaveForm", &DetectorExample_LUX_RUN03::SinglePEWaveForm); 227 | 228 | // Binding for the TestSpectra class 229 | py::class_>(m, "TestSpectra") 230 | .def(py::init<>()) 231 | .def_static("CH3T_spectrum", 232 | &TestSpectra::CH3T_spectrum, 233 | py::arg("xMin") = 0., 234 | py::arg("xMax") = 18.6 235 | ) 236 | .def_static("C14_spectrum", 237 | &TestSpectra::C14_spectrum, 238 | py::arg("xMin") = 0., 239 | py::arg("xMax") = 156. 240 | ) 241 | .def_static("B8_spectrum", 242 | &TestSpectra::B8_spectrum, 243 | py::arg("xMin") = 0., 244 | py::arg("xMax") = 4. 245 | ) 246 | .def_static("AmBe_spectrum", 247 | &TestSpectra::AmBe_spectrum, 248 | py::arg("xMin") = 0., 249 | py::arg("xMax") = 200. 250 | ) 251 | .def_static("Cf_spectrum", 252 | &TestSpectra::Cf_spectrum, 253 | py::arg("xMin") = 0., 254 | py::arg("xMax") = 200. 255 | ) 256 | .def_static("DD_spectrum", 257 | &TestSpectra::DD_spectrum, 258 | py::arg("xMin") = 0., 259 | py::arg("xMax") = 80., 260 | py::arg("expFall") = 10., 261 | py::arg("peakFrac") = 0.1, 262 | py::arg("peakMu") = 60., 263 | py::arg("peakSig") = 25. 264 | ) 265 | .def_static("ppSolar_spectrum", 266 | &TestSpectra::ppSolar_spectrum, 267 | py::arg("xMin") = 0., 268 | py::arg("xMax") = 250. 269 | ) 270 | .def_static("atmNu_spectrum", 271 | &TestSpectra::atmNu_spectrum, 272 | py::arg("xMin") = 0., 273 | py::arg("xMax") = 85. 274 | ) 275 | .def_static("WIMP_prep_spectrum", 276 | &TestSpectra::WIMP_prep_spectrum, 277 | py::arg("mass") = 50., 278 | py::arg("eStep") = 5., 279 | py::arg("day")=0. 280 | ) 281 | .def_static("WIMP_spectrum", 282 | &TestSpectra::WIMP_spectrum, 283 | py::arg("wprep"), 284 | py::arg("mass") = 50., 285 | py::arg("day") = 0. 286 | ); 287 | 288 | // Binding for the NESTcalc class 289 | py::class_>(m, "NESTcalc") 290 | //.def(py::init<>()) 291 | .def(py::init()) 292 | .def_readonly_static("default_NRYieldsParam", &default_NRYieldsParam) 293 | .def_readonly_static("default_NRERWidthsParam", &default_NRERWidthsParam) 294 | .def_readonly_static("default_ERYieldsParam", &default_ERYieldsParam) 295 | // .def_static("BinomFluct", &NEST::NESTcalc::BinomFluct) 296 | .def("FullCalculation", &NEST::NESTcalc::FullCalculation, 297 | "Perform the full yield calculation with smearings") 298 | .def("PhotonTime", &NEST::NESTcalc::PhotonTime) 299 | .def("AddPhotonTransportTime", &NEST::NESTcalc::AddPhotonTransportTime) 300 | .def("GetPhotonTimes", &NEST::NESTcalc::GetPhotonTimes) 301 | .def("GetYieldKr83m", 302 | &NEST::NESTcalc::GetYieldKr83m, 303 | py::arg("energy") = 41.5, 304 | py::arg("density") = 2.9, 305 | py::arg("drift_field") = 124, 306 | py::arg("maxTimeSeparation") = 2000., 307 | py::arg("minTimeSeparation") = 0.0 308 | ) 309 | .def("GetYieldERWeighted", 310 | &NEST::NESTcalc::GetYieldERWeighted, 311 | py::arg("energy") = 5.2, 312 | py::arg("density") = 2.9, 313 | py::arg("drift_field") = 124, 314 | py::arg("ERYieldsParam") = std::vector({-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.}), 315 | py::arg("EnergyParams") = std::vector({0.23, 0.77, 2.95, -1.44}), 316 | py::arg("FieldParams") = std::vector({421.15, 3.27}) 317 | ) 318 | .def("GetYields", 319 | &NEST::NESTcalc::GetYields, 320 | py::arg("interaction") = NEST::INTERACTION_TYPE::NR, 321 | py::arg("energy") = 100, 322 | py::arg("density") = 2.9, 323 | py::arg("drift_field") = 124, 324 | py::arg("A") = 131.293, 325 | py::arg("Z") = 54, 326 | py::arg("nuisance_parameters") = std::vector({ 11., 1.1, 0.0480, -0.0533, 12.6, 0.3, 2., 0.3, 2., 0.5, 1., 1.}), 327 | py::arg("ERYieldsParam") = std::vector({-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.,-1.}), 328 | py::arg("oldModelER") = false 329 | ) 330 | .def("GetQuanta", &NEST::NESTcalc::GetQuanta, 331 | py::arg("yields"), 332 | py::arg("density") = 2.9, 333 | py::arg("free_parameters") = std::vector({0.4,0.4,0.04,0.5,0.19,2.25,1.,0.046452,0.205,0.45,-0.2}), 334 | py::arg("oldModelER") = false, 335 | py::arg("SkewnessER") = -999. 336 | ) 337 | .def("GetS1", &NEST::NESTcalc::GetS1) 338 | .def("GetSpike", &NEST::NESTcalc::GetSpike) 339 | // Currently VDetector.FitTBA() requires we reinitialize the detector every time: 340 | .def("GetS2", &NEST::NESTcalc::GetS2) 341 | .def("CalculateG2", &NEST::NESTcalc::CalculateG2) 342 | .def("SetDriftVelocity", &NEST::NESTcalc::SetDriftVelocity) 343 | .def("SetDriftVelocity_NonUniform", &NEST::NESTcalc::SetDriftVelocity_NonUniform) 344 | .def("SetDensity", &NEST::NESTcalc::SetDensity) 345 | .def_static("GetDensity", &NEST::NESTcalc::GetDensity, 346 | py::arg("T") = 174., 347 | py::arg("P") = 1.80, 348 | py::arg("inGas") = false, 349 | py::arg("evtNum") = 0, 350 | py::arg("molarMass") = 131.293 351 | ) 352 | .def_static("WorkFunction", &NEST::NESTcalc::WorkFunction, 353 | py::arg("rho") = 2.89, 354 | py::arg("MolarMass") = 131.293, 355 | py::arg("OldW13eV") = true 356 | ) 357 | 358 | // Currently VDetector.FitTBA() requires we reinitialize the detector every time: 359 | .def("xyResolution", &NEST::NESTcalc::xyResolution) 360 | .def("PhotonEnergy", &NEST::NESTcalc::PhotonEnergy) 361 | .def("CalcElectronLET", &NEST::NESTcalc::CalcElectronLET) 362 | .def("GetDetector", &NEST::NESTcalc::GetDetector); 363 | 364 | // execNEST function 365 | m.def("execNEST", &execNEST); 366 | m.def("GetEnergyRes", &GetEnergyRes); 367 | m.def("GetBand", &GetBand); 368 | m.def("default_nr_yields_params", []() { return default_NRYieldsParam; }); 369 | m.def("default_nrer_widths_params", []() { return default_NRERWidthsParam; }); 370 | m.def("default_er_yields_params", []() { return default_ERYieldsParam; }); 371 | 372 | //----------------------------------------------------------------------- 373 | // LAr NEST bindings 374 | 375 | // Binding for the enumeration LArInteraction 376 | py::enum_(m, "LArInteraction", py::arithmetic()) 377 | .value("NR", NEST::LArInteraction::NR) 378 | .value("ER", NEST::LArInteraction::ER) 379 | .value("Alpha", NEST::LArInteraction::Alpha) 380 | .export_values(); 381 | 382 | // NR Yields Parameters 383 | py::class_(m, "LArNRYieldsParameters", py::dynamic_attr()) 384 | .def(py::init<>()) 385 | .def_readwrite("alpha", &NEST::LArNRYieldsParameters::alpha) 386 | .def_readwrite("beta", &NEST::LArNRYieldsParameters::beta) 387 | .def_readwrite("gamma", &NEST::LArNRYieldsParameters::gamma) 388 | .def_readwrite("delta", &NEST::LArNRYieldsParameters::delta) 389 | .def_readwrite("epsilon", &NEST::LArNRYieldsParameters::epsilon) 390 | .def_readwrite("zeta", &NEST::LArNRYieldsParameters::zeta) 391 | .def_readwrite("eta", &NEST::LArNRYieldsParameters::eta); 392 | 393 | // ER Electron Yields Alpha Parameters 394 | py::class_(m, "LArERElectronYieldsAlphaParameters", py::dynamic_attr()) 395 | .def(py::init<>()) 396 | .def_readwrite("A", &NEST::LArERElectronYieldsAlphaParameters::A) 397 | .def_readwrite("B", &NEST::LArERElectronYieldsAlphaParameters::B) 398 | .def_readwrite("C", &NEST::LArERElectronYieldsAlphaParameters::C) 399 | .def_readwrite("D", &NEST::LArERElectronYieldsAlphaParameters::D) 400 | .def_readwrite("E", &NEST::LArERElectronYieldsAlphaParameters::E) 401 | .def_readwrite("F", &NEST::LArERElectronYieldsAlphaParameters::F) 402 | .def_readwrite("G", &NEST::LArERElectronYieldsAlphaParameters::G); 403 | 404 | // ER Electron Yields Beta Parameters 405 | py::class_(m, "LArERElectronYieldsBetaParameters", py::dynamic_attr()) 406 | .def(py::init<>()) 407 | .def_readwrite("A", &NEST::LArERElectronYieldsBetaParameters::A) 408 | .def_readwrite("B", &NEST::LArERElectronYieldsBetaParameters::B) 409 | .def_readwrite("C", &NEST::LArERElectronYieldsBetaParameters::C) 410 | .def_readwrite("D", &NEST::LArERElectronYieldsBetaParameters::D) 411 | .def_readwrite("E", &NEST::LArERElectronYieldsBetaParameters::E) 412 | .def_readwrite("F", &NEST::LArERElectronYieldsBetaParameters::F); 413 | 414 | // ER Electron Yields Gamma Parameters 415 | py::class_(m, "LArERElectronYieldsGammaParameters", py::dynamic_attr()) 416 | .def(py::init<>()) 417 | .def_readwrite("A", &NEST::LArERElectronYieldsGammaParameters::A) 418 | .def_readwrite("B", &NEST::LArERElectronYieldsGammaParameters::B) 419 | .def_readwrite("C", &NEST::LArERElectronYieldsGammaParameters::C) 420 | .def_readwrite("D", &NEST::LArERElectronYieldsGammaParameters::D) 421 | .def_readwrite("E", &NEST::LArERElectronYieldsGammaParameters::E) 422 | .def_readwrite("F", &NEST::LArERElectronYieldsGammaParameters::F); 423 | 424 | // ER Electron Yields DokeBirks Parameters 425 | py::class_(m, "LArERElectronYieldsDokeBirksParameters", py::dynamic_attr()) 426 | .def(py::init<>()) 427 | .def_readwrite("A", &NEST::LArERElectronYieldsDokeBirksParameters::A) 428 | .def_readwrite("B", &NEST::LArERElectronYieldsDokeBirksParameters::B) 429 | .def_readwrite("C", &NEST::LArERElectronYieldsDokeBirksParameters::C) 430 | .def_readwrite("D", &NEST::LArERElectronYieldsDokeBirksParameters::D) 431 | .def_readwrite("E", &NEST::LArERElectronYieldsDokeBirksParameters::E); 432 | 433 | // ER Electron Yields Parameters 434 | py::class_(m, "LArERYieldsParameters", py::dynamic_attr()) 435 | .def(py::init<>()) 436 | .def_readwrite("alpha", &NEST::LArERYieldsParameters::alpha) 437 | .def_readwrite("beta", &NEST::LArERYieldsParameters::beta) 438 | .def_readwrite("gamma", &NEST::LArERYieldsParameters::gamma) 439 | .def_readwrite("doke_birks", &NEST::LArERYieldsParameters::doke_birks) 440 | .def_readwrite("p1", &NEST::LArERYieldsParameters::p1) 441 | .def_readwrite("p2", &NEST::LArERYieldsParameters::p2) 442 | .def_readwrite("p3", &NEST::LArERYieldsParameters::p3) 443 | .def_readwrite("p4", &NEST::LArERYieldsParameters::p4) 444 | .def_readwrite("p5", &NEST::LArERYieldsParameters::p5) 445 | .def_readwrite("delta", &NEST::LArERYieldsParameters::delta) 446 | .def_readwrite("let", &NEST::LArERYieldsParameters::let); 447 | 448 | // Alpha Electron Yields Parameters 449 | py::class_(m, "LArAlphaElectronYieldsParameters", py::dynamic_attr()) 450 | .def(py::init<>()) 451 | .def_readwrite("A", &NEST::LArAlphaElectronYieldsParameters::A) 452 | .def_readwrite("B", &NEST::LArAlphaElectronYieldsParameters::B) 453 | .def_readwrite("C", &NEST::LArAlphaElectronYieldsParameters::C) 454 | .def_readwrite("D", &NEST::LArAlphaElectronYieldsParameters::D) 455 | .def_readwrite("E", &NEST::LArAlphaElectronYieldsParameters::E) 456 | .def_readwrite("F", &NEST::LArAlphaElectronYieldsParameters::F) 457 | .def_readwrite("G", &NEST::LArAlphaElectronYieldsParameters::G) 458 | .def_readwrite("H", &NEST::LArAlphaElectronYieldsParameters::H) 459 | .def_readwrite("I", &NEST::LArAlphaElectronYieldsParameters::I) 460 | .def_readwrite("J", &NEST::LArAlphaElectronYieldsParameters::J); 461 | 462 | // Alpha Photon Yields Parameters 463 | py::class_(m, "LArAlphaPhotonYieldsParameters", py::dynamic_attr()) 464 | .def(py::init<>()) 465 | .def_readwrite("A", &NEST::LArAlphaPhotonYieldsParameters::A) 466 | .def_readwrite("B", &NEST::LArAlphaPhotonYieldsParameters::B) 467 | .def_readwrite("C", &NEST::LArAlphaPhotonYieldsParameters::C) 468 | .def_readwrite("D", &NEST::LArAlphaPhotonYieldsParameters::D) 469 | .def_readwrite("E", &NEST::LArAlphaPhotonYieldsParameters::E) 470 | .def_readwrite("F", &NEST::LArAlphaPhotonYieldsParameters::F) 471 | .def_readwrite("G", &NEST::LArAlphaPhotonYieldsParameters::G) 472 | .def_readwrite("H", &NEST::LArAlphaPhotonYieldsParameters::H) 473 | .def_readwrite("I", &NEST::LArAlphaPhotonYieldsParameters::I) 474 | .def_readwrite("J", &NEST::LArAlphaPhotonYieldsParameters::J) 475 | .def_readwrite("J", &NEST::LArAlphaPhotonYieldsParameters::K) 476 | .def_readwrite("J", &NEST::LArAlphaPhotonYieldsParameters::L) 477 | .def_readwrite("J", &NEST::LArAlphaPhotonYieldsParameters::M); 478 | 479 | // Alpha Yields Parameters 480 | py::class_(m, "LArAlphaYieldsParameters", py::dynamic_attr()) 481 | .def(py::init<>()) 482 | .def_readwrite("Ye", &NEST::LArAlphaYieldsParameters::Ye) 483 | .def_readwrite("Yph", &NEST::LArAlphaYieldsParameters::Yph); 484 | 485 | // Thomas-Imel Parameters 486 | py::class_(m, "ThomasImelParameters", py::dynamic_attr()) 487 | .def(py::init<>()) 488 | .def_readwrite("A", &NEST::ThomasImelParameters::A) 489 | .def_readwrite("B", &NEST::ThomasImelParameters::B); 490 | 491 | // Drift Parameters 492 | py::class_(m, "DriftParameters", py::dynamic_attr()) 493 | .def(py::init<>()) 494 | .def_readwrite("A", &NEST::DriftParameters::A) 495 | .def_readwrite("B", &NEST::DriftParameters::B) 496 | .def_readwrite("C", &NEST::DriftParameters::B) 497 | .def_readwrite("TempLow", &NEST::DriftParameters::TempLow) 498 | .def_readwrite("TempHigh", &NEST::DriftParameters::TempHigh); 499 | 500 | // LAr Mean Yield Result 501 | py::class_(m, "LArYieldResult", py::dynamic_attr()) 502 | .def(py::init<>()) 503 | .def_readwrite("TotalYield", &NEST::LArYieldResult::TotalYield) 504 | .def_readwrite("QuantaYield", &NEST::LArYieldResult::QuantaYield) 505 | .def_readwrite("LightYield", &NEST::LArYieldResult::LightYield) 506 | .def_readwrite("Nph", &NEST::LArYieldResult::Nph) 507 | .def_readwrite("Ne", &NEST::LArYieldResult::Ne) 508 | .def_readwrite("Nex", &NEST::LArYieldResult::Nex) 509 | .def_readwrite("Nion", &NEST::LArYieldResult::Nion) 510 | .def_readwrite("Lindhard", &NEST::LArYieldResult::Lindhard) 511 | .def_readwrite("ElectricField", &NEST::LArYieldResult::ElectricField); 512 | 513 | // LAr Fluctuation Result 514 | py::class_(m, "LArYieldFluctuationResult", py::dynamic_attr()) 515 | .def(py::init<>()) 516 | .def_readwrite("NphFluctuation", &NEST::LArYieldFluctuationResult::NphFluctuation) 517 | .def_readwrite("NeFluctuation", &NEST::LArYieldFluctuationResult::NeFluctuation) 518 | .def_readwrite("NexFluctuation", &NEST::LArYieldFluctuationResult::NexFluctuation) 519 | .def_readwrite("NionFluctuation", &NEST::LArYieldFluctuationResult::NionFluctuation); 520 | 521 | // LAr Yields Result 522 | py::class_(m, "LArNESTResult", py::dynamic_attr()) 523 | .def(py::init<>()) 524 | .def_readwrite("yields", &NEST::LArNESTResult::yields) 525 | .def_readwrite("fluctuations", &NEST::LArNESTResult::fluctuations) 526 | .def_readwrite("photon_times", &NEST::LArNESTResult::photon_times); 527 | 528 | // Binding for the LArNEST class 529 | py::class_>(m, "LArNEST") 530 | .def(py::init()) 531 | .def("set_density", &NEST::LArNEST::SetDensity) 532 | .def("set_r_ideal_gas", &NEST::LArNEST::SetRIdealGas) 533 | .def("set_real_gas_a", &NEST::LArNEST::SetRealGasA) 534 | .def("set_real_gas_b", &NEST::LArNEST::SetRealGasB) 535 | .def("set_work_quanta_function", &NEST::LArNEST::SetWorkQuantaFunction) 536 | .def("set_work_ion_function", &NEST::LArNEST::SetWorkIonFunction) 537 | .def("set_work_photon_function", &NEST::LArNEST::SetWorkPhotonFunction) 538 | .def("set_fano_er", &NEST::LArNEST::SetFanoER) 539 | .def("set_nex_over_nion", &NEST::LArNEST::SetNexOverNion) 540 | // .def("set_nuisance_parameters", &NEST::LArNEST::setNuisanceParameters) 541 | // .def("set_temperature", &NEST::LArNEST::setTemperature) 542 | // .def("set_nr_yields_parameters", &NEST::LArNEST::setNRYieldsParameters) 543 | // .def("set_er_yields_parameters", &NEST::LArNEST::setERYieldsParameters) 544 | // .def("set_er_electron_yields_alpha_parameters", &NEST::LArNEST::setERElectronYieldsAlphaParameters) 545 | // .def("set_er_electron_yields_beta_parameters", &NEST::LArNEST::setERElectronYieldsBetaParameters) 546 | //.def("set_er_electron_yields_gamma_parameters", &NEST::LArNEST::setERElectronYieldsGammaParameters) 547 | // .def("set_er_electron_yields_doke_birks_parameters", &NEST::LArNEST::setERElectronYieldsDokeBirksParameters) 548 | // .def("set_thomas_imel_parameters", &NEST::LArNEST::setThomasImelParameters) 549 | //.def("set_drift_parameters", &NEST::LArNEST::setDriftParameters) 550 | 551 | //.def("get_density", &NEST::LArNEST::GetDensity) 552 | .def("get_r_ideal_gas", &NEST::LArNEST::GetRIdealGas) 553 | .def("get_real_gas_a", &NEST::LArNEST::GetRealGasA) 554 | .def("get_real_gas_b", &NEST::LArNEST::GetRealGasB) 555 | .def("get_work_quanta_function", &NEST::LArNEST::GetWorkQuantaFunction) 556 | .def("get_work_ion_function", &NEST::LArNEST::GetWorkIonFunction) 557 | .def("get_work_photon_function", &NEST::LArNEST::GetWorkPhotonFunction) 558 | .def("get_fano_er", &NEST::LArNEST::GetFanoER) 559 | .def("get_nex_over_nion", &NEST::LArNEST::GetNexOverNion) 560 | .def("get_nr_yields_parameters", &NEST::LArNEST::GetNRYieldsParameters) 561 | .def("get_er_yields_parameters", &NEST::LArNEST::GetERYieldsParameters) 562 | .def("get_er_electron_yields_alpha_parameters", &NEST::LArNEST::GetERElectronYieldsAlphaParameters) 563 | .def("get_er_electron_yields_beta_parameters", &NEST::LArNEST::GetERElectronYieldsBetaParameters) 564 | .def("get_er_electron_yields_gamma_parameters", &NEST::LArNEST::GetERElectronYieldsGammaParameters) 565 | .def("get_er_electron_yields_doke_birks_parameters", &NEST::LArNEST::GetERElectronYieldsDokeBirksParameters) 566 | .def("get_thomas_imel_parameters", &NEST::LArNEST::GetThomasImelParameters) 567 | .def("get_drift_parameters", &NEST::LArNEST::GetDriftParameters) 568 | 569 | .def("get_recombination_yields", &NEST::LArNEST::GetRecombinationYields) 570 | .def("get_yields", &NEST::LArNEST::GetYields) 571 | .def("get_yield_fluctuations", &NEST::LArNEST::GetYieldFluctuations) 572 | .def("full_calculation", &NEST::LArNEST::FullCalculation) 573 | .def("get_nr_total_yields", &NEST::LArNEST::GetNRTotalYields) 574 | .def("get_nr_electron_yields", &NEST::LArNEST::GetNRElectronYields) 575 | .def("get_nr_photon_yields", &NEST::LArNEST::GetNRPhotonYields) 576 | .def("get_nr_photon_yields_conserved", &NEST::LArNEST::GetNRPhotonYieldsConserved) 577 | .def("get_nr_yields", &NEST::LArNEST::GetNRYields) 578 | .def("get_er_total_yields", &NEST::LArNEST::GetERTotalYields) 579 | .def("get_er_electron_yields_alpha", &NEST::LArNEST::GetERElectronYieldsAlpha) 580 | .def("get_er_electron_yields_beta", &NEST::LArNEST::GetERElectronYieldsBeta) 581 | .def("get_er_electron_yields_gamma", &NEST::LArNEST::GetERElectronYieldsGamma) 582 | .def("get_er_electron_yields_doke_birks", &NEST::LArNEST::GetERElectronYieldsDokeBirks) 583 | .def("get_er_electron_yields", &NEST::LArNEST::GetERElectronYields) 584 | .def("get_er_yields", &NEST::LArNEST::GetERYields) 585 | .def("get_alpha_total_yields", &NEST::LArNEST::GetAlphaTotalYields) 586 | .def("get_alpha_electron_yields", &NEST::LArNEST::GetAlphaElectronYields) 587 | .def("get_alpha_photon_yields", &NEST::LArNEST::GetAlphaPhotonYields) 588 | .def("get_alpha_yields", &NEST::LArNEST::GetAlphaYields) 589 | 590 | //.def("get_default_fluctuations", &NEST::LArNEST::GetDefaultFluctuations) 591 | .def("get_photon_time", &NEST::LArNEST::GetPhotonTime) 592 | //.def("get_photon_energy", &NEST::LArNEST::GetPhotonEnergy) 593 | //.def("get_drift_velocity_liquid", &NEST::LArNEST::GetDriftVelocity_Liquid) 594 | //.def("get_drift_velocity_magboltz", &NEST::LArNEST::GetDriftVelocity_MagBoltz) 595 | //.def("get_let", &NEST::LArNEST::GetLinearEnergyTransfer) 596 | //.def("get_density", &NEST::LArNEST::GetDensity) 597 | //.def("calculate_g2", &NEST::LArNEST::CalculateG2) 598 | 599 | .def("legacy_get_yields", &NEST::LArNEST::LegacyGetYields) 600 | .def("legacy_calculation", &NEST::LArNEST::LegacyCalculation) 601 | .def("legacy_get_recombination_probability", &NEST::LArNEST::LegacyGetRecombinationProbability) 602 | .def("legacy_get_let", &NEST::LArNEST::LegacyGetLinearEnergyTransfer); 603 | 604 | 605 | } 606 | -------------------------------------------------------------------------------- /src/nestpy/helpers.py: -------------------------------------------------------------------------------- 1 | """ 2 | vectorized_yields.py 3 | Makes plots of nestpy. 4 | 5 | This contains all of the functions that are used to make the plots 6 | which will be called via flask on main.py 7 | 8 | The main components are: 9 | 1. Getting the yields for the interaction types of interest (done via numpy vectorized, rather than a loop) 10 | 11 | Main ingredients for the above steps: 12 | 1. np.vectorize, dictionary with yields, field array and energy array. 13 | """ 14 | 15 | import numpy as np 16 | 17 | from nestpy import DetectorExample_XENON10, NESTcalc, INTERACTION_TYPE # This is C++ library 18 | 19 | # Detector identification for default 20 | # Performing NEST calculations according to the given detector example. 21 | # Yields are ambivalent to detector. 22 | #DETECTOR = DetectorExample_XENON10() 23 | #NC = NESTcalc(DETECTOR) 24 | 25 | NEST_INTERACTION_NUMBER = dict( 26 | nr=0, 27 | wimp=1, 28 | b8=2, 29 | dd=3, 30 | ambe=4, 31 | cf=5, 32 | ion=6, 33 | gammaray=7, 34 | beta=8, 35 | ch3t=9, 36 | c14=10, 37 | kr83m=11, 38 | nonetype=12, 39 | ) 40 | 41 | 42 | # Add local variable to cache the NESTcalc(DETECTOR) object 43 | _NestCalcInit = dict() 44 | 45 | 46 | def ListInteractionTypes(): 47 | return NEST_INTERACTION_NUMBER.keys() 48 | 49 | def GetInteractionObject(name): 50 | ''' 51 | This function returns the NEST interaction object for a given string. 52 | Parameters: 53 | name (str): interaction type (e.g. 'NR' or 'nr'.) 54 | To see all options available, run nestpy.ListInteractionTypes(). 55 | 56 | Returns: 57 | nestpy.INTERACTION_TYPE(Number), where Number corresponds to the string you provided. 58 | ''' 59 | 60 | name = name.lower() 61 | 62 | if name == 'er': 63 | raise ValueError("For 'er', specify either 'gammaray' or 'beta'") 64 | 65 | interaction_object = INTERACTION_TYPE(NEST_INTERACTION_NUMBER[name]) 66 | return interaction_object 67 | 68 | @np.vectorize 69 | def GetYieldsVectorized(interaction, yield_type, nc=None, **kwargs): 70 | ''' 71 | This function calculates nc.GetYields for the various interactions and arguments we pass into it. 72 | 73 | Requires: 74 | - GetInteractionObject from interactionkeys 75 | - strings passed through get us the numeric equivalent for each interaction 76 | - energy array 77 | - nc.GetYields (pass through interaction, energies, field value) 78 | - Returns dictionary with yield types and yield values at each interaction energy value. 79 | 80 | Parameters: 81 | nc (NESTcalc object): must specify nc=nestpy.NESTcalc(detector) to use non-default 82 | if no argument is provided - a default is loaded and written to cache. 83 | interaction (str): interaction type, here using 'nr' (nuclear recoil), 84 | gammaray', 'beta', '206Pb', and 'alpha'. 85 | yield_type (str): Either 'PhotonYield' or 'ElectronYield' to return proper yield values. 86 | **kwargs (var): Field values (array), energy values (array), 87 | can also contain other allowed nc.GetYields arguments. 88 | 89 | Calculates: 90 | yield_object (dict): Keys of yield_type, values of yields for given type based on nc.GetYields 91 | 92 | Returns: 93 | getattr(yield_object, yield_type) (array): array of yield values for a given yield_object (nr, etc) 94 | and a given yield_type (photon, electron yield as defined in parameters.) 95 | ''' 96 | if nc is None: 97 | # Cache the default in _NestCalcInit 98 | if 'default' not in _NestCalcInit: 99 | _NestCalcInit['default'] = NESTcalc(DetectorExample_XENON10()) 100 | nc = _NestCalcInit['default'] 101 | if type(interaction) == str: 102 | interaction_object = GetInteractionObject(interaction) 103 | else: 104 | interaction_object = interaction 105 | 106 | yield_object = nc.GetYields(interaction = interaction_object, **kwargs) 107 | # returns the yields for the type of yield we are considering 108 | return getattr(yield_object, yield_type) 109 | 110 | def PhotonYield(**kwargs): 111 | ''' 112 | Calculates photon yield based on GetYieldsVectorized function. 113 | 114 | Parameters: 115 | interaction (str): interaction type, here using 'nr' (nuclear reacoil), 116 | gammaray', 'beta', '206Pb', and 'alpha'. 117 | energy (array): Array of interactions to calculate yields of each. 118 | - Array MUST be the dimensions of # of energy values by # of drift fields (i.e. 2000x14 here) 119 | drift_field (array): Array of drift fields to use, which will be vectorized with energy. 120 | 121 | Returns: 122 | GetYieldsVectorized(yield_object, yield_type='PhotonYield') (array): array of yield values same dimensions as energies 123 | 124 | ''' 125 | return GetYieldsVectorized(yield_type='PhotonYield', **kwargs) 126 | 127 | def ElectronYield(**kwargs): 128 | ''' 129 | Calculates electron yield based on GetYieldsVectorized function. 130 | 131 | Parameters: 132 | interaction (str): interaction type, here using 'nr' (nuclear reacoil), 133 | gammaray', 'beta', '206Pb', and 'alpha'. 134 | energy (array): Array of interactions to calculate yields of each. 135 | - Array MUST be the dimensions of # of energy values by # of drift fields (i.e. 2000x14 here) 136 | drift_field (array): Array of drift fields to use, which will be vectorized with energy. 137 | 138 | Returns: 139 | GetYieldsVectorized(yield_object, yield_type='ElectronYield') (array): array of yield values same dimensions as energies 140 | 141 | ''' 142 | return GetYieldsVectorized(yield_type='ElectronYield', **kwargs) 143 | 144 | def Yield(**kwargs): 145 | ''' 146 | Calculates both electron and photon yields and puts in single dictionary. 147 | - Useful for analysis of one interaction_type. 148 | 149 | Parameters: 150 | Same as PhotonYield and ElectronYield 151 | 152 | Returns: 153 | (dict): dict with photon and electron yields arranged together by keys. 154 | ''' 155 | return {'photon': PhotonYield(**kwargs), 156 | 'electron': ElectronYield(**kwargs), 157 | # What is missing? Aren't there other parts of YieldObject? 158 | } 159 | -------------------------------------------------------------------------------- /tests/core_nest_tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import nestpy 3 | import platform 4 | 5 | class ConstructorTest(unittest.TestCase): 6 | """Test constructors 7 | 8 | These are used in the setup of later tests. Therefore, seperate test 9 | here. 10 | """ 11 | 12 | def test_vdetector_constructor(self): 13 | detector = nestpy.VDetector() 14 | assert detector is not None 15 | assert isinstance(detector, nestpy.VDetector) 16 | 17 | def test_vdetector_initialization(self): 18 | detector = nestpy.VDetector() 19 | detector.Initialization() 20 | assert detector is not None 21 | assert isinstance(detector, nestpy.VDetector) 22 | 23 | def test_xenon_example_constructor(self): 24 | detector = nestpy.DetectorExample_XENON10() 25 | assert detector is not None 26 | assert isinstance(detector, nestpy.DetectorExample_XENON10) 27 | 28 | def test_nestcalc_constructor_vdetect(self): 29 | detector = nestpy.VDetector() 30 | detector.Initialization() 31 | nestcalc = nestpy.NESTcalc(detector) 32 | assert nestcalc is not None 33 | assert isinstance(nestcalc, nestpy.NESTcalc) 34 | 35 | def test_intteraction_type_constructor(self): 36 | it = nestpy.INTERACTION_TYPE(0) 37 | assert it is not None 38 | assert str(it) != "" 39 | assert isinstance(it, nestpy.INTERACTION_TYPE) 40 | 41 | 42 | class VDetectorTest(unittest.TestCase): 43 | 44 | @classmethod 45 | def setUpClass(cls): 46 | cls.detector = nestpy.VDetector() 47 | cls.detector.Initialization() 48 | cls.it = nestpy.INTERACTION_TYPE(0) 49 | cls.nestcalc = nestpy.NESTcalc(cls.detector) 50 | cls.nuisance = cls.nestcalc.default_NRYieldsParam 51 | cls.free = cls.nestcalc.default_NRERWidthsParam 52 | cls.nestcalc = nestpy.NESTcalc(cls.detector) 53 | # def test_fit_s1(self): 54 | # self.detector.FitS1(1.0, 2.0, 3.0) 55 | 56 | def test_fit_ef(self): 57 | self.detector.FitEF(1.0, 2.0, 3.0) 58 | 59 | # def test_fit_s2(self): 60 | # self.detector.FitS2(1.0, 2.0, 3.0) 61 | 62 | def test_fit_tba(self): 63 | self.detector.FitTBA(1.0, 2.0, 3.0) 64 | 65 | 66 | class NESTcalcTest(unittest.TestCase): 67 | 68 | @classmethod 69 | def setUpClass(cls): 70 | cls.detector = nestpy.VDetector() 71 | cls.detector.Initialization() 72 | cls.it = nestpy.INTERACTION_TYPE(0) 73 | cls.nestcalc = nestpy.NESTcalc(cls.detector) 74 | 75 | cls.nuisance = cls.nestcalc.default_NRYieldsParam 76 | cls.free = cls.nestcalc.default_NRERWidthsParam 77 | cls.er_params = cls.nestcalc.default_ERYieldsParam 78 | 79 | def test_interaction_type_constructor(self): 80 | for i in range(5): 81 | it = nestpy.INTERACTION_TYPE(i) 82 | 83 | def test_nestcalc_full_calculation(self): 84 | result = self.nestcalc.FullCalculation(self.it, 1., 2., 3., 4, 5, 85 | self.nuisance, 86 | self.free, 87 | self.er_params, 88 | False) 89 | assert isinstance(result, nestpy.NESTresult) 90 | 91 | def test_nestcalc_get_photon_times(self): 92 | self.nestcalc.GetPhotonTimes(self.it, 10, 10, 10., 10.) 93 | 94 | def test_nestcalc_get_yields(self): 95 | yields = self.nestcalc.GetYields( 96 | self.it, 10., 10., 10., 10., 10., self.nuisance) 97 | 98 | def test_nestcalc_get_yields_defaults(self): 99 | yields = self.nestcalc.GetYields(nestpy.INTERACTION_TYPE(0), 100 | 10) 101 | 102 | def test_nestcalc_get_yields_named(self): 103 | yields = self.nestcalc.GetYields(nestpy.INTERACTION_TYPE(0), 104 | energy=10) 105 | 106 | # def test_nestcalc_get_spike(self): 107 | # # This is stalling some builds. Need to improe the test. 108 | # self.nestcalc.GetSpike(10, 10., 20., 30., 10., 10., [0, 1, 2]) 109 | 110 | def test_nestcalc_get_yield_ER_weighted(self): 111 | self.nestcalc.GetYieldERWeighted(energy=5.2, 112 | density=2.9, 113 | drift_field=124, 114 | ) 115 | 116 | def test_nestcalc_calculate_g2(self): 117 | assert self.nestcalc.CalculateG2(True)[3] > 10 118 | 119 | def test_nestcalc_set_drift_velocity(self): 120 | self.nestcalc.SetDriftVelocity(190, 10, 10) 121 | 122 | def test_nestcalc_set_drift_velocity_non_uniform(self): 123 | self.nestcalc.SetDriftVelocity_NonUniform(190, 10, 10, 10) 124 | 125 | def test_nestcalc_set_denisty(self): 126 | self.nestcalc.SetDensity(190, 10) 127 | 128 | def test_nestcalc_photon_energy(self): 129 | self.nestcalc.PhotonEnergy(True, True, 190) 130 | 131 | def test_nestcalc_calc_electron_LET(self): 132 | # shouldn't have to set third argument.. 133 | # but not a used feature by many so non-urgent to solve 134 | self.nestcalc.CalcElectronLET(100., 54, True) # energy, atom num.(Xe), CSDA 135 | 136 | def test_nest_calc_get_detector(self): 137 | self.nestcalc.GetDetector() 138 | 139 | def test_equality(self): 140 | # Will call a test for the nearlyEqual function to ensure it still works. 141 | self.nestcalc.GetYields(nestpy.INTERACTION_TYPE(0), 100., 2.9, 100., 0., 54, nestpy.default_nr_yields_params(), nestpy.default_er_yields_params(), False) 142 | 143 | 144 | class TestSpectraWIMPTest(unittest.TestCase): 145 | @classmethod 146 | def setUpClass(cls): 147 | cls.spec = nestpy.TestSpectra() 148 | 149 | def test_WIMP_spectrum(self): 150 | self.spec.WIMP_prep_spectrum( 50., 10. ) #mass and energy integration step 151 | self.spec.WIMP_spectrum( self.spec.WIMP_prep_spectrum( 50., 10. ), 50., 0. ) 152 | 153 | 154 | class NESTcalcFullCalculationTest(unittest.TestCase): 155 | 156 | @classmethod 157 | def setUpClass(cls): 158 | cls.detector = nestpy.VDetector() 159 | cls.detector.Initialization() 160 | cls.it = nestpy.INTERACTION_TYPE(0) 161 | 162 | cls.nestcalc = nestpy.NESTcalc(cls.detector) 163 | cls.nuisance = cls.nestcalc.default_NRYieldsParam 164 | cls.free = cls.nestcalc.default_NRERWidthsParam 165 | cls.er_params = cls.nestcalc.default_ERYieldsParam 166 | cls.result = cls.nestcalc.FullCalculation( 167 | cls.it, 10., 3., 100., 131, 56, 168 | cls.nuisance, 169 | cls.free, 170 | cls.er_params, 171 | True) 172 | 173 | cls.position = [2,3,4] 174 | 175 | def test_nestcalc_add_photon_transport_time(self): 176 | # print(self.result.photon_times) 177 | self.nestcalc.AddPhotonTransportTime( 178 | self.result.photon_times, 1.0, 2.0, 3.0) 179 | 180 | def test_nestcalc_get_quanta(self): 181 | self.nestcalc.GetQuanta(self.result.yields, 10., self.free) 182 | 183 | def test_nestcalc_get_quanta_defaults(self): 184 | self.nestcalc.GetQuanta(self.result.yields) 185 | 186 | def test_nestcalc_get_s1(self): 187 | self.nestcalc.GetS1(self.result.quanta, 188 | 10., 10., -30., 189 | 10., 10., -30., 190 | 10., 10., 191 | self.it, 192 | 100, 10., 10., 193 | nestpy.S1CalculationMode.Full, False, 194 | [0, 1, 2], 195 | [0., 1., 2.]) 196 | 197 | def test_nestcalc_get_s2(self): 198 | self.nestcalc.GetS2(self.result.quanta.electrons, #int ne 199 | 10., 10., -30., #truth pos x y z 200 | 10., 10., -30., #smear pos x y z 201 | 10., 10., 202 | 100, 10., 203 | nestpy.S2CalculationMode.Full, False, 204 | [0, 1, 2], 205 | [0., 1., 2.], 206 | [0., 82., 2., 3., 4.]) 207 | 208 | def test_nestcalc_get_xyresolution(self): 209 | self.detector = nestpy.DetectorExample_XENON10() 210 | self.detector.Initialization() 211 | self.nestcalc = nestpy.NESTcalc(self.detector) 212 | self.nestcalc.xyResolution( 213 | 0., 1.,2.) 214 | 215 | class LArNESTTest(unittest.TestCase): 216 | @classmethod 217 | def setUpClass(cls): 218 | cls.detector = nestpy.VDetector() 219 | cls.detector.Initialization() 220 | cls.it = nestpy.LArInteraction(0) 221 | 222 | cls.larnest = nestpy.LArNEST(cls.detector) 223 | cls.result = cls.larnest.full_calculation( 224 | cls.it, 100., 1., 500., 1.393, True 225 | ) 226 | 227 | def test_larnest_get_yields(self): 228 | self.larnest.get_yields(self.it, 100., 1., 500., 1.393) 229 | 230 | if __name__ == "__main__": 231 | unittest.main() 232 | -------------------------------------------------------------------------------- /tests/example_tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class nestpyExamplesTest(unittest.TestCase): 5 | 6 | def test_readme_example(self): 7 | import nestpy 8 | 9 | # This is same as C++ NEST with naming 10 | nc = nestpy.NESTcalc(nestpy.VDetector()) 11 | 12 | interaction = nestpy.INTERACTION_TYPE(0) # NR 13 | 14 | E = 10 # keV 15 | print('For an %s keV %s' % (E, interaction)) 16 | 17 | # Get particle yields 18 | y = nc.GetYields(interaction, E) 19 | 20 | print('The photon yield is:', y.PhotonYield) 21 | print('With statistical fluctuations', nc.GetQuanta(y).photons) 22 | 23 | 24 | if __name__ == "__main__": 25 | unittest.main() 26 | -------------------------------------------------------------------------------- /travis.yml: -------------------------------------------------------------------------------- 1 | # This file is responsible for running the below commands each commit 2 | # on the TravisCI platform. 3 | 4 | language: cpp 5 | 6 | # A matrix build means that the following combinations of configurations 7 | # are tested. 8 | matrix: 9 | include: 10 | - os: osx # Note: we pay extra for OSX for Travis 11 | compiler: clang 12 | - os: linux 13 | compiler: gcc 14 | - os: linux 15 | compiler: clang 16 | 17 | # Email notifications 18 | notifications: 19 | email: 20 | - ncarrara.physics@gmail.com 21 | 22 | # Commands to install 23 | install: 24 | - git submodule update --init --recursive 25 | - pip install . 26 | 27 | # Test commands 28 | script: 29 | - ls 30 | - python tests/core_nest_tests.py -------------------------------------------------------------------------------- /tutorials/InstallAndBasicUsage.ipynb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NESTCollaboration/nestpy/3b5ce873e844666eb6316b0fe9dc4b1ed60ec3fe/tutorials/InstallAndBasicUsage.ipynb -------------------------------------------------------------------------------- /tutorials/arxiv/benchmark_plots.py: -------------------------------------------------------------------------------- 1 | ''' 2 | benchmark_plots.py 3 | Makes plots of nestpy. 4 | 5 | This contains all of the functions that are used to make the plots 6 | which will be called via flask on main.py 7 | 8 | The main components are: 9 | 1. Getting the yields for the interaction types of interest (done via numpy vectorized, rather than a loop) 10 | 2. Defining the plots for each of the yields (these aren't looped over because each of them slightly differs) 11 | 3. Making the plots via one function so that in main.py, you only have to call the one makeplots() 12 | function to make all plots. 13 | 14 | Main ingredients for the above steps: 15 | 1. np.vectorize, dictionary with yields, field array and energy array. 16 | - Note: some of the yields will crash the plots at too high of energies (way above physical meaning) 17 | so np.nan is returned to keep things running. 18 | 2. Plotting tools via matplotlib, but note that all plots are saved in an arbitrary "IMAGE_OBJECTS" object, 19 | which, rather than a file, will store the images in a dictionary when called in main.py 20 | (easier for using with flask.) 21 | ''' 22 | 23 | import matplotlib.pylab as pylab 24 | import matplotlib.pyplot as plt 25 | import numpy as np 26 | import os 27 | 28 | import nestpy 29 | from nestpy import GetInteractionObject 30 | 31 | # Figure parameters common throughout all plots 32 | version_textbox = "NEST v{0} \n nestpy v{1}".format(nestpy.__nest_version__, nestpy.__version__) 33 | bbox = dict(boxstyle="round", fc="1.00", edgecolor='none') 34 | params = {'xtick.labelsize':'x-large', 35 | 'ytick.labelsize':'x-large', 36 | } 37 | # Updates plots to apply the above formatting to all plots in doc 38 | pylab.rcParams.update(params) 39 | 40 | @np.vectorize 41 | def GetYieldsVectorized(interaction, yield_type, **kwargs): 42 | ''' 43 | This function calculates nc.GetYields for the various interactions and arguments we pass into it. 44 | 45 | Requires: 46 | - GetInteractionObject from interactionkeys 47 | - strings passed through get us the numeric equivalent for each interaction 48 | - energy array 49 | - nc.GetYields (pass through interaction, energies, field value) 50 | - Returns dictionary with yield types and yield values at each interaction energy value. 51 | 52 | Parameters: 53 | interaction (str): interaction type, here using 'nr' (nuclear reacoil), 54 | gammaray', 'beta', '206Pb', and 'alpha'. 55 | yield_type (str): Either 'PhotonYield' or 'ElectronYield' to return proper yield values. 56 | **kwargs (var): Field values (array), energy values (array), 57 | can also contain other allowed nc.GetYields arguments. 58 | 59 | Calculates: 60 | yield_object (dict): Keys of yield_type, values of yields for given type based on nc.GetYields 61 | 62 | Returns: 63 | getattr(yield_object, yield_type) (array): array of yield values for a given yield_object (nr, etc) 64 | and a given yield_type (photon, electron yield as defined in parameters.) 65 | ''' 66 | 67 | interaction_object = GetInteractionObject(interaction) 68 | if 'energy' in kwargs.keys(): 69 | if interaction_object == GetInteractionObject('nr') and kwargs['energy'] > 2e2: 70 | return np.nan 71 | if interaction_object == GetInteractionObject('gammaray') and kwargs['energy'] > 3e3: 72 | return np.nan 73 | if interaction_object == GetInteractionObject('beta') and kwargs['energy'] > 3e3: 74 | return np.nan 75 | yield_object = nc.GetYields(interaction = interaction_object, **kwargs) 76 | # returns the yields for the type of yield we are considering 77 | return getattr(yield_object, yield_type) 78 | 79 | def PhotonYield(**kwargs): 80 | ''' 81 | Calculates photon yield based on GetYieldsVectorized function. 82 | 83 | Parameters: 84 | interaction (str): interaction type, here using 'nr' (nuclear reacoil), 85 | gammaray', 'beta', '206Pb', and 'alpha'. 86 | energy (array): Array of interactions to calculate yields of each. 87 | - Array MUST be the dimensions of # of energy values by # of drift fields (i.e. 2000x14 here) 88 | drift_field (array): Array of drift fields to use, which will be vectorized with energy. 89 | 90 | Returns: 91 | GetYieldsVectorized(yield_object, yield_type='PhotonYield') (array): array of yield values same dimensions as energies 92 | 93 | ''' 94 | return GetYieldsVectorized(yield_type = 'PhotonYield', **kwargs) 95 | 96 | def ElectronYield(**kwargs): 97 | ''' 98 | Calculates electron yield based on GetYieldsVectorized function. 99 | 100 | Parameters: 101 | interaction (str): interaction type, here using 'nr' (nuclear reacoil), 102 | gammaray', 'beta', '206Pb', and 'alpha'. 103 | energy (array): Array of interactions to calculate yields of each. 104 | - Array MUST be the dimensions of # of energy values by # of drift fields (i.e. 2000x14 here) 105 | drift_field (array): Array of drift fields to use, which will be vectorized with energy. 106 | 107 | Returns: 108 | GetYieldsVectorized(yield_object, yield_type='ElectronYield') (array): array of yield values same dimensions as energies 109 | 110 | ''' 111 | return GetYieldsVectorized(yield_type = 'ElectronYield', **kwargs) 112 | 113 | def Yield(**kwargs): 114 | ''' 115 | Calculates both electron and photon yields and puts in single dictionary. 116 | - Useful for analysis of one interaction_type. 117 | 118 | Parameters: 119 | Same as PhotonYield and ElectronYield 120 | 121 | Returns: 122 | (dict): dict with photon and electron yields arranged together by keys. 123 | ''' 124 | return {'photon' : PhotonYield(**kwargs), 125 | 'electron' : ElectronYield(**kwargs), 126 | # What is missing? Aren't there other parts of YieldObject? 127 | } 128 | 129 | def make_subplot( 130 | x, 131 | y_photons, 132 | y_electrons, 133 | driftFields, 134 | plot_type, 135 | ): 136 | fig1, ax1 = plt.subplots(1, 1, figsize=(9,6)) 137 | fig2, ax2 = plt.subplots(1, 1, figsize=(9,6)) 138 | 139 | ax1.plot([],[],label=f" NEST v{nestpy.__nest_version__} \n nestpy v{nestpy.__version__}\n", marker='',linestyle='') 140 | ax2.plot([],[],label=f" NEST v{nestpy.__nest_version__} \n nestpy v{nestpy.__version__}\n", marker='',linestyle='') 141 | 142 | for i in range(0, len(driftFields)-2): 143 | ax1.plot(x[i,:], y_photons[i,:], label="{0} V/cm".format(driftFields[i])) 144 | ax2.plot(x[i,:], y_electrons[i,:], label="{0} V/cm".format(driftFields[i])) 145 | 146 | for ax in ax1, ax2: 147 | ax.set_xscale('log') 148 | ax.set_ylim(0) 149 | ax.legend(bbox_to_anchor=(1.05, 1.0), loc='upper left',fontsize=14) 150 | ax.set_xlabel('Recoil Energy [keV]', fontsize=20) 151 | ax.margins(0) 152 | 153 | # ax1.text(1.05, 0.0, 154 | # version_textbox, 155 | # bbox=bbox, horizontalalignment='right', fontsize='x-large') 156 | # ax2.text(1.05, 0.0, 157 | # version_textbox, 158 | # bbox=bbox, horizontalalignment='right', fontsize='x-large') 159 | 160 | ax1.set_ylabel('Light Yield [n$_\gamma$/keV]', fontsize=20) 161 | ax1.set_title('Light Yields for Nuclear Recoils', fontsize=24) 162 | ax2.set_title('Charge Yields for Nuclear Recoils', fontsize=24) 163 | ax2.set_ylabel('Charge Yield [n$_e$/keV]', fontsize=20) 164 | fig1.tight_layout() 165 | fig2.tight_layout() 166 | fig1.savefig(f'plots/{plot_type}_LY.png') 167 | fig2.savefig(f'plots/{plot_type}_QY.png') 168 | 169 | 170 | if __name__ == "__main__": 171 | if not os.path.isdir("plots/"): 172 | os.makedirs("plots/") 173 | 174 | # Detector identification 175 | detector = nestpy.DetectorExample_XENON10() 176 | # Performing NEST calculations according to the given detector example 177 | nc = nestpy.NESTcalc(detector) 178 | #Once you have interaction, you can get yields 179 | 180 | ''' 181 | Below are field and energy arrays. 182 | - Energies are broadcase to be repeated by the dimensions of the fields, 183 | owing to the nature of vectorized functions below. 184 | - Functions will loop over each energy and field simultaneously that way, 185 | rather than nesting for loops inside each other. 186 | ''' 187 | fields = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000] 188 | energies = np.logspace(-1, 4, 2000) 189 | energies = np.broadcast_to(energies, (len(fields), len(energies))) 190 | 191 | # Calculate yields for various benchmark calculations 192 | ''' 193 | This is where the nest calculations actually occur. 194 | - All functions below are essentially the same exact thing, jus__version__ = .nestpy.__version__ 195 | __nest_version__ = .nestpy.__nest_version__t iterated over the 5 interaction types 196 | and the 2 yield types (electron and photon yields). 197 | - Everything done from this point on is just plotting all of this info. 198 | ''' 199 | kwargs = {'energy': energies.T, 'drift_field': fields} 200 | nr_electrons = ElectronYield(interaction='nr', **kwargs).T/energies 201 | nr_photons = PhotonYield(interaction='nr', **kwargs).T/energies 202 | beta_electrons = ElectronYield(interaction='beta', **kwargs).T/energies 203 | beta_photons = PhotonYield(interaction='beta', **kwargs).T/energies 204 | gamma_electrons = ElectronYield(interaction='gammaray', **kwargs).T/energies 205 | gamma_photons = PhotonYield(interaction='gammaray', **kwargs).T/energies 206 | alpha_electrons = ElectronYield(interaction='ion', Z=2, A = 4, **kwargs).T/energies 207 | alpha_photons = PhotonYield(interaction='ion',Z=2, A=4, **kwargs).T/energies 208 | Pb_electrons = ElectronYield(interaction='ion', Z=82, A = 206, **kwargs).T/energies 209 | Pb_photons = PhotonYield(interaction='ion',Z=82, A=206, **kwargs).T/energies 210 | 211 | ''' 212 | This function just takes the above plots and combines into one function to make main.py 213 | easier to manage. 214 | Each are essentially the same thing. 215 | 216 | Parameters: 217 | energies (array): energies broadcasted to the dimensions of fields. (in keV) 218 | photon and electron yields: e.g. nr_photons, nr_electrions (array): calculated from GetYields 219 | fields (array): field values of interest for plotting (V/cm) 220 | IMAGE_DICT (dict): Dictionary that will store the images as objects to call later in flask app. 221 | ''' 222 | make_subplot(energies, nr_photons, nr_electrons, fields, "NR") 223 | make_subplot(energies, beta_photons, beta_electrons, fields, "beta") 224 | make_subplot(energies, gamma_photons, gamma_electrons, fields, "gamma") 225 | make_subplot(energies, alpha_photons, alpha_electrons, fields, "alpha") 226 | make_subplot(energies, Pb_photons, Pb_electrons, fields, "Pb206") -------------------------------------------------------------------------------- /tutorials/arxiv/how_to_maintain.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "How to Maintain nestpy\n", 8 | "--------------------------\n", 9 | "Sophia Andaloro \n", 10 | "
\n", 11 | "Born: July 6, 2020\n", 12 | "
\n", 13 | "Last edit: November 11, 2020" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "## 1. Versioning and updating with NEST" 21 | ] 22 | }, 23 | { 24 | "cell_type": "markdown", 25 | "metadata": {}, 26 | "source": [ 27 | "Run:\n", 28 | "```\n", 29 | "git clone git@github.com:NESTCollaboration/nestpy.git\n", 30 | "```\n", 31 | "Then go to website:\n", 32 | "https://github.com/NESTCollaboration/nest/tags\n", 33 | "To see which tag you want to bind to. In this case 'v2.1.2', so then you go to\n", 34 | "`src/nestpy/__init__.py`\n", 35 | "
\n", 36 | "Then change the version:\n", 37 | "
\n", 38 | "`__nest_version__ = '2.1.2'`" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "Then you have to install nestpy into some environment:
\n", 46 | "`pip freeze | grep nest # no nestpy exists `
\n", 47 | "`python setup.py install`\n", 48 | "
\n", 49 | "such that:\n", 50 | "```\n", 51 | "python -c \"import nestpy;print(nestpy.__nest_version__)\"\n", 52 | "```\n", 53 | "Returns the version you want. Now run `sync.sh` (can run one at a time)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "## sync.sh File:" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "```\n", 68 | "# This script is used for syncing to the NEST main repository\n", 69 | "# to ensure that the bindings bind to the same version of NEST\n", 70 | "export VERSION=`python -c \"import nestpy;print(nestpy.__nest_version__)\"`\n", 71 | "echo $VERSION \n", 72 | "git clone https://github.com/NESTCollaboration/nest.git nest_source\n", 73 | "cd nest_source\n", 74 | "git fetch --all --tags --prune\n", 75 | "git checkout tags/v${VERSION} -b test\n", 76 | "cd ..\n", 77 | "cd src/nestpy\n", 78 | "for filename in *.{cpp,hh}; do\n", 79 | " export REPO_FILE=`find ../../nest_source/ -name ${filename}`\n", 80 | " if [ ! -z \"$REPO_FILE\" -a \"$REPO_FILE\" != \" \" ]; then\n", 81 | " cp $REPO_FILE $filename\n", 82 | " fi\n", 83 | "done\n", 84 | "cd ../..\n", 85 | "#rm -Rf nest_source\n", 86 | "#git commit -m \"Sync with $VERSION\" -a\n", 87 | "```" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "**For now, we have to go to execNEST function and put in the nuisparam and free params**:\n", 95 | "```\n", 96 | "NRYieldsParam = {11., 1.1, 0.0480, -0.0533, 12.6, 0.3, 2., 0.3, 2., 0.5, 1., 1.};\n", 97 | "NRERWidthsParam = {1.,1.,0.1,0.5,0.19,2.25, 0.0015, 0.0553, 0.205, 0.45, -0.2};\n", 98 | "ERWeightParam = {0.23, 0.77, 2.95, -1.44, 1.0, 1.0, 0., 0.};\n", 99 | " ```" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "**Additionally, nestpy requires a different minimum cmake version than the C++ version, so we need to remove the use of gcem in nestpy**:\n", 107 | " \n", 108 | "In NEST.hh, comment out `#include \"gcem.hpp\" `\n", 109 | "And change the lines:\n", 110 | "```\n", 111 | " static constexpr double two_PI = 2. * M_PI;\n", 112 | " static constexpr double sqrt2 = gcem::sqrt(2.);\n", 113 | " static constexpr double sqrt2_PI = gcem::sqrt( 2. * M_PI );\n", 114 | " static constexpr double inv_sqrt2_PI = 1./gcem::sqrt( 2. * M_PI );\n", 115 | "```\n", 116 | "To\n", 117 | "```\n", 118 | " double two_PI = 2. * M_PI;\n", 119 | " double sqrt2 = sqrt(2.);\n", 120 | " double sqrt2_PI = sqrt( 2. * M_PI );\n", 121 | " double inv_sqrt2_PI = 1./sqrt( 2. * M_PI );\n", 122 | "```\n", 123 | "\n", 124 | "\n", 125 | "Additionally, do a similar thing to RandomGen.hh:\n", 126 | "Comment out `#include \"gcem.hpp\"`\n", 127 | "and Change the lines:\n", 128 | "```\n", 129 | " static constexpr double xoroshiro128plus64_min = static_cast(xoroshiro128plus64::min());\n", 130 | " static constexpr double xoroshiro128plus64_minmax = static_cast(xoroshiro128plus64::max() -xoroshiro128plus64::min());\n", 131 | "\n", 132 | " static constexpr double two_PI = 2. * M_PI;\n", 133 | " static constexpr double four_minus_PI_div_2 = 0.5*(4. - M_PI);\n", 134 | " static constexpr double sqrt2 = gcem::sqrt(2.);\n", 135 | " static constexpr double sqrt2_PI = gcem::sqrt( 2. * M_PI );\n", 136 | " static constexpr double sqrt2_div_PI = gcem::sqrt(2./M_PI);\n", 137 | " static constexpr double log2 = gcem::log(2.);\n", 138 | "```\n", 139 | "to \n", 140 | "```\n", 141 | " double xoroshiro128plus64_min = static_cast(xoroshiro128plus64::min());\n", 142 | " double xoroshiro128plus64_minmax = static_cast(xoroshiro128plus64::max() - xoroshiro128plus64::min());\n", 143 | "\n", 144 | " double two_PI = 2. * M_PI;\n", 145 | " double four_minus_PI_div_2 = 0.5*(4. - M_PI);\n", 146 | " double sqrt2 = sqrt(2.);\n", 147 | " double sqrt2_PI = sqrt( 2. * M_PI );\n", 148 | " double sqrt2_div_PI = sqrt(2./M_PI);\n", 149 | " double log2 = log(2.);\n", 150 | "```\n", 151 | "\n", 152 | "So in both files, we've removed any use of gcem for handling constant expressions. " 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "## Edit the histories " 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "- Edit HISTORY with new versions\n", 167 | "```\n", 168 | "cd nestpy\n", 169 | "nano HISTORY.md \n", 170 | "git commit -m \"Edit HISTORY.md for v\" HISTORY.md\n", 171 | "nano src/nestpy/__init__.py\n", 172 | "# Change the version of nestpy here \n", 173 | "```\n", 174 | "- Push changes\n", 175 | "```\n", 176 | "git push\n", 177 | "bumpversion minor # or patch, or major, depending on versioning changes\n", 178 | "git push --tags\n", 179 | "```" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": {}, 185 | "source": [ 186 | "Then you'll want to go into travisCI and see if all checks complete on the commit " 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "# Download custom nestpy" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": {}, 199 | "source": [ 200 | "`pip install --user -U git+https://github.com/NESTCollaboration/nestpy.git` " 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": null, 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [] 209 | } 210 | ], 211 | "metadata": { 212 | "kernelspec": { 213 | "display_name": "Python 3", 214 | "language": "python", 215 | "name": "python3" 216 | }, 217 | "language_info": { 218 | "codemirror_mode": { 219 | "name": "ipython", 220 | "version": 3 221 | }, 222 | "file_extension": ".py", 223 | "mimetype": "text/x-python", 224 | "name": "python", 225 | "nbconvert_exporter": "python", 226 | "pygments_lexer": "ipython3", 227 | "version": "3.8.5" 228 | } 229 | }, 230 | "nbformat": 4, 231 | "nbformat_minor": 4 232 | } 233 | -------------------------------------------------------------------------------- /tutorials/arxiv/setup_notebook.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | warnings.filterwarnings('ignore') 3 | 4 | import matplotlib.pyplot as plt 5 | import matplotlib.pylab as pylab 6 | from matplotlib import cm 7 | from matplotlib.colors import LogNorm 8 | from scipy.stats import gaussian_kde, norm, skewnorm 9 | from scipy.optimize import curve_fit 10 | import pandas as pd 11 | import numpy as np 12 | 13 | 14 | import pprint 15 | pp = pprint.PrettyPrinter(indent=4) 16 | 17 | import nestpy 18 | print('nestpy version: v'+nestpy.__version__) 19 | print('NEST version: v'+nestpy.__nest_version__) 20 | 21 | plt.rcParams['xtick.labelsize']=12 22 | plt.rcParams['ytick.labelsize']=12 23 | plt.rcParams['xtick.direction']='out' 24 | plt.rcParams['ytick.direction']='out' 25 | 26 | plt.rcParams['xtick.major.size']=10 27 | plt.rcParams['ytick.major.size']=10 28 | plt.rcParams['xtick.major.pad']=5 29 | plt.rcParams['ytick.major.pad']=5 30 | 31 | plt.rcParams['xtick.minor.size']=5 32 | plt.rcParams['ytick.minor.size']=5 33 | plt.rcParams['xtick.minor.pad']=5 34 | plt.rcParams['ytick.minor.pad']=5 35 | 36 | font_small = {'family': 'serif', 37 | 'color': 'darkred', 38 | 'weight': 'normal', 39 | 'size': 16, 40 | } 41 | 42 | font_medium = {'family': 'serif', 43 | 'color': 'darkred', 44 | 'weight': 'normal', 45 | 'size': 20, 46 | } 47 | 48 | font_large = {'family': 'serif', 49 | 'color': 'darkred', 50 | 'weight': 'normal', 51 | 'size': 24, 52 | } 53 | params = {'xtick.labelsize':'x-large', 54 | 'ytick.labelsize':'x-large', 55 | } 56 | # Updates plots to apply the above formatting to all plots in doc 57 | pylab.rcParams.update(params) --------------------------------------------------------------------------------