diff --git a/code/plot_functions.py b/code/plot_functions.py index f8ea237..7bf001f 100644 --- a/code/plot_functions.py +++ b/code/plot_functions.py @@ -110,11 +110,14 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c # Define color based on the category of the point color = next((c for cat, c in color_mapping.items() if point in points_categories[cat]), 'gray') + # Find the category of the point + point_category = next((cat for cat, pts in points_categories.items() if point in pts), "Unknown") + # Shade the region around the point where the integral was calculated ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point:.2f} Hz') - # Print out point and color - print(f"Integral around {point:.2f} Hz: {integral:.5e}, Color: {color}") + # Print out point, category, and color + print(f"{point_category}: Integral: {integral:.5e}, Color: {color}") # Annotate the plot with the point and its color ax.text(point, max(power) * 0.9, f'{point:.2f}', color=color, fontsize=10, ha='center') diff --git a/code/useful_functions.py b/code/useful_functions.py index a4a2d27..c0861c3 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -154,6 +154,59 @@ def calculate_integral(freq, power, point, delta = 2.5): local_mean = np.mean([l_integral, r_integral]) return integral, local_mean, p_power +def contrast_sorting(sams, con_1 = 20, con_2 = 10, con_3 = 5, stim_count = 3, stim_dur = 2): + ''' + sorts the sams into three contrasts + + Parameters + ---------- + sams : ReproRuns + The sams to be sorted. + con_1 : int, optional + the first contrast. The default is 20. + con_2 : int, optional + the second contrast. The default is 10. + con_3 : int, optional + the third contrast. The default is 5. + stim_count : int, optional + the amount of stimuli per sam in a good sam. The default is 3. + stim_dur : int, optional + The stimulus duration. The default is 2. + + Returns + ------- + contrast_sams : dictionary + A dictionary containing all sams sorted to the contrasts. + + ''' + # dictionary for the contrasts + contrast_sams = {con_1 : [], + con_2 : [], + con_3 : []} + # loop over all sams + for sam in sams: + # get the contrast + avg_dur, contrast, _, _, _, _, _ = sam_data(sam) + # check for valid trails + if np.isnan(contrast): + continue + elif sam.stimulus_count < stim_count: #aborted trials + continue + elif avg_dur < (stim_dur * 0.8): + continue + else: + contrast = int(contrast) # get integer of contrast + # sort them accordingly + if contrast == con_1: + contrast_sams[con_1].append(sam) + elif contrast == con_2: + contrast_sams[con_2].append(sam) + elif contrast == con_3: + contrast_sams[con_3].append(sam) + else: + continue + return contrast_sams + def extract_stim_data(stimulus): ''' extracts all necessary metadata for each stimulus @@ -483,9 +536,9 @@ def valid_integrals(integral, local_mean, point, threshold = 0.1): """ valid = integral > (local_mean * (1 + threshold)) if valid: - print(f"The point {point} is valid, as its integral exceeds the threshold.") + print(f"The point {point} is valid.") else: - print(f"The point {point} is not valid, as its integral does not exceed the threshold.") + print(f"The point {point} is not valid.") return valid '''TODO Sarah: AM-freq plot: