-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move common prediction code to SpecModel method. Add basic polycal te…
…st; fix imports; fix speccal bugs in SpecModel.
- Loading branch information
Showing
5 changed files
with
127 additions
and
25 deletions.
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
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
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from .observation import Observation | ||
from .observation import Photometry, Spectrum, Lines, UndersampledSpectrum, IntrinsicSpectrum | ||
from .observation import Photometry, Spectrum, Lines | ||
from .observation import UndersampledSpectrum, IntrinsicSpectrum | ||
from .observation import PolyOptCal, SplineOptCal | ||
from .observation import from_oldstyle, from_serial | ||
|
||
__all__ = ["Observation", | ||
"Photometry", "Spectrum", "Lines", | ||
"UndersampledSpectrum", "InstrinsicSpectrum", | ||
"PolyOptCal", "SplineOptCal", | ||
"from_oldstyle", "from_serial"] |
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
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from prospect.sources import CSPSpecBasis | ||
from prospect.models import SpecModel, templates | ||
from prospect.observation import Spectrum, Photometry, PolyOptCal | ||
|
||
|
||
class PolySpectrum(PolyOptCal, Spectrum): | ||
pass | ||
|
||
|
||
|
||
@pytest.fixture | ||
def get_sps(): | ||
sps = CSPSpecBasis(zcontinuous=1) | ||
return sps | ||
|
||
|
||
def build_model(add_neb=False): | ||
model_params = templates.TemplateLibrary["parametric_sfh"] | ||
if add_neb: | ||
model_params.update(templates.TemplateLibrary["nebular"]) | ||
return SpecModel(model_params) | ||
|
||
|
||
def build_obs(multispec=False): | ||
N = 1500 * (2 - multispec) | ||
wmax = 7000 | ||
wsplit = wmax - N * multispec | ||
|
||
fnames = list([f"sdss_{b}0" for b in "ugriz"]) | ||
Nf = len(fnames) | ||
phot = [Photometry(filters=fnames, | ||
flux=np.ones(Nf), | ||
uncertainty=np.ones(Nf)/10)] | ||
spec = [PolySpectrum(wavelength=np.linspace(4000, wsplit, N), | ||
flux=np.ones(N), | ||
uncertainty=np.ones(N) / 10, | ||
mask=slice(None), | ||
polynomial_order=5) | ||
] | ||
|
||
if multispec: | ||
spec += [Spectrum(wavelength=np.linspace(wsplit+1, wmax, N), | ||
flux=np.ones(N), uncertainty=np.ones(N) / 10, | ||
mask=slice(None))] | ||
|
||
obslist = spec + phot | ||
[obs.rectify() for obs in obslist] | ||
return obslist | ||
|
||
|
||
def test_polycal(plot=False): | ||
"""Make sure the polynomial optimization works | ||
""" | ||
sps = get_sps | ||
observations = build_obs() | ||
model = build_model() | ||
|
||
preds, extra = model.predict(model.theta, observations=observations, sps=sps) | ||
obs = observations[0] | ||
|
||
assert np.any(obs.response != 0) | ||
|
||
if plot: | ||
import matplotlib.pyplot as pl | ||
fig, axes = pl.subplots(3, 1, sharex=True) | ||
ax = axes[0] | ||
ax.plot(obs.wavelength, obs.flux, label="obseved flux (ones)") | ||
ax.plot(obs.wavelength, preds[0], label="model flux (times response)") | ||
ax = axes[1] | ||
ax.plot(obs.wavelength, obs.response, label="instrumental response (polynomial)") | ||
ax = axes[2] | ||
ax.plot(obs.wavelength, preds[0]/ obs.response, label="intrinsic model spectrum") | ||
ax.set_xlabel("wavelength") | ||
[ax.legend() for ax in axes] |