-
Notifications
You must be signed in to change notification settings - Fork 65
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
adding G10 and C11 intrinsic scattering models #378
Open
bastiencarreres
wants to merge
21
commits into
sncosmo:master
Choose a base branch
from
bastiencarreres:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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.
Open
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a7ac69b
add G10 model
6558af3
G10 update
1eea86e
Update models.py
b6cedd9
add C11
c85fe40
modify doc
b265691
modify comments
e211155
Merge pull request #1 from bastiencarreres/C11_model
9ef280e
Remove random variability between call
d741c9e
Merge pull request #2 from bastiencarreres/C11_model
28ea5e0
Delete machinefile
38a8ead
update
6eae0a0
Merge branch 'sncosmo:master' into master
e05557e
add doc for color dependant scatter
f2209bb
Merge pull request #3 from bastiencarreres/dev_docs
4883594
add test for G10
315bf38
add test for G10 and C11
f30afbc
Merge pull request #4 from bastiencarreres/dev_tests
91f8428
Update models.rst
3beb6c4
Add asked changes
bastiencarreres 63b56b9
correct style
bastiencarreres 252a473
correct style
bastiencarreres File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
) | ||
from .magsystems import get_magsystem | ||
from .salt2utils import BicubicInterpolator, SALT2ColorLaw | ||
from .utils import integration_grid | ||
from .utils import integration_grid, sine_interp | ||
|
||
__all__ = ['get_source', 'Source', 'TimeSeriesSource', 'StretchSource', | ||
'SUGARSource', 'SALT2Source', 'SALT3Source', 'MLCS2k2Source', | ||
|
@@ -2030,3 +2030,95 @@ def propagate(self, wave, flux, phase=None): | |
"""Propagate the flux.""" | ||
ebv = self._parameters[0] | ||
return extinction.apply(self._f(wave, ebv * self._r_v), flux) | ||
|
||
|
||
class G10(PropagationEffect): | ||
"""Guy (2010) SNe Ia non-coherent scattering. | ||
|
||
Implementation is done following arxiv:1209.2482.""" | ||
|
||
_param_names = ['L0', 'F0', 'F1', 'dL'] | ||
param_names_latex = [r'\lambda_0', 'F_0', 'F_1', 'd_L'] | ||
|
||
def __init__(self, SALTsource): | ||
"""Initialize G10 class.""" | ||
self._parameters = np.array([2157.3, 0.0, 1.08e-4, 800]) | ||
self._colordisp = SALTsource._colordisp | ||
self._minwave = SALTsource.minwave() | ||
self._maxwave = SALTsource.maxwave() | ||
|
||
def compute_sigma_nodes(self): | ||
"""Computes the sigma nodes.""" | ||
L0, F0, F1, dL = self._parameters | ||
lam_nodes = np.arange(self._minwave, self._maxwave, dL) | ||
if lam_nodes.max() < self._maxwave: | ||
lam_nodes = np.append(lam_nodes, self._maxwave) | ||
siglam_values = self._colordisp(lam_nodes) | ||
|
||
siglam_values[lam_nodes < L0] *= 1 + (lam_nodes[lam_nodes < L0] - L0) * F0 | ||
siglam_values[lam_nodes > L0] *= 1 + (lam_nodes[lam_nodes > L0] - L0) * F1 | ||
siglam_values *= np.random.normal(size=len(lam_nodes)) | ||
|
||
return lam_nodes, siglam_values | ||
|
||
def propagate(self, wave, flux): | ||
"""Propagate the effect to the flux.""" | ||
lam_nodes, siglam_values = self.compute_sigma_nodes() | ||
magscat = sine_interp(wave, lam_nodes, siglam_values) | ||
return flux * 10**(-0.4 * magscat) | ||
|
||
|
||
class C11(PropagationEffect): | ||
"""C11 scattering effect for sncosmo. | ||
Use COV matrix between the vUBVRI bands from N. Chottard thesis. | ||
Implementation is done following arxiv:1209.2482.""" | ||
|
||
_param_names = ["C_vU", 'S_f'] | ||
param_names_latex = ["\rho_\mathrm{vU}", 'S_f'] | ||
_minwave = 2000 | ||
_maxwave = 11000 | ||
|
||
def __init__(self): | ||
"""Initialise C11 class.""" | ||
self._parameters = np.array([0., 1.3]) | ||
|
||
# vUBVRI lambda eff | ||
self._lam_nodes = np.array([2500.0, 3560.0, 4390.0, 5490.0, 6545.0, 8045.0]) | ||
|
||
# vUBVRI correlation matrix extract from SNANA, came from N.Chotard thesis | ||
self._corr_matrix = np.array( | ||
[ | ||
[+1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000], | ||
[ 0.000000, +1.000000, -0.118516, -0.768635, -0.908202, -0.219447], | ||
[ 0.000000, -0.118516, +1.000000, +0.570333, -0.238470, -0.888611], | ||
[ 0.000000, -0.768635, +0.570333, +1.000000, +0.530320, -0.399538], | ||
[ 0.000000, -0.908202, -0.238470, +0.530320, +1.000000, +0.490134], | ||
[ 0.000000, -0.219447, -0.888611, -0.399538, +0.490134, +1.000000] | ||
] | ||
) | ||
|
||
self._corr_matrix[0, 1:] = self._parameters[0] * self._corr_matrix[1, 1:] | ||
self._corr_matrix[1:, 0] = self._parameters[0] * self._corr_matrix[1:, 1] | ||
|
||
# vUBVRI sigma | ||
self._siglam_values = np.array([0.5900, 0.06001, 0.040034, 0.050014, 0.040017, 0.080007]) | ||
|
||
# Convert corr to cov | ||
self._cov_matrix = self._corr_matrix * np.outer(self._siglam_values, | ||
self._siglam_values) | ||
# Rescale covariance as in arXiv:1209.2482 | ||
self._cov_matrix *= self._parameters[1] | ||
|
||
def propagate(self, wave, flux): | ||
"""Propagate the effect to the flux.""" | ||
siglam_values = np.random.multivariate_normal(np.zeros(len(self._lam_nodes)), self._cov_matrix) | ||
|
||
inf_mask = wave <= self._lam_nodes[0] | ||
sup_mask = wave >= self._lam_nodes[-1] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these first three statements could be moved to |
||
magscat = np.zeros(len(wave)) | ||
magscat[inf_mask] = siglam_values[0] | ||
magscat[sup_mask] = siglam_values[-1] | ||
magscat[~inf_mask & ~sup_mask] = sine_interp(wave[~inf_mask & ~sup_mask], self._lam_nodes, siglam_values) | ||
|
||
return flux * 10**(-0.4 * magscat) |
This file contains 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
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.
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.
Would moving this to
__init__
make thisSALTwithG10.bandflux
the same on repeated calls?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.
Yes it should works since the random part is in
self.compute_sigma_nodes()
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.
Moving this part in
__init__
leads to a non-functionalModel.set()
since the updates onself._parameters
will not be taken into account. I set aself._seed
parameter in the__init__
to fix the randomness when init the model.