nicer.plotutils

Plotting and event-selection helpers used by the quick-look scripts.

Most functions take an event table (etable, an astropy.table.Table read from a NICER event file, usually with the TIME column renamed to MET), a filter-file table (mktable, read from the .mkf file), and/or a GTI table (gtitable, with START, STOP and, for the elapsed-time helpers, CUMTIME columns).

The plotting functions draw into the current matplotlib axes, and the page-layout functions in nicer.sci_plots, nicer.eng_plots and nicer.bkg_plots combine them into figures.

Functions

apply_gti(etable, gtitable)

Select the events that fall inside a set of GTIs.

calc_nresets(mktable, IDS)

Count the undershoot-only resets of each detector.

calc_pi(etable, calfile)

Compute PI from the slow-chain PHA, using a linear calibration per detector.

choose_N(orig_N)

Choose an efficient FFT length.

convert_from_elapsed_goodtime(elapsedstarts, ...)

Convert intervals in elapsed good time back to MET.

convert_to_elapsed_goodtime(mets, vals, gtitable)

Select values that fall inside GTIs and convert their times to elapsed good time.

event_counter(etable)

Count the events from each detector.

filt_ratio(etable, ratiocut)

Remove events with a slow/fast PHA ratio at or above a cut.

filt_ratio_trumpet(etable)

Remove events above the energy-dependent "trumpet" cut on the slow/fast PI ratio.

find_hot_detectors(etable)

Identify detectors with an anomalously high number of events.

format_gti_longstring(gticolumn[, nCut])

Format one GTI column as fixed-width text for annotating a figure.

gti_colormap()

Colors used to tell GTI segments apart in time-series plots.

hist_use(etable)

Count events per detector and pick a bar color for each detector.

light_curve(etable, startmet, stopmet, binsize)

Bin event times into a light curve.

plot_SAA(mktable, gtitable)

Mark the times the spacecraft was in the SAA.

plot_angles(mktable, gtitable)

Plot the Sun, bright Earth and Moon angles and the elevation against elapsed good time.

plot_cor(mktable, gtitable)

Plot the cutoff rigidity (COR_SAX, GeV) against elapsed good time.

plot_deadtime(etable)

Plot a histogram of the per-event deadtime, in 1 microsecond bins.

plot_detector_chart(etable, num_events, ax_map)

Plot per-detector values as an image of the focal plane.

plot_energy_spec(etable[, binscale, plot_pos])

Plot the PI energy spectrum in counts/keV on log-log axes.

plot_fft_of_power(etable, nyquist, pslog, ...)

Plot the power spectrum of the event times.

plot_latlon(mktable, gtitable)

Plot the spacecraft latitude against elapsed good time.

plot_light_curve(etable, lclog, gtitable[, ...])

Compute and plot a light curve over a set of GTIs.

plot_overshoot(mktable, ovbintable, ...)

Plot the overshoot rate against elapsed good time.

plot_pointing(mktable, gtitable)

Plot the pointing offset (ANG_DIST) against elapsed good time.

plot_resetrate(IDS, reset_rates)

Plot a bar chart of the reset rate of each detector.

plot_slowfast(etable, args)

Plot the ratio of slow to fast PI against energy.

plot_total_count_hist(etable, ax_rate, ax_counts)

Plot a bar chart of the number of events from each detector.

plot_undershoot(mktable, gtitable, args)

Plot the undershoot rate against elapsed good time, marking times in sunshine.

pulse_profile(ax, etable, args)

Compute pulse phases with PINT and plot a 32-bin pulse profile.

pulse_profile_fixed(etable, F0)

Fold the events at a fixed frequency and plot a 32-bin pulse profile.

structure(etable, num_events)

Arrange per-detector values on the focal-plane grid.

nicer.plotutils.event_counter(etable)[source]

Count the events from each detector.

Parameters:

etable (astropy.table.Table) -- Event table with a DET_ID column.

Returns:

numpy.ndarray -- Number of events for each detector, in the order of nicer.values.IDS.

nicer.plotutils.find_hot_detectors(etable)[source]

Identify detectors with an anomalously high number of events.

