def test_xspecvar_zero_handling(bexp, yexp, dyexp): """How does XSPEC variance handle 0 in source and/or background? The values were calculated using XSPEC 12.10.1m (HEASOFT 6.26.1) using the following commands to create the file foo.dat which contains (after three 'header' lines) the data 'x 0.5 y dy' data foo.fits iplot data wplot foo.dat quit where foo.fits is a fake PHA file set up to have the channel/count values used below (a CSC-style PHA file was used so that source and background were in the same file but a separate bgnd PHA file could also have been used). """ stat = Chi2XspecVar() chans = numpy.arange(1, 10, dtype=numpy.int16) scnts = numpy.asarray([0, 0, 0, 1, 3, 1, 1, 3, 3], dtype=numpy.int16) bcnts = numpy.asarray([0, 1, 3, 0, 0, 1, 3, 1, 3], dtype=numpy.int16) s = DataPHA('src', chans, scnts, exposure=1) b = DataPHA('bkg', chans, bcnts, exposure=bexp) s.set_background(b) s.subtract() y, dy, other = s.to_fit(staterrfunc=stat.calc_staterror) assert other is None assert y == pytest.approx(yexp) assert dy == pytest.approx(dyexp)