feat: Refactor ascan.py, filtrage.py and selection_filtre.py

merge: Merge with latest commit
This commit is contained in:
2024-05-30 13:23:41 +02:00
parent d3f21e2aec
commit 81338e3d76
67 changed files with 6476 additions and 194 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,400,410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,710,720,730,740,750,760,770,780,790,800,810,820,830,840,850,860,870,880,890,900,910,920,930,940,950,960,970,980,990,1000
1 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990 1000

View File

@ -0,0 +1 @@
0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,400,410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560,570,580,590,600
1 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600

File diff suppressed because one or more lines are too long

View File

@ -1,42 +1,49 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert,butter, filtfilt,wiener,hamming, convolve
from scipy.signal import hilbert, butter, filtfilt, wiener, hamming, convolve
#transformer du Hilbert
# transformer du Hilbert
def transformer_hilbert(data_input):
data_output=np.abs(hilbert(data_input))
data_output = np.abs(hilbert(data_input))
return data_output
#filtre de moyenne mobile
def filtre_moyenne_mobile(data_input,window_size):
data_output=pd.Series(data_input).rolling(window=window_size).mean()
# filtre de moyenne mobile
def filtre_moyenne_mobile(data_input, window_size):
data_output = pd.Series(data_input).rolling(window=window_size).mean()
return data_output
# filtre passe bas
def filtre_passe_bas(data_input,fs,cut_off,order):
nyq=0.5*fs
normal_cut_off=cut_off/nyq
[b,a]=butter(order,normal_cut_off,btype='low', analog=False)
data_output=filtfilt(b,a,data_input)
def filtre_passe_bas(data_input, fs, cut_off, order):
nyq = 0.5 * fs
normal_cut_off = cut_off / nyq
[b, a] = butter(order, normal_cut_off, btype="low", analog=False)
data_output = filtfilt(b, a, data_input)
return data_output
#filtre adaptatif de réduction de bruit
# filtre adaptatif de réduction de bruit
def filtre_adaptatif(data_input):
data_output=wiener(data_input)
data_output = wiener(data_input)
return data_output
#Le filtre à réponse impulsionnelle infinie
def filtre_RII(data_input,window_size):
b1=hamming(window_size)/np.sum(window_size)
data_output=filtfilt(b1,1,data_input)
# Le filtre à réponse impulsionnelle infinie
def filtre_RII(data_input, window_size):
b1 = hamming(window_size) / np.sum(window_size)
data_output = filtfilt(b1, 1, data_input)
return data_output
# Le filtre à réponse impulsionnelle finie
def filtre_RIF(data_input,window_size):
h=hamming(window_size)/np.sum(window_size)
data_output=convolve(data_input, h, mode='same')
def filtre_RIF(data_input, window_size):
h = hamming(window_size) / np.sum(window_size)
data_output = convolve(data_input, h, mode="same")
return data_output

View File

