Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
filterbank
Commits
0a2a4fea
Commit
0a2a4fea
authored
Oct 12, 2017
by
Tammo Jan Dijkema
Browse files
Fix flip error, fix chunksize
parent
743d1952
Changes
1
Hide whitespace changes
Inline
Side-by-side
tofil.py
View file @
0a2a4fea
...
@@ -41,7 +41,8 @@ def create_filterbank(infile, outfile=None, date=None, source=None):
...
@@ -41,7 +41,8 @@ def create_filterbank(infile, outfile=None, date=None, source=None):
else
:
else
:
date
=
Time
(
date
,
format
=
'isot'
)
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
(
"Source name: {}"
.
format
(
source
))
print
(
"Observation time: {}"
.
format
(
date
.
isot
))
print
(
"Observation time: {}"
.
format
(
date
.
isot
))
...
@@ -77,21 +78,25 @@ def create_filterbank(infile, outfile=None, date=None, source=None):
...
@@ -77,21 +78,25 @@ def create_filterbank(infile, outfile=None, date=None, source=None):
filesize
=
os
.
stat
(
infile
).
st_size
filesize
=
os
.
stat
(
infile
).
st_size
print
(
"File size:"
,
filesize
)
print
(
"File size:"
,
filesize
)
offset
=
0
offset
=
0
while
offset
<
filesize
and
False
:
CHUNKSIZE
=
10000
while
offset
<
filesize
:
# Loop through file in chunks of 256*10000 numbers
# 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
)
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
# Check that no packets were dropped
if
np
.
sum
(
data
[
1
:,
0
]
-
data
[:
-
1
,
0
]
-
1
)
>
0.1
:
if
np
.
sum
(
data
[
1
:,
-
1
]
-
data
[:
-
1
,
-
1
]
-
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
))
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
# Write data
out
.
append_spectra
(
data
)
out
.
append_spectra
(
data
)
offset
+=
256
*
10000
*
4
offset
+=
256
*
CHUNKSIZE
*
4
# Close file
# Close file
out
.
close
()
out
.
close
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment