diff --git a/code/test.py b/code/test.py index fe621f7..b08d495 100644 --- a/code/test.py +++ b/code/test.py @@ -129,6 +129,61 @@ def remove_poor(files): good_files.append(files[i]) return good_files +def sam_data(sam): + ''' + Gets metadata for each SAM + + Parameters + ---------- + sam : ReproRun object + The sam the metdata should be extracted from. + + Returns + ------- + sam_amp : float + amplitude in percent, relative to the fish amplitude. + sam_am : float + Amplitude modulation frequency. + sam_df : float + Difference from the stimulus to the current fish eodf. + sam_eodf : float + The current EODf. + sam_nyquist : float + The Nyquist frequency of the EODf. + sam_stim : float + The stimulus frequency. + + ''' + # create lists for the values we want + amplitudes = [] + dfs = [] + eodfs = [] + stim_freqs = [] + amp_mods = [] + ny_freqs = [] + + # get the stimuli + stimuli = sam.stimuli + + # loop over the stimuli + for stim in stimuli: + amplitude, df, eodf, stim_freq, amp_mod, ny_freq = extract_stim_data(stim) + amplitudes.append(amplitude) + dfs.append(df) + eodfs.append(eodf) + stim_freqs.append(stim_freq) + amp_mods.append(amp_mod) + ny_freqs.append(ny_freq) + + # get the means + sam_amp = np.mean(amplitudes) + sam_am = np.mean(amp_mods) + sam_df = np.mean(dfs) + sam_eodf = np.mean(eodfs) + sam_nyquist = np.mean(ny_freqs) + sam_stim = np.mean(stim_freqs) + return sam_amp, sam_am,sam_df, sam_eodf, sam_nyquist, sam_stim + #find example data datafolder = "../../data" diff --git a/code/useful_functions.py b/code/useful_functions.py index 1115ef5..eb750e8 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -170,4 +170,59 @@ def remove_poor(files): if quality != "poor": # if its good or fair add it to the good files good_files.append(files[i]) - return good_files \ No newline at end of file + return good_files + +def sam_data(sam): + ''' + Gets metadata for each SAM + + Parameters + ---------- + sam : ReproRun object + The sam the metdata should be extracted from. + + Returns + ------- + sam_amp : float + amplitude in percent, relative to the fish amplitude. + sam_am : float + Amplitude modulation frequency. + sam_df : float + Difference from the stimulus to the current fish eodf. + sam_eodf : float + The current EODf. + sam_nyquist : float + The Nyquist frequency of the EODf. + sam_stim : float + The stimulus frequency. + + ''' + # create lists for the values we want + amplitudes = [] + dfs = [] + eodfs = [] + stim_freqs = [] + amp_mods = [] + ny_freqs = [] + + # get the stimuli + stimuli = sam.stimuli + + # loop over the stimuli + for stim in stimuli: + amplitude, df, eodf, stim_freq, amp_mod, ny_freq = extract_stim_data(stim) + amplitudes.append(amplitude) + dfs.append(df) + eodfs.append(eodf) + stim_freqs.append(stim_freq) + amp_mods.append(amp_mod) + ny_freqs.append(ny_freq) + + # get the means + sam_amp = np.mean(amplitudes) + sam_am = np.mean(amp_mods) + sam_df = np.mean(dfs) + sam_eodf = np.mean(eodfs) + sam_nyquist = np.mean(ny_freqs) + sam_stim = np.mean(stim_freqs) + return sam_amp, sam_am,sam_df, sam_eodf, sam_nyquist, sam_stim \ No newline at end of file