changed Dianas Plot function
This commit is contained in:
parent
71d8c78f5c
commit
86272cc18a
@ -6,6 +6,7 @@ import matplotlib.pyplot as plt
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import rlxnix as rlx
|
import rlxnix as rlx
|
||||||
from useful_functions import power_spectrum
|
from useful_functions import power_spectrum
|
||||||
|
import sys
|
||||||
|
|
||||||
'''IMPORT DATA'''
|
'''IMPORT DATA'''
|
||||||
datafolder = '../data' #./ wo ich gerade bin; ../ eine ebene höher; ../../ zwei ebenen höher
|
datafolder = '../data' #./ wo ich gerade bin; ../ eine ebene höher; ../../ zwei ebenen höher
|
||||||
@ -66,8 +67,12 @@ def power_spectrum_plot(f, p):
|
|||||||
ax.set_xlim(0, 1000)
|
ax.set_xlim(0, 1000)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
####### ADD DIANAS POWER SPECTRUM PLOT
|
# DIANAS POWER SPECTRUM PLOT
|
||||||
def plot_highlighted_integrals(frequency, power, exceeding_points, delta, threshold, color_mapping, points_categories):
|
functions_path = r"C:\Users\diana\OneDrive - UT Cloud\Master\GPs\GP1_Grewe\Projekt\gpgrewe2024\code"
|
||||||
|
sys.path.append(functions_path)
|
||||||
|
import useful_functions as u
|
||||||
|
|
||||||
|
def plot_highlighted_integrals(frequency, power, points, color_mapping, points_categories, delta = 2.5):
|
||||||
"""
|
"""
|
||||||
Plot the power spectrum and highlight integrals that exceed the threshold.
|
Plot the power spectrum and highlight integrals that exceed the threshold.
|
||||||
|
|
||||||
@ -96,9 +101,13 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
|
|||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
ax.plot(frequency, power) # Plot power spectrum
|
ax.plot(frequency, power) # Plot power spectrum
|
||||||
|
|
||||||
for point in exceeding_points:
|
for point in points:
|
||||||
integral, local_mean = calculate_integral(frequency, power, point, delta)
|
# Use the imported function to calculate the integral and local mean
|
||||||
valid, _ = valid_integrals(integral, local_mean, threshold, point)
|
integral, local_mean, _ = u.calculate_integral(frequency, power, point)
|
||||||
|
|
||||||
|
# Use the imported function to check if the point is valid
|
||||||
|
valid = u.valid_integrals(integral, local_mean, point)
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
# Define color based on the category of the point
|
# 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')
|
color = next((c for cat, c in color_mapping.items() if point in points_categories[cat]), 'gray')
|
||||||
@ -106,7 +115,6 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
|
|||||||
ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point:.2f} Hz')
|
ax.axvspan(point - delta, point + delta, color=color, alpha=0.3, label=f'{point:.2f} Hz')
|
||||||
print(f"Integral around {point:.2f} Hz: {integral:.5e}")
|
print(f"Integral around {point:.2f} Hz: {integral:.5e}")
|
||||||
|
|
||||||
|
|
||||||
# Define left and right boundaries of adjacent regions
|
# Define left and right boundaries of adjacent regions
|
||||||
left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]]
|
left_boundary = frequency[np.where((frequency >= point - 5 * delta) & (frequency < point - delta))[0][0]]
|
||||||
right_boundary = frequency[np.where((frequency > point + delta) & (frequency <= point + 5 * delta))[0][-1]]
|
right_boundary = frequency[np.where((frequency > point + delta) & (frequency <= point + 5 * delta))[0][-1]]
|
||||||
@ -115,7 +123,6 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
|
|||||||
ax.axvline(x=left_boundary, color="k", linestyle="--")
|
ax.axvline(x=left_boundary, color="k", linestyle="--")
|
||||||
ax.axvline(x=right_boundary, color="k", linestyle="--")
|
ax.axvline(x=right_boundary, color="k", linestyle="--")
|
||||||
|
|
||||||
|
|
||||||
ax.set_xlim([0, 1200])
|
ax.set_xlim([0, 1200])
|
||||||
ax.set_xlabel('Frequency (Hz)')
|
ax.set_xlabel('Frequency (Hz)')
|
||||||
ax.set_ylabel('Power')
|
ax.set_ylabel('Power')
|
||||||
@ -124,3 +131,4 @@ def plot_highlighted_integrals(frequency, power, exceeding_points, delta, thresh
|
|||||||
|
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user