The per-detector counts from event_counter() are sigma-clipped (3 sigma, 3 iterations), and any detector with more than the clipped mean plus 3 times the clipped standard deviation is flagged as hot.

Parameters:

etable (astropy.table.Table) -- Event table with a DET_ID column.

Returns:

numpy.ndarray or None -- DET_ID values of the hot detectors, or None if none were found.

nicer.plotutils.hist_use(etable)[source]

Count events per detector and pick a bar color for each detector.

Hot detectors (see find_hot_detectors()) are colored red, all others black.

Parameters:

etable (astropy.table.Table) -- Event table with a DET_ID column.

Returns:

  • IDevents (numpy.ndarray) -- Number of events for each detector in nicer.values.IDS.

  • colors (numpy.ndarray) -- Matplotlib color for each detector.

nicer.plotutils.plot_total_count_hist(etable, ax_rate, ax_counts)[source]

Plot a bar chart of the number of events from each detector.

Hot detectors are drawn in red. The twin axis ax_rate is scaled to show the equivalent count rate, using etable.meta["EXPOSURE"].

Parameters:
Returns:

numpy.ndarray -- Number of events for each detector in nicer.values.IDS.

nicer.plotutils.structure(etable, num_events)[source]

Arrange per-detector values on the focal-plane grid.

The RAWX, RAWY position of each detector is taken from its first event in etable. Detectors with no events are left at zero.

Parameters:
Returns:

numpy.ndarray -- Array of shape (7, 8), indexed as [RAWY, RAWX].

nicer.plotutils.plot_detector_chart(etable, num_events, ax_map)[source]

Plot per-detector values as an image of the focal plane.

The image is drawn in the current axes, using structure() to place the values.

Parameters:
nicer.plotutils.light_curve(etable, startmet, stopmet, binsize)[source]

Bin event times into a light curve.

Parameters:
  • etable (astropy.table.Table) -- Event table with a MET column, sorted by time.

  • startmet (float or None) -- Time range (MET seconds) to include. If both are None, the full span of etable is used.

  • stopmet (float or None) -- Time range (MET seconds) to include. If both are None, the full span of etable is used.

  • binsize (float) -- Bin size in seconds.

Returns:

  • bins (numpy.ndarray) -- Left edge of each bin, in seconds since startmet.

  • sums (numpy.ndarray) -- Number of events in each bin.

nicer.plotutils.gti_colormap()[source]

Colors used to tell GTI segments apart in time-series plots.

Returns:

  • colornames (list of str) -- The color names, in order.

  • cmap (matplotlib.colors.Colormap) -- Colormap mapping GTI index to color.

  • norm (matplotlib.colors.Normalize) -- Normalization to use with cmap.

nicer.plotutils.plot_light_curve(etable, lclog, gtitable, binsize=1.0, noplot=False, plot_pos=None)[source]

Compute and plot a light curve over a set of GTIs.

Each GTI is binned separately with light_curve(), and the segments are concatenated in elapsed good time, so gaps between GTIs are removed. Points are colored by GTI segment and the mean rate is drawn as a dashed line.

Parameters:
  • etable (astropy.table.Table) -- Event table with a MET column.

  • lclog (bool) -- If True, use a logarithmic y axis.

  • gtitable (astropy.table.Table) -- GTI table with START and STOP columns.

  • binsize (float, optional) -- Bin size in seconds.

  • noplot (bool, optional) -- If True, only compute the light curve.

  • plot_pos ({None, "corner", "left", "center"}, optional) -- Position of this panel in a grid of plots (see nicer.eng_plots.plot_all_lc()), which controls the axis labels.

Returns:

  • mean_rate (float) -- Mean count rate (counts/s).

  • sums (numpy.ndarray) -- Number of events in each bin.

nicer.plotutils.plot_slowfast(etable, args)[source]

Plot the ratio of slow to fast PI against energy.

Only events that triggered both the slow and fast chains are used. Events above the “trumpet” cut (PI/PI_FAST > 1.1 + 120/PI, the same cut as filt_ratio_trumpet()) are drawn in red. If there are more than 50000 events, a subset is plotted. The numbers of fast-only, slow-only, both and rejected events are written on the plot.

