Skip to content

Commit

Permalink
raises NotImplementedError for certain sampling frequencies (see #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trybnetic committed Apr 28, 2021
1 parent 486f1df commit 648e639
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions paat/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _create_time_array(time_data, hz=100):

# check if the sampling frequenzy can fit into equal parts within a 1000ms window
if 1000 % hz != 0:
logging.error('Sampling frequenzy {} cannot be split into equal parts within a 1s window'.format(hz))
raise NotImplementedError("Creating time array does not support sampling frequencies other than 100hz yet. See https://github.com/Trybnetic/paat/issues/10")

# calculate the step size of hz in 1s (so 100hz means 100 measurements in 1sec, so if we need to fill 1000ms then we need use a step size of 10)
step_size = 1000 / hz
Expand Down Expand Up @@ -438,8 +438,7 @@ def _create_time_vector(start, n_samples, hz):

# check if the sampling frequenzy can fit into equal parts within a nanosecond window
if ms_in_sec % hz != 0:
logging.error('Sampling frequenzy {} cannot be split into equal parts within a 1s window'.format(hz))
exit(1)
raise NotImplementedError("Creating time vector does not support sampling frequencies other than 100hz yet. See https://github.com/Trybnetic/paat/issues/10")

step_size = ms_in_sec / hz

Expand Down
16 changes: 16 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
import h5py
import pytest

from paat import io

Expand All @@ -29,3 +30,18 @@ def test_hdf5():

for key, value in meta.items():
assert meta[key] == new_meta[key]


def test_exceptions():
with pytest.raises(NotImplementedError) as e_info:
time_data = np.arange(10)
hz = 33
io._create_time_array(time_data, hz)
assert e_info

with pytest.raises(NotImplementedError) as e_info:
start = np.asarray(np.datetime64('today'), dtype='datetime64[ms]')
n_samples = 330
hz = 33
io._create_time_vector(start, n_samples, hz)
assert e_info

0 comments on commit 648e639

Please sign in to comment.