-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgen_spectra.py
98 lines (50 loc) · 2.72 KB
/
gen_spectra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from threeML import *
from threeML.utils.OGIP.response import OGIPResponse
from threeML.utils.photometry import PhotometericObservation
# The filter library takes a while to load so you must import it explicitly.
from threeML.utils.photometry import get_photometric_filter_library
import numpy as np
np.random.seed(12345)
threeML_filter_library = get_photometric_filter_library()
# generates the example data for the tutorial
rsp = OGIPResponse("c_data/acis.rmf", "c_data/acis.arf")
update_logging_level("INFO")
bb = Blackbody(K=2.,kT = 1.)
bkg = Powerlaw(K=1e2 ,index=-1.2) + Gaussian(F=1e2, mu=0.75, sigma=.1) + Gaussian(F=1e2, mu=5, sigma=.1)
xx = rsp.monte_carlo_energies
gen = DispersionSpectrumLike.from_function('gen',source_function=bb, response= rsp, background_function=bkg, scale_factor=1e-2)
gen.write_pha("c_data/obs", overwrite=True)
src = Powerlaw(K=1.e-2, index = -2., piv=5) + Gaussian(F=3e-2, mu=6.4, sigma=.1)
bkg = Powerlaw(K=1e1,index=-1.5, piv=5) + Gaussian(F=1.5e1, mu=3., sigma=.2)
xx = rsp.monte_carlo_energies
gen = DispersionSpectrumLike.from_function('gen',source_function=src, response= rsp, background_function=bkg, scale_factor=1e-2)
gen.write_pha("c_data/obs_bkg_demo", overwrite=True)
# joint fits
plaw = Broken_powerlaw(alpha=-1.5,
beta=-2,
K=1.e0)
plaw.xb.bounds = (None, None)
plaw.xb=1.
ps = PointSource("demo", 0,0, spectral_shape=plaw)
model = Model(ps)
grond_filters = threeML_filter_library.LaSilla.GROND
grond_observation = PhotometericObservation.from_kwargs(g=(21.5,0.02),
r=(22.,0.03),
i=(21.8, 0.01),
z=(21.2, 0.01),
J=(19.6, 0.1),
H=(18.6, 0.01),
K=(18.0, 0.1))
photo = PhotometryLike("GROND",observation=grond_observation,filters=grond_filters)
photo.set_model(model)
p2 = photo.get_simulated_dataset()
p2._observation.to_hdf5("joint_data/grond_data.h5", overwrite=True)
src = plaw
bkg = Powerlaw(K=1e1,index=-1.2, piv=5)
gen = DispersionSpectrumLike.from_function('gen',
source_function=src,
response= rsp,
background_function=bkg,
scale_factor=.01
)
gen.write_pha("joint_data/obs_demo", overwrite=True)