def sigproc_object_from_writer(your_writer): """ Convert a `your_writer` object to Sigproc object for writing Args: your_writer: `your_writer` object Returns: sigproc object """ logger.debug(f"Generating Sigproc object") fil_obj = SigprocFile() fil_obj.rawdatafile = your_writer.outname fil_obj.source_name = your_writer.your_object.your_header.source_name fil_obj.machine_id = 0 # use "Fake" for now fil_obj.barycentric = 0 # by default the data isn't barycentered fil_obj.pulsarcentric = 0 fil_obj.telescope_id = 6 # use only GBT for now fil_obj.data_type = 0 fil_obj.nchans = your_writer.nchans fil_obj.foff = your_writer.your_object.your_header.foff fil_obj.fch1 = your_writer.chan_freqs[0] fil_obj.nbeams = 1 fil_obj.ibeam = 0 fil_obj.nbits = your_writer.your_object.your_header.nbits fil_obj.tsamp = your_writer.your_object.your_header.tsamp fil_obj.tstart = your_writer.tstart fil_obj.nifs = 1 # Only use Intensity values if (your_writer.your_object.your_header.ra_deg and your_writer.your_object.your_header.dec_deg): ra = your_writer.your_object.your_header.ra_deg dec = your_writer.your_object.your_header.dec_deg else: ra = 0 dec = 0 from astropy.coordinates import SkyCoord import numpy as np loc = SkyCoord(ra, dec, unit="deg") ra_hms = loc.ra.hms dec_dms = loc.dec.dms fil_obj.src_raj = float( f"{int(ra_hms[0]):02d}{np.abs(int(ra_hms[1])):02d}{np.abs(ra_hms[2]):07.4f}" ) fil_obj.src_dej = float( f"{int(dec_dms[0]):02d}{np.abs(int(dec_dms[1])):02d}{np.abs(dec_dms[2]):07.4f}" ) fil_obj.az_start = -1 fil_obj.za_start = -1 return fil_obj
def make_sigproc_obj(filfile, lowband_obj, nchan, fch1, foff): """ Use Your class object of the lower band to make Sigproc class object with the relevant parameters :param filfile: Name of the Filterbank file :param lowband_obj: Your object for the lower frequency band :param nchan: Number of channels in the combined data :param fch1: Frequency of the first channel :return fil_obj: Sigproc class object """ logger.debug(f"Generating Sigproc object") fil_obj = SigprocFile() logger.debug(f"Setting attributes of Sigproc object from Your object.") fil_obj.rawdatafile = filfile fil_obj.source_name = lowband_obj.your_header.source_name # Verify the following parameters fil_obj.machine_id = ( 0 # since mock isn't a machine in the standard list, we use fake ) fil_obj.barycentric = 0 # by default the data isn't barycentered fil_obj.pulsarcentric = 0 fil_obj.telescope_id = 1 # its always Arecibo fil_obj.data_type = 0 fil_obj.nchans = ( nchan # lowband_obj.your_header.nchans * 2 - lowchanskip - upchanskip ) fil_obj.foff = foff fil_obj.fch1 = fch1 fil_obj.nbeams = 1 fil_obj.ibeam = 0 fil_obj.nbits = lowband_obj.your_header.nbits fil_obj.tsamp = lowband_obj.your_header.tsamp fil_obj.tstart = lowband_obj.your_header.tstart fil_obj.nifs = 1 # always write single pol should use "lowband_obj.your_header.npol" if needed otherwise from astropy.coordinates import SkyCoord loc = SkyCoord( lowband_obj.your_header.ra_deg, lowband_obj.your_header.dec_deg, unit="deg" ) ra_hms = loc.ra.hms dec_dms = loc.dec.dms fil_obj.src_raj = float( f"{int(ra_hms[0]):02d}{int(np.abs(ra_hms[1])):02d}{np.abs(ra_hms[2]):07.4f}" ) fil_obj.src_dej = float( f"{int(dec_dms[0]):02d}{int(np.abs(dec_dms[1])):02d}{np.abs(dec_dms[2]):07.4f}" ) fil_obj.az_start = -1 fil_obj.za_start = -1 return fil_obj
def make_sigproc_object( rawdatafile: str, source_name: str, nchans: int, foff: float, fch1: float, tsamp: float, tstart: float, src_raj: float = 112233.44, src_dej: float = 112233.44, machine_id: int = 0, nbeams: int = 0, ibeam: int = 0, nbits: int = 8, nifs: int = 1, barycentric: int = 0, pulsarcentric: int = 0, telescope_id: int = 6, data_type: int = 0, az_start: float = -1, za_start: float = -1, ): """ Create a Sigprocfile from scratch. Args: rawdatafile (str) : Raw file name source_name (str) : Source Name nchans (int) : Number of channels foff (float) : Channel Bandwidth (MHz) fch1 (float) : Frequncy of first channel (MHz) tsamp (float) : Sampling interval (seconds) tstart (float) : MJD of the start sample src_raj (float) : RA of the source in format HHMMSS.SS src_dej (float) : Dec of source in format DDMMSS.SS machine_id (int) : Machine ID nbeams (int) : Number of beams in the rcvr ibeam (int) : Beam number nbits (int) : Number of bits nifs (int) : Number of IFs barycentric (int) : 0 for not barycentered data, 1 otherwise. pulsarcentric (int) : 0 for not pulsarcentered data, 1 otherwise. telescope_id (int) : Telescope ID data_type (int) : Data Type az_start (float) : Azimuth Angle start za_start (float): Zenith Angle start Returns: sigproc object """ logger.debug(f"Generating Sigproc object") fil_obj = SigprocFile() fil_obj.rawdatafile = rawdatafile fil_obj.source_name = source_name fil_obj.machine_id = machine_id fil_obj.barycentric = barycentric fil_obj.pulsarcentric = pulsarcentric fil_obj.telescope_id = telescope_id fil_obj.data_type = data_type fil_obj.nchans = nchans fil_obj.foff = foff fil_obj.fch1 = fch1 fil_obj.nbeams = nbeams fil_obj.ibeam = ibeam fil_obj.nbits = nbits fil_obj.tsamp = tsamp fil_obj.tstart = tstart fil_obj.nifs = nifs fil_obj.src_raj = src_raj fil_obj.src_dej = src_dej fil_obj.az_start = az_start fil_obj.za_start = za_start return fil_obj
def make_sigproc_obj(filfile, y, nchans, chan_freq, nstart): """ Use Your class to make Sigproc class object with relevant parameters Args: filfile: Name of the Filterbank file y: Your object for the PSRFITS files nchans: No. of channels in the frequency range chan_freq: Required frequency channel range Returns: obj: Object of class SigprocFile """ logger.debug(f'Generating Sigproc object') fil_obj = SigprocFile() logger.debug(f'Setting attributes of Sigproc object from Your object.') fil_obj.rawdatafile = filfile fil_obj.source_name = y.your_header.source_name # Verify the following parameters fil_obj.machine_id = 0 # use "Fake" for now fil_obj.barycentric = 0 # by default the data isn't barycentered fil_obj.pulsarcentric = 0 fil_obj.telescope_id = 6 # use only GBT for now fil_obj.data_type = 0 fil_obj.nchans = nchans fil_obj.foff = y.your_header.foff fil_obj.fch1 = chan_freq[0] fil_obj.nbeams = 1 fil_obj.ibeam = 0 fil_obj.nbits = y.your_header.nbits fil_obj.tsamp = y.your_header.tsamp if not nstart: nstart = 0 fil_obj.tstart = y.your_header.tstart + nstart * y.your_header.tsamp / ( 60 * 60 * 24) fil_obj.nifs = 1 # Only use Intensity values if y.your_header.ra_deg and y.your_header.dec_deg: ra = y.your_header.ra_deg dec = y.your_header.dec_deg else: ra = 0 dec = 0 from astropy.coordinates import SkyCoord loc = SkyCoord(ra, dec, unit='deg') ra_hms = loc.ra.hms dec_dms = loc.dec.dms fil_obj.src_raj = float( f'{int(ra_hms[0]):02d}{np.abs(int(ra_hms[1])):02d}{np.abs(ra_hms[2]):07.4f}' ) fil_obj.src_dej = float( f'{int(dec_dms[0]):02d}{np.abs(int(dec_dms[1])):02d}{np.abs(dec_dms[2]):07.4f}' ) fil_obj.az_start = -1 fil_obj.za_start = -1 return fil_obj