Commit 0a2a4fea authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema

Fix flip error, fix chunksize

parent 743d1952
......@@ -41,7 +41,8 @@ def create_filterbank(infile, outfile=None, date=None, source=None):
else:
date = Time(date, format='isot')
print("Creating filterbank file {} from {}".format(outfile, infile))
print("Input file: {}".format(infile))
print("Output file: {}".format(outfile))
print("Source name: {}".format(source))
print("Observation time: {}".format(date.isot))
......@@ -77,21 +78,25 @@ def create_filterbank(infile, outfile=None, date=None, source=None):
filesize = os.stat(infile).st_size
print("File size:", filesize)
offset = 0
while offset < filesize and False:
CHUNKSIZE = 10000
while offset < filesize:
# Loop through file in chunks of 256*10000 numbers
# i.e. 256*10000*4 bytes (10Mb) to avoid memory problems
# i.e. 256*CHUNKSIZE*4 bytes (10Mb) to avoid memory problems
f.seek(offset, os.SEEK_SET)
data = np.fromfile(f, dtype='>u4', count=256*100000).reshape(-1,256)
data = np.fliplr(np.fromfile(f, dtype='>u4', count=256*CHUNKSIZE).reshape(-1,256))
# Check that no packets were dropped
if np.sum(data[1:,0]-data[:-1,0]-1) > 0.1:
print("Packets were dropped:", np.count_nonzero(data[:-1,0]-data[1:,0]-1), np.sum(data[1:,0]-data[:-1,0]-1))
if np.sum(data[1:,-1] - data[:-1,-1] - 1) > 0.1:
print("Packets were dropped:", np.count_nonzero(data[:-1,-1] - data[1:,-1] - 1),
np.sum(data[1:,-1] - data[:-1,-1] - 1))
print("Offset: {}".format(offset))
print("Size: {}".format(os.stat(outfile).st_size))
# Write data
out.append_spectra(data)
offset += 256*10000*4
offset += 256*CHUNKSIZE*4
# Close file
out.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment