Plotting

Note

Functions for making plots, both analysis and detector plots, as well as sensitivity calculations. These are used internally in the FRA package.

Plotting functions

fast_response.plotting_utils.plot_zoom(scan, ra, dec, title, reso=3, var='pVal', range=[0, 6], cmap=None)[source]

Make a zoomed-in skymap around a particular point (RA, decl) on the sky

Parameters:
  • scan (numpy array) – Healpix map of values to be plotted (usually a skymap)

  • ra (float) – Right Ascension value at the center of the plot (best-fit RA or source RA)

  • dec (float) – Declination value at the center of the plot (best-fit dec or source dec)

  • title (str) – Plot title to use

  • reso (float) – Resolution (arcmins), default 3

  • cmap (matplotlib colormap or None) – colormap to use. if not set default is Seaborn “Blues”

fast_response.plotting_utils.plot_color_bar(labels=[0.0, 2.0, 4.0, 6.0], col_label='IceCube Event Time', range=[0, 6], cmap=None, offset=-35)[source]

Adds a color bar to an existing healpy map

Parameters:
  • labels (float list) – list of points to be used (default [0., 2., 4., 6.])

  • col_label (str) – label for colorbar (default IceCube Event Time)

  • cmap (matplotlib colormap or None) – colormap to use. if not set default is “Blues”

  • offset (int) – offset value for colorbar’s label. default is -35

fast_response.plotting_utils.plot_labels(src_dec, src_ra, reso)[source]

Add labels to healpy zoom

Parameters:
  • src_dec (float) – Declination value at the center of the plot (best-fit dec or source dec)

  • src_ra (float) – Right Ascension value at the center of the plot (best-fit RA or source RA)

  • reso (float) – Resolution (arcmins)

fast_response.plotting_utils.plot_events(dec, ra, sigmas, src_ra, src_dec, reso, sigma_scale=5.0, col='k', constant_sigma=False, same_marker=False, energy_size=False, with_mark=True, with_dash=False, label='')[source]

Adds events to a healpy zoom plot. Events are expected to be from self.llh.exp

Parameters:
  • dec (float array) – Array of declination values for each event

  • ra (float array) – Array of Right Ascension values for each event

  • sigmas (float array) – Angular error (circularized) to be plotted. Usually a 90% CL angular error

  • src_ra (float) – Right Ascension value at the center of the plot (best-fit RA or source RA)

  • src_dec (float) – Declination value at the center of the plot (best-fit dec or source dec)

  • reso (float) – Resolution (arcmins)

  • sigma_scale (float or None) – Value to rescale the sigma parameter (default 5.0). If None: no angular undertainty is plotted (sometimes used for very long time windows)

  • col (str or str array) – color to use for each event plotted (default k=black)

  • constant_sigma (bool) – Ignores sigma parameter and plots all markers with a size of 20.

  • with_mark (bool) – Uses an x marker instead of o

  • with_dash (bool) – Plot the angular error as a dashed contour. Usually used to indicated a removed event (e.g. alert event that triggered the analysis)

  • same_marker (bool) – Currently unused options.

  • energy_size (bool) – Currently unused options.

fast_response.plotting_utils.load_plotting_settings()[source]

Load settings to be used as default plot settings. Includes Times New Roman font and size 12 font

fast_response.plotting_utils.contour(ra, dec, sigma, nside)[source]

Function for plotting contours on skymaps

Parameters:
  • ra (ndarray) – Array of ra for events

  • dec (ndarray) – Array of dec for events

  • sigma (ndarray) – Array of sigma to make contours around events

  • nside – nside of healpy map

Returns:

  • Theta (array) – array of theta values of contour

  • Phi (array) – array of phi values of contour

fast_response.plotting_utils.plot_contours(proportions, samples)[source]

Plot containment contour around desired level. E.g 90% containment of a PDF on a healpix map

Parameters:
  • proportions (list) – list of containment level to make contours for. E.g [0.68,0.9]

  • samples (array) – array of values read in from healpix map E.g samples = hp.read_map(file)

Returns:

  • theta_list (list) – List of arrays containing theta values for desired contours

  • phi_list (list) – List of arrays containing phi values for desired contours

Detector status plots

fast_response.make_ontime_plots.time_axis(ax, run_table, time_window)[source]

Make an axis that is in times, formatted as ISO times

Parameters:
  • ax (matplotlib.pyplot Axis) – axis to convert to times and format

  • run_table (dict-like) – Table of run information for events

  • time_window (tuple astropy Time object) – (start, stop) of the time window, in mjd

fast_response.make_ontime_plots.time_series(ax, run_table, time_window, t1, t2, n, scale=1, ymax=0, xerr=False, **kwargs)[source]

Make a plot that is a rate over time

