From 2ac8d20f50afd27b1e6c186e93d5d0f883d0c2f1 Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Tue, 2 Aug 2022 17:29:49 -0500 Subject: [PATCH 1/6] Line 121: wf = Waterfall(in_path, max_load=None) LOFAR-related issue --- blimpy/dsamp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blimpy/dsamp.py b/blimpy/dsamp.py index 7df24ec..f7fd1df 100644 --- a/blimpy/dsamp.py +++ b/blimpy/dsamp.py @@ -118,7 +118,7 @@ def make_h5_file(in_path, out_path, group_size): """ # Load input filterbank .fil or .h5 file. - wf = Waterfall(in_path, load_data=True) + wf = Waterfall(in_path, max_load=None) # Down-sample input. t0 = time.time() From cafdd0f11d7b520ca9a3787bb5d3a3a331aad552 Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Tue, 2 Aug 2022 17:30:13 -0500 Subject: [PATCH 2/6] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6c4136d..8def913 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ """ from setuptools import setup, find_packages -__version__ = '2.1.2' +__version__ = '2.1.3' with open("README.md", "r") as fh: long_description = fh.read() From fcf9cc533abdf1e3eb80e39f4e91b3c177582461 Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Tue, 2 Aug 2022 17:58:32 -0500 Subject: [PATCH 3/6] Add ability to write a SIGPROC file (.fil) --- blimpy/dsamp.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/blimpy/dsamp.py b/blimpy/dsamp.py index f7fd1df..a5825f3 100644 --- a/blimpy/dsamp.py +++ b/blimpy/dsamp.py @@ -6,6 +6,7 @@ # External dependencies: import sys +import pathlib import time from argparse import ArgumentParser import numpy as np @@ -21,6 +22,7 @@ # Blimpy functions required: from blimpy import Waterfall from blimpy.io.hdf_writer import __write_to_hdf5_heavy as write_to_h5 +from blimpy.io.fil_writer import write_to_fil def downer(in_np_array, in_tsamp, group_size, out_dtype="float32"): @@ -104,11 +106,11 @@ def downer(in_np_array, in_tsamp, group_size, out_dtype="float32"): return out_np_array, out_tsamp, out_nints -def make_h5_file(in_path, out_path, group_size): +def make_output_file(in_path, out_path, group_size, flag_h5): """ 1. Load input filterbank .fil or .h5 file. 2. Call downer to perform down-sampling. - 3. Save result to the specified .h5 file. + 3. Save result to the specified file. Args: in_path (str): Name of filterbank file to load @@ -136,7 +138,10 @@ def make_h5_file(in_path, out_path, group_size): wf.data = out_data LOGGER.info(f"Output data shape: {wf.data.shape}") t0 = time.time() - write_to_h5(wf, out_path) + if flag_h5: + write_to_h5(wf, out_path) + else: + write_to_fil(wf, out_path) LOGGER.info(f"Write-output time: {time.time() - t0 :f}s") return 0 @@ -147,7 +152,7 @@ def cmd_tool(args=None): parser = ArgumentParser(description="Downsample an input Filterbank file (.fil or .h5) to an output .h5 Filterbank file.") parser.add_argument("in_path", type=str, help="Path of input Filterbank file (.fil or .h5)") - parser.add_argument("out_path", type=str, help="Path of output Filterbank file (.h5 only)") + parser.add_argument("out_path", type=str, help="Path of output Filterbank file (.fil or .h5)") parser.add_argument("-s", "--group_size", dest="group_size", type=int, required=True, help="Group size for the purpose of summing 2 or more time samples. Required.") @@ -160,9 +165,20 @@ def cmd_tool(args=None): LOGGER.error(f"Input group size = {args.group_size} but it must be at least 2 !!") sys.exit(1) - rc = make_h5_file(args.in_path, - args.out_path, - args.group_size) + _, in_ext = pathlib.Path(args.in_path).suffix + _, out_ext = pathlib.Path(args.out_path).suffix + if in_ext not in [".fil", ".h5"]: + LOGGER.error("Input file extension must be .fil or .h5 !!") + sys.exit(1) + if out_ext not in [".fil", ".h5"]: + LOGGER.error("Output file extension must be .fil or .h5 !!") + sys.exit(1) + flag_h5 = bool(out_ext == ".h5") + + rc = make_output_file(args.in_path, + args.out_path, + args.group_size, + flag_h5) if rc != 0: sys.exit(rc) From 21c118f5f9686294b1a8fabb68942d5f2eff3a75 Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Tue, 2 Aug 2022 18:01:25 -0500 Subject: [PATCH 4/6] Update dsamp.py --- blimpy/dsamp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blimpy/dsamp.py b/blimpy/dsamp.py index a5825f3..b641be3 100644 --- a/blimpy/dsamp.py +++ b/blimpy/dsamp.py @@ -165,8 +165,8 @@ def cmd_tool(args=None): LOGGER.error(f"Input group size = {args.group_size} but it must be at least 2 !!") sys.exit(1) - _, in_ext = pathlib.Path(args.in_path).suffix - _, out_ext = pathlib.Path(args.out_path).suffix + in_ext = pathlib.Path(args.in_path).suffix + out_ext = pathlib.Path(args.out_path).suffix if in_ext not in [".fil", ".h5"]: LOGGER.error("Input file extension must be .fil or .h5 !!") sys.exit(1) From 9fbe0fb14cf47e9d1ae0d15200edcf807b01b48f Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Tue, 2 Aug 2022 18:12:32 -0500 Subject: [PATCH 5/6] Fix issue #272 --- VERSION-HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/VERSION-HISTORY.md b/VERSION-HISTORY.md index 146daaf..f41de6f 100644 --- a/VERSION-HISTORY.md +++ b/VERSION-HISTORY.md @@ -3,6 +3,7 @@ This file is a version history of blimpy amendments, beginning with version 2.0.
| Date | Version | Contents | | :--: | :--: | :-- | +| 2022-08-02 | 2.1.2 | 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). | From 521d21b8c99e80baf53934f687733ab091ef7fcd Mon Sep 17 00:00:00 2001 From: Richard Elkins Date: Tue, 2 Aug 2022 18:42:03 -0500 Subject: [PATCH 6/6] Test fixes for dsamp .fil output --- tests/test_dsamp.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_dsamp.py b/tests/test_dsamp.py index 9bf1eef..8b0e4af 100644 --- a/tests/test_dsamp.py +++ b/tests/test_dsamp.py @@ -4,7 +4,7 @@ import pytest import blimpy as bl -from tests.data import voyager_fil, voyager_h5, test_h5 +from tests.data import voyager_fil, voyager_h5, test_h5, test_fil GROUP_SIZE = 3 @@ -13,13 +13,25 @@ def test_dsamp_fil_to_h5(): """ fil to h5 test. """ - bl.dsamp.make_h5_file(voyager_fil, test_h5, GROUP_SIZE) + bl.dsamp.make_output_file(voyager_fil, test_h5, GROUP_SIZE, True) def test_dsamp_h5_to_h5(): """ h5 to h5 test. """ - bl.dsamp.make_h5_file(voyager_h5, test_h5, GROUP_SIZE) + bl.dsamp.make_output_file(voyager_h5, test_h5, GROUP_SIZE, True) + + +def test_dsamp_h5_to_fil(): + """ h5 to fil test. + """ + bl.dsamp.make_output_file(voyager_h5, test_fil, GROUP_SIZE, False) + + +def test_dsamp_fil_to_fil(): + """ fil to fil test. + """ + bl.dsamp.make_output_file(voyager_fil, test_fil, GROUP_SIZE, False) def test_cmd_tool():