JOINT-FIT ANALYSIS

[1]:
from vtspy import *

WARNING: version mismatch between CFITSIO header (v4.000999999999999) and linked library (v4.01).


WARNING: version mismatch between CFITSIO header (v4.000999999999999) and linked library (v4.01).


WARNING: version mismatch between CFITSIO header (v4.000999999999999) and linked library (v4.01).

Step 1. Load Fermi-LAT and VERITAS datasets

[2]:
joint = JointAnalysis(veritas="analyzed", fermi="analyzed")
2022-06-24 11:25:23 INFO    : Initialize the joint-fit analysis...
2022-06-24 11:25:23 INFO    : Initialize the VERITAS analysis.
2022-06-24 11:25:23 INFO    : The setup is found [state_file = analyzed]. Read the state.
2022-06-24 11:25:23 INFO    : Completed (VERITAS initialization).
2022-06-24 11:25:23 INFO    : Initialize the Fermi-LAT analysis.
2022-06-24 11:25:28 INFO    : The setup and configuration is found [state_file = analyzed]. Loading the configuration...
2022-06-24 11:25:38 INFO    : The target, 4FGL J1221.3+3010, is associated with 2 source(s).
2022-06-24 11:25:38 INFO    : Completed (Fermi-LAT initialization).
2022-06-24 11:25:38 INFO    : Loading the Fermi-LAT events...
2022-06-24 11:25:39 INFO    : Loading the Fermi-LAT IRFs...
WARNING: FITSFixedWarning: RADECSYS= 'FK5 '
the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]
2022-06-24 11:25:39 WARNING : FITSFixedWarning: RADECSYS= 'FK5 '
the RADECSYS keyword is deprecated, use RADESYSa.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2001-01-01T00:01:04.184' from MJDREF.
Set MJD-OBS to 58849.000000 from DATE-OBS.
Set MJD-END to 58850.000000 from DATE-END'. [astropy.wcs.wcs]
2022-06-24 11:25:39 WARNING : FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2001-01-01T00:01:04.184' from MJDREF.
Set MJD-OBS to 58849.000000 from DATE-OBS.
Set MJD-END to 58850.000000 from DATE-END'.
2022-06-24 11:25:39 INFO    : Loading the Fermi-LAT models...
2022-06-24 11:25:41 INFO    : Ready to perform a gammapy analysis.
2022-06-24 11:25:41 INFO    : Constructing a joint datasets
2022-06-24 11:25:41 INFO    : Completed.

Check datasets and models

[3]:
joint.print_models()
[3]:
Table length=5
modeltypenamevalueuniterrorminmaxfrozenis_normlink
str11str8str9float64str14float64float64float64boolboolstr1
1ES1218+304spectralindex3.1484e+001.313e-01nannanFalseFalse
1ES1218+304spectralamplitude4.2436e-12cm-2 s-1 TeV-16.788e-13nannanFalseTrue
1ES1218+304spectralreference1.0000e+00TeV0.000e+00nannanTrueFalse
1ES1218+304spatiallon_01.8534e+02deg0.000e+00nannanTrueFalse
1ES1218+304spatiallat_03.0168e+01deg0.000e+00-9.000e+019.000e+01TrueFalse

Check a global SED before the fit

[4]:
joint.plot_sed()
../_images/examples_Tutorial_3_Jointi-fit_analysis_7_0.png

Change a spectral model

[5]:
joint.change_model("logparabola", optimize=True, method="inst")
joint.plot("sed")
2022-06-24 11:25:44 INFO    : The spectral model for the target is chaged:
2022-06-24 11:25:44 INFO    : PowerLawSpectralModel->LogParabolaSpectralModel
../_images/examples_Tutorial_3_Jointi-fit_analysis_9_1.png
[6]:
joint.print_models()
[6]:
Table length=6
modeltypenamevalueuniterrorminmaxfrozenis_normlink
str11str8str9float64str14float64float64float64boolboolstr1
1ES1218+304spectralamplitude4.2617e-12cm-2 s-1 TeV-17.615e-13nannanFalseTrue
1ES1218+304spectralreference1.0000e+00TeV0.000e+00nannanTrueFalse
1ES1218+304spectralalpha3.5385e+003.332e-01nannanFalseFalse
1ES1218+304spectralbeta2.8214e-011.984e-01nannanFalseFalse
1ES1218+304spatiallon_01.8534e+02deg0.000e+00nannanTrueFalse
1ES1218+304spatiallat_03.0168e+01deg0.000e+00-9.000e+019.000e+01TrueFalse

Step 2. Run a joint-fit analysis

[7]:
joint.fit()
2022-06-24 11:25:44 INFO    : Start fitting...
2022-06-24 11:35:04 INFO    : Fit successfully.

Check a global SED after the fit

[8]:
joint.plot("sed", show_flux_points=True)
../_images/examples_Tutorial_3_Jointi-fit_analysis_14_0.png
[9]:
joint.print_models()
[9]:
Table length=6
modeltypenamevalueuniterrorminmaxfrozenis_normlink
str11str8str9float64str14float64float64float64boolboolstr1
1ES1218+304spectralamplitude4.0987e-12cm-2 s-1 TeV-17.240e-13nannanFalseTrue
1ES1218+304spectralreference1.0000e+00TeV0.000e+00nannanTrueFalse
1ES1218+304spectralalpha3.4837e+001.847e-01nannanFalseFalse
1ES1218+304spectralbeta2.0962e-013.391e-02nannanFalseFalse
1ES1218+304spatiallon_01.8534e+02deg0.000e+00nannanTrueFalse
1ES1218+304spatiallat_03.0168e+01deg0.000e+00-9.000e+019.000e+01TrueFalse

Bonus. Test the ‘agnpy’ model

