Spectral analysis (RPP)

Scripts for the rotation-powered pulsar catalog spectral analysis. They need HEASoft and PyXspec. See RPP spectral analysis for how they fit together.

RPP-prep.py

Make files needed for RPP catalog spectral analysis. NOTE: This script is to be called from within the dir where we want the _pipe output dirs to be written.

usage: RPP-prep.py [-h] [--srcname SRCNAME] [--no_psrpipe] [--rephase]
                   [--par_range] [--cps_cut_percentile CPS_CUT_PERCENTILE]
                   [--emin EMIN] [--emax EMAX] [--p0 P0]
                   parfile datadir

Positional Arguments

parfile

Full path to the par file (possibly in /mnt/nicer/pars).

datadir

Full path to the NICER data dir (usually a subdir in /mnt/nicer/data).

Named Arguments

--srcname

Source name (used in output .yml file).

--no_psrpipe

Skip psrpipe.py, if <obsid>_pipe dirs are already made.

Default: False

--rephase

Skip psrpipe.py, rephase .evt files in existing <obsid>_pipe dirs with the provided par file.

Default: False

--par_range

Use only data within the time range covered by the provided par file.

Default: False

--cps_cut_percentile

Data bins above this percentile in terms of counts/s will be discarded.

Default: 95

--emin

Emin (keV) of the optimal energy range, if known (if Emin and Emax are not both specified, nioptcuts.py will be used to determine them).

--emax

Emax (keV) of the optimal energy range, if known.

--p0

Bayesian Blocks false-positive rate (passed to RPP-profile.py). Typical values: 0.005–0.3.

Default: 0.005

RPP-profile.py

Do RPP catalog pulse profile analysis on a merged event file.

usage: RPP-profile.py [-h] [--nbins NBINS] [--numharm NUMHARM]
                      [--optemin OPTEMIN] [--optemax OPTEMAX] [--p0 P0]
                      [--outbase OUTBASE] [--srcname SRCNAME] [--fermi FERMI]
                      [--lat3pc LAT3PC] [--toa-mc]
                      [--toa-mc-trials TOA_MC_TRIALS]
                      evtfile

Positional Arguments

evtfile

Input event file to process. Must have PULSE_PHASE column

Named Arguments

--nbins

Number of profile bins

Default: 32

--numharm

Number of Fourier harmonics to use (-1=auto)

Default: 4

--optemin

Minimum energy to include.

Default: 0.4

--optemax

Maximum energy to include.

Default: 2.0

--p0

p0 probability for Bayesian block analysis

Default: 0.005

--outbase

Output file for plot (type determined by extension)

--srcname

Source name (used in output .yml file).

--fermi

Fermi LAT event file (FT1) name, with PULSE_PHASE and MODEL_WEIGHT columns

--lat3pc

Fermi LAT 3PC data file for this pulsar, e.g. J0218+4232_3PC_data.fits

--toa-mc

Check the TOA Cramer-Rao bound with a Monte Carlo of simulated 5 ks observations

Default: False

--toa-mc-trials

Number of simulated observations for --toa-mc

Default: 500

RPP-pulsedspec.py

Makes on-pulse and off-pulse spectra, using the off-pulse phase range found by RPP-profile.py.

Do RPP catalog pulsed spectral analysis on a merged event file.

usage: RPP-pulsedspec.py [-h] evtfile profres resp arf

Positional Arguments

evtfile

Input event file to process. Must have PULSE_PHASE column

profres

YAML file of profile results

resp

Response file from non-phase-resolved spectrum

arf

ARF file from non-phase-resolved spectrum

RPP-driver.py

Fits the standard set of models to the total spectrum, with the SCORPEON background model, by running RPP-spec.py for each.

Do RPP catalog spectral analysis.

