Skip to content

Commit fb86c5a

Browse files
authored
Merge pull request #277 from texadactyl/master
Make bl_scrunch work
2 parents c6d6b4b + 3b3f197 commit fb86c5a

File tree

7 files changed

+15
-196
lines changed

7 files changed

+15
-196
lines changed

VERSION-HISTORY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ This file is a version history of blimpy amendments, beginning with version 2.0.
33
<br>
44
| Date | Version | Contents |
55
| :--: | :--: | :-- |
6-
| 2022-08-02 | 2.1.2 | Write .fil files as well as .h5 files (issue #272). |
6+
| 2022-11-16 | 2.1.4 | Make bl_scrunch actually work (issue #276). |
7+
| 2022-08-02 | 2.1.3 | Write .fil files as well as .h5 files (issue #272). |
78
| 2022-07-22 | 2.1.2 | More container fields needed (issue #270). |
89
| 2022-07-21 | 2.1.1 | New Waterfall class option, an alternative to file loading (issue #264). |
910
| 2022-07-08 | 2.1.0 | New utility: dsamp (issue #267). |

blimpy/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from . import rawhdr
1414
from . import stax
1515
from . import stix
16-
from . import match_fils
1716
from . import dsamp
1817
from blimpy.io import file_wrapper
1918
except:

blimpy/bl_scrunch.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
producing a new HDF5 file of Filterbank file.
44
"""
55

6-
import os
6+
import os, sys
77
from argparse import ArgumentParser
88
from blimpy.waterfall import Waterfall
99
from .utils import change_the_ext
@@ -40,6 +40,10 @@ def bl_scrunch(in_path, out_dir='./', new_filename='', max_load=None, f_scrunch=
4040
else:
4141
out_path = out_dir + new_filename
4242

43+
if f_scrunch < 2 or f_scrunch >= wf.header["nchans"] :
44+
print("\n*** Number of frequency channels to average together must be > 1 and < the input file header nchans value!!\n")
45+
sys.exit(1)
46+
4347
print("bl_scrunch: Output path: {}".format(out_path))
4448
wf.write_to_hdf5(out_path, f_scrunch=f_scrunch)
4549
print("bl_scrunch: End")
@@ -49,9 +53,9 @@ def cmd_tool(args=None):
4953
r""" Command line utility for scrunching an input HDF5 file or Filterbank file.
5054
"""
5155

52-
p = ArgumentParser(description='Command line utility for converting HDF5 (.h5) to Sigproc filterbank (.fil) format \n >>h52fil <FULL_PATH_TO_FIL_FILE> [options]')
53-
p.add_argument('filepath', type=str, help='Name of file path to open (.h5 or .fil).')
54-
p.add_argument('-f', '--fscrunch', dest='f_scrunch', type=int,
56+
p = ArgumentParser(description='Command line utility for scrunching an HDF5 file (.h5) or a Sigproc Filterbank file (.fil) to an output HDF5 file.')
57+
p.add_argument('filepath', type=str, help='Input file path to open (.h5 or .fil).')
58+
p.add_argument('-f', '--fscrunch', dest='f_scrunch', type=int, required=True,
5559
help='Number of frequency channels to average (scrunch) together.')
5660
p.add_argument('-o', '--out_dir', dest='out_dir', type=str, default='./',
5761
help='Location for output files. Default: current directory.')
@@ -66,7 +70,7 @@ def cmd_tool(args=None):
6670
args = p.parse_args()
6771
else:
6872
args = p.parse_args(args)
69-
73+
7074
bl_scrunch(args.filepath, out_dir=args.out_dir, new_filename=args.new_filename,
7175
max_load=args.max_load, f_scrunch=args.f_scrunch)
7276

@@ -78,3 +82,4 @@ def cmd_tool(args=None):
7882
if __name__ == "__main__":
7983

8084
cmd_tool()
85+

blimpy/io/hdf_writer.py

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __write_to_hdf5_heavy(wf, filename_out, f_scrunch=None, *args, **kwargs):
7878
dout_shape[-1] //= f_scrunch
7979
dout_chunk_dim[-1] //= f_scrunch
8080
wf.header['foff'] *= f_scrunch
81+
wf.header['nchans'] //= f_scrunch
8182

8283
dset = h5.create_dataset('data',
8384
shape=tuple(dout_shape),
@@ -220,6 +221,7 @@ def __write_to_hdf5_light(wf, filename_out, f_scrunch=None, *args, **kwargs):
220221
wf.logger.info('Frequency scrunching by %i' % f_scrunch)
221222
data_out = utils.rebin(wf.data, n_z=f_scrunch)
222223
wf.header['foff'] *= f_scrunch
224+
wf.header['nchans'] //= f_scrunch
223225

224226
dset = h5.create_dataset('data',
225227
data=data_out,

blimpy/match_fils.py

-159
This file was deleted.

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
from setuptools import setup, find_packages
55

6-
__version__ = '2.1.3'
6+
__version__ = '2.1.4'
77

88
with open("README.md", "r") as fh:
99
long_description = fh.read()
@@ -19,7 +19,6 @@
1919
'fil2h5 = blimpy.fil2h5:cmd_tool',
2020
'h52fil = blimpy.h52fil:cmd_tool',
2121
'h5diag = blimpy.h5diag:cmd_tool',
22-
'matchfils = blimpy.match_fils:cmd_tool',
2322
'peek = blimpy.peek:cmd_tool',
2423
'rawhdr = blimpy.rawhdr:cmd_tool',
2524
'rawutil = blimpy.guppi:cmd_tool',

tests/test_match_fils.py

-28
This file was deleted.

0 commit comments

Comments
 (0)