diff --git a/rfplot.py b/rfplot.py new file mode 100644 index 0000000..2940c54 --- /dev/null +++ b/rfplot.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import numpy as np +from strf.rfio import Spectrogram + +import matplotlib.pyplot as plt + +if __name__ == "__main__": + # Settings + path = "data" + prefix = "2021-08-04T20:48:35" + ifile = 50 + nsub = 1800 + + # Read spectrogram + s = Spectrogram(path, prefix, ifile, nsub, 4171) + + # Create plot + vmin, vmax = np.percentile(s.z, (5, 99.95)) + + fig, ax = plt.subplots() + ax.imshow(s.z, origin="lower", aspect="auto", interpolation="None", + vmin=vmin, vmax=vmax) + + plt.show() diff --git a/strf/__init__.py b/strf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/strf/rfio.py b/strf/rfio.py new file mode 100644 index 0000000..c8be4cc --- /dev/null +++ b/strf/rfio.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +import os +import re + +from datetime import datetime + +import numpy as np + +class Spectrogram: + """Spectrogram class""" + + def __init__(self, path, prefix, ifile, nsub, siteid): + """Define a spectrogram""" + + # Read first file to get number of channels + fname = os.path.join(path, "{:s}_{:06d}.bin".format(prefix, ifile)) + with open(fname, "rb") as fp: + header = parse_header(fp.read(256)) + + # Set frequencies + freq = np.linspace(-0.5*header["bw"], 0.5*header["bw"], header["nchan"], endpoint=False)+header["freq"]+0.5*header["bw"]/header["nchan"] + + # Loop over subints and files + zs = [] + mjds = [] + isub = 0; + while isub