Created
October 17, 2022 09:22
-
-
Save cbassa/589747d5dc012566f22bf2cecc550d5e to your computer and use it in GitHub Desktop.
Tool to convert VLBI VDIF format to complex floats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import sys | |
import argparse | |
import numpy as np | |
import baseband | |
import astropy.units as u | |
if __name__ == "__main__": | |
# Read command line arguments | |
parser = argparse.ArgumentParser(description="Convert VDIF VLBI format to complex floats") | |
parser.add_argument("file", help="Input VDIF file", | |
metavar="FILE") | |
parser.add_argument("-l", "--length", help="Time length to extract [seconds; defaul: 1.0]", type=float, | |
default=1.0) | |
args = parser.parse_args() | |
# Arguments logic | |
if not os.path.exists(args.file): | |
print(f"{args.file} not found.") | |
sys.exit() | |
# Open file | |
fp = baseband.open(args.file) | |
# Read parameters | |
tstart = fp.start_time | |
samp_rate = fp.sample_rate.to(u.Hz).value | |
tsamp = 1.0 / samp_rate | |
bw = 0.5 * samp_rate * 1e-6 # in MHz | |
# Read data file | |
nsamp = int(args.length / tsamp) | |
data = fp.read(nsamp) | |
# Write out results | |
tstr = fp.start_time.isot | |
fname = f"DBBC_{tstr}_1575.000MHz_{samp_rate * 1e-6:.3f}Msps_RCP_RT0_real.raw" | |
data[:, 0].tofile(fname) | |
fname = f"DBBC_{tstr}_1575.000MHz_{samp_rate * 1e-6:.3f}Msps_LCP_RT0_real.raw" | |
data[:, 1].tofile(fname) | |
# Close input file | |
fp.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment