Skip to content

Commit

Permalink
fixed myFil bug. Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pravirkr committed May 9, 2023
1 parent 4e613e6 commit c5fac89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
comment: false
coverage:
status:
project:
default:
target: 80%
threshold: 5%
if_ci_failed: error
4 changes: 2 additions & 2 deletions sigpyproc/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_data(self, pad_mode: str = "median") -> FilterbankBlock:
self.logger.debug(
f"nstart_file = {self.nstart_file}, nsamps_file = {self.nsamps_file}"
)
data = self.myFil.read_block(start=self.nstart_file, nsamps=self.nsamps_file)
data = self.fil.read_block(start=self.nstart_file, nsamps=self.nsamps_file)

if self.nstart < 0 or self.nstart + self.nsamps > self.header.nsamples:
data = self._pad_data(data, pad_mode=pad_mode)
Expand Down Expand Up @@ -396,7 +396,7 @@ def _pad_data(
else:
raise ValueError(f"pad_mode {pad_mode} not supported.")

data_pad = np.ones((self.header.nchans, self.nsamps), dtype=self.header.dtype)
data_pad = np.ones((self.header.nchans, self.nsamps), dtype=pad_arr.dtype)
data_pad *= pad_arr[:, None]

offset = min(0, self.nstart)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_readers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from sigpyproc.readers import FilReader, PFITSReader
from sigpyproc.readers import FilReader, PFITSReader, PulseExtractor
from sigpyproc.header import Header
from sigpyproc.block import FilterbankBlock

Expand Down Expand Up @@ -81,3 +81,19 @@ def test_read_block_outofrange(self, fitsfile_4bit):
fits.read_block(-10, 100)
with np.testing.assert_raises(ValueError):
fits.read_block(100, fits.header.nsamples + 1)

def test_read_plan(self, fitsfile_4bit):
fits = PFITSReader(fitsfile_4bit)
for nsamps, ii, data in fits.read_plan(gulp=512, nsamps=1024):
assert isinstance(data, np.ndarray)

class TestPulseExtractor(object):
def test_filterbank_single(self, filfile_4bit):
pulse = PulseExtractor(filfile_4bit, 1000, 50, 0)
block = pulse.get_data()
assert isinstance(block, FilterbankBlock)

def test_filterbank_dm(self, filfile_4bit):
pulse = PulseExtractor(filfile_4bit, 1000, 50, 10)
block = pulse.get_data()
assert isinstance(block, FilterbankBlock)

0 comments on commit c5fac89

Please sign in to comment.