Parameters:
nicer.plotutils.calc_pi(etable, calfile)[source]

Compute PI from the slow-chain PHA, using a linear calibration per detector.

Parameters:
  • etable (astropy.table.Table) -- Event table with PHA and DET_ID columns.

  • calfile (str) -- Text file with three columns: DET_ID, offset E0 (keV) and gain (keV per PHA channel).

Returns:

numpy.ndarray -- PI value for each event (integer, units of 10 eV).

nicer.plotutils.plot_energy_spec(etable, binscale=1.0, plot_pos=None)[source]

Plot the PI energy spectrum in counts/keV on log-log axes.

Bins are 0.02 keV wide below 2 keV and 0.1 keV wide from 2 to 15 keV, both multiplied by binscale.

Parameters:
  • etable (astropy.table.Table) -- Event table with a PI column.

  • binscale (float, optional) -- Factor to multiply the bin widths by.

  • plot_pos ({None, "corner", "left", "bottom", "center"}, optional) -- Position of this panel in a grid of plots (see nicer.eng_plots.plot_all_spectra()), which controls the axis labels.

nicer.plotutils.choose_N(orig_N)[source]

Choose an efficient FFT length.

Returns a value at least as large as orig_N that is either a power of two or a highly factorable number, whichever is smaller. The returned value is divisible by at least 16 (twice the maximum downsample factor of 8).

Parameters:

orig_N (int or float) -- Minimum number of points.

Returns:

int -- The chosen length (at least 1024).

nicer.plotutils.plot_fft_of_power(etable, nyquist, pslog, writeps)[source]

Plot the power spectrum of the event times.

Events are binned at 0.5/nyquist seconds, with the number of bins chosen by choose_N(). The power is normalized by the number of events, and the lowest 50 frequency bins are set to zero. The frequency and power of the highest peak are printed.

Parameters:
  • etable (astropy.table.Table) -- Event table with a MET column.

  • nyquist (float) -- Nyquist frequency (Hz).

  • pslog (bool) -- If True, use a logarithmic y axis.

  • writeps (bool) -- If True, also write the power spectrum to powspec.txt.

nicer.plotutils.plot_deadtime(etable)[source]

Plot a histogram of the per-event deadtime, in 1 microsecond bins.

Parameters:

etable (astropy.table.Table) -- Event table with a DEADTIME column (seconds).

nicer.plotutils.pulse_profile_fixed(etable, F0)[source]

Fold the events at a fixed frequency and plot a 32-bin pulse profile.

Phases are measured from the first event in etable; no barycentering is done.

Parameters:
nicer.plotutils.pulse_profile(ax, etable, args)[source]

Compute pulse phases with PINT and plot a 32-bin pulse profile.

The H-test value is written on the plot. Nothing is done unless both args.orb and args.par are given.

Parameters:
nicer.plotutils.apply_gti(etable, gtitable)[source]

Select the events that fall inside a set of GTIs.

Parameters:
Returns:

astropy.table.Table -- The events with START < MET < STOP for some GTI.

nicer.plotutils.convert_from_elapsed_goodtime(elapsedstarts, elapsedstops, gtitable)[source]

Convert intervals in elapsed good time back to MET.

This is the inverse of convert_to_elapsed_goodtime(), used for selecting time ranges interactively on a light curve plot.

Parameters:
  • elapsedstarts (array_like) -- Interval start and stop times in elapsed good time (seconds).

  • elapsedstops (array_like) -- Interval start and stop times in elapsed good time (seconds).

  • gtitable (astropy.table.Table) -- GTI table with START and CUMTIME columns.

Returns:

startmets, stopmets (numpy.ndarray) -- The intervals in MET seconds.

nicer.plotutils.convert_to_elapsed_goodtime(mets, vals, gtitable)[source]

Select values that fall inside GTIs and convert their times to elapsed good time.

Elapsed good time is the time since the start of the GTI plus the total duration of all earlier GTIs (the CUMTIME column), so plots made against it have no gaps between GTIs.

Parameters:
  • mets (array_like) -- Times of the values (MET seconds).

  • vals (array_like) -- Values at those times.

  • gtitable (astropy.table.Table) -- GTI table with START, STOP and CUMTIME columns.

