Last active
February 7, 2022 04:25
-
-
Save jcheong0428/7d5759f78145fc0dc979337f82c6ea33 to your computer and use it in GitHub Desktop.
Revisions
-
jcheong0428 revised this gist
Mar 13, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ def crosscorr(datax, datay, lag=0, wrap=False): seconds = 5 fps = 30 rs = [crosscorr(d1,d2, lag) for lag in range(-int(seconds*fps),int(seconds*fps+1))] offset = np.floor(len(rs)/2)-np.argmax(rs) f,ax=plt.subplots(figsize=(14,3)) ax.plot(rs) ax.axvline(np.ceil(len(rs)/2),color='k',linestyle='--',label='Center') -
jcheong0428 revised this gist
Aug 20, 2019 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,6 +28,7 @@ def crosscorr(datax, datay, lag=0, wrap=False): ax.plot(rs) ax.axvline(np.ceil(len(rs)/2),color='k',linestyle='--',label='Center') ax.axvline(np.argmax(rs),color='r',linestyle='--',label='Peak synchrony') ax.set(title=f'Offset = {offset} frames\nS1 leads <> S2 leads',ylim=[.1,.31],xlim=[0,301], xlabel='Offset',ylabel='Pearson r') ax.set_xticks([0, 50, 100, 151, 201, 251, 301]) ax.set_xticklabels([-150, -100, -50, 0, 50, 100, 150]); plt.legend() -
jcheong0428 revised this gist
Aug 20, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def crosscorr(datax, datay, lag=0, wrap=False): d2 = df['S2_Joy'] seconds = 5 fps = 30 rs = [crosscorr(d1,d2, lag) for lag in range(-int(seconds*fps),int(seconds*fps+1))] offset = np.ceil(len(rs)/2)-np.argmax(rs) f,ax=plt.subplots(figsize=(14,3)) ax.plot(rs) -
jcheong0428 revised this gist
May 13, 2019 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,5 +28,6 @@ def crosscorr(datax, datay, lag=0, wrap=False): ax.plot(rs) ax.axvline(np.ceil(len(rs)/2),color='k',linestyle='--',label='Center') ax.axvline(np.argmax(rs),color='r',linestyle='--',label='Peak synchrony') ax.set(title=f'Offset = {offset} frames\nS1 leads <> S2 leads',ylim=[.1,.31],xlim=[0,300], xlabel='Offset',ylabel='Pearson r') ax.set_xticklabels([int(item-150) for item in ax.get_xticks()]) plt.legend() -
jcheong0428 created this gist
May 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ def crosscorr(datax, datay, lag=0, wrap=False): """ Lag-N cross correlation. Shifted data filled with NaNs Parameters ---------- lag : int, default 0 datax, datay : pandas.Series objects of equal length Returns ---------- crosscorr : float """ if wrap: shiftedy = datay.shift(lag) shiftedy.iloc[:lag] = datay.iloc[-lag:].values return datax.corr(shiftedy) else: return datax.corr(datay.shift(lag)) d1 = df['S1_Joy'] d2 = df['S2_Joy'] seconds = 5 fps = 30 rs = [crosscorr(d1,d2, lag) for lag in range(-int(seconds*fps-1),int(seconds*fps))] offset = np.ceil(len(rs)/2)-np.argmax(rs) f,ax=plt.subplots(figsize=(14,3)) ax.plot(rs) ax.axvline(np.ceil(len(rs)/2),color='k',linestyle='--',label='Center') ax.axvline(np.argmax(rs),color='r',linestyle='--',label='Peak synchrony') ax.set(title=f'Offset = {offset} frames\nS1 leads <> S2 leads',ylim=[.1,.31]) plt.legend()