usage: RPP-driver.py [-h] [--loadfile LOADFILE] [--bbody1_kt BBODY1_KT]
                     [--bbody2_kt BBODY2_KT] [--bbody_norm BBODY_NORM]
                     [--powerlaw_index POWERLAW_INDEX]
                     [--powerlaw_norm POWERLAW_NORM] [--add-gauss ADD_GAUSS]
                     [--gauss-e-window GAUSS_E_WINDOW]
                     [--gauss-sigma-bounds GAUSS_SIGMA_BOUNDS]
                     [--nxb-set NXB_SET] [--sky-set SKY_SET]
                     srcname

Positional Arguments

srcname

The source name (or any string) that you want to appear in plots and output file names.

Named Arguments

--loadfile

Python load script made by nicerl3-spect.

Default: 'merged_cutmpu7_loadRPP.py'

--bbody1_kt

The starting value of kT (keV) for the first blackbody.

Default: '0.2'

--bbody2_kt

The starting value of kT (keV) for the second blackbody (ignored in 1BB models).

Default: '0.5'

--bbody_norm

The starting value of the blackbody normalization (will be used for both blackbodies in 2BB models).

Default: '1.e-6'

--powerlaw_index

The starting value of the powerlaw photon index.

Default: '2.0'

--powerlaw_norm

The starting value of the powerlaw normalization.

Default: '0.01'

--add-gauss

Add one Gaussian (repeatable). Format: LineE_keV,Sigma_keV,Norm. If at least one --add-gauss is provided, Gaussians will be enabled. Omitting the other Gaussian flags uses fit_rpp.py defaults.

Default: []

--gauss-e-window

±ΔE (keV) window around initial LineE for each Gaussian. If omitted, RPP-spec.py uses its default: 0.05 keV.

--gauss-sigma-bounds

Sigma bounds for all Gaussians as ‘smin,smax’ in keV. If omitted, RPP-spec.py uses its default: 0.001,0.1 keV.

--nxb-set

Set NXB parameter values (XSPEC syntax). Repeatable. Each option may contain multiple assignments separated by ‘;’. Examples: “nxb(4)=8.7” or “nxb(4)=8.7; nxb(6)=0” or “nxb(4)=8.7,0.05,0,0,1e20,1e24”.

Default: []

--sky-set

Set SKY parameter values (XSPEC syntax). Repeatable. Each option may contain multiple assignments separated by ‘;’. Examples: “sky(6)=0” or “sky(8)=1e-3; sky(6)=0” or “sky(8)=1e-3,0,0,0,1e20,1e24”.

Default: []

RPP-spec.py

Fits one model to the total spectrum, with the SCORPEON background model.

Do RPP catalog spectral analysis (extended with Gaussians via CLI).

usage: RPP-spec.py [-h] [--add-gauss ADD_GAUSS]
                   [--gauss-e-window GAUSS_E_WINDOW]
                   [--gauss-sigma-bounds GAUSS_SIGMA_BOUNDS] [--errors]
                   [--err-max ERR_MAX] [--loadfile LOADFILE]
                   [--outname OUTNAME] [--srcname SRCNAME] [--freeze FREEZE]
                   [--thaw THAW] [--warn] [--timestamp] [--nxb-set NXB_SET]
                   [--sky-set SKY_SET]
                   model_str model_startvals

Positional Arguments

model_str

Base model string, e.g. ‘tbabs*(bbody+powerlaw)’

model_startvals

Comma-separated starting values for the base model (no spaces).

Named Arguments

--add-gauss

Add one Gaussian (repeatable). Format: LineE_keV,Sigma_keV,Norm

Default: []

--gauss-e-window

Symmetric window ±ΔE (keV) to constrain each Gaussian LineE around its initial value.

Default: 0.05

--gauss-sigma-bounds

Constrain Gaussian Sigma for all lines: ‘min,max’ in keV (hard+soft bounds). Default: 0.001,0.1 keV.

Default: [0.001, 0.1]

--errors

Run XSPEC Fit.error on Gaussian parameters as well.

