Пример #1
0
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)
Пример #2
0
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])
Пример #3
0
def test_get_running_df(running_data, timestamps, lowpass):
    actual = get_running_df(running_data, timestamps, lowpass=lowpass)
    np.testing.assert_array_equal(actual.index, timestamps)
    assert sorted(list(actual)) == ["dx", "speed", "v_in", "v_sig"]
    # Should bring raw data through
    np.testing.assert_array_equal(
        actual["v_sig"].values,
        running_data["items"]["behavior"]["encoders"][0]["vsig"])
    np.testing.assert_array_equal(
        actual["v_in"].values,
        running_data["items"]["behavior"]["encoders"][0]["vin"])
    np.testing.assert_array_equal(
        actual["dx"].values,
        running_data["items"]["behavior"]["encoders"][0]["dx"])
    if lowpass:
        assert np.count_nonzero(np.isnan(actual["speed"])) == 0
Пример #4
0
    def from_json(
        cls,
        dict_repr: dict,
    ) -> "RunningAcquisition":
        stimulus_file = StimulusFile.from_json(dict_repr)
        stimulus_timestamps = StimulusTimestamps.from_json(dict_repr)
        running_acq_df = get_running_df(
            data=stimulus_file.data,
            time=stimulus_timestamps.value,
        )
        running_acq_df.drop("speed", axis=1, inplace=True)

        return cls(
            running_acquisition=running_acq_df,
            stimulus_file=stimulus_file,
            stimulus_timestamps=stimulus_timestamps,
        )
Пример #5
0
 def _get_running_speed_df(stimulus_file: StimulusFile,
                           stimulus_timestamps: StimulusTimestamps,
                           filtered: bool = True,
                           zscore_threshold: float = 1.0) -> pd.DataFrame:
     running_data_df = get_running_df(data=stimulus_file.data,
                                      time=stimulus_timestamps.value,
                                      lowpass=filtered,
                                      zscore_threshold=zscore_threshold)
     if running_data_df.index.name != "timestamps":
         raise DataFrameIndexError(
             f"Expected running_data_df index to be named 'timestamps' "
             f"But instead got: '{running_data_df.index.name}'")
     running_speed = pd.DataFrame({
         "timestamps": running_data_df.index.values,
         "speed": running_data_df.speed.values
     })
     return running_speed
Пример #6
0
    def from_lims(
        cls,
        db: PostgresQueryMixin,
        behavior_session_id: int,
        ophys_experiment_id: Optional[int] = None,
    ) -> "RunningAcquisition":

        stimulus_file = StimulusFile.from_lims(db, behavior_session_id)
        stimulus_timestamps = StimulusTimestamps.from_stimulus_file(
            stimulus_file=stimulus_file)
        running_acq_df = get_running_df(
            data=stimulus_file.data,
            time=stimulus_timestamps.value,
        )
        running_acq_df.drop("speed", axis=1, inplace=True)

        return cls(
            running_acquisition=running_acq_df,
            stimulus_file=stimulus_file,
            stimulus_timestamps=stimulus_timestamps,
        )