Skip to content

Commit

Permalink
tutoiral more additions
Browse files Browse the repository at this point in the history
  • Loading branch information
InfantLab committed May 8, 2022
1 parent 6eb571b commit f56e12a
Show file tree
Hide file tree
Showing 5 changed files with 788 additions and 44 deletions.
Binary file added DrumTutorial/1fa339b.trial3.ISI500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified DrumTutorial/LittleDrummers_TutorialManualCoding.xlsx
Binary file not shown.
5 changes: 4 additions & 1 deletion DrumTutorial/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Below the frame image we have several drop-downs and buttons that let us interac
3. You might delete sets for whom all data is too poor quality. But they can also be excluded in **Step 3** by a flag in the data spreadsheet.
4. Tag the infant and adult in first frame of interest. So both individuals should be in first frame. In the current example The adult has been labelled 1, while the child is 0. We always want child to be 0. So we use the `Swap to child(0)` button swap the data.
<img src="step2.swap.png">
*Note that this swap applies to the current frame **and all subsequent frames**. *
*Note that this swap applies to the current frame* **and all subsequent frames**.

5. Try to automatically tag then in subsequent frames. (See below)
6. Manually fix anything the automatic process gets wrong.
Expand Down Expand Up @@ -156,6 +156,9 @@ For the Little Drummers study we manually coded each video to indicate if the in

Once we know if an infant was drumming and which hand they used, we can use Fourier Transforms to find the main frequency of their drumming. For each child we plot the vertical (y-axis) displacement of the (averaged) hand location and then transform the time-series into a frequency plot. We filter slow movements (less than 1 Hertz) and plot the distribution of other frequencies. We use numpy's `argmax()` function to locate the maximum (fundamental) frequency.

<img src="1fa339b.trial3.ISI500.png">
*Plots for infant 1fa3339b Trial 3. The target interstimulus interval as 500ms, (2Hz). The left most plot shows the vertical displacement of the left hand, the next plot shows the corresponding frequency plot. The other two plots show same info for right hand. The infant was drummming with frequency of 2.27 Hz, an ISI of 440ms.


<!-- #endregion -->

Expand Down
810 changes: 774 additions & 36 deletions Step3.ExtractMovement.ipynb

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions Step3.ExtractMovement.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ def updateAll(forceUpdate = False):

manualcoding = pd.read_excel(excelfile, sheet_name = "ManualCoding", header=[0,1])

#fourier = pd.read_excel(excelfile, sheet_name = "Fourier.All.0.5Hzcuttoff", header=[0,1])
fourier = pd.read_excel(excelfile, sheet_name = "Fourier.All.1.0Hzcuttoff", header=[0,1])

nchildren = len(manualcoding)
Expand All @@ -589,7 +588,7 @@ def updateAll(forceUpdate = False):

# ## Step 3.4.1 Find trial info
#
# For each trail we need to know the target inter stimulus interval (ISI) for each trial. For children in condition 0 the trial order was (400, 600, 500, 700), in condition 1 the order was (700,500,600,400). Then we need to know
# For each trail we need to know the target inter stimulus interval (ISI) for each trial. For children in condition 0 the trial order was (SMT1, 400, 600, 500, 700, SMT2), in condition 1 the order was (SMT1, 700,500,600,400, SMT2). We create few helper functions to keep track of this and read information from the manual coding spreadsheet.

# +
#Create a look up arrays to find out the ISI for each trial + condition
Expand Down Expand Up @@ -628,7 +627,7 @@ def vidStringtoTrialName(vidString):
#see if it works as expected
print(trialNames[500][0])
print(trialTypes["Trial4"][1])
vidstring = "16d2b71_12-test-trials"
vidstring = "1fa339b_12-test-trials"
print(vidStringtoTrialName(vidstring))


Expand Down Expand Up @@ -702,6 +701,7 @@ def annotate_axes(ax, text, fontsize=18):
# +
trial = TrialInfo(manualcoding, fourier,vidstring)
print(trial.ID)
print(trial.error)
print(trial.respcompleted)
print(trial.inView )

Expand Down Expand Up @@ -782,10 +782,9 @@ def annotate_axes(ax, text, fontsize=18):
frames = videos[vid]['camera1']['frames'] #how many frames?
start = videos[vid][cam]["start"]
end = videos[vid][cam]["end"]
sampleframes = end - start
fps = videos[vid]['camera1']['fps'] #how many frames per second?
x_data = np.linspace(start,end,sampleframes+1) #x axis
x_time = x_data / fps #x axis in units of time (seconds)
#sampleframes = end - start

if plotgraphs:
fig, axs = plt.subplots(ncols=4, nrows=1, figsize=(18, 4), constrained_layout=True)

Expand All @@ -811,6 +810,9 @@ def annotate_axes(ax, text, fontsize=18):
#we are just interested in the periodic elements (not absolute value above zero) so substract the mean
y_normed = np.subtract(y_data,np.average(y_data))

x_data = np.linspace(start,start+len(y_data),len(y_data)) #x axis
x_time = x_data / fps #x axis in units of time (seconds)

try:
yfft = scipy.fft.rfft(y_normed)
power = np.abs(yfft)**2
Expand Down Expand Up @@ -906,6 +908,8 @@ def annotate_axes(ax, text, fontsize=18):





# -


Expand All @@ -914,7 +918,6 @@ def annotate_axes(ax, text, fontsize=18):
resultRight.to_excel(videos_out + "\\RightHand.FixedBinFreq.xlsx")



def plotHistograms(targetISI,fs):
# the histogram of the data
binList = np.linspace(1.00,3.6,14)
Expand Down

0 comments on commit f56e12a

Please sign in to comment.