Code to read spectrogram file
from __future__ import print_function
def rd_datfile(file):
''' Read EOVSA binary spectrogram file and return a dictionary with times
in Julian Date, frequencies in GHz, and cross-power data in sfu.
Return Keys:
'time' Numpy array of nt times in JD format
'fghz' Numpy array of nf frequencies in GHz
'data' Numpy array of size [nf, nt] containing cross-power data
Returns empty dictionary ({}) if file size is not compatible with inferred dimensions
'''
import struct
import numpy as np
def dims(file):
# Determine time and frequency dimensions (assumes the file has fewer than 10000 times)
f = open(file,'rb')
tmp = f.read(83608) # max 10000 times and 451 frequencies
f.close()
nbytes = len(tmp)
tdat = struct.unpack(str(int(nbytes/8))+'d',tmp[:nbytes])
nt = np.where(np.array(tdat) < 2400000.)[0]
nf = np.where(np.array(tdat) < 1.1)[0] - nt[0]
return nt[0], nf[0]
nt, nf = dims(file)
f = open(file,'rb')
tmp = f.read(nt*8)
times = struct.unpack(str(nt)+'d',tmp)
tmp = f.read(nf*8)
fghz = struct.unpack(str(nf)+'d',tmp)
tmp = f.read()
f.close()
if len(tmp) != nf*nt*4:
print('File size is incorrect for nt=',nt,'and nf=',nf)
return {}
data = np.array(struct.unpack(str(nt*nf)+'f',tmp)).reshape(nf,nt)
return {'time':times, 'fghz':fghz, 'data':data}
List of EOVSA Flares with Spectrogram Data