-
Notifications
You must be signed in to change notification settings - Fork 30
PISN & type Ia models - On hold #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jpkneller
wants to merge
55
commits into
main
Choose a base branch
from
jpkneller-pisn-models
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
b6e6393
Add files via upload
jpkneller 6085250
Rename doc/source/nb/Wright_2017.ipynb to doc/source/nb/pisn/Wright_2…
jpkneller e98787d
Add files via upload
jpkneller 9cdad25
TypeIa SN models
jpkneller 4b97bcd
Add files via upload
jpkneller e3d6d47
Add files via upload
jpkneller 96254aa
Rename doc/source/nb/TypeIa.ipynb to doc/source/nb/TypeIa/TypeIa.ipynb
jpkneller 0b21198
Merge pull request #416 from SNEWS2/jpkneller-TypeIa
JostMigenda 66b0724
Update ccsn.py
jpkneller f504a57
Update base.py
jpkneller 97c6715
Update typeIa_loaders.py
jpkneller 06a505a
Update typeIa.py
jpkneller ae38d88
Update pisn_loaders.py
jpkneller 08a9f53
Update model_files.yml
jpkneller e6dd5cc
Merge branch 'main' into jpkneller-pisn-models
jpkneller d5ae064
Update SNOwGLoBES_models.ipynb
jpkneller 411a35b
Update base.py
jpkneller c6dcbf7
Update base.py
jpkneller c3da4d7
Update typeIa.py
jpkneller aefbb76
Update typeIa_loaders.py
jpkneller 6df4791
Update TypeIa.ipynb
jpkneller 40de9b2
Update base.py
jpkneller 1d27eab
Update typeIa_loaders.py
jpkneller eb2623f
Update pisn_loaders.py
jpkneller 867c829
Update base.py
jpkneller 72c8421
Update model_files.yml
jpkneller b95458b
Update model_files.yml
jpkneller 47bd360
Create test_pisn_rates.py
jpkneller c6500ee
Update test_pisn_rates.py
jpkneller 6eec0fc
Update test_pisn_rates.py
jpkneller e3f6e81
Update test_pisn_rates.py
jpkneller 40472c1
Update test_pisn_rates.py
jpkneller 3f18a04
Update test_pisn_rates.py
jpkneller ba5743b
Update test_pisn_rates.py
jpkneller 28fb4fa
Update base.py
jpkneller 61dbfbd
Update base.py
jpkneller 35280e1
Update base.py
jpkneller 46e03da
Update base.py
jpkneller ad74522
Update base.py
jpkneller 7949db1
Update base.py
jpkneller a628f16
Update base.py
jpkneller 176c47d
Update base.py
jpkneller 472de1f
Update base.py
jpkneller aef02fa
Update base.py
jpkneller ac70072
Update base.py
jpkneller 154efe6
Update base.py
jpkneller 856922b
Update base.py
jpkneller 71ae985
Update base.py
jpkneller e904771
Update model_files.yml
jpkneller f871788
Update test_pisn_rates.py
jpkneller 8392556
Update test_pisn_rates.py
jpkneller a547450
Create test_typeIa_rates.py
jpkneller cb54312
Merge branch 'main' into jpkneller-pisn-models
jpkneller d38ee56
Update ccsn_loaders.py
jpkneller f22d332
Update ccsn.py
jpkneller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| The submodule ``snewpy.models.pisn`` contains models of pair-instability supernova neutrino fluxes, | ||
| """ | ||
| import logging | ||
| import os | ||
|
|
||
| from astropy import units as u | ||
|
|
||
| from snewpy.models import pisn_loaders as loaders | ||
| from .base import SupernovaModel | ||
|
|
||
| from snewpy.models.registry_model import RegistryModel, Parameter | ||
| from snewpy.models.registry_model import all_models | ||
|
|
||
| @RegistryModel( | ||
| progenitor_mass = [150, 250] * u.Msun, | ||
| eos = ['SFHo', 'Helm'] | ||
| ) | ||
| class Wright_2017(loaders.Wright_2017): | ||
| """PISN model described in the paper `Neutrino signal from pair-instability supernovae' by Wright et al., | ||
| Phys. Rev. D96 (2017) 103008 <https://journals.aps.org/prd/abstract/10.1103/PhysRevD.96.103008>`_ | ||
| """ | ||
| def _metadata_from_filename(self, filename:str): | ||
| metadata = { | ||
| 'Progenitor mass': float(filename.split('_')[1].strip('Msun')) * u.Msun, | ||
| 'EOS': filename.split('_')[2].strip('EOS=') | ||
| } | ||
| return metadata | ||
|
|
||
| def __init__(self, progenitor_mass:u.Quantity, eos:str): | ||
| filename=f"PISN_{progenitor_mass.to_value('Msun'):.0f}Msun_EOS={eos}_NeutrinoFlux.tar.bz2" | ||
| super().__init__(filename, self.metadata) | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| The submodule ``snewpy.models.pisn_loaders`` contains classes to load pair-instability supernova | ||
| models from files stored on disk. | ||
| """ | ||
| import logging | ||
| import os | ||
| import numpy as np | ||
| import pandas as pd | ||
| import tarfile | ||
|
|
||
| from astropy import units as u | ||
| from astropy.table import Table | ||
|
|
||
| from scipy import interpolate | ||
|
|
||
| from snewpy.models.base import SupernovaModel | ||
| from snewpy.flavor import ThreeFlavor | ||
| from snewpy.flux import Spectrum | ||
| from snewpy import _model_downloader | ||
|
|
||
|
|
||
| class Wright_2017(SupernovaModel): | ||
| """PISN model described in the paper `Neutrino signal from pair-instability supernovae' by Wright et al., | ||
| Phys. Rev. D96 (2017) 103008 <https://journals.aps.org/prd/abstract/10.1103/PhysRevD.96.103008>` | ||
| """ | ||
|
|
||
| def __init__(self, filename, metadata={}): | ||
| """ | ||
| Parameters | ||
| ---------- | ||
| tarfilename: str | ||
| Absolute or relative path to tar archive | ||
| """ | ||
| # Open the requested filename using the model downloader. | ||
| datafile = self.request_file(filename) | ||
|
|
||
| tf = tarfile.open(datafile) | ||
|
|
||
| # Find the "NoOsc" files. | ||
| datafiles = sorted([f.name for f in tf if '.dat' in f.name]) | ||
| nooscfiles = [df for df in datafiles if 'NoOsc' in df] | ||
| nooscfiles.sort(key=len) | ||
|
|
||
| # Loop through the NoOsc files and pull out the number fluxes. | ||
| self.time = [] | ||
| self.energy = None | ||
| self.initial_spectra = {} | ||
| self.interpolation = {} | ||
|
|
||
| self._flavorkeys = {ThreeFlavor.NU_E: 'NuE', | ||
| ThreeFlavor.NU_E_BAR: 'aNuE', | ||
| ThreeFlavor.NU_MU: 'NuMu', | ||
| ThreeFlavor.NU_MU_BAR: 'aNuMu', | ||
| ThreeFlavor.NU_TAU: 'NuTau', | ||
| ThreeFlavor.NU_TAU_BAR: 'aNuTau'} | ||
|
|
||
| for nooscfile in nooscfiles: | ||
| with tf.extractfile(nooscfile) as f: | ||
| logging.debug('Reading {}'.format(nooscfile)) | ||
| meta = f.readline() | ||
| metatext = meta.decode('utf-8') | ||
| t = float(metatext.split('TBinMid=')[-1].split('sec')[0]) | ||
| dt = float(metatext.split('tBinWidth=')[-1].split('s')[0]) | ||
| dE = float(metatext.split('eBinWidth=')[-1].split('MeV')[0]) | ||
|
|
||
| data = Table.read(f, format='ascii.commented_header', header_start=-1) | ||
| data.meta['t'] = t | ||
| data.meta['dt'] = dt | ||
| data.meta['dE'] = dE | ||
|
|
||
| self.time.append(t) | ||
|
|
||
| if self.energy is None: | ||
| self.energy = (data['E(GeV)'].data*1000).tolist() | ||
|
|
||
| for flavor in ThreeFlavor: | ||
| key = self._flavorkeys[flavor] | ||
| # convert from flux back to initial spectra: number per /s/erg | ||
| spectrum = data[key].data.tolist() * (4*np.pi*(10*u.kpc)**2) /dt/dE | ||
| if flavor in self.initial_spectra: | ||
| self.initial_spectra[flavor].append(spectrum) | ||
| else: | ||
| self.initial_spectra[flavor] = [spectrum] | ||
|
|
||
| for flavor in ThreeFlavor: | ||
| self.interpolation[flavor] = interpolate.RegularGridInterpolator((self.time, self.energy), self.initial_spectra[flavor], method='cubic') | ||
|
|
||
| self.time *= u.s | ||
| self.energy *= u.MeV | ||
|
|
||
| self.filename = os.path.basename(filename) | ||
|
|
||
| def _get_initial_spectra_dict(self, t, E, flavors=ThreeFlavor): | ||
| """Get neutrino spectra/luminosity curves after oscillation. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| t : astropy.Quantity | ||
| Time to evaluate initial spectra. | ||
| E : astropy.Quantity or ndarray of astropy.Quantity | ||
| Energies to evaluate the initial spectra. | ||
| flavors: iterable of snewpy.neutrino.Flavor | ||
| Return spectra for these flavors only (default: all) | ||
|
|
||
| Returns | ||
| ------- | ||
| spectra : dict | ||
| Dictionary of model spectra, keyed by neutrino flavor. | ||
| """ | ||
| #convert input arguments to 1D arrays | ||
| t = u.Quantity(t, ndmin=1) | ||
| E = u.Quantity(E, ndmin=1) | ||
|
|
||
| initial_spectra = {} | ||
| for flavor in ThreeFlavor: | ||
| initial_spectra[flavor] = self.interpolation[flavor]((t, E)) / (u.MeV * u.s) | ||
|
|
||
| return initial_spectra | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| The submodule ``snewpy.models.typeIa`` contains models of neutrino fluxes from Type Ia supernovae | ||
| """ | ||
| import logging | ||
| import os | ||
|
|
||
| from astropy import units as u | ||
|
|
||
| from snewpy.models import typeIa_loaders as loaders | ||
| from .base import SupernovaModel | ||
|
|
||
| from snewpy.models.registry_model import RegistryModel, Parameter | ||
| from snewpy.models.registry_model import all_models | ||
|
|
||
| @RegistryModel( | ||
| mechanism = ['GCD', 'DDT'], | ||
| ) | ||
| class TypeIa(loaders.TypeIa): | ||
| """The DDT model is described in 'Neutrinos from type Ia supernovae: The deflagration-to-detonation transition scenario', by Warren P. Wright et al., | ||
| [Phys. Rev. D94 (2016) 025026](https://journals.aps.org/prd/abstract/10.1103/PhysRevD.94.025026), [arXiv:1605.01408](https://arxiv.org/abs/1605.01408). | ||
| There are 30 snapshots in time and the format of each data file is the SNOwGLoBES format. | ||
|
|
||
| The GCD model is described in 'Neutrinos from type Ia supernovae: The gravitationally confined detonation scenario' by Warren P. Wright et al., | ||
| [Phys. Rev. D95 (2017) 043006](https://journals.aps.org/prd/abstract/10.1103/PhysRevD.95.043006), [arXiv:1609.07403](https://arxiv.org/abs/1609.07403). | ||
| There are 64 snapshots in time and the format of each data file is the SNOwGLoBES format. | ||
| """ | ||
| def _metadata_from_filename(self, filename:str): | ||
| metadata = { | ||
| 'mechanism': filename.split('_')[0] | ||
| } | ||
| return metadata | ||
|
|
||
| def __init__(self, mechanism:str): | ||
| filename = f"{mechanism}_NeutrinoFlux.tar.bz2" | ||
| super().__init__(filename) | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both
tandEare multi-element arrays (e.g. if we domodel.get_flux(times, energies, d)as demonstrated inFlavorTransformation.ipynb), this will fail.The fix could be something like:
(Note that we also need to remove the units in between, otherwise
np.stackwill complain that we’re mixing units.)I’ve played around with a toy example to figure out the correct order of indices (
self.interpolation[flavor](tE_grid)[i, j] == self.interpolation[flavor]((t[i], E[j]))), but since this is so easy to mix up, I would appreciate if someone could double-check that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same applies to the
TypeIaclass.