Skip to content

Commit 630dd82

Browse files
committed
add unit tests for normalisation flag
1 parent 0acf0db commit 630dd82

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pyspi/calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Calculator:
3434
A pre-configured subset of SPIs to use. Options are "all", "fast", "sonnet", or "fabfour", defaults to "all".
3535
configfile (str, optional):
3636
The location of the YAML configuration file for a user-defined subset. See :ref:`Using a reduced SPI set`, defaults to :code:`'</path/to/pyspi>/pyspi/config.yaml'`
37-
normalise (nool, optional):
37+
normalise (bool, optional):
3838
Normalise the dataset along the time axis before computing SPIs, defaults to True.
3939
"""
4040
_optional_dependencies = None

pyspi/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def set_data(
183183
data = detrend(data, axis=1)
184184
except ValueError as err:
185185
print(f"Could not detrend data: {err}")
186+
else:
187+
print("Skipping normalisation of the dataset...\n")
186188

187189
nans = np.isnan(data)
188190
if nans.any():

tests/test_calc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ def test_calculator_frame_normal_operation():
284284
# check that compute runs
285285
calc_frame.compute()
286286

287-
288287
def test_correlation_frame_normal_operation():
289288
"""Test whether the correlation frame instantiates as expected."""
290289
datasets = [np.random.randn(3, 100) for _ in range(3)]
@@ -297,3 +296,13 @@ def test_correlation_frame_normal_operation():
297296
cf = calc_frame.get_correlation_df()
298297

299298
assert not(cf[0].empty), "Correlation frame is empty."
299+
300+
def test_normalisation_flag():
301+
"""Test whether the normalisation flag when instantiating
302+
the calculator works as expected."""
303+
data = np.random.randn(3, 100)
304+
calc = Calculator(dataset=data, normalise=False)
305+
calc_loaded_dataset = calc.dataset.to_numpy().squeeze()
306+
307+
assert (calc_loaded_dataset == data).all(), f"Calculator normalise=False not producing the correct output."
308+

0 commit comments

Comments
 (0)