diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fab88b04..4a8667d7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,15 @@ # Change Log All notable changes to this project will be documented in this file. +## [2.3.2] = 2020-10-19 + +### Bug Fixes +- (Internal) Fixed a running\_processing bug for behavior ophys experiments when the input data would have one more encoder entry than timestamp. The behavior of the code now matches what the warning says. + ## [2.3.1] = 2020-10-13 ### Bug Fixes -- (Internal) Fixed a write_nwb bug for behavior ophys experiments involving the BehaviorOphysJsonApi expecting a mesoscope-specific method. +- (Internal) Fixed a write\_nwb bug for behavior ophys experiments involving the BehaviorOphysJsonApi expecting a mesoscope-specific method. ## [2.3.0] = 2020-10-09 diff --git a/allensdk/__init__.py b/allensdk/__init__.py index 3a0977cbb..52182f1f1 100644 --- a/allensdk/__init__.py +++ b/allensdk/__init__.py @@ -37,7 +37,7 @@ -__version__ = '2.3.1' +__version__ = '2.3.2' try: diff --git a/allensdk/brain_observatory/behavior/running_processing.py b/allensdk/brain_observatory/behavior/running_processing.py index 0916adcb5..95de0e10a 100644 --- a/allensdk/brain_observatory/behavior/running_processing.py +++ b/allensdk/brain_observatory/behavior/running_processing.py @@ -55,7 +55,7 @@ def _shift( Iterable containing numeric data. If int, will be converted to float in returned object. periods: int (default=1) - The number of elements to shift. + The number of elements to shift. fill_value: float (default=np.nan) The value to fill at the beginning of the shifted array Returns @@ -364,7 +364,9 @@ def get_running_df(data, time: np.ndarray, lowpass: bool = True): if len(v_in) == len(time) + 1: warnings.warn( "Time array is 1 value shorter than encoder array. Last encoder " - "value removed\n", stacklevel=1) + "value removed\n", UserWarning, stacklevel=1) + v_in = v_in[:-1] + v_sig = v_sig[:-1] # dx = 'd_theta' = angular change # There are some issues with angular change in the raw data so we diff --git a/allensdk/test/brain_observatory/behavior/test_running_processing.py b/allensdk/test/brain_observatory/behavior/test_running_processing.py index fe4c3a858..4fbd49aed 100644 --- a/allensdk/test/brain_observatory/behavior/test_running_processing.py +++ b/allensdk/test/brain_observatory/behavior/test_running_processing.py @@ -71,6 +71,43 @@ def test_get_running_df(running_data, timestamps, lowpass): assert np.count_nonzero(np.isnan(actual["speed"])) == 0 +@pytest.mark.parametrize( + "lowpass", [True, False] +) +def test_get_running_df_one_fewer_timestamp_check_warning(running_data, + timestamps, + lowpass): + with pytest.warns( + UserWarning, + match="Time array is 1 value shorter than encoder array.*" + ): + # Call with one fewer timestamp, check for a warning + _ = get_running_df( + data=running_data, + time=timestamps[:-1], + lowpass=lowpass + ) + + +@pytest.mark.parametrize( + "lowpass", [True, False] +) +def test_get_running_df_one_fewer_timestamp_check_truncation(running_data, + timestamps, + lowpass): + # Call with one fewer timestamp + output = get_running_df( + data=running_data, + time=timestamps[:-1], + lowpass=lowpass + ) + + # Check that the output is actually trimmed, and the values are the same + assert len(output) == len(timestamps) - 1 + np.testing.assert_equal(output["v_sig"], running_data["items"]["behavior"]["encoders"][0]["vsig"][:-1]) + np.testing.assert_equal(output["v_in"], running_data["items"]["behavior"]["encoders"][0]["vin"][:-1]) + + @pytest.mark.parametrize( "arr, periods, fill, expected", [ diff --git a/doc_template/index.rst b/doc_template/index.rst index f4dc52194..7196fc07f 100644 --- a/doc_template/index.rst +++ b/doc_template/index.rst @@ -91,12 +91,20 @@ The Allen SDK provides Python code for accessing experimental metadata along wit See the `mouse connectivity section `_ for more details. +What's New - 2.3.2 (October 19, 2020) +----------------------------------------------------------------------- +As of the 2.3.2 release: + +- (Internal) Fixed a running_processing bug for behavior ophys experiments when the input data would have one more encoder entry than timestamp. The behavior of the code now matches what the warning says. + + What's New - 2.3.1 (October 13, 2020) ----------------------------------------------------------------------- As of the 2.3.1 release: - (Internal) Fixed a write_nwb bug for behavior ophys experiments involving the BehaviorOphysJsonApi expecting a mesoscope-specific method. + What's New - 2.3.0 (October 9, 2020) ----------------------------------------------------------------------- As of the 2.3.0 release: