-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript_test_vela_fermi.py
80 lines (67 loc) · 2.29 KB
/
script_test_vela_fermi.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
import matplotlib.pyplot as plt
import numpy as np
from astropy.table import Table
from gammapy.maps import MapAxis, RegionGeom
from gammapy.modeling import Fit
from gammapy.modeling.models import Models
from gammapy.utils.scripts import make_path
from gammapypulsar import (
AsymmetricLorentzianPhaseModel,
CountsDataset,
LogNormalPhaseModel,
SkyModelPhase,
)
filename = make_path(
"$GAMMAPY_DATA/catalogs/fermi/3PC_auxiliary_20230728/J0835-4510_3PC_data.fits.gz"
)
table = Table.read(filename)
table = table[: int(len(table) / 2)]
# [int(0.18*len(table)):int(0.4*len(table))] to only have the bridge
phase_min = table["Ph_Min"]
phase_max = table["Ph_Max"]
phase_tot = np.append(phase_min, phase_max[-1])
phases = MapAxis.from_edges(phase_tot, interp="lin", name="phase")
data = table["300_1000_WtCt"]
geom = RegionGeom(region=None, axes=[phases])
counts_dataset = CountsDataset.create(geom=geom)
counts_dataset.counts.data = data
print(counts_dataset)
model1 = AsymmetricLorentzianPhaseModel(
amplitude=8000, center=0.13, width_1=0.006, width_2=0.03
)
model1.amplitude.frozen = True
model2 = LogNormalPhaseModel.from_expected(amplitude=300, center=0.23, width=0.01)
model2 = LogNormalPhaseModel(amplitude=755, center=-1.36, width=0.5)
model2.amplitude.frozen = True
model2.center.frozen = True
model2.width.frozen = True
model3 = AsymmetricLorentzianPhaseModel(
amplitude=8000, center=0.56, width_1=0.03, width_2=-0.005
)
model3.amplitude.frozen = True
compound_model = model1 + model2 + model3
compound_model.plot()
for model in compound_model.models:
model.plot()
counts_dataset.counts.plot()
plt.show()
sky_model = SkyModelPhase(phase_model=compound_model, name="test")
counts_dataset.models = Models(sky_model)
counts_dataset
print(counts_dataset.models)
fit = Fit()
result = fit.run(counts_dataset)
print(result)
print(result.covariance_result)
for param in counts_dataset.models.parameters:
print(param.name, param.value, param.error)
print(counts_dataset.models[0].parameters["amplitude"])
print(counts_dataset.npred().data)
ax = plt.gca()
counts_dataset.models[0].phase_model.plot(ax=ax, label="Model")
counts_dataset.models[0].phase_model.plot_error(ax=ax, label="error")
counts_dataset.counts.plot(ax=ax, label="Counts")
plt.legend()
plt.show()
counts_dataset.plot_residuals()
plt.show()