@ -10,18 +10,20 @@ from filtrage import *
from selection_filtre import *
dash.register_page(__name__, path="/ascan", title='A-Scan filters', name='A-Scan filters')
dash.register_page(
__name__, path="/ascan", title="A-Scan filters", name="A-Scan filters"
)
# on définit le dossier et les fichiers à lire
dossier = "Dataset/Shear_Wave_Rot00_CSV_Data"
fichiers_selectionnes = [
"Shear_x001-x101_y{:03d}_Rot00.csv".format(i) for i in range(10,13)
"Shear_x001-x101_y{:03d}_Rot00.csv".format(i) for i in range(10, 13)
]
# on lit les fichiers et on les met dans un tableau
pre_volume = np.array(lire_fichier_csv(dossier, fichiers_selectionnes))
volume = pre_volume[:, :, :]
data_traits=volume
data_traits = volume
dim_x, dim_y, dim_z = volume.shape
X, Y, Z = np.mgrid[0:dim_x, 0:dim_y, 0:dim_z]
@ -64,8 +66,14 @@ layout = html.Div(
{"label": "filtre passe bas ", "value": "3"},
{"label": "filtre de moyenne mobile", "value": "4"},
{"label": "filtre adaptatif (wiener)", "value": "5"},
{"label": "filtre à réponse impulsionnelle infinie", "value": "6"},
{"label": "filtre à réponse impulsionnelle finie", "value": "7"},
{
"label": "filtre à réponse impulsionnelle infinie",
"value": "6",
},
{
"label": "filtre à réponse impulsionnelle finie",
"value": "7",
},
],
value=2,
style={"margin-bottom": "15px"},
@ -82,13 +90,18 @@ layout = html.Div(
{"label": "filtre passe bas ", "value": "3"},
{"label": "filtre de moyenne mobile", "value": "4"},
{"label": "filtre adaptatif (wiener)", "value": "5"},
{"label": "filtre à réponse impulsionnelle infinie", "value": "6"},
{"label": "filtre à réponse impulsionnelle finie", "value": "7"},
{
"label": "filtre à réponse impulsionnelle infinie",
"value": "6",
},
{
"label": "filtre à réponse impulsionnelle finie",
"value": "7",
},
],
value=2,
style={"margin-bottom": "15px"},
),
],
width=3,
),
@ -97,15 +110,15 @@ layout = html.Div(
dbc.Label("applique les filtres selections sur tous les data"),
dbc.Button(
id="button-validate-filter",
children="Valider",
children=dbc.Spinner(
html.Div(id="loading"), show_initially=False
),
color="primary",
style={"marginBottom": "15px"},
),
],
width=3,
),
]
),
dbc.Row(
@ -136,7 +149,7 @@ layout = html.Div(
value=1,
step=1,
marks={
str(i): str(i) for i in range(1, dim_z+1,1)
str(i): str(i) for i in range(1, dim_z + 1, max(1, int(dim_z / 20)))
},
),
dbc.Label("y"),
@ -146,145 +159,146 @@ layout = html.Div(
max=dim_x,
value=1,
step=1,
marks={
str(i): str(i) for i in range(1, dim_x+1,1)
},
marks={str(i): str(i) for i in range(1, dim_x + 1, 1)},
),
dbc.Label("z"),
dcc.RangeSlider(
id="layer-slider-ascan-solo-z",
min=1,
max=dim_y,
value=[dim_y/dim_y,dim_y],
value=[dim_y / dim_y, dim_y],
step=1,
marks={
str(i): str(i) for i in range(1, dim_y+1,1)
},
str(i): str(i) for i in range(0, dim_x + 1, max(1, int(dim_x / 20)))
},
),
dbc.Row(
[
dbc.Label(" paramètre du 1er filtre ", html_for="Fs "),
dbc.Col(
[
dbc.Label("Fs ", html_for="Fs "),
dbc.Input(
id="input-ascan-solo-fs",
type="number",
placeholder="Fs",
value=1,
step=0.1,
style={"marginTop": "15px"},
dbc.Label(" paramètre du 1er filtre ", html_for="Fs "),
dbc.Col(
[
dbc.Label("Fs ", html_for="Fs "),
dbc.Input(
id="input-ascan-solo-fs",
type="number",
placeholder="Fs",
value=1,
step=0.1,
style={"marginTop": "15px"},
),
],
width=3,
),
],
width=3,
dbc.Col(
[
dbc.Label("cut off ", html_for="cut off"),
dbc.Input(
id="input-ascan-solo-cutoff",
type="number",
placeholder="cut_off",
value=1,
step=0.1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("order ", html_for="order"),
dbc.Input(
id="input-ascan-solo-order",
type="number",
placeholder="order",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("window size ", html_for="window size"),
dbc.Input(
id="input-ascan-solo-windowsize",
type="number",
placeholder="window_size",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
]
),
dbc.Col(
dbc.Row(
[
dbc.Label("cut off ", html_for="cut off"),
dbc.Input(
id="input-ascan-solo-cutoff",
type="number",
placeholder="cut_off",
value=1,
step=0.1,
style={"marginTop": "15px"},
dbc.Label("paramètre de 2eme filtre ", html_for="Fs "),
dbc.Col(
[
dbc.Label("Fs ", html_for="Fs "),
dbc.Input(
id="input-ascan-solo-fs-2",
type="number",
placeholder="Fs",
value=1,
step=0.1,
style={"marginTop": "15px"},
),
],
width=3,
),
],
width=3,
dbc.Col(
[
dbc.Label("cut off ", html_for="cut off"),
dbc.Input(
id="input-ascan-solo-cutoff-2",
type="number",
placeholder="cut_off",
value=1,
step=0.1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("order ", html_for="order"),
dbc.Input(
id="input-ascan-solo-order-2",
type="number",
placeholder="order",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("window size ", html_for="window size"),
dbc.Input(
id="input-ascan-solo-windowsize-2",
type="number",
placeholder="window_size",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
]
),
dbc.Col(
[
dbc.Label("order ", html_for="order"),
dbc.Input(
id="input-ascan-solo-order",
type="number",
placeholder="order",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("window size ", html_for="window size"),
dbc.Input(
id="input-ascan-solo-windowsize",
type="number",
placeholder="window_size",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),]),
dbc.Row(
[
dbc.Label("paramètre de 2eme filtre ", html_for="Fs "),
dbc.Col(
[
dbc.Label("Fs ", html_for="Fs "),
dbc.Input(
id="input-ascan-solo-fs-2",
type="number",
placeholder="Fs",
value=1,
step=0.1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("cut off ", html_for="cut off"),
dbc.Input(
id="input-ascan-solo-cutoff-2",
type="number",
placeholder="cut_off",
value=1,
step=0.1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("order ", html_for="order"),
dbc.Input(
id="input-ascan-solo-order-2",
type="number",
placeholder="order",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
dbc.Col(
[
dbc.Label("window size ", html_for="window size"),
dbc.Input(
id="input-ascan-solo-windowsize-2",
type="number",
placeholder="window_size",
value=1,
step=1,
style={"marginTop": "15px"},
),
],
width=3,
),
]),
],
style={"padding": "20px"},
)
# callback to update filter values
@callback(
[
@ -303,24 +317,45 @@ layout = html.Div(
],
)
def update_filter_values(select_filtre_1, select_filtre_2):
fs_1=True;cutoff_1=True;ordre_1=True;windowsize_1=True
fs_2=True;cutoff_2=True;ordre_2=True;windowsize_2=True
if (int(select_filtre_1)==3):
fs_1=False;cutoff_1=False;ordre_1=False
if(int(select_filtre_2)==3):
fs_2=False;cutoff_2=False;ordre_2=False
if(int(select_filtre_1) in (4, 5, 6, 7)):
windowsize_1=False
if(int(select_filtre_2) in (4, 5, 6, 7)):
windowsize_2=False
return [fs_1, cutoff_1, ordre_1, windowsize_1, fs_2, cutoff_2, ordre_2, windowsize_2]
fs_1 = True
cutoff_1 = True
ordre_1 = True
windowsize_1 = True
fs_2 = True
cutoff_2 = True
ordre_2 = True
windowsize_2 = True
if int(select_filtre_1) == 3:
fs_1 = False
cutoff_1 = False
ordre_1 = False
if int(select_filtre_2) == 3:
fs_2 = False
cutoff_2 = False
ordre_2 = False
if int(select_filtre_1) in (4, 5, 6, 7):
windowsize_1 = False
if int(select_filtre_2) in (4, 5, 6, 7):
windowsize_2 = False
return [
fs_1,
cutoff_1,
ordre_1,
windowsize_1,
fs_2,
cutoff_2,
ordre_2,
windowsize_2,
]
# callback to update the heatmap
@callback(
[Output("heatmap-ascan-solo", "figure"), Output("heatmap-bscan-solo", "figure")],
[
Output("heatmap-ascan-solo", "figure"),
Output("heatmap-bscan-solo", "figure"),
Output("loading", "children"),
],
[
Input("select-ascan-filter1", "value"),
Input("select-ascan-filter2", "value"),
@ -339,36 +374,110 @@ def update_filter_values(select_filtre_1, select_filtre_2):
Input("input-ascan-solo-windowsize-2", "value"),
],
)
def update_heatmap_ascan(selec_transforme_hilbert,select_filtre_1,select_filtre_2,select_ascan_x,select_ascan_y,select_ascan_z,n_clicks,fs_filtre_1,cutoff_filtre_1,order_filtre_1,windowsize_filtre_1,fs_filtre_2,cutoff_filtre_2,order_filtre_2,windowsize_filtre_2):
def update_heatmap_ascan(
selec_transforme_hilbert,
select_filtre_1,
select_filtre_2,
select_ascan_x,
select_ascan_y,
select_ascan_z,
n_clicks,
fs_filtre_1,
cutoff_filtre_1,
order_filtre_1,
windowsize_filtre_1,
fs_filtre_2,
cutoff_filtre_2,
order_filtre_2,
windowsize_filtre_2,
):
# TODO: implement the filter
print("debut du traitement")
data_avec_traitement=volume[int(select_ascan_y)-1,select_ascan_z[0]:select_ascan_z[1],int(select_ascan_x)-1]
data_sans_traitement=volume[int(select_ascan_y)-1,select_ascan_z[0]:select_ascan_z[1],int(select_ascan_x)-1]
data_avec_traitement=switch_case(data_avec_traitement,int(selec_transforme_hilbert))
data_sans_traitement=switch_case(data_sans_traitement,int(selec_transforme_hilbert))
data_avec_traitement=switch_case(data_avec_traitement,int(select_filtre_1),float(fs_filtre_1),float(cutoff_filtre_1),int(order_filtre_1),int(windowsize_filtre_1))
data_avec_traitement=switch_case(data_avec_traitement,int(select_filtre_2),float(fs_filtre_2),float(cutoff_filtre_2),int(order_filtre_2),int(windowsize_filtre_2))
data_avec_traitement = volume[
int(select_ascan_y) - 1,
select_ascan_z[0] : select_ascan_z[1],
int(select_ascan_x) - 1,
]
data_sans_traitement = volume[
int(select_ascan_y) - 1,
select_ascan_z[0] : select_ascan_z[1],
int(select_ascan_x) - 1,
]
data_avec_traitement = switch_case(
data_avec_traitement, int(selec_transforme_hilbert)
)
data_sans_traitement = switch_case(
data_sans_traitement, int(selec_transforme_hilbert)
)
data_avec_traitement = switch_case(
data_avec_traitement,
int(select_filtre_1),
float(fs_filtre_1),
float(cutoff_filtre_1),
int(order_filtre_1),
int(windowsize_filtre_1),
)
data_avec_traitement = switch_case(
data_avec_traitement,
int(select_filtre_2),
float(fs_filtre_2),
float(cutoff_filtre_2),
int(order_filtre_2),
int(windowsize_filtre_2),
)
print("fin du traitement")
if(n_clicks!=None):
data_traits=switch_case(data_traits,int(selec_transforme_hilbert))
data_traits=switch_case(data_traits,int(select_filtre_1),float(fs_filtre_1),float(cutoff_filtre_1),int(order_filtre_1),int(windowsize_filtre_1))
data_traits=switch_case(data_traits,int(select_filtre_2),float(fs_filtre_2),float(cutoff_filtre_2),int(order_filtre_2),int(windowsize_filtre_2))
fig = px.line( title="A-scan")
new_trace = go.Scatter(y=data_avec_traitement, mode='lines', name=' Ascan trait ')
if n_clicks != None:
data_traits = switch_case(volume, int(selec_transforme_hilbert))
data_traits = switch_case(
data_traits,
int(select_filtre_1),
float(fs_filtre_1),
float(cutoff_filtre_1),
int(order_filtre_1),
int(windowsize_filtre_1),
)
data_traits = switch_case(
data_traits,
int(select_filtre_2),
float(fs_filtre_2),
float(cutoff_filtre_2),
int(order_filtre_2),
int(windowsize_filtre_2),
)
fig = px.line(title="A-scan")
new_trace = go.Scatter(y=data_avec_traitement, mode="lines", name=" Ascan trait ")
fig.add_trace(new_trace)
new_trace = go.Scatter(y=data_sans_traitement, mode='lines', name=' Ascan (hilbert) ')
new_trace = go.Scatter(
y=data_sans_traitement, mode="lines", name=" Ascan (hilbert) "
)
fig.add_trace(new_trace)
data_bscan=switch_case(volume[select_ascan_y - 1, select_ascan_z[0]:select_ascan_z[1], :],int(selec_transforme_hilbert))
data_bscan=switch_case(data_bscan,int(select_filtre_1),float(fs_filtre_1),float(cutoff_filtre_1),int(order_filtre_1),int(windowsize_filtre_1))
data_bscan=switch_case(data_bscan,int(select_filtre_2),float(fs_filtre_2),float(cutoff_filtre_2),int(order_filtre_2),int(windowsize_filtre_2))
data_bscan = switch_case(
volume[select_ascan_y - 1, select_ascan_z[0] : select_ascan_z[1], :],
int(selec_transforme_hilbert),
)
data_bscan = switch_case(
data_bscan,
int(select_filtre_1),
float(fs_filtre_1),
float(cutoff_filtre_1),
int(order_filtre_1),
int(windowsize_filtre_1),
)
data_bscan = switch_case(
data_bscan,
int(select_filtre_2),
float(fs_filtre_2),
float(cutoff_filtre_2),
int(order_filtre_2),
int(windowsize_filtre_2),
)
fig2 = px.imshow(
data_bscan,
color_continuous_scale="Jet",
aspect="auto",
title="B-scan ZX",
)
return [fig, fig2]
return [fig, fig2, "Valider"]

View File

@ -1,19 +1,21 @@
from filtrage import *
def switch_case(data_input,select,fs=1,cut_off=1,order=1,window_size=1):
def switch_case(data_input, select, fs=1, cut_off=1, order=1, window_size=1):
match select:
case 1:
return transformer_hilbert(data_input)
case 2:
return data_input
case 3:
return filtre_passe_bas(data_input,fs,cut_off,order)
return filtre_passe_bas(data_input, fs, cut_off, order)
case 4:
return filtre_moyenne_mobile(data_input,window_size)
return filtre_moyenne_mobile(data_input, window_size)
case 5:
return filtre_adaptatif(data_input)
case 6:
return filtre_RII(data_input,window_size)
return filtre_RII(data_input, window_size)
case 7:
return filtre_RIF(data_input,window_size)
return filtre_RIF(data_input, window_size)
case _:
return data_input
return data_input