# SED Analysis¶

The sed() method computes a spectral energy distribution (SED) by fitting for the flux normalization of a source in a sequence of energy bins. The normalization in each bin is fit independently using a power-law spectrum with a fixed index. The value of this index can be set with the bin_index parameter or allowed to vary over the energy range according to the local slope of the global spectral model (with the use_local_index parameter).

The free_background and cov_scale parameters can be used to control how nuisance parameters are dealt with in the fit. By default this method will fix the parameters of background components ROI when fitting the source normalization in each energy bin (free_background = False). Setting free_background to True will profile the normalizations of all background components that were free when the method was executed. In order to minimize overfitting, background normalization parameters are constrained with priors taken from the global fit. The strength of the priors is controlled with the cov_scale parameter. A larger (smaller) value of cov_scale applies a weaker (stronger) constraint on the background amplitude. Setting cov_scale to None can be used to perform the fit without priors.

## Examples¶

The sed() method is executed by passing the name of a source in the ROI as a single argument. Additional keyword argument can also be provided to override the default configuration of the method:

# Run analysis with default energy binning
sed = gta.sed('sourceA')

# Override the energy binning and the assumed power-law index
# within the bin
sed = gta.sed('sourceA', loge_bins=[2.0,2.5,3.0,3.5,4.0,4.5,5.0], bin_index=2.3)

# Profile background normalization parameters with prior scale of 5.0
sed = gta.sed('sourceA', free_background=True, cov_scale=5.0)


By default the method will use the energy bins of the underlying analysis. The loge_bins keyword argument can be used to override the default binning with the restriction that the SED energy bins most align with the analysis bins.

The return value of sed() is a dictionary with the results of the analysis. The output dictionary is also saved to the sed dictionary of the Source instance which is written to the output file generated by write_roi().

The following example shows how the output dictionary can be captured from either from the method return value or later accessed from the ROIModel instance:

# Get the sed results from the return argument
sed = gta.sed('sourceA')

# Get the sed results from the source object
sed = gta.roi['sourceA']

# Print the SED flux values
print(sed['flux'])


The contents of the FITS file and output dictionary are documented in SED FITS File and SED Dictionary.

## SED FITS File¶

The following table describes the contents of the FITS file written by sed(). The SED HDU uses that data format specification for SEDs documented here.

sed Output Dictionary
HDU Column Name Description
SED e_min Lower edges of SED energy bins (MeV).
SED e_ref Upper edges of SED energy bins (MeV).
SED e_max Centers of SED energy bins (MeV).
SED ref_dnde_e_min Differential flux of the reference model evaluated at the lower bin edge ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$)
SED ref_dnde_e_max Differential flux of the reference model evaluated at the upper bin edge ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$)
SED ref_flux Flux of the reference model in each bin ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
SED ref_eflux Energy flux of the reference model in each bin ($$\mathrm{MeV}~\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
SED ref_dnde Differential flux of the reference model evaluated at the bin center ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$)
SED ref_npred Number of predicted counts in the reference model in each bin.
SED norm Normalization in each bin in units of the reference model.
SED norm_err Symmetric error on the normalization in each bin in units of the reference model.
SED norm_errn Lower 1-sigma error on the normalization in each bin in units of the reference model.
SED norm_errp Upper 1-sigma error on the normalization in each bin in units of the reference model.
SED norm_UL Upper limit on the normalization in each bin in units of the reference model.
SED loglike Log-likelihood value of the model for the best-fit amplitude.
SED norm_scan Array of NxM normalization values for the profile likelihood scan in N energy bins and M scan points. A row-wise multiplication with any of ref columns can be used to convert this matrix to the respective unit.
SED dloglike_scan Array of NxM delta-loglikelihood values for the profile likelihood scan in N energy bins and M scan points.
MODEL_FLUX energy Energies at which the spectral band is evaluated (MeV).
MODEL_FLUX dnde Central value of spectral band ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$).
MODEL_FLUX dnde_lo Lower 1-sigma bound of spectral band ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$).
MODEL_FLUX dnde_hi Upper 1-sigma bound of spectral band ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$).
MODEL_FLUX dnde_err Symmetric error of spectral band ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$).
MODEL_FLUX dnde_ferr Fractional width of spectral band.
PARAMS name Name of the parameter.
PARAMS value Value of the parameter.
PARAMS error 1-sigma parameter error (nan indicates that the parameter was not included in the fit).
PARAMS covariance Covariance matrix among free parameters.
PARAMS correlation Correlation matrix among free parameters.

## SED Dictionary¶

The following table describes the contents of the sed() output dictionary:

