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
|
Select the events that fall inside a set of GTIs. |
|
Count the undershoot-only resets of each detector. |
|
Compute PI from the slow-chain PHA, using a linear calibration per detector. |
|
Choose an efficient FFT length. |
|
Convert intervals in elapsed good time back to MET. |
|
Select values that fall inside GTIs and convert their times to elapsed good time. |
|
Count the events from each detector. |
|
Remove events with a slow/fast PHA ratio at or above a cut. |
|
Remove events above the energy-dependent "trumpet" cut on the slow/fast PI ratio. |
|
Identify detectors with an anomalously high number of events. |
|
Format one GTI column as fixed-width text for annotating a figure. |
Colors used to tell GTI segments apart in time-series plots. |
|
|
Count events per detector and pick a bar color for each detector. |
|
Bin event times into a light curve. |
|
Mark the times the spacecraft was in the SAA. |
|
Plot the Sun, bright Earth and Moon angles and the elevation against elapsed good time. |
|
Plot the cutoff rigidity ( |
|
Plot a histogram of the per-event deadtime, in 1 microsecond bins. |
|
Plot per-detector values as an image of the focal plane. |
|
Plot the PI energy spectrum in counts/keV on log-log axes. |
|
Plot the power spectrum of the event times. |
|
Plot the spacecraft latitude against elapsed good time. |
|
Compute and plot a light curve over a set of GTIs. |
|
Plot the overshoot rate against elapsed good time. |
|
Plot the pointing offset ( |
|
Plot a bar chart of the reset rate of each detector. |
|
Plot the ratio of slow to fast PI against energy. |
|
Plot a bar chart of the number of events from each detector. |
|
Plot the undershoot rate against elapsed good time, marking times in sunshine. |
|
Compute pulse phases with PINT and plot a 32-bin pulse profile. |
|
Fold the events at a fixed frequency and plot a 32-bin pulse profile. |
|
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_IDcolumn.- 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_IDcolumn.- Returns:
numpy.ndarray or None --
DET_IDvalues 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_IDcolumn.- 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_rateis scaled to show the equivalent count rate, usingetable.meta["EXPOSURE"].- Parameters:
etable (astropy.table.Table) -- Event table with a
DET_IDcolumn andEXPOSUREin its metadata.ax_rate (matplotlib.axes.Axes) -- Axes for the count-rate scale (typically
ax_counts.twinx()).ax_counts (matplotlib.axes.Axes) -- Axes to draw the bar chart in.
- 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,RAWYposition of each detector is taken from its first event inetable. Detectors with no events are left at zero.- Parameters:
etable (astropy.table.Table) -- Event table with
DET_ID,RAWXandRAWYcolumns.num_events (array_like) -- Value for each detector, in the order of
nicer.values.IDS.
- 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:
etable (astropy.table.Table) -- Event table with
DET_ID,RAWXandRAWYcolumns.num_events (array_like) -- Value for each detector, in the order of
nicer.values.IDS.ax_map (matplotlib.axes.Axes) -- Not used; the image is drawn in the current axes.
- 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
METcolumn, sorted by time.startmet (float or None) -- Time range (MET seconds) to include. If both are None, the full span of
etableis used.stopmet (float or None) -- Time range (MET seconds) to include. If both are None, the full span of
etableis 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
METcolumn.lclog (bool) -- If True, use a logarithmic y axis.
gtitable (astropy.table.Table) -- GTI table with
STARTandSTOPcolumns.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 asfilt_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:
etable (astropy.table.Table) -- Event table with
PI,PI_FASTandEVENT_FLAGScolumns.args (argparse.Namespace) -- Not used.
- 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
PHAandDET_IDcolumns.calfile (str) -- Text file with three columns:
DET_ID, offsetE0(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
PIcolumn.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_Nthat 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).
- 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/nyquistseconds, with the number of bins chosen bychoose_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
METcolumn.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
DEADTIMEcolumn (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:
etable (astropy.table.Table) -- Event table with a
METcolumn.F0 (float) -- Folding frequency (Hz).
- 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.orbandargs.parare given.- Parameters:
ax (matplotlib.axes.Axes) -- Axes to draw the profile in.
etable (astropy.table.Table) -- Event table with a
Tcolumn of event times (as accepted bypint.toa.TOA).args (argparse.Namespace) -- Must have
orb(NICER orbit file) andpar(timing model) attributes.
- nicer.plotutils.apply_gti(etable, gtitable)[source]
Select the events that fall inside a set of GTIs.
- Parameters:
etable (astropy.table.Table) -- Event table with a
METcolumn.gtitable (astropy.table.Table) -- GTI table with
STARTandSTOPcolumns (MET seconds).
- Returns:
astropy.table.Table -- The events with
START < MET < STOPfor 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
STARTandCUMTIMEcolumns.
- 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
CUMTIMEcolumn), 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,STOPandCUMTIMEcolumns.
- 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_COUNTfrom the filter file, colored by GTI, along with the expected overshoot rate1.52 * COR_SAX**(-0.633). Ifovbintableis given, the binned overshoot rate is also plotted; otherwiseFPM_DOUBLE_COUNT(events with both overshoot and undershoot flags) is plotted.- Parameters:
mktable (astropy.table.Table) -- Filter (
.mkf) table.ovbintable (astropy.table.Table or None) -- Binned overshoot table from
nicer.NicerFileSet.NicerFileSet.getbinnedovershoots().gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.args (argparse.Namespace) -- Not used.
- nicer.plotutils.plot_SAA(mktable, gtitable)[source]
Mark the times the spacecraft was in the SAA.
SAA times (
NICER_SAAflag in the filter file) are drawn at the height of the maximum overshoot rate, so they can be overlaid onplot_overshoot().- Parameters:
mktable (astropy.table.Table) -- Filter (
.mkf) table.gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.
- nicer.plotutils.plot_undershoot(mktable, gtitable, args)[source]
Plot the undershoot rate against elapsed good time, marking times in sunshine.
- Parameters:
mktable (astropy.table.Table) -- Filter (
.mkf) table withFPM_UNDERONLY_COUNTandSUNSHINEcolumns.gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.args (argparse.Namespace) -- If
args.lclogis True, a logarithmic y axis is used.
- 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 withSUN_ANGLE,BR_EARTH,MOON_ANGLEandELVcolumns.gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.
- nicer.plotutils.plot_pointing(mktable, gtitable)[source]
Plot the pointing offset (
ANG_DIST) against elapsed good time.A red line marks 1 arcminute.
- Parameters:
mktable (astropy.table.Table) -- Filter (
.mkf) table.gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.
- nicer.plotutils.plot_latlon(mktable, gtitable)[source]
Plot the spacecraft latitude against elapsed good time.
- Parameters:
mktable (astropy.table.Table) -- Filter (
.mkf) table with aSAT_LATcolumn.gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.
- 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:
mktable (astropy.table.Table) -- Filter (
.mkf) table.gtitable (astropy.table.Table) -- GTI table with
START,STOPandCUMTIMEcolumns.
- nicer.plotutils.calc_nresets(mktable, IDS)[source]
Count the undershoot-only resets of each detector.
- Parameters:
mktable (astropy.table.Table) -- Filter (
.mkf) table with anMPU_UNDERONLY_COUNTcolumn.IDS (numpy.ndarray) -- Detector IDs (normally
nicer.values.IDS).
- 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
PHAorPHA_FASTis not positive are kept.- Parameters:
etable (astropy.table.Table) -- Event table with
PHAandPHA_FASTcolumns.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 whosePIorPI_FASTis not positive are also kept.- Parameters:
etable (astropy.table.Table) -- Event table with
PIandPI_FASTcolumns.- 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*nCutrows, only the first and lastnCutare shown, and the omitted rows are replaced by...(or, for theDURATIONcolumn, 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.