def extract_data(filename, npts_per_bin=None, chunksize=1024): logger.info('Loading data') with fitsio.FITS(filename) as infile: logger.debug('SLOWWWWWW') hdu = infile[args.hdu] napertures = hdu.get_info()['dims'][0] med_flux = np.zeros(napertures, dtype=np.float32) frms = np.zeros(napertures, dtype=np.float32) for lcs, start, end in read_lightcurves_chunked(hdu, chunksize=chunksize): logger.debug('Reading apertures %d to %d', start, end) sc = sigma_clip(lcs, axis=1) if npts_per_bin is not None: sc = fast_bin(sc, npts_per_bin) m = np.median(sc, axis=1) mad_flux = np.median(np.abs(sc - m[:, np.newaxis]), axis=1) std_flux = 1.48 * mad_flux f = std_flux / m med_flux[start:end] = m frms[start:end] = f ind = np.where((med_flux > 0) & (frms > 0))[0] return ind, med_flux, frms
def test_fast_bin(input, expected): data, bin_size = input assert (fast_bin(data, bin_size=bin_size) == expected).all()
def bin_2d(arr, npts): return fast_bin(arr, npts)