Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# This will return an EventList, a light curve, a Powerspectrum, ...
# depending on the contents of the file
try:
ftype, contents = get_file_type(fname)
except:
contents = _retrieve_pickle_object(fname)
if isinstance(contents, Lightcurve):
return DataSet.get_lightcurve_dataset_from_stingray_Lightcurve(contents)
elif isinstance(contents, EventList):
return DataSet.get_eventlist_dataset_from_stingray_Eventlist(contents)
# This also work for Powerspectrum and AveragedCrosspowerspectrum, clearly
elif isinstance(contents, Crossspectrum):
logging.error("Unsupported intermediate file type: Crossspectrum")
else:
logging.error("Unsupported intermediate file type: %s" % type(stingray_object).__name__)
return None