From 6e54a8c508e5bb5f1fbb5d75406d9ab7e77f2975 Mon Sep 17 00:00:00 2001 From: Diana Date: Thu, 24 Oct 2024 10:20:46 +0200 Subject: [PATCH 1/4] Changed my plot function --- code/useful_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/useful_functions.py b/code/useful_functions.py index 9f56b57..4bd1360 100644 --- a/code/useful_functions.py +++ b/code/useful_functions.py @@ -483,9 +483,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: From b0d5d5ccfbdbf352dfe7cca9e599d35f2778718b Mon Sep 17 00:00:00 2001 From: Diana Date: Thu, 24 Oct 2024 10:21:15 +0200 Subject: [PATCH 2/4] Changed my plot function --- code/plot_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/plot_functions.py b/code/plot_functions.py index f8ea237..78cfcea 100644 --- a/code/plot_functions.py +++ b/code/plot_functions.py @@ -114,7 +114,7 @@ def plot_highlighted_integrals(frequency, power, points, color_mapping, points_c 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(f"{points_categories}: {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') From 89b1254425aca1513e914f749f17e7c0bcce2276 Mon Sep 17 00:00:00 2001 From: Diana Date: Thu, 24 Oct 2024 10:25:26 +0200 Subject: [PATCH 3/4] Changed my plot function --- code/plot_functions.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/plot_functions.py b/code/plot_functions.py index 78cfcea..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"{points_categories}: {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') From 873be0a69814a54e22ffd9e5aaea14ca68e4f912 Mon Sep 17 00:00:00 2001 From: mbergmann Date: Thu, 24 Oct 2024 10:59:29 +0200 Subject: [PATCH 4/4] [useful_functions.py] added contrast_sorting function --- code/useful_functions.py | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/code/useful_functions.py b/code/useful_functions.py index 9f56b57..72a58f6 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