Skip to content

Commit

Permalink
Merge pull request #214 from texadactyl/master
Browse files Browse the repository at this point in the history
Improve testing and error messaging
  • Loading branch information
texadactyl authored Jul 8, 2021

Verified

This commit was signed with the committer’s verified signature.
Vlatombe Vincent Latombe
2 parents 3b3eeca + 51e45ac commit d21019c
Showing 4 changed files with 132 additions and 17 deletions.
14 changes: 8 additions & 6 deletions VERSION-HISTORY.md
Original file line number Diff line number Diff line change
@@ -3,12 +3,14 @@ This file is a version history of turbo_seti amendments, beginning with version
<br>
| Date | Version | Contents |
| :--: | :--: | :-- |
| 2021-06-14 | 2.0.15 | Fix issue #210 - Guard against unusual Filterbank headers created by setigen apps |
| 2021-06-12 | 2.0.14 | Fix issue #208 - Miscalculated max_data_array_size when available RAM < 1 GB |
| 2021-06-10 | 2.0.13 | Fix issue #205 - Define MeerKAT in the list of observatories |
| | | Fix issue #207 guppi.py generate_filterban_header()
| 2021-05-29 | 2.0.12 | Fix issue #203 - calc_n_coarse_chan default to 1 |
| 2021-04-14 | 2.0.11 | Fix issue #196 - automate memory requirements |
| 2021-07-08 | 2.0.16 | Increase test coverage of calc_n_coarse_chan(). |
| | | Improve messaging when calc_n_coarse_chan() emits warnings. |
| 2021-06-14 | 2.0.15 | Fix issue #210 - Guard against unusual Filterbank headers created by setigen apps. |
| 2021-06-12 | 2.0.14 | Fix issue #208 - Miscalculated max_data_array_size when available RAM < 1 GB. |
| 2021-06-10 | 2.0.13 | Fix issue #205 - Define MeerKAT in the list of observatories. |
| | | Fix issue #207 guppi.py generate_filterban_header(). |
| 2021-05-29 | 2.0.12 | Fix issue #203 - calc_n_coarse_chan default to 64. |
| 2021-04-14 | 2.0.11 | Fix issue #196 - automate memory requirements. |
| 2021-03-11 | 2.0.10 | Reopened enhancement #178 - calcload utility - added a verbose parameter. |
| 2021-03-08 | 2.0.9 | Implemented enhancement #182 - rawhdr utility (get header from raw files). |
| | | Amended setup.cfg to enable hdf5plugin to be installed optimized by installation. |
36 changes: 26 additions & 10 deletions blimpy/io/base_reader.py
Original file line number Diff line number Diff line change
@@ -50,6 +50,13 @@ def _setup_selection_range(self, f_start=None, f_stop=None, t_start=None, t_stop
init (bool): If call during __init__
"""


def _dump_parms():
wstr = "f_start={}, f_stop={}, t_start={}, t_stop={}, init={}" \
.format(f_start, f_stop, t_start, t_stop, init)
logger.warning(wstr)


# This avoids resetting values
if init is True:
if t_start is None:
@@ -84,27 +91,31 @@ def _setup_selection_range(self, f_start=None, f_stop=None, t_start=None, t_stop
else:
if init is False or t_start != None:
logger.warning('Setting t_start = %f, since t_start not given or not valid.'%self.t_begin)
_dump_parms()
self.t_start = self.t_begin

if t_stop <= self.t_end and t_stop > self.t_begin:
self.t_stop = int(t_stop)
else:
if init is False or t_stop:
logger.warning('Setting t_stop = %f, since t_stop not given or not valid.'%self.t_end)
_dump_parms()
self.t_stop = self.t_end

if f_start >= self.f_begin and f_start < self.f_end:
self.f_start = f_start
else:
if init is False or f_start:
logger.warning('Setting f_start = %f, since f_start not given or not valid.'%self.f_begin)
_dump_parms()
self.f_start = self.f_begin

if f_stop <= self.f_end and f_stop > self.f_begin:
self.f_stop = f_stop
else:
if init is False or f_stop:
logger.warning('Setting f_stop = %f, since f_stop not given or not valid.'%self.f_end)
_dump_parms()
self.f_stop = self.f_end

# Now we have setup bounds, we can calculate shape of selection
@@ -240,12 +251,18 @@ def adjust_n_coarse_chan(self, n_coarse_chan, nchans):
r"""Don't let the calculated n_coarse_chan be < 1
nor exceed the number of fine channels."""
if n_coarse_chan < 1:
errmsg = "blimpy:io:base_reader:adjust_n_coarse_chan: n_coarse_chan < 1. Replacing that with a value of 1."
logger.warning(errmsg)
return 1
errmsg1 = "blimpy:io:base_reader:adjust_n_coarse_chan: n_coarse_chan={}, nchans={}" \
.format(n_coarse_chan, nchans)
logger.warning(errmsg1)
errmsg2 = "blimpy:io:base_reader:adjust_n_coarse_chan: n_coarse_chan < 1. Replacing that with a value of 64 (SWAG)."
logger.warning(errmsg2)
return 64
if n_coarse_chan > nchans: # exceeds the number of fine channels?
errmsg = "blimpy:io:base_reader:adjust_n_coarse_chan: n_coarse_chan > nchans. Replacing that with the value of nchans."
logger.warning(errmsg)
errmsg1 = "blimpy:io:base_reader:adjust_n_coarse_chan: n_coarse_chan={}, nchans={}" \
.format(n_coarse_chan, nchans)
logger.warning(errmsg1)
errmsg2 = "blimpy:io:base_reader:adjust_n_coarse_chan: n_coarse_chan > nchans. Replacing that with the value of nchans (SWAG)."
logger.warning(errmsg2)
return nchans
return n_coarse_chan

@@ -282,9 +299,9 @@ def calc_n_coarse_chan(self, chan_bw=None):
else:
errmsg1 = "blimpy:io:base_reader:calc_n_coarse_chan: hires nchans not divisible by 2^20 and not GBT"
logger.warning(errmsg1)
errmsg2 = "Setting a value of 1. In turbo_seti, you can specify n_course_chan explicitly."
errmsg2 = "Setting a value of 64 (SWAG). In turbo_seti, you can specify n_course_chan explicitly."
logger.info(errmsg2)
return 1
return 64

# Not high resolution data. GBT?
if self.header['telescope_id'] == 6:
@@ -298,9 +315,9 @@ def calc_n_coarse_chan(self, chan_bw=None):
else:
errmsg1 = "blimpy:io:base_reader:calc_n_coarse_chan: not hires and not GBT. Setting a value of 1"
logger.warning(errmsg1)
errmsg2 = "Setting a value of 1. In turbo_seti, you can specify n_course_chan explicitly."
errmsg2 = "Setting a value of 64 (SWAG). In turbo_seti, you can specify n_course_chan explicitly."
logger.info(errmsg2)
return 1
return 64

def calc_n_blobs(self, blob_dim):
""" Given the blob dimensions, calculate how many fit in the data selection.
@@ -325,4 +342,3 @@ def isheavy(self):
return True
else:
return False

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

__version__ = '2.0.15'
__version__ = '2.0.16'

with open("README.md", "r") as fh:
long_description = fh.read()
97 changes: 97 additions & 0 deletions tests/test_calc_n_coarse_chan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from blimpy import Waterfall
from tests.data import voyager_h5, test_ifs_fil


HIRES_THRESHOLD = 2**20


def test_ncc_chan_bw():
wf = Waterfall(voyager_h5)
print("test_bcc_chan_bw: telescope_id:", wf.header['telescope_id'])
print("test_ncc_chan_bw: nchans:", wf.header['nchans'])

n_coarse_chan = wf.calc_n_coarse_chan(16)
print("test_ncc_chan_bw: n_coarse_chan [chan_bw=16]:", n_coarse_chan)
assert n_coarse_chan == 64

n_coarse_chan = wf.calc_n_coarse_chan(1)
print("test_ncc_chan_bw: n_coarse_chan [chan_bw=1]:", n_coarse_chan)
assert n_coarse_chan > 2.9 and n_coarse_chan < 3.0


def test_ncc_gbt():
wf = Waterfall(test_ifs_fil)
wf.header['telescope_id'] = 6
print("test_ncc_gbt: telescope_id:", wf.header['telescope_id'])
print("test_ncc_gbt: starting nchans:", wf.header['nchans'])

n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_gbt: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 64

wf.header['nchans'] = 3 * HIRES_THRESHOLD
print("\ntest_ncc_gbt: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_gbt: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 3

wf.header['nchans'] = HIRES_THRESHOLD
print("\ntest_ncc_gbt: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_gbt: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 1

wf.header['nchans'] = HIRES_THRESHOLD - 1
print("\ntest_ncc_gbt: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_gbt: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 64

wf.header['nchans'] = HIRES_THRESHOLD + 1
print("\ntest_ncc_gbt: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_gbt: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 64


def test_ncc_42():
wf = Waterfall(test_ifs_fil)
wf.header['telescope_id'] = 42
print("test_ncc_42: telescope_id:", wf.header['telescope_id'])
print("test_ncc_42: starting nchans:", wf.header['nchans'])

n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_42: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 64

wf.header['nchans'] = 3 * HIRES_THRESHOLD
print("\ntest_ncc_42: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_42: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 3

wf.header['nchans'] = HIRES_THRESHOLD
print("\ntest_ncc_42: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_42: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 1

wf.header['nchans'] = HIRES_THRESHOLD - 1
print("\ntest_ncc_42: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_42: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 64

wf.header['nchans'] = HIRES_THRESHOLD + 1
print("\ntest_ncc_42: nchans:", wf.header['nchans'])
n_coarse_chan = wf.calc_n_coarse_chan()
print("test_ncc_42: n_coarse_chan [chan_bw=None]:", n_coarse_chan)
assert n_coarse_chan == 64


if __name__ == "__main__":
wf = Waterfall(test_ifs_fil)
wf.info()
test_ncc_chan_bw()
test_ncc_gbt()
test_ncc_42()

0 comments on commit d21019c

Please sign in to comment.