def load_lcurve(fname): """Load light curve from a file.""" if get_file_format(fname) == 'pickle': data = _load_data_pickle(fname) elif get_file_format(fname) == 'nc': data = _load_data_nc(fname) lcurve = Lightcurve(data['time'], data['counts'], err=data['counts_err'], gti=data['gti'], err_dist=data['err_dist'], mjdref=data['mjdref']) if 'instr' in list(data.keys()): lcurve.instr = data["instr"] if 'expo' in list(data.keys()): lcurve.expo = data["expo"] if 'e_intervals' in list(data.keys()): lcurve.e_intervals = data["e_intervals"] if 'e_interval' in list(data.keys()): lcurve.e_interval = data["e_interval"] if 'use_pi' in list(data.keys()): lcurve.use_pi = bool(data["use_pi"]) if 'header' in list(data.keys()): lcurve.header = data["header"] if 'base' in list(data.keys()): lcurve.base = data["base"] return lcurve
def correct_lightcurve(lc_file, uf_file, outname=None, expo_limit=1e-7): """Apply exposure correction to light curve. Parameters ---------- lc_file : str The light curve file, in HENDRICS format uf_file : str The unfiltered event file, in FITS format Returns ------- outdata : str Output data structure Other Parameters ---------------- outname : str Output file name """ outname = _assign_value_if_none( outname, hen_root(lc_file) + "_lccorr" + HEN_FILE_EXTENSION) ftype, contents = get_file_type(lc_file) time = contents.time lc = contents.counts dt = contents.dt gti = contents.gti expo = get_exposure_from_uf(time, uf_file, dt=dt, gti=gti) newlc = np.array(lc / expo * dt, dtype=np.float64) newlc[expo < expo_limit] = 0 newlc_err = np.array(contents.counts_err / expo * dt, dtype=np.float64) newlc_err[expo < expo_limit] = 0 lcurve = Lightcurve(time, newlc, err=newlc_err, gti=gti, err_dist='gauss', mjdref=contents.mjdref) lcurve.expo = expo save_lcurve(lcurve, outname) return outname