Skip to content

Instantly share code, notes, and snippets.

@cbassa
Created February 11, 2019 21:14
Show Gist options
  • Save cbassa/94df00e8b7d88505b251efc9325989cb to your computer and use it in GitHub Desktop.
Save cbassa/94df00e8b7d88505b251efc9325989cb to your computer and use it in GitHub Desktop.
rtl_power to STRF converter
import numpy as np
from astropy.time import Time
import matplotlib.pyplot as plt
def parse_line(line):
# Strip line and split
line = [part.strip() for part in line.strip().split(",")]
# Get MJD
t = Time("%sT%s"%(line[0], line[1]), format="isot", scale="utc")
fmin, fmax = float(line[2]), float(line[3])
z = np.array([float(part) for part in line[6:]])
return t, fmin, fmax, z
if __name__ == "__main__":
# Open file and read lines
with open("satellites.csv", "r") as fp:
lines = fp.readlines()
fp = open("test_000000.bin", "wb")
for line in lines:
t, fmin, fmax, z = parse_line(line)
if (fmin==400000000.0) & (fmax==401000000.0):
header = "HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %s s\nNCHAN %d\nNSUB 60\nEND\n"%(t.isot, 0.5*(fmin+fmax),fmax-fmin, 30.0, len(z))
header += " "*(256-len(header))
fp.write(header.encode("utf-8"))
(10.0**(0.1*z)).astype("float32").tofile(fp)
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment