Quick Start Guide#

Prerequisites

JinWu’s spectral fitting relies on HEASoft + XSPEC + model data. The recommended way is via conda, but any working HEASoft installation works:

conda create -n hea -c https://heasarc.gsfc.nasa.gov/docs/software/lheasoft/conda \\
    heasoft xspec xspec-data
conda activate hea
pip install jinwu

If HEASoft is already installed outside conda, use:

from jinwu.core.heasoft import HeasoftEnvManager
HeasoftEnvManager().init_heasoft()

This guide walks through common JinWu workflows.

Reading OGIP FITS Files#

JinWu provides a unified interface for reading standard OGIP FITS files:

import jinwu as jw

# Read a PHA spectrum file
pha = jw.read_pha("source.pha")
print(f"Exposure: {pha.exposure} s")
print(f"Channels: {len(pha.channels)}")

# Read a lightcurve
lc = jw.read_lc("lightcurve.fits")
print(f"Time range: {lc.time.min():.1f}{lc.time.max():.1f} s")

# Read ARF and RMF
arf = jw.read_arf("source.arf")
rmf = jw.read_rmf("source.rmf")

# Use the generic readfits to auto-detect type
data = jw.readfits("mystery.fits")
print(f"Detected: {data.kind}")

Working with Energy Bands#

from jinwu.core import EnergyBand, ChannelBand

# Define an energy band
soft_band = EnergyBand(0.3, 2.0, unit="keV")
hard_band = EnergyBand(2.0, 10.0, unit="keV")

# Convert to channel indices from an ARF
arf = jw.read_arf("source.arf")
ch_soft = ChannelBand.from_energy_band(soft_band, arf)
ch_hard = ChannelBand.from_energy_band(hard_band, arf)

Computing Net Data#

The jinwu.netdata() function computes net (background-subtracted) count rates and errors with proper uncertainty propagation:

net, net_err = jw.netdata(
    src=src_counts,
    bkg=bkg_counts,
    exposure=1000.0,
    backscale=0.1,     # BKG / SRC area ratio
)
snr = net / net_err
print(f"S/N = {snr:.1f}")

Next Steps#