Default: False

--err-max

Maximum steps for Fit.error (used with --errors).

Default: 100

--loadfile

Python load script produced by nicerl3-spect.

Default: 'merged_cutmpu7_loadRPP.py'

--outname

Basename for output files.

Default: 'rpp-scorp'

--srcname

Source name shown on the plot.

Default: ''

--freeze

Comma-separated parameters to freeze (no spaces), e.g. ‘nxb(7),m1(12)’.

Default: nxb(7)

--thaw

Comma-separated parameters to thaw (no spaces).

Default: sky(12)

--warn

Ask before overwriting .xcm (otherwise overwrite silently).

Default: False

--timestamp

Append date/time to output filenames.

Default: False

--nxb-set

Set NXB parameter values (XSPEC syntax). Multiple assignments may be separated by ‘;’.

Default: []

--sky-set

Set SKY parameter values (XSPEC syntax). Multiple assignments may be separated by ‘;’.

Default: []

RPP-spec-from-xcm.py

Do RPP catalog spectral analysis from a full src+bkg model saved from xspec as an .xcm file.

First use Xspec to fit your src+bck model and use 'save all mymodel.xcm'.
then run RPP-spec-from-xcm.py mymodel.xcm.

usage: RPP-spec-from-xcm.py [-h] [--outroot OUTROOT] [--ylim YLIM [YLIM ...]]
                            xcmfile psrname

Positional Arguments

xcmfile

xcm file init script (template generated by --init)

psrname

PSR name for output figures and yaml

Named Arguments

--outroot

rootname of output files

--ylim

tuple for y-limits. Ex: --ylim 1e-6 1e-2

RPP-xcm-plot.py

Load SCORPEON .xcm file saved with Xspec; make plot and .yml file for RPP catalog.

usage: RPP-xcm-plot.py [-h] [--loadfile LOADFILE] [--srcname SRCNAME]
                       [--timestamp] [--outname OUTNAME]
                       xcmfile

Positional Arguments

xcmfile

Xspec .xcm file to load.

Named Arguments

--loadfile

Python load script made by nicerl3-spect.

Default: 'merged_cutmpu7_loadRPP.py'

--srcname

Source name, if you want it to appear on spectral plot.

Default: ''

--timestamp

Add the date and time to output filenames.

Default: False

--outname

Basename for output files.

Default: 'rpp-scorp'

RPP-driver-onoff.py

Fits the standard set of models to the pulsed (on-pulse minus off-pulse) spectrum, by running RPP-spec-onoff.py for each.

Do RPP catalog spectral analysis.

usage: RPP-driver-onoff.py [-h] [--loadfile LOADFILE] [--bbody1_kt BBODY1_KT]
                           [--bbody2_kt BBODY2_KT] [--bbody_norm BBODY_NORM]
                           [--powerlaw_index POWERLAW_INDEX]
                           [--powerlaw_norm POWERLAW_NORM]
                           srcname

Positional Arguments

srcname

The source name (or any string) that you want to appear in plots and output file names.

Named Arguments

--loadfile

Python load script made by RPP-pulsedspec.py.

Default: 'load_pulsedspec.py'

--bbody1_kt

The starting value of kT (keV) for the first blackbody.

Default: '0.2'

--bbody2_kt

The starting value of kT (keV) for the second blackbody (ignored in 1BB models).

Default: '0.5'

--bbody_norm

The starting value of the blackbody normalization (will be used for both blackbodies in 2BB models).

Default: '1.e-6'

--powerlaw_index

The starting value of the powelaw photon index.

Default: '2.0'

--powerlaw_norm

The starting value of the powelaw normalization.

Default: '0.01'

RPP-spec-onoff.py

Fits one model to the pulsed (on-pulse minus off-pulse) spectrum.

Do RPP catalog spectral analysis.

