Skip to content

Commit

Permalink
Merge branch 'main' into cevns-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheshuk committed May 21, 2024
2 parents 6d02296 + f5281c2 commit e800707
Show file tree
Hide file tree
Showing 47 changed files with 4,518 additions and 1,194 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -38,3 +38,14 @@ jobs:
run: |
python -m unittest python/snewpy/test/simplerate_integrationtest.py
pytest -m 'snowglobes'
- name: Run Jupyter notebooks
run: |
pip install nbclient ipykernel
jupyter kernelspec list
cd doc/nb/
jupyter execute ccsn/*.ipynb
jupyter execute presn/*.ipynb
jupyter execute AnalyticFluence.ipynb FlavorTransformation.ipynb
# Download necessary progenitor file, before executing the notebook
python -c 'from snewpy.models.ccsn import Zha_2021; from astropy import units as u; _ = Zha_2021(progenitor_mass=17*u.solMass)'
jupyter execute SNOwGLoBES_usage.ipynb
24 changes: 14 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,35 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Check and get Version Number
id: get_version
run: |
pip install .
PYTHON_VERSION=`python -c 'import snewpy; print(snewpy.__version__)'`
echo "PYTHON_VERSION=${PYTHON_VERSION}"
GIT_VERSION=${GITHUB_REF/refs\/tags\/v/}
echo "GIT_VERSION=${GIT_VERSION}"
if [ $PYTHON_VERSION != $GIT_VERSION ]; then exit 1; fi
echo "VERSION=${PYTHON_VERSION}" >> $GITHUB_OUTPUT
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_JM }}
run: |
python -c 'import python.snewpy; python.snewpy._get_model_urls()'
cat python/snewpy/_model_urls.py
pip install .
python -c 'import snewpy; snewpy.get_models(models="Bollig_2016")'
rm -r SNEWPY_models/
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Get Version Number
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Create Draft Release
# Go to https://github.com/SNEWS2/snewpy/releases to edit this draft release and publish it
# Once it is published, the release automatically is pushed to Zenodo: https://doi.org/10.5281/zenodo.4498940
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Set up the Python environment and dependencies
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Install SNEWPY
run: |
pip install ".[dev]"
pip install ".[dev,docs]"
# Run the unit tests
- name: Test with pytest
- name: Run unit tests with pytest
run: |
pytest -m 'not snowglobes'
- name: Build HTML docs
run: |
cd doc/
make html
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ dist/
# default directory for downloaded model files
SNEWPY_models/

# snewpy.snowglobes output files
## SNEWPY output files
# snewpy.snowglobes intermediate results
*_SNOprocessed.tar.gz
*.npy
*.npz

# used for integration tests in test_snowglobes.py
fluence_Bollig_2016_s*
# plots generated by FlavorTransformation.ipynb
doc/nb/*_adiabaticmsw*.pdf

# editor-specific
.ipynb_checkpoints/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SNEWPY: Supernova Neutrino Early Warning Models for Python

<img src="/doc/source/snewpy-logo.png" alt="snewpy logo: The word 'snewpy' in a monospace font, with an explosion emoji inside the letter 'p'." style="width: 300px; max-width: 100%;" />
<img src="https://github.com/SNEWS2/snewpy/blob/v1.4/doc/source/snewpy-logo.png?raw=true" alt="snewpy logo: The word 'snewpy' in a monospace font, with an explosion emoji inside the letter 'p'." style="width: 300px; max-width: 100%;" />

[![DOI](https://zenodo.org/badge/221705586.svg)](https://zenodo.org/badge/latestdoi/221705586)
[![PyPI](https://img.shields.io/pypi/v/snewpy)](https://pypi.org/project/snewpy/)
Expand Down Expand Up @@ -53,9 +53,9 @@ flux = bollig.get_flux(distance=10*u.kpc, transformation=msw_nmo)

You can also calculate the observed event rate in all neutrino detectors supported by SNOwGLoBES, use the included SN models and flavor transformations in event generators like sntools, and much more.

Example scripts which show how SNEWPY can be used are available in the
`python/snewpy/scripts/` subfolder as well as notebooks in `doc/nb/`.
Most downloadable models also include a Jupyter notebook with simple usage examples.
Jupyter notebooks showcasing the downloadable supernova models available through SNEWPY and much of its functionality are available in the `doc/nb/` subfolder.
Additional example scripts are in the
`python/snewpy/scripts/` subfolder.

Papers describing SNEWPY and the underlying physics are published in the Astrophysical Journal ([DOI:10.3847/1538-4357/ac350f](https://dx.doi.org/10.3847/1538-4357/ac350f), [arXiv:2109.08188](https://arxiv.org/abs/2109.08188)) and the Journal of Open Source Software ([DOI:10.21105/joss.03772](https://dx.doi.org/10.21105/joss.03772)).

Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
ALLSPHINXOPTS = -W --keep-going -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source

Expand Down
22 changes: 8 additions & 14 deletions doc/nb/AnalyticFluence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,17 @@
"import matplotlib as mpl\n",
"import numpy as np\n",
"\n",
"from snewpy import snowglobes\n",
"from snewpy import snowglobes, model_path\n",
"from snewpy.neutrino import Flavor\n",
"from snewpy.models import Analytic3Species\n",
"from snewpy.models.ccsn import Analytic3Species\n",
"\n",
"mpl.rc('font', size=14)\n",
"\n",
"SNOwGLoBES_path = None # change to SNOwGLoBES directory if using a custom detector configuration\n",
"SNEWPY_models_base = \"/path/to/snewpy/models/\" # change to local directory where models are located\n",
"\n",
"model_folder = f\"{SNEWPY_models_base}/AnalyticFluence/\"\n",
"try:\n",
" os.mkdir(model_folder)\n",
"except OSError as e:\n",
" print(model_folder)\n",
" print(f\"Folder {model_folder} already exists or path is wrong\")\n",
"else:\n",
" print(f\"Created folder {model_folder}\")\n"
"\n",
"model_folder = f\"{model_path}/AnalyticFluence/\"\n",
"os.makedirs(model_folder, exist_ok=True)\n",
"print(f\"Using folder `{model_folder}`.\")"
]
},
{
Expand Down Expand Up @@ -97,7 +91,7 @@
" print(\"incorrect second moment method: rms or pinch\")\n",
"\n",
"filename = \"AnalyticFluence_demo.dat\"\n",
"table.write(model_folder+\"/\"+filename,format='ascii',overwrite=True)"
"table.write(model_folder + filename, format='ascii', overwrite=True)"
]
},
{
Expand All @@ -115,7 +109,7 @@
"source": [
"%matplotlib inline\n",
"filename = \"AnalyticFluence_demo.dat\"\n",
"model = Analytic3Species(model_folder+\"/\"+filename)\n",
"model = Analytic3Species(model_folder + filename)\n",
"flavors = [Flavor.NU_E,Flavor.NU_E_BAR,Flavor.NU_X]\n",
"\n",
"fig,axes = plt.subplots(1,3,figsize=(16,3))\n",
Expand Down
14 changes: 9 additions & 5 deletions doc/nb/FlavorTransformation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,11 @@
"outputs": [],
"source": [
"fig = plot_total_flux(model, AdiabaticMSW(), AdiabaticMSW(mh=MassHierarchy.INVERTED) )\n",
"fig.savefig('flux_adiabaticmsw.pdf')\n",
"fig.show()\n",
"# fig.savefig('flux_adiabaticmsw.pdf')\n",
"fig = plot_spectra(model, AdiabaticMSW(), AdiabaticMSW(mh=MassHierarchy.INVERTED), 100*u.ms)\n",
"fig.savefig('spectra_adiabaticmsw.pdf')"
"fig.show()\n",
"# fig.savefig('spectra_adiabaticmsw.pdf')"
]
},
{
Expand All @@ -264,9 +266,11 @@
"xf_imo = AdiabaticMSWes(angles_imo)\n",
"\n",
"fig = plot_total_flux(model, xf_nmo, xf_imo)\n",
"fig.savefig('flux_adiabaticmswes.pdf')\n",
"fig.show()\n",
"# fig.savefig('flux_adiabaticmswes.pdf')\n",
"fig = plot_spectra(model, xf_nmo, xf_imo, 100*u.ms)\n",
"fig.savefig('spectra_adiabaticmswes.pdf')"
"fig.show()\n",
"# fig.savefig('spectra_adiabaticmswes.pdf')"
]
}
],
Expand All @@ -286,7 +290,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
"version": "3.12.3"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit e800707

Please sign in to comment.