<jupyter_start><jupyter_text>AE Example> First Blogpost based on a notebook. Displaying functionalities of AE signals analysis.- toc: true - badges: true- comments: true- categories: [jupyter]- image: images/chart-preview.png  Acoustic Emission in `python`> This module contains a set of functions and classes to ease the processing of acoustic emission signals  Install`pip install aetools`It has not yet been uploaded to pip, so the best thing would be to download the git project, going to the folder, and from there run the following command:`pip install .`If the setup.py is defined correctly the installation should be ok<jupyter_code>#hide
from aetools import *# here we import our own module
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>How to use<jupyter_code>#hide
from pathlib import Path, PureWindowsPath, WindowsPath
import numpy as np
messdaten_walze = Path('M:/Schneidtechnik/Rotationsprüfstand/Messdaten/Walze4.0')
output_path = messdaten_walze / 'Python_Analysis'
mother_wavelet = 'db6'
step_seconds = 0.5
threshold=300
sampling_rate_hz = 1e6
time_average=5

file_list =list(messdaten_walze.glob('*/Block*/*/AEWalze*.csv')) 

f= file_list[0]<jupyter_output><empty_output><jupyter_text>For this example we located some acoustic emission data, and saved the path to the variable `f`.With the function `read_ae` we can read the signal contained in the file<jupyter_code>data = read_ae(f)<jupyter_output><empty_output><jupyter_text>aeSignal Once we read the signal we can pass it as the first argument to the class `aeSignal`<jupyter_code>my_signal = aeSignal(data,fs=1e6,file_name = "My Signal")<jupyter_output><empty_output><jupyter_text>To show the signal you can use:<jupyter_code>my_signal.plot_signal()<jupyter_output><empty_output><jupyter_text>In the same way it is possible to plot visualize some parameters of it<jupyter_code>my_signal.plot_fft()<jupyter_output><empty_output><jupyter_text>One of the functionalities is performing a multi-feature analysis. To perform a hits analysis you may use the following method and you will obtain a `pandas.DataFrame` with a wide variety of features calculated for each single hit found.<jupyter_code>my_signal.get_hits(threshold=300).head()<jupyter_output><empty_output><jupyter_text>In a similar way we can calculate the features for a whole signal.<jupyter_code>my_signal.get_summary()<jupyter_output><empty_output><jupyter_text>We can visualize one hit in this way<jupyter_code>#hide_input
hits = my_signal.get_hits(threshold=300)

sta,end = int(hits.loc[0,'Start']),int(hits.loc[0,'End'])

x = my_signal.signal[sta:end]

plt.plot(x)<jupyter_output><empty_output><jupyter_text>Check function for single hits<jupyter_code>#hide
my_signal.hits.columns<jupyter_output><empty_output><jupyter_text>Single Hit analysis<jupyter_code>#hide_input
start,end = my_signal.hits.loc[25,['Start','End']]

x = my_signal.get_signal()[int(start):int(end)]

plt.plot(x)
#hide
wts = {*wavelet_params(x,'db6',1e6)}
#hide
signal = x
mother_wavelet = 'db6'
fs = 1e6
decomp_levels = 6
#hide
import pywt<jupyter_output><empty_output><jupyter_text>Wavelet analysis<jupyter_code>#hide
PackageMatrix = pywt.WaveletPacket(data=signal, wavelet=mother_wavelet, maxlevel=decomp_levels)
# n = len(sub_signal)
mylevels = [node.path for node in PackageMatrix.get_level(decomp_levels, 'freq')]
cwtmat = []
for level in mylevels:
    cwtmat.append(PackageMatrix[level].data**2)
cwtmat = np.array(cwtmat)
myfreq = np.arange(len(mylevels))*fs/(2**(1+decomp_levels))
myfreq += fs/(2**(2+decomp_levels))
wavelet_energy = np.mean(cwtmat,axis=1)
# print(wavelet_energy)
wt_centroid_Hz=(np.dot(myfreq,wavelet_energy)/np.sum(myfreq))
wt_energy=(np.mean(wavelet_energy))
    # self.wavelt_matrix = cwtmat
#hide
import seaborn as sn
import matplotlib.pyplot as plt
#hide_input
map = sn.heatmap(cwtmat)
plt.show()<jupyter_output><empty_output><jupyter_text>Interval Analysis<jupyter_code>#my_signal.get_interval_params()<jupyter_output><empty_output><jupyter_text>In a similar way to the **Hit Analysis**, we can perform an **Interval Analysis**. In this case instead of calculating the features for the duration of the hits, an interval size is defined and then the feature calculation is performed for each interval within the signal<jupyter_code>my_signal.get_interval_params(threshold=300,interval_seconds = 0.5).head()<jupyter_output><empty_output><jupyter_text>Features  MARSEThe MARSE is the Mean Area under the Rectified Signal Envelope.We can visualize the marse<jupyter_code>#hide_input
from scipy.signal import find_peaks

peak,height = find_peaks(np.abs(x))

fig = plt.figure(figsize=[10,7])
plt.plot(peak,np.abs(x[peak]),label="Rectified Signal Envelope")
plt.plot(np.abs(x),label="Absolute value of the signal")
plt.legend()
plt.ylabel("Voltage (mV)")
plt.xlabel("Samples")
marse(x,0,1e6)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10633066994468347, 'fraction_numerical': 0.009834050399508297, 'mean_word_length': 7.749103942652329, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '564382', 'license': 'Apache-2.0', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1680, 'n_words': 418, 'path': '_notebooks/2021-02-08-AE-test.ipynb', 'repo_name': 'pabloms92/research-blog', 'size': '4881'}