def test_load_and_save_pds(self): pds = Powerspectrum() pds.freq = np.linspace(0, 10, 15) pds.power = np.random.poisson(30, 15) pds.mjdref = 54385.3254923845 pds.gti = np.longdouble([[-0.5, 3.5]]) save_pds(pds, self.dum) pds2 = load_pds(self.dum) assert np.allclose(pds.gti, pds2.gti) assert np.allclose(pds.mjdref, pds2.mjdref) assert pds.m == pds2.m
def test_load_and_save_xps_quick(self): lcurve1 = Lightcurve(np.linspace(0, 10, 150), np.random.poisson(30, 150), mjdref=54385.3254923845, gti=np.longdouble([[-0.5, 3.5]])) lcurve2 = Lightcurve(np.linspace(0, 10, 150), np.random.poisson(30, 150), mjdref=54385.3254923845, gti=np.longdouble([[-0.5, 3.5]])) xps = AveragedCrossspectrum(lcurve1, lcurve2, 1) save_pds(xps, self.dum) xps2 = load_pds(self.dum, nosub=True) assert np.allclose(xps.gti, xps2.gti) assert xps.m == xps2.m assert not hasattr(xps2, 'pds1')
def test_load_and_save_xps_no_all(self): lcurve1 = Lightcurve(np.linspace(0, 10, 150), np.random.poisson(30, 150), mjdref=54385.3254923845, gti=np.longdouble([[-0.5, 3.5]])) lcurve2 = Lightcurve(np.linspace(0, 10, 150), np.random.poisson(30, 150), mjdref=54385.3254923845, gti=np.longdouble([[-0.5, 3.5]])) xps = AveragedCrossspectrum(lcurve1, lcurve2, 1) outfile = 'small_xps' + HEN_FILE_EXTENSION save_pds(xps, outfile, save_all=False) xps2 = load_pds(outfile) assert np.allclose(xps.gti, xps2.gti) assert xps.m == xps2.m assert not hasattr(xps2, 'pds1')
def save_to_intermediate_file(stingray_object, fname): """Save Stingray object to intermediate file.""" from stingray.lightcurve import Lightcurve from stingray.events import EventList from stingray.crossspectrum import Crossspectrum from hendrics.io import save_lcurve, save_events, save_pds if isinstance(stingray_object, Lightcurve): save_lcurve(stingray_object, fname) elif isinstance(stingray_object, EventList): save_events(stingray_object, fname) # This also work for Powerspectrum and AveragedCrosspowerspectrum, clearly elif isinstance(stingray_object, Crossspectrum): save_pds(stingray_object, fname) else: logging.error("save_to_intermediate_file: Unknown object type: %s" % type(stingray_object).__name__) return False return True
def test_load_and_save_xps(self): lcurve1 = Lightcurve(np.linspace(0, 10, 150), np.random.poisson(30, 150), mjdref=54385.3254923845, gti = np.longdouble([[-0.5, 3.5]])) lcurve2 = Lightcurve(np.linspace(0, 10, 150), np.random.poisson(30, 150), mjdref=54385.3254923845, gti = np.longdouble([[-0.5, 3.5]])) xps = AveragedCrossspectrum(lcurve1, lcurve2, 1) save_pds(xps, self.dum) xps2 = load_pds(self.dum) assert np.allclose(xps.gti, xps2.gti) assert xps.m == xps2.m lag, lag_err = xps.time_lag() lag2, lag2_err = xps2.time_lag() assert np.allclose(lag, lag2)