sed Output Dictionary
Key Type Description
loge_min ndarray Lower edges of SED energy bins (log10(E/MeV)).
loge_max ndarray Upper edges of SED energy bins (log10(E/MeV)).
loge_ctr ndarray Centers of SED energy bins (log10(E/MeV)).
loge_ref ndarray Reference energies of SED energy bins (log10(E/MeV)).
e_min ndarray Lower edges of SED energy bins (MeV).
e_max ndarray Upper edges of SED energy bins (MeV).
e_ctr ndarray Centers of SED energy bins (MeV).
e_ref ndarray Reference energies of SED energy bins (MeV).
ref_flux ndarray Flux of the reference model in each bin ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
ref_eflux ndarray Energy flux of the reference model in each bin ($$\mathrm{MeV}~\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
ref_dnde ndarray Differential flux of the reference model evaluated at the bin center ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$)
ref_dnde_e_min ndarray Differential flux of the reference model evaluated at the lower bin edge ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$)
ref_dnde_e_max ndarray Differential flux of the reference model evaluated at the upper bin edge ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$)
ref_e2dnde ndarray E^2 x the differential flux of the reference model evaluated at the bin center ($$\mathrm{MeV}~\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$)
ref_npred ndarray Number of predicted counts in the reference model in each bin.
norm ndarray Normalization in each bin in units of the reference model.
flux ndarray Flux in each bin ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
eflux ndarray Energy flux in each bin ($$\mathrm{MeV}~\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
dnde ndarray Differential flux in each bin ($$\mathrm{cm}^{-2}~\mathrm{s}^{-1}~\mathrm{MeV}^{-1}$$).
e2dnde ndarray E^2 x the differential flux in each bin ($$\mathrm{MeV}~\mathrm{cm}^{-2}~\mathrm{s}^{-1}$$).
dnde_err ndarray 1-sigma error on dnde evaluated from likelihood curvature.
dnde_err_lo ndarray Lower 1-sigma error on dnde evaluated from the profile likelihood (MINOS errors).
dnde_err_hi ndarray Upper 1-sigma error on dnde evaluated from the profile likelihood (MINOS errors).
dnde_ul95 ndarray 95% CL upper limit on dnde evaluated from the profile likelihood (MINOS errors).
dnde_ul ndarray Upper limit on dnde evaluated from the profile likelihood using a CL = ul_confidence.
e2dnde_err ndarray 1-sigma error on e2dnde evaluated from likelihood curvature.
e2dnde_err_lo ndarray Lower 1-sigma error on e2dnde evaluated from the profile likelihood (MINOS errors).
e2dnde_err_hi ndarray Upper 1-sigma error on e2dnde evaluated from the profile likelihood (MINOS errors).
e2dnde_ul95 ndarray 95% CL upper limit on e2dnde evaluated from the profile likelihood (MINOS errors).
e2dnde_ul ndarray Upper limit on e2dnde evaluated from the profile likelihood using a CL = ul_confidence.
ts ndarray Test statistic.
loglike ndarray Log-likelihood of model for the best-fit amplitude.
npred ndarray Number of model counts.
fit_quality ndarray Fit quality parameter for MINUIT and NEWMINUIT optimizers (3 - Full accurate covariance matrix, 2 - Full matrix, but forced positive-definite (i.e. not accurate), 1 - Diagonal approximation only, not accurate, 0 - Error matrix not calculated at all).
fit_status ndarray Fit status parameter (0=ok).
index ndarray Spectral index of the power-law model used to fit this bin.
norm_scan ndarray Array of NxM normalization values for the profile likelihood scan in N energy bins and M scan points. A row-wise multiplication with any of ref columns can be used to convert this matrix to the respective unit.
dloglike_scan ndarray Array of NxM delta-loglikelihood values for the profile likelihood scan in N energy bins and M scan points.
loglike_scan ndarray Array of NxM loglikelihood values for the profile likelihood scan in N energy bins and M scan points.
param_covariance ndarray Covariance matrix for the best-fit spectral parameters of the source.
param_names ndarray Array of names for the parameters in the global spectral parameterization of this source.
param_values ndarray Array of parameter values.
param_errors ndarray Array of parameter errors.
model_flux dict Dictionary containing the differential flux uncertainty band of the best-fit global spectral parameterization for the source.
config dict Copy of input configuration to this method.

## Configuration¶

The default configuration of the method is controlled with the sed section of the configuration file. The default configuration can be overriden by passing the option as a kwargs argument to the method.

sed Options
Option Default Description
bin_index 2.0 Spectral index that will be use when fitting the energy distribution within an energy bin.
cov_scale 3.0 Scale factor that sets the strength of the prior on nuisance parameters that are free. Setting this to None disables the prior.
free_background False Leave background parameters free when performing the fit. If True then any parameters that are currently free in the model will be fit simultaneously with the source of interest.
free_radius None Free normalizations of background sources within this angular distance in degrees from the source of interest. If None then no sources will be freed.
make_plots False Generate diagnostic plots.
ul_confidence 0.95 Confidence level for flux upper limit.
use_local_index False Use a power-law approximation to the shape of the global spectrum in each bin. If this is false then a constant index set to bin_index will be used.
write_fits True Write the output to a FITS file.
write_npy True Write the output dictionary to a numpy file.

## Reference/API¶

GTAnalysis.sed(name, **kwargs)

Generate a spectral energy distribution (SED) for a source. This function will fit the normalization of the source in each energy bin. By default the SED will be generated with the analysis energy bins but a custom binning can be defined with the loge_bins parameter.

Parameters: name (str) – Source name. prefix (str) – Optional string that will be prepended to all output files (FITS and rendered images). loge_bins (ndarray) – Sequence of energies in log10(E/MeV) defining the edges of the energy bins. If this argument is None then the analysis energy bins will be used. The energies in this sequence must align with the bin edges of the underyling analysis instance. bin_index (float) – Spectral index that will be use when fitting the energy distribution within an energy bin. (default : 2.0) cov_scale (float) – Scale factor that sets the strength of the prior on nuisance parameters that are free. Setting this to None disables the prior. (default : 3.0) free_background (bool) – Leave background parameters free when performing the fit. If True then any parameters that are currently free in the model will be fit simultaneously with the source of interest. (default : False) free_radius (float) – Free normalizations of background sources within this angular distance in degrees from the source of interest. If None then no sources will be freed. (default : None) make_plots (bool) – Generate diagnostic plots. (default : False) ul_confidence (float) – Confidence level for flux upper limit. (default : 0.95) use_local_index (bool) – Use a power-law approximation to the shape of the global spectrum in each bin. If this is false then a constant index set to bin_index will be used. (default : False) write_fits (bool) – Write the output to a FITS file. (default : True) write_npy (bool) – Write the output dictionary to a numpy file. (default : True) optimizer (dict) – Dictionary that overrides the default optimizer settings. sed – Dictionary containing output of the SED analysis. dict