def testWrite(make_data_path): fname = make_data_path('3c273.pi') ui.load_pha(1, fname) pha_orig = ui.get_data(1) ofh = tempfile.NamedTemporaryFile(suffix='sherpa_test') ui.save_pha(1, ofh.name, ascii=False, clobber=True) # limited checks pha = ui.unpack_pha(ofh.name) assert isinstance(pha, DataPHA) for key in ["channel", "counts"]: newval = getattr(pha, key) oldval = getattr(pha_orig, key) assert_allclose(oldval, newval, err_msg=key) # at present grouping and quality are not written out for key in ["exposure", "backscal", "areascal"]: newval = getattr(pha, key) oldval = getattr(pha_orig, key) assert newval == pytest.approx(oldval), key """
def create_xspec_comparison_dataset(make_data_path, keep_background=False): """Hack up the data set used in the XSPEC comparison tests. This is to avoid adding a new data set to the sherpa-test-data repository. """ infile = make_data_path('3c273.pi') dset = ui.unpack_pha(infile) # Remove background (if asked), ignore grouping, add bad channels and # an AREASCAL column. Sherpa ignores the error arrays in # the PHA file by default; the asserts are to check this. # assert dset.staterror is None assert dset.syserror is None dset.grouped = False chans = dset.channel quality = dset.quality ascal = np.ones(chans.size) ascal[(chans > 200) & (chans < 300)] = 0.1 for cnum in [150, 151, 250, 251, 252]: quality[chans == cnum] = 1 ascal[chans == cnum] = 0 dset.areascal = ascal if not keep_background: dset.delete_background() return dset # Adjust the background # bkg = dset.get_background() ascal = np.ones(chans.size) * 1.2 ascal[(chans > 150) & (chans < 250)] = 1.4 bkg.areascal = ascal return dset
def create_xspec_comparison_dataset(make_data_path, keep_background=False): """Hack up the data set used in the XSPEC comparison tests. This is to avoid adding a new data set to the sherpa-test-data repository. """ infile = make_data_path("3c273.pi") dset = ui.unpack_pha(infile) # Remove background (if asked), ignore grouping, add bad channels and # an AREASCAL column. Sherpa ignores the error arrays in # the PHA file by default; the asserts are to check this. # assert dset.staterror is None assert dset.syserror is None dset.grouped = False chans = dset.channel quality = dset.quality ascal = np.ones(chans.size) ascal[(chans > 200) & (chans < 300)] = 0.1 for cnum in [150, 151, 250, 251, 252]: quality[chans == cnum] = 1 ascal[chans == cnum] = 0 dset.areascal = ascal if not keep_background: dset.delete_background() return dset # Adjust the background # bkg = dset.get_background() ascal = np.ones(chans.size) * 1.2 ascal[(chans > 150) & (chans < 250)] = 1.4 bkg.areascal = ascal return dset
def testWrite(self): ofh = tempfile.NamedTemporaryFile(suffix='sherpa_test') ui.save_pha(self._id, ofh.name, ascii=False, clobber=True) # limited checks pha = ui.unpack_pha(ofh.name) self.assertIsInstance(pha, DataPHA) for key in ["channel", "counts"]: newval = getattr(pha, key) oldval = getattr(self._pha, key) assert_allclose(oldval, newval, err_msg=key) # at present grouping and quality are not written out for key in ["exposure", "backscal", "areascal"]: newval = getattr(pha, key) oldval = getattr(self._pha, key) self.assertAlmostEqual(oldval, newval, msg=key) """
def testWrite(self): ofh = tempfile.NamedTemporaryFile(suffix='sherpa_test') ui.save_pha(self._id, ofh.name, ascii=False, clobber=True) # limited checks pha = ui.unpack_pha(ofh.name) self.assertIsInstance(pha, DataPHA) for key in ["channel", "counts"]: newval = getattr(pha, key) oldval = getattr(self._pha, key) assert_allclose(oldval, newval, err_msg=key) # at present grouping and quality are not written out for key in ["exposure", "backscal", "areascal"]: newval = getattr(pha, key) oldval = getattr(self._pha, key) self.assertAlmostEqual(oldval, newval, msg=key) """