Returns:

  • etimes (numpy.ndarray) -- Elapsed good time of each selected value (seconds).

  • goodvals (numpy.ndarray) -- The selected values.

  • cc (numpy.ndarray) -- Index of the GTI each value falls in, for coloring plots by GTI.

nicer.plotutils.plot_overshoot(mktable, ovbintable, gtitable, args)[source]

Plot the overshoot rate against elapsed good time.

Plots FPM_OVERONLY_COUNT from the filter file, colored by GTI, along with the expected overshoot rate 1.52 * COR_SAX**(-0.633). If ovbintable is given, the binned overshoot rate is also plotted; otherwise FPM_DOUBLE_COUNT (events with both overshoot and undershoot flags) is plotted.

Parameters:
nicer.plotutils.plot_SAA(mktable, gtitable)[source]

Mark the times the spacecraft was in the SAA.

SAA times (NICER_SAA flag in the filter file) are drawn at the height of the maximum overshoot rate, so they can be overlaid on plot_overshoot().

Parameters:
nicer.plotutils.plot_undershoot(mktable, gtitable, args)[source]

Plot the undershoot rate against elapsed good time, marking times in sunshine.

Parameters:
nicer.plotutils.plot_angles(mktable, gtitable)[source]

Plot the Sun, bright Earth and Moon angles and the elevation against elapsed good time.

Parameters:
  • mktable (astropy.table.Table) -- Filter (.mkf) table with SUN_ANGLE, BR_EARTH, MOON_ANGLE and ELV columns.

  • gtitable (astropy.table.Table) -- GTI table with START, STOP and CUMTIME columns.

nicer.plotutils.plot_pointing(mktable, gtitable)[source]

Plot the pointing offset (ANG_DIST) against elapsed good time.

A red line marks 1 arcminute.

Parameters:
nicer.plotutils.plot_latlon(mktable, gtitable)[source]

Plot the spacecraft latitude against elapsed good time.

Parameters:
nicer.plotutils.plot_cor(mktable, gtitable)[source]

Plot the cutoff rigidity (COR_SAX, GeV) against elapsed good time.

A dashed line marks 1.5 GeV.

Parameters:
nicer.plotutils.calc_nresets(mktable, IDS)[source]

Count the undershoot-only resets of each detector.

Parameters:
Returns:

numpy.ndarray -- Total number of resets for each detector, summed over the table.

nicer.plotutils.plot_resetrate(IDS, reset_rates)[source]

Plot a bar chart of the reset rate of each detector.

Parameters:
  • IDS (array_like) -- Detector IDs.

  • reset_rates (array_like) -- Reset rate (Hz) for each detector.

nicer.plotutils.filt_ratio(etable, ratiocut)[source]

Remove events with a slow/fast PHA ratio at or above a cut.

Events whose PHA or PHA_FAST is not positive are kept.

Parameters:
  • etable (astropy.table.Table) -- Event table with PHA and PHA_FAST columns.

  • ratiocut (float) -- Maximum allowed PHA/PHA_FAST.

Returns:

astropy.table.Table -- The events that pass the cut.

nicer.plotutils.filt_ratio_trumpet(etable)[source]

Remove events above the energy-dependent “trumpet” cut on the slow/fast PI ratio.

Events are kept if PI/PI_FAST < 1.1 + 120/PI. Events whose PI or PI_FAST is not positive are also kept.

Parameters:

etable (astropy.table.Table) -- Event table with PI and PI_FAST columns.

Returns:

astropy.table.Table -- The events that pass the cut.

nicer.plotutils.format_gti_longstring(gticolumn, nCut=3)[source]

Format one GTI column as fixed-width text for annotating a figure.

If there are more than 2*nCut rows, only the first and last nCut are shown, and the omitted rows are replaced by ... (or, for the DURATION column, by their total duration in parentheses).

Parameters:
  • gticolumn (astropy.table.Column) -- A GTI table column, with a unit.

  • nCut (int, optional) -- Number of rows to show at each end.

Returns:

  • str -- The formatted column, with a header.

  • int -- Number of omitted rows.