Analyze

class fermi_stacking.analyze_results.Analyze[source]

Analyzes stacked results.

plot_final_array(savefig, array, use_index='default', stack_mode='flux_index')[source]

Plots the stacked profile.

Parameters:
  • savefig (str) – Name of image file to be saved.

  • array (str) – Name of input array to plot. Must include “.npy”.

  • use_index (float, optional) – Option to calculate flux for specified index (default is best-fit index).

  • stack_mode (str, optional) – Mode of stacking. Default is flux_index. Other options are alpha_beta or alpha_beta_interp.

power_law_2(N, gamma, E, Emin, Emax)[source]

Function for dN/dE in units of ph/cm^s/s/MeV.

Parameters:
  • N (float) – Integrated flux between Emin and Emax in ph/cm^2/s.

  • gamma (float) – Spectral index.

  • E (array) – Energy range in MeV.

  • Emin (float) – Minimum energy in MeV.

  • Emax (Maximum energy in MeV.)

Returns:

Function for dN/dE.

Return type:

array

make_butterfly(name, fig_kwargs={}, show_contour=False)[source]

Calculate butterfly plot.

Parameters:
  • name (str) – name of input array (not including .npy). Note: this name is also used for output files.

  • fig_kwargs (dict, optional) – pass any kwargs to plt.gca().set()

  • show_contour (bool, optional) – Sets contour region to zero, as sanity check (default is False).

get_stack_UL95(array_file, ul_index=2.0)[source]

Calculate one-sided 95% UL from the 2D TS arrays: 2(logL_max - logL) = 2.71.

Parameters:
  • array_file (array) – 2D array to calculate UL from.

  • ul_index (float, optional) – Spectral index to use for UL calculation (default value is 2.0).

Note

Since the TS array is used, the factor of 2 is already included in the calculation!

This methed is not applicable if TS<1.

calc_upper_limit(srcname, ul_emin, ul_emax, comp_list=[0, 1, 2, 3], mult_lt=False)[source]

Calculate upper limits using both a bayesian approach and a frequentist approach using results from preprocessing.

The frequentist appraoch uses the profile likelihood method, with 2.71/2 for 95% UL. This is standard in LAT analysis. However, when there is a physical boundary on a parameter (such as a normalization) the profile likelihood is always restricted to the physical region such that for a negative MLE the maximum is evaluated at zero.

For low significant sources the bayesian approach may be a better estimate (Thanks to Jean Ballet for pointing this out).

Parameters:
  • srcname (str) – Name of source for UL calculation.

  • ul_emin (float) – Lower energy bound for UL calculation in MeV.

  • ul_emax (float) – Upper energy bound for UL calculation in MeV.

  • comp_list (list, optional) – List of components to add to the SummedLikelihood object for the JLA (default is for typical JLA with 4 components). The added components must be defined in the energy range of the UL calculation. The function supports up to 10 components (0-9). For more, further definitions must be added.

  • mult_lt (bool, optional) – If using lt cubes for each component, set to True (default is False, for single lt cube.

Note

If getting ‘IndexError’, try moving the lower energy bound slightly below the bin.

Returns:

Frequentist and Bayesian upper limit value, respectively.

Return type:

float, float