From 2732fd7e9d1d1a4f64d9e7e046fe2a2cb025a60c Mon Sep 17 00:00:00 2001 From: mathur04 <90455442+mathur04@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:22:08 +0200 Subject: [PATCH] Add files via upload --- visu_coupe/__pycache__/util.cpython-310.pyc | Bin 0 -> 850 bytes visu_coupe/main.py | 115 ++++++++++++++++++++ visu_coupe/util.py | 24 ++++ 3 files changed, 139 insertions(+) create mode 100644 visu_coupe/__pycache__/util.cpython-310.pyc create mode 100644 visu_coupe/main.py create mode 100644 visu_coupe/util.py diff --git a/visu_coupe/__pycache__/util.cpython-310.pyc b/visu_coupe/__pycache__/util.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2f9ef6ab3e425297ed810c14d2241f1a19737ba9 GIT binary patch literal 850 zcmYjPPm9w)6rVSlq;c6@>Q=2%kRzmqmGUa2-4+~!PRF<$WMQ`OXwr7k?W@@1QAe@ zbf+N&K}GO|q*O2wq7DR1$te1Tk>nx=ul5w9_WTC9{*GcsT0o|TSj61YZ^Je)u%I^Z zm|tnjEITKcy*9LP9oX;&fP5Uh!^{l7Z2+W-Uy}OSC-nR8J+fg2qXiq1Eo=e*e%wZw zBi#A-zN5Bh!|T9A7Hn@wY~-Um^fOEUXBu0Im4p`#^esFefx9PUSu6`9wf1$5dXA}; ztXz=SYZqzBh14$MEA$B$YF^Ex3rY+KuS&(uD0WP6!_x!9Ka`R;+4$TAXs0m(WLHHg z(*tkqkkYU$W|eeMI9U83x{oPuC&}Ad>N;6+W2Bll+Hj$g>84Vpnr+T?v6jiy@R`h( zyvBznlZ~0HYNFLb<|bJeb(7_)S;?d^Mfqa2af7nZGHWW#pU(@aGkgK_6FNn~fWaXg zLyVICIsN^BG3di1JTcHG7?Atb_(vfc5pp-+F&cij$bt2P=(o%eKVEDwvFwI!0dMFv zvq9JTsB1S|jKU7tQB^y(;%4sHLKT(vtAlrksM6m4v1zPj-IRu#w6|}nKE{BqSvzqb zkFMVpd8b1E_S!@F3S&6gRrC-YBc^=~dfbE~>-~ literal 0 HcmV?d00001 diff --git a/visu_coupe/main.py b/visu_coupe/main.py new file mode 100644 index 0000000..58064e8 --- /dev/null +++ b/visu_coupe/main.py @@ -0,0 +1,115 @@ +# Import data +import time +import numpy as np +from skimage import io +import plotly.graph_objects as go +from scipy.ndimage import uniform_filter1d +from scipy.signal import savgol_filter +from scipy import * +from scipy.signal import * +from util import * +""" +vol = io.imread("https://s3.amazonaws.com/assets.datacamp.com/blog_assets/attention-mri.tif") +volume = vol.T +r, c = volume[0].shape +""" + +# Import data +dossier = "Dataset/Shear_Wave_Rot00_CSV_Data" +fichiers_selectionnes= fichiers_selectionnes = ['Shear_x001-x101_y{:03d}_Rot00.csv'.format(i) for i in range(10, 62)] +print(fichiers_selectionnes) + +pre_volume= np.array(lire_fichier_csv(dossier,fichiers_selectionnes)) +pre_traitement = abs(hilbert(pre_volume)) + +traitement = savgol_filter(pre_traitement, window_length=50, polyorder=5) + +volume = traitement[:, ::10, :] +#volume = np.load('Dataset/3D_Dataset_All_Wave_PY_Data/3D_Dataset_shear_Wave_Rot00.npy') +r, c = volume[0].shape +# Define the number of frames based on the depth of the 3D volume +nb_frames = volume.shape[0] + +# Define the z-scale based on the number of frames +z_scale = 6.7 / nb_frames + +#custom_colorscale = [(0, 'blue'), (0.5, 'cyan'), (1, 'red')] + +fig = go.Figure(frames=[go.Frame(data=go.Surface( + z=(z_scale * nb_frames - k * z_scale) * np.ones((r, c)), + surfacecolor=np.flipud(volume[nb_frames - 1 - k]), + cmin=0, cmax=20000, + colorscale='Jet' + ), + name=str(k) # you need to name the frame for the animation to behave properly + ) + for k in range(nb_frames)]) + +# Add data to be displayed before animation starts +fig.add_trace(go.Surface( + z=z_scale * nb_frames * np.ones((r, c)), + surfacecolor=np.flipud(volume[nb_frames - 1]), + colorscale='Jet', + cmin=-20000, cmax=20000, + colorbar=dict(thickness=20, ticklen=4) + )) + +def frame_args(duration): + return { + "frame": {"duration": duration}, + "mode": "immediate", + "fromcurrent": True, + "transition": {"duration": duration, "easing": "linear"}, + } + +sliders = [ + { + "pad": {"b": 10, "t": 60}, + "len": 0.9, + "x": 0.1, + "y": 0, + "steps": [ + { + "args": [[f.name], frame_args(0)], + "label": str(k), + "method": "animate", + } + for k, f in enumerate(fig.frames) + ], + } + ] + +# Layout +fig.update_layout( + title='Slices in volumetric data', + width=600, + height=600, + scene=dict( + zaxis=dict(range=[-0.1, z_scale * nb_frames], autorange=False), + aspectratio=dict(x=1, y=1, z=1), + ), + updatemenus = [ + { + "buttons": [ + { + "args": [None, frame_args(50)], + "label": "▶", # play symbol + "method": "animate", + }, + { + "args": [[None], frame_args(0)], + "label": "◼", # pause symbol + "method": "animate", + }, + ], + "direction": "left", + "pad": {"r": 10, "t": 70}, + "type": "buttons", + "x": 0.1, + "y": 0, + } + ], + sliders=sliders +) + +fig.show() \ No newline at end of file diff --git a/visu_coupe/util.py b/visu_coupe/util.py new file mode 100644 index 0000000..d503e85 --- /dev/null +++ b/visu_coupe/util.py @@ -0,0 +1,24 @@ +import csv +import os + +def lire_un_fichier_csv(data): + tableau_2D = [] + tab = [] + with open(data, "r") as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + for ligne in csv_reader: + tableau_2D.append(ligne) + for i in range(len(tableau_2D[0])): + ligne = [] + for j in range(len(tableau_2D)): + ligne.append(float(tableau_2D[j][i])) + tab.append(ligne) + return tab + +def lire_fichier_csv(data,fichier): + resultat=[] + tableau=[] + for i in fichier: + tableau=lire_un_fichier_csv(os.path.join(data,i)) + resultat.append(tableau) + return resultat \ No newline at end of file