Created
September 5, 2019 14:03
-
-
Save DougBurke/3cd22224e633c46c508fb0c5c2cbcf26 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
from sherpa.astro import ui | |
# fake up a PHA data set | |
chans = np.arange(1, 11, dtype=np.int8) | |
counts = np.ones(chans.size) | |
# bin width is not 0.1 but something slightly different | |
ebins = np.linspace(0.1, 1.2, num=chans.size + 1) | |
elo = ebins[:-1] | |
ehi = ebins[1:] | |
dset = ui.DataPHA('test', chans, counts) | |
# make sure ARF isn't 1 to make sure it's being applied | |
arf = ui.create_arf(elo, ehi, specresp=0.7 * np.ones(chans.size)) | |
rmf = ui.create_rmf(elo, ehi, e_min=elo, e_max=ehi) | |
ui.set_data(1, dset) | |
ui.set_arf(1, arf) | |
ui.set_rmf(1, rmf) | |
ui.set_source(ui.const1d.mdl) | |
# again not 1 | |
mdl.c0 = 8 | |
# Copy the values from the plot structures, since get_xxx_plot | |
# returns the same object so m1.y == m2.y will not note a difference. | |
# | |
d1y = ui.get_data_plot().y.copy() | |
m1y = ui.get_model_plot().y.copy() | |
s1y = ui.get_source_plot().y.copy() | |
d2y = ui.get_data_plot().y.copy() | |
m2y = ui.get_model_plot().y.copy() | |
s2y = ui.get_source_plot().y.copy() | |
def compare_plot(label, p1, p2): | |
if np.any(p1 != p2): | |
print("{} diffs".format(label)) | |
print(" {}".format(p1)) | |
print(" {}".format(p2)) | |
compare_plot('data', d1y, d2y) | |
compare_plot('model', m1y, m2y) | |
compare_plot('source', s1y, s2y) | |
# We expect the model plot to be arf * mdl.c0, so 0.7 * 8 = 5.6 | |
# source mdl.c0, so 8 | |
# Note that 50.909 is 5.6 / 0.11 (ie the bin width of the ARF/RMF) | |
# 72.7272... 8 / 0.11 |
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
% python bugs.py | |
WARNING: imaging routines will not be available, | |
failed to import sherpa.image.ds9_backend due to | |
'RuntimeErr: DS9Win unusable: Could not find ds9 on your PATH' | |
WARNING: failed to import sherpa.astro.xspec; XSPEC models will not be available | |
model diffs | |
[5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6] | |
[50.90909091 50.90909091 50.90909091 50.90909091 50.90909091 50.90909091 | |
50.90909091 50.90909091 50.90909091 50.90909091] | |
source diffs | |
[8. 8. 8. 8. 8. 8. 8. 8. 8. 8.] | |
[72.72727273 72.72727273 72.72727273 72.72727273 72.72727273 72.72727273 | |
72.72727273 72.72727273 72.72727273 72.72727273] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment