Skip to content

Commit

Permalink
Merge pull request #277 from texadactyl/master
Browse files Browse the repository at this point in the history
Make bl_scrunch work
  • Loading branch information
texadactyl authored Nov 16, 2022
2 parents c6d6b4b + 3b3f197 commit fb86c5a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 196 deletions.
3 changes: 2 additions & 1 deletion VERSION-HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ This file is a version history of blimpy amendments, beginning with version 2.0.
<br>
| Date | Version | Contents |
| :--: | :--: | :-- |
| 2022-08-02 | 2.1.2 | Write .fil files as well as .h5 files (issue #272). |
| 2022-11-16 | 2.1.4 | Make bl_scrunch actually work (issue #276). |
| 2022-08-02 | 2.1.3 | Write .fil files as well as .h5 files (issue #272). |
| 2022-07-22 | 2.1.2 | More container fields needed (issue #270). |
| 2022-07-21 | 2.1.1 | New Waterfall class option, an alternative to file loading (issue #264). |
| 2022-07-08 | 2.1.0 | New utility: dsamp (issue #267). |
Expand Down
1 change: 0 additions & 1 deletion blimpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from . import rawhdr
from . import stax
from . import stix
from . import match_fils
from . import dsamp
from blimpy.io import file_wrapper
except:
Expand Down
15 changes: 10 additions & 5 deletions blimpy/bl_scrunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
producing a new HDF5 file of Filterbank file.
"""

import os
import os, sys
from argparse import ArgumentParser
from blimpy.waterfall import Waterfall
from .utils import change_the_ext
Expand Down Expand Up @@ -40,6 +40,10 @@ def bl_scrunch(in_path, out_dir='./', new_filename='', max_load=None, f_scrunch=
else:
out_path = out_dir + new_filename

if f_scrunch < 2 or f_scrunch >= wf.header["nchans"] :
print("\n*** Number of frequency channels to average together must be > 1 and < the input file header nchans value!!\n")
sys.exit(1)

print("bl_scrunch: Output path: {}".format(out_path))
wf.write_to_hdf5(out_path, f_scrunch=f_scrunch)
print("bl_scrunch: End")
Expand All @@ -49,9 +53,9 @@ def cmd_tool(args=None):
r""" Command line utility for scrunching an input HDF5 file or Filterbank file.
"""

p = ArgumentParser(description='Command line utility for converting HDF5 (.h5) to Sigproc filterbank (.fil) format \n >>h52fil <FULL_PATH_TO_FIL_FILE> [options]')
p.add_argument('filepath', type=str, help='Name of file path to open (.h5 or .fil).')
p.add_argument('-f', '--fscrunch', dest='f_scrunch', type=int,
p = ArgumentParser(description='Command line utility for scrunching an HDF5 file (.h5) or a Sigproc Filterbank file (.fil) to an output HDF5 file.')
p.add_argument('filepath', type=str, help='Input file path to open (.h5 or .fil).')
p.add_argument('-f', '--fscrunch', dest='f_scrunch', type=int, required=True,
help='Number of frequency channels to average (scrunch) together.')
p.add_argument('-o', '--out_dir', dest='out_dir', type=str, default='./',
help='Location for output files. Default: current directory.')
Expand All @@ -66,7 +70,7 @@ def cmd_tool(args=None):
args = p.parse_args()
else:
args = p.parse_args(args)

bl_scrunch(args.filepath, out_dir=args.out_dir, new_filename=args.new_filename,
max_load=args.max_load, f_scrunch=args.f_scrunch)

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

cmd_tool()

2 changes: 2 additions & 0 deletions blimpy/io/hdf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __write_to_hdf5_heavy(wf, filename_out, f_scrunch=None, *args, **kwargs):
dout_shape[-1] //= f_scrunch
dout_chunk_dim[-1] //= f_scrunch
wf.header['foff'] *= f_scrunch
wf.header['nchans'] //= f_scrunch

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

dset = h5.create_dataset('data',
data=data_out,
Expand Down
159 changes: 0 additions & 159 deletions blimpy/match_fils.py

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from setuptools import setup, find_packages

__version__ = '2.1.3'
__version__ = '2.1.4'

with open("README.md", "r") as fh:
long_description = fh.read()
Expand All @@ -19,7 +19,6 @@
'fil2h5 = blimpy.fil2h5:cmd_tool',
'h52fil = blimpy.h52fil:cmd_tool',
'h5diag = blimpy.h5diag:cmd_tool',
'matchfils = blimpy.match_fils:cmd_tool',
'peek = blimpy.peek:cmd_tool',
'rawhdr = blimpy.rawhdr:cmd_tool',
'rawutil = blimpy.guppi:cmd_tool',
Expand Down
28 changes: 0 additions & 28 deletions tests/test_match_fils.py

This file was deleted.

0 comments on commit fb86c5a

Please sign in to comment.