Parameters:
  • ax (matplotlib.pyplot Axis) – axis to convert to times and format

  • run_table (dict-like) – Table of run information for events

  • time_window (tuple astropy Time object) – (start, stop) of the time window, in mjd

  • t1 (astropy Time object) – start time to use in the plot, utc

  • t2 (astropy Time object) – stop time to use in the plot, utc

  • n (list or array-like) – value to plot on the y-axis (usually, a rate value)

  • scale (float) – rescale value/unit for the y-axis (default 1, not rescaled)

  • ymax (float) – maximum value to plot for the y-axis (default 0, no max)

  • kwargs (optional) – passed to matplotlib.pyplot.ax.errorbar

fast_response.make_ontime_plots.make_rate_plots(time_window, run_table, query_events, dirname, season='neutrino')[source]

Make plots of filter rates for the time window we’re interested in. Rates plotted are:

  • GFU singlet rate

  • Badness

  • Online L2

  • Muon filter

  • In Ice Simple Multiplicity

Parameters:
  • time_window (tuple astropy Time object) – (start, stop) of the time window, in mjd

  • run_table (dict-like) – Table of run information for events

  • dirname (str) – Directory events are saved to

  • season (str) – Season to load (default neutrino)

Sensitivity functions

fast_response.sensitivity_utils.find_nearest_idx(array, value)[source]

Find the index where an array is nearest to a given value. For the closest value, rather than index, see find_nearest.

Parameters:
  • array (list or array) – Array to check

  • value (float) – Particular value to look for in an array

Returns:

Index where array is closest to value

Return type:

int

fast_response.sensitivity_utils.find_nearest(array, value)[source]

Find the value of an array closest to a given value. For the index, rather than value, see find_nearest_idx.

Parameters:
  • array (list or array) – Array to check

  • value (float) – Particular value to look for in an array

Returns:

value of the array that is closest to the value given

Return type:

float

fast_response.sensitivity_utils.deltaPsi(dec1, ra1, dec2, ra2)[source]

Calculate angular distance between two given points Values in Right Ascension/declination

Parameters:
  • dec1 (float) – Declination of first direction in radian

  • ra1 (float) – Right ascension of first direction in radian

  • dec2 (float) – Declination of second direction in radian

  • ra2 (float) – Right ascension of second direction in radian

Returns:

angular distance in radian

Return type:

float

fast_response.sensitivity_utils.deltaPsi2(sDec1, cDec1, sRa1, cRa1, sDec2, cDec2, sRa2, cRa2)[source]

Helper function to calculate angular distance. Should not be called directly, rather call deltaPsi which calls this helper function.

Parameters:
  • sDec1 (float) – sin(Declination of first direction)

  • cDec1 (float) – cos(Declination of first direction)

  • sRa1 (float) – sin(Right ascension of first direction)

  • cRa1 (float) – cos(Right ascension of first direction)

  • sDec2 (float) – sin(Declination of second direction)

  • cDec2 (float) – cos(Declination of second direction)

  • sRa2 (float) – sin(Right ascension of second direction)

  • cRa2 (float) – cos(Right ascension of second direction)

Returns:

angular distance in radian

Return type:

float

fast_response.sensitivity_utils.sensitivity_fit(signal_fluxes, passing, errs, fit_func, p0=None, conf_lev=0.9)[source]

Given an array of injected fluxes (or events) and passing fraction relative to the unblinded TS, do a fit given a CDF. Built on curve_fit from scipy.optimize.

Parameters:
  • signal_fluxes (float Numpy array) – set of injected flux values (or signal events).

  • passing (float Numpy array) – corresponding fraction of trials with TS > threshold TS value, for each signal flux value.

  • errs (float Numpy array) – binomial error for the given passing values. See also: binomial_error

  • fit_func (function) – function to use in the fit. See also: Error function (erfunc), Chi squared (chi2cdf), Incomplete gamma (incomplete_gamma)

  • p0 (None, scalar or N-length sequence) – initial guess for parameters, passed directly to scipy.optimize.curve_fit

  • conf_lev (float) – confidence level used (default 0.9 = 90% CL)

Returns:

Fit values, with keys:

  • popt, pcov: returned fit values from scipy.optimize.curve_fit

  • chi2, dof, pval: chi squared, degrees of freedom, and p-value from fit

  • xfit, yfit: arrays of values, using the fitted parameters of the given function

  • name: name of fit used

  • ls: linestyle, returns –

  • sens: calculated sensitivity value, in flux or ns (whichever is passed in signal_fluxes)

Return type:

dict

fast_response.sensitivity_utils.erfunc(x, a, b)[source]

Error function

fast_response.sensitivity_utils.chi2cdf(x, df1, loc, scale)[source]

Chi-squared CDF

fast_response.sensitivity_utils.incomplete_gamma(x, a, scale)[source]

Incomplete gamma function

fast_response.sensitivity_utils.poissoncdf(x, mu, loc)[source]

Poisson CDF function

fast_response.sensitivity_utils.binomial_error(p, number)[source]

Calculates binomial errors for given passing fraction values

Parameters:
  • p (float Numpy array) – passing fraction values

  • number (int Numpy array) – number of signal trials run for each injected value

Returns:

Numpy array of calculated binomial errors

Return type:

float array