Skip to content

Commit

Permalink
Merge pull request #220 from hamogu/spectra_tests
Browse files Browse the repository at this point in the history
Add additional tests to see that spectral density is handled right
  • Loading branch information
hamogu authored Sep 19, 2020
2 parents fa9272c + 6f3dae6 commit f8a2bb8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions marxs/source/tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,26 @@ def test_disk_distribution(diskclass, diskpar, n_expected):
# better: Test number of expected photons matches
# Allow large variation so that this is not triggered by chance
assert np.isclose(n.mean(), n_expected, rtol=.2)


def test_spectral_density():
'''Two tests that check that spectral density units are treated correctly'''
spec1 = QTable({'energy': [1, 2, 3] * u.keV,
'fluxdensity': [1, 1, 1.] / u.s / u.cm**2 / u.keV})
spec2 = QTable({'energy': [1, 1.5, 2, 2.5, 3] * u.keV,
'fluxdensity': [1, 1, 1, 1., 1.] / u.s / u.cm**2 / u.keV})
spec3 = QTable({'energy': [1, 2, 3] * u.keV,
'fluxdensity': [1, 1, 2.] / u.s / u.cm**2 / u.keV})
spec4 = QTable({'energy': [1, 1.5, 2, 2.5, 3] * u.keV,
'fluxdensity': [1, 1, 1, 2., 2.] / u.s / u.cm**2 / u.keV})

for sp1, sp2 in zip([spec1, spec3], [spec2, spec4]):
s1 = PointSource(coords=SkyCoord(-123., -43., unit=u.deg),
energy=sp1, flux=1/u.s/u.cm**2)
s2 = PointSource(coords=SkyCoord(-123., -43., unit=u.deg),
energy=sp2, flux=1/u.s/u.cm**2)

photons = [s.generate_photons(1e5 * u.s) for s in [s1, s2]]
hists = [np.histogram(p['energy'], bins=np.arange(1, 3, .1))
for p in photons]
assert np.allclose(hists[0][0], hists[1][0], rtol=0.14)

0 comments on commit f8a2bb8

Please sign in to comment.