def write_fil(data, y, nchans=None, chan_freq=None, filename=None, outdir=None, nstart=None): """ Write Filterbank file given the Your object Args: data: Data to write to the Filterbank file y: Your object for the PSRFITS files nchans: No. of channels in the frequency range chan_freq: Required frequency channel range filename: Output name of the Filterbank file outdir: Output directory for the Filterbank file nstart: Start sample number """ filfile = outdir + '/' + filename # Add checks for an existing fil file logger.info(f'Trying to write data to filterbank file: {filfile}') try: if os.stat( filfile ).st_size > 8192: # check and replace with the size of header logger.warning( f'Filterbank file already exists at {filfile}. Appending spectra to it.' ) logger.info(f'Writing {data.shape[0]} spectra to file: {filfile}') SigprocFile.append_spectra(data, filfile) else: logger.warning(f'Filterbank file already exists at {filfile}') logger.info( 'Size of the Filerbank file is too small. Overwriting it.') fil_obj = make_sigproc_obj(filfile, y, nchans, chan_freq, nstart) fil_obj.write_header(filfile) logger.info(f'Writing {data.shape[0]} spectra to file: {filfile}') fil_obj.append_spectra(data, filfile) except FileNotFoundError: logger.info( f'Output file does not already exist. Creating a new Filterbank file.' ) fil_obj = make_sigproc_obj(filfile, y, nchans, chan_freq, nstart) fil_obj.write_header(filfile) logger.info(f'Writing {data.shape[0]} spectra to file: {filfile}') fil_obj.append_spectra(data, filfile) logger.info(f'Successfully written data to Filterbank file: {filfile}')
def write_fil(data, lowband_obj, upband_obj, filename=None, outdir=None): """ Write Filterbank file given the upper and lower band Your objects and combined data Args: lowband_obj: Your object for the lower frequency band upband_obj: Your object for the upper frequency band upband_obj: Your object for the upper frequency band data: Combined data from two bands filename: Output name of the Filterbank file outdir: Output directory for the Filterbank file """ original_dir, orig_lowband_basename = os.path.split( lowband_obj.your_header.filename ) if not filename: filename = ".".join(orig_lowband_basename.split(".")[:-3]) + ".fil" if not outdir: outdir = original_dir filfile = outdir + "/" + filename # Add checks for an existing fil file logger.info("Trying to write data to filterbank file: %s", filfile) try: if os.stat(filfile).st_size > 8192: # check and replace with the size of header logger.info("Writing %i spectra to file: %s", data.shape[0], filfile) SigprocFile.append_spectra(data, filfile) else: nchan = data.shape[1] fch1 = upband_obj.chan_freqs.max() foff = lowband_obj.foff if lowband_obj.foff < 0 else -1 * lowband_obj.foff fil_obj = make_sigproc_obj(filfile, lowband_obj, nchan, fch1, foff) fil_obj.write_header(filfile) logger.info("Writing %i spectra to file: %s", data.shape[0], filfile) fil_obj.append_spectra(data, filfile) except FileNotFoundError: nchan = data.shape[1] fch1 = upband_obj.chan_freqs.max() foff = lowband_obj.foff if lowband_obj.foff < 0 else -1 * lowband_obj.foff fil_obj = make_sigproc_obj(filfile, lowband_obj, nchan, fch1, foff) fil_obj.write_header(filfile) logger.info("Writing %i spectra to file: %s", data.shape[0], filfile) fil_obj.append_spectra(data, filfile) logger.info("Successfully written data to Filterbank file: %s", filfile)
def write_fil(data, lowband_obj, upband_obj, filename=None, outdir=None): ''' Write Filterbank file given the upper and lower band Your objects and combined data :param lowband_obj: Your object for the lower frequency band :param upband_obj: Your object for the upper frequency band :param upband_obj: Your object for the upper frequency band :param data: Combined data from two bands :param filename: Output name of the Filterbank file :param outdir: Output directory for the Filterbank file ''' original_dir, orig_lowband_basename = os.path.split(lowband_obj.your_header.filename) if not filename: filename = '.'.join(orig_lowband_basename.split('.')[:-3]) + '.fil' if not outdir: outdir = original_dir filfile = outdir + '/' + filename # Add checks for an existing fil file logger.info(f'Trying to write data to filterbank file: {filfile}') try: if os.stat(filfile).st_size > 8192: # check and replace with the size of header logger.info(f'Writing {data.shape[0]} spectra to file: {filfile}') SigprocFile.append_spectra(data, filfile) else: nchan = data.shape[1] fch1 = upband_obj.chan_freqs.max() foff = lowband_obj.foff if lowband_obj.foff < 0 else -1 * lowband_obj.foff fil_obj = make_sigproc_obj(filfile, lowband_obj, nchan, fch1, foff) fil_obj.write_header(filfile) logger.info(f'Writing {data.shape[0]} spectra to file: {filfile}') fil_obj.append_spectra(data, filfile) except FileNotFoundError: nchan = data.shape[1] fch1 = upband_obj.chan_freqs.max() foff = lowband_obj.foff if lowband_obj.foff < 0 else -1 * lowband_obj.foff fil_obj = make_sigproc_obj(filfile, lowband_obj, nchan, fch1, foff) fil_obj.write_header(filfile) logger.info(f'Writing {data.shape[0]} spectra to file: {filfile}') fil_obj.append_spectra(data, filfile) logger.info(f'Successfully written data to Filterbank file: {filfile}')