[10]:
from vtspy.model import default_model
[11]:
agnpy = default_model("agnpy", redshift=0.182)

Check initial parameters

[12]:
agnpy.parameters.to_table()
[12]:
Table length=11
typenamevalueuniterrorminmaxfrozenis_normlink
str8str15float64str4int64float64float64boolboolstr1
spectralnorm_e5.0000e-06cm-30.000e+001.000e-201.000e+00FalseTrue
spectralp10.0000e+000.000e+00-2.000e+005.000e+00FalseFalse
spectralp23.0000e+000.000e+00-2.000e+005.000e+00FalseFalse
spectrallog10_gamma_b4.0000e+000.000e+001.000e+007.000e+00FalseFalse
spectrallog10_gamma_min2.6990e+000.000e+000.000e+004.000e+00TrueFalse
spectrallog10_gamma_max6.0000e+000.000e+004.000e+008.000e+00TrueFalse
spectraldelta_D1.0000e+010.000e+000.000e+006.000e+01FalseFalse
spectrallog10_B1.0000e+000.000e+00-4.000e+002.000e+00FalseFalse
spectralt_var1.0000e+00d0.000e+001.000e+013.142e+07TrueFalse
spectralz1.8200e-010.000e+001.000e-021.000e+00TrueFalse
spectrald_L2.8128e+27cm0.000e+001.000e+251.000e+33TrueFalse
[13]:
agnpy.plot([100 * u.MeV, 30 * u.TeV], sed_type="e2dnde", label="AGN", color="r")
joint.plot("sed", show_flux_points=True)
../_images/examples_Tutorial_3_Jointi-fit_analysis_21_0.png

Change a spectral model

[14]:
joint.change_model(agnpy, optimize=True, method="flux")
joint.plot("sed", show_flux_points=True)
2022-06-24 11:35:06 INFO    : A model, agnpy(SYN+SSC), is imported
2022-06-24 11:35:38 INFO    : The spectral model for the target is chaged:
2022-06-24 11:35:38 INFO    : LogParabolaSpectralModel->agnpy(SYN+SSC)
../_images/examples_Tutorial_3_Jointi-fit_analysis_23_1.png
[15]:
joint.print_models()
[15]:
Table length=13
modeltypenamevalueuniterrorminmaxfrozenis_normlink
str11str8str15float64str14float64float64float64boolboolstr1
1ES1218+304spectralnorm_e5.7602e-06cm-36.219e-071.000e-201.000e+00FalseTrue
1ES1218+304spectralp12.2308e-015.860e-01-2.000e+005.000e+00FalseFalse
1ES1218+304spectralp23.2369e+007.854e-02-2.000e+005.000e+00FalseFalse
1ES1218+304spectrallog10_gamma_b4.0559e+002.065e-021.000e+007.000e+00FalseFalse
1ES1218+304spectrallog10_gamma_min2.6990e+000.000e+000.000e+004.000e+00TrueFalse
1ES1218+304spectrallog10_gamma_max6.0000e+000.000e+004.000e+008.000e+00TrueFalse
1ES1218+304spectraldelta_D1.0295e+011.302e+000.000e+006.000e+01FalseFalse
1ES1218+304spectrallog10_B1.2411e+007.700e-02-4.000e+002.000e+00FalseFalse
1ES1218+304spectralt_var1.0000e+00d0.000e+001.000e+013.142e+07TrueFalse
1ES1218+304spectralz1.8200e-010.000e+001.000e-021.000e+00TrueFalse
1ES1218+304spectrald_L2.8128e+27cm0.000e+001.000e+251.000e+33TrueFalse
1ES1218+304spatiallon_01.8534e+02deg0.000e+00nannanTrueFalse
1ES1218+304spatiallat_03.0168e+01deg0.000e+00-9.000e+019.000e+01TrueFalse

Fit the data

[16]:
joint.fit()
2022-06-24 12:03:18 INFO    : Start fitting...
2022-06-24 12:56:19 INFO    : Fit successfully.
[19]:
joint.plot("sed", show_flux_points=True)
../_images/examples_Tutorial_3_Jointi-fit_analysis_27_0.png
[20]:
joint.print_models()
[20]:
Table length=13
modeltypenamevalueuniterrorminmaxfrozenis_normlink
str11str8str15float64str14float64float64float64boolboolstr1
1ES1218+304spectralnorm_e4.8566e-06cm-35.329e-061.000e-201.000e+00FalseTrue
1ES1218+304spectralp1-1.9420e+001.581e+00-2.000e+005.000e+00FalseFalse
1ES1218+304spectralp23.1134e+001.793e-01-2.000e+005.000e+00FalseFalse
1ES1218+304spectrallog10_gamma_b4.0534e+005.281e-021.000e+007.000e+00FalseFalse
1ES1218+304spectrallog10_gamma_min2.6990e+000.000e+000.000e+004.000e+00TrueFalse
1ES1218+304spectrallog10_gamma_max6.0000e+000.000e+004.000e+008.000e+00TrueFalse
1ES1218+304spectraldelta_D1.0111e+012.442e-010.000e+006.000e+01FalseFalse
1ES1218+304spectrallog10_B1.5034e+007.587e-01-4.000e+002.000e+00FalseFalse
1ES1218+304spectralt_var1.0000e+00d0.000e+001.000e+013.142e+07TrueFalse
1ES1218+304spectralz1.8200e-010.000e+001.000e-021.000e+00TrueFalse
1ES1218+304spectrald_L2.8128e+27cm0.000e+001.000e+251.000e+33TrueFalse
1ES1218+304spatiallon_01.8534e+02deg0.000e+00nannanTrueFalse
1ES1218+304spatiallat_03.0168e+01deg0.000e+00-9.000e+019.000e+01TrueFalse