Page MenuHomec4science

Channel Visualize.py
No OneTemporary

File Metadata

Created
Sat, Feb 8, 17:05

Channel Visualize.py

# -*- coding: utf-8 -*-
"""
Created on Sun Aug 29 23:08:34 2021
@author: srpv
contact: vigneashwara.solairajapandiyan@empa.ch
The codes in this following script will be used for the publication of the following work
"Dynamics of in-situ alloying of Ti6Al4V-Fe by means of acoustic emission monitoring
supported by operando synchrotron X-ray diffraction"
@any reuse of this code should be authorized by the first owner, code author
"""
# %%
# Librariies to import
import os
import ntpath
import matplotlib.pyplot as plt
import pandas as pd
import glob
import numpy as np
import glob
import seaborn as sns
import matplotlib.pyplot as mpl
mpl.rcParams['agg.path.chunksize'] = 1000000
# %% Inputs to be added
# Folder details --> Ensure all files are present in the folder in order
path_ = r'C:\Users\srpv\Desktop\Sinergia Offline\Reza\Ti-Fe\CM\Ti64\CM_1'
sample_rate = 1500000 # rate at which the acquistion happend.
# %%
# channel_0 is trigger from the RTC card
# channel_1 is trigger from the AE signal
# Helper functions
def path_leaf(path):
head, tail = ntpath.split(path)
return tail
# %%
path = os.path.join(path_)
isDirectory = os.path.isdir(path) # To check if its a directory
if isDirectory:
print(path)
print(isDirectory)
Channel0 = (os.path.join(path, 'channel_0_decoded')) # use channel_0 or channel_0_decoded
print(Channel0)
Channel1 = (os.path.join(path, 'channel_1_decoded'))
print(Channel1)
all_files = glob.glob(Channel0 + "/*.csv")
for filename in all_files:
tail = path_leaf(filename)
A = tail.split('.')
data_file_name = A[0]
print(data_file_name) # Name extracted from the .csv file
Channel_0 = (os.path.join(Channel0, tail))
print(Channel0)
Channel_1 = (os.path.join(Channel1, tail))
print(Channel1)
data1 = pd.read_csv(Channel_0)
data1 = data1.to_numpy()
data1 = np.ravel(data1)
data2 = pd.read_csv(Channel_1)
data2 = data2.to_numpy()
data2 = np.ravel(data2)
'''To look at the useful part of the data try to truncate...
...the data stream --> used 800000 here''' # the value can be change iteratively
data1 = data1[0:800000]
data2 = data2[0:800000]
''' Lets dynamically create a Time stamp as we know the sampling rate'''
length = len(data1)
N = length
t0 = 0
dt = 1/sample_rate
y = np.arange(0, N) * dt + t0
''' Now the lets Target on the ploting function'''
plt.rcParams.update(plt.rcParamsDefault)
fig = plt.figure(figsize=(10, 6), dpi=800)
fig, ((ax1, ax2)) = plt.subplots(2, 1)
title = ' AE '+'Signal'
fig.suptitle(title)
plt.rc("font", size=8)
ax1.plot(y, data1, 'red', linewidth=2.5, label='Laser')
ax1.legend(fontsize=15)
ax1.set_ylabel('Voltage (V)')
ax2.plot(y, data2, 'blue', linewidth=1, label='AE')
ax2.legend(fontsize=15)
ax2.set_xlabel('Time (sec)', labelpad=5)
ax2.set_ylabel('Voltage (V)')
graph_2 = str(data_file_name)+'_'+'AE'+'signal'+'.png'
for ax in fig.get_axes():
ax.label_outer()
# plt.xlim((0, 40e5))
plt.savefig(os.path.join(path, graph_2), bbox_inches='tight', dpi=200)
plt.show()

Event Timeline