usage: RPP-spec-onoff.py [-h] [--loadfile LOADFILE] [--outname OUTNAME]
                         [--srcname SRCNAME] [--warn] [--timestamp]
                         model_str model_startvals

Positional Arguments

model_str

String describing the model, e.g. ‘tbabs* (bb + pow)’

model_startvals

Comma-separated list of starting parameter values; no spaces.

Named Arguments

--loadfile

Python load script made by RPP-pulsedspec.py.

Default: 'load_pulsedspec.py'

--outname

Basename for output files.

Default: 'rpp-onoff'

--srcname

Source name, if you want it to appear on spectral plot.

Default: ''

--warn

Warn if an existing .xcm file will be overwritten (requires interactive user input). Default: overwrite without warning (non-interactive).

Default: False

--timestamp

Add the date and time to output filenames.

Default: False

RPP-xcm-plot-onoff.py

Load On/Off .xcm file saved with Xspec; make plot and .yml file for RPP catalog.

usage: RPP-xcm-plot-onoff.py [-h] [--loadfile LOADFILE] [--srcname SRCNAME]
                             [--timestamp] [--outname OUTNAME]
                             xcmfile

Positional Arguments

xcmfile

Xspec .xcm file to load.

Named Arguments

--loadfile

Python load script made by RPP-pulsedspec.py.

Default: 'load_pulsedspec.py'

--srcname

Source name, if you want it to appear on spectral plot.

Default: ''

--timestamp

Add the date and time to output filenames.

Default: False

--outname

Basename for output files.

Default: 'rpp-onoff'

RPP-scorpeon_errorsfluxes.py

Read PSRNAME_scorpeon_bestfit.log and write an XSPEC script (PSRNAME_scorpeon_errorsfluxes.xcm) that computes parameter errors, steppar scans and fluxes for the SCORPEON-background spectral fit.

usage: RPP-scorpeon_errorsfluxes.py [-h] [-n PSRNAME] [-f PARAMERR_FACTOR]
                                    [-s STEPPAR_NSTEPS]

Named Arguments

-n, --psrname

Pulsar name

-f, --paramerr_factor

Factor by which to multiply the uncertainty values of the model parameters, in order to run steppar from (param_value-param_unc*factor) to (param_value+param_unc*factor)

Default: 1.5

-s, --steppar_nsteps

Number of steps to use in steppar

Default: 12

RPP-scorpeon_yml.py

Collect the best-fit parameters, confidence intervals and fluxes from the PSRNAME_scorpeon_final.log file in the current directory into PSRNAME_scorpeon.yml.

usage: RPP-scorpeon_yml.py [-h]

RPP-pulsed_errorsfluxes.py

Read PSRNAME_pulsed_bestfit.log and write an XSPEC script (PSRNAME_pulsed_errorsfluxes.xcm) that computes parameter errors, steppar scans and fluxes for the pulsed-spectrum fit.

usage: RPP-pulsed_errorsfluxes.py [-h] [-n PSRNAME] [-f PARAMERR_FACTOR]
                                  [-s STEPPAR_NSTEPS]

Named Arguments

-n, --psrname

Pulsar name

-f, --paramerr_factor

Factor by which to multiply the uncertainty values of the model parameters, in order to run steppar from (param_value-param_unc*factor) to (param_value+param_unc*factor)

Default: 1.5

-s, --steppar_nsteps

Number of steps to use in steppar

Default: 12

RPP-pulsed_yml.py

Collect the best-fit parameters, confidence intervals and fluxes from the PSRNAME_pulsed_final.log file in the current directory into PSRNAME_pulsed.yml.

usage: RPP-pulsed_yml.py [-h]

plotsrcbkg.py

Plot source and background spectra

usage: plotsrcbkg.py [-h] [--outfile OUTFILE] tot bkg

Positional Arguments

tot

PHA file name with src+bkg spectrum

bkg

PHA file name with bkg estimate spectrum

Named Arguments

--outfile

Output plot file name.