motion_correction_win(photometry_dict: dict) will replace motion_correction(photometry_dict: dict)
The function cut the photometry data (analog_1_filt) into 30 s-long chunks with 50% overlap.
Compute linregress() for each chunk separately, so the regression can follow the slow changes in data
Combine the predicted data for each chunk
When two chunks are overlapping, use the average of the two chunks for the same data points
When not overlapping (i.e. the first half of the first chunk and the last chunk), just use the data from the one existing chunk
Use this as analog_1_est_motion
2. Compute $\Delta F / F$ for analog_2
Using the same method (simple subtraction of the low-pass filtered data)
3. Compute last_bar_off
def get_last_bar_off_before_first_spout(df_trial):
# Find the last bar_off before the first spout in trial
# You can prepare df_trial for debugging/development as below:
#
# for i in range(1, np.max(df_event['trial_nb'])):
# df_trial = df_event[df_event['trial_nb'] == i]
# df_trial = the row for event of interest
bar_off = df_trial[df_trial['name']=='bar_off']
spout = df_trial[df_trial['name']=='spout']
if spout.shape[0] > 0 and bar_off.shape[0] > 0:
spout1 = spout.iloc[0]
filtered_df = bar_off[bar_off['trial_time'] < spout1['trial_time']]
max_time = filtered_df['trial_time'].max()
result = filtered_df[filtered_df['trial_time'] == max_time]
if len(result) >0:
return result.iloc[0]
This Pull Request includes:
1. a New Method of Motion Correction
motion_correction_win(photometry_dict: dict)
will replacemotion_correction(photometry_dict: dict)
analog_1_filt
) into 30 s-long chunks with 50% overlap.linregress()
for each chunk separately, so the regression can follow the slow changes in dataanalog_1_est_motion
2. Compute $\Delta F / F$ for analog_2
Using the same method (simple subtraction of the low-pass filtered data)
3. Compute
last_bar_off