{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.datasets import make_blobs\n",
    "from sklearn.metrics import accuracy_score\n",
    "import plotly.graph_objects as go\n",
    "import PySimpleGUI as sg\n",
    "from os import listdir\n",
    "import matplotlib.pyplot as plt\n",
    "from mpl_toolkits.mplot3d import Axes3D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def selection_fichier(dossier):\n",
    "    # Liste des fichiers dans le répertoire\n",
    "    nom_fichiers = listdir(dossier)\n",
    "    # Créer une liste de tuples pour les options de la liste déroulante\n",
    "    options = [(fichier) for fichier in nom_fichiers]\n",
    "    # Créer la disposition de l'interface graphique\n",
    "    layout = [\n",
    "        [sg.Text(\"Sélectionnez les fichiers à traiter :\")],\n",
    "        [sg.Listbox(values=options, select_mode=sg.LISTBOX_SELECT_MODE_EXTENDED, size=(40, 10))],\n",
    "        [sg.Button(\"OK\"), sg.Button(\"Annuler\")]\n",
    "        ]\n",
    "    # Créer la fenêtre de l'interface graphique\n",
    "    window = sg.Window(\"Sélection des fichiers\", layout)\n",
    "    # Attendre que l'utilisateur interagisse avec l'interface graphique\n",
    "    while True:\n",
    "        event, values = window.read()\n",
    "        if event == sg.WINDOW_CLOSED or event == \"Annuler\":\n",
    "            fichiers_selectionnes = []\n",
    "            break\n",
    "        elif event == \"OK\":\n",
    "            fichiers_selectionnes = values[0]\n",
    "            break\n",
    "    # Fermer la fenêtre de l'interface graphique\n",
    "    window.close()\n",
    "    return fichiers_selectionnes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "def lire_un_fichier_csv(data):\n",
    "  \n",
    "  tableau_2D=[]\n",
    "  tab=[]\n",
    "  with open(data,\"r\") as csv_file:\n",
    "      csv_reader=csv.reader(csv_file,delimiter=',')\n",
    "      for ligne in csv_reader:\n",
    "        tableau_2D.append(ligne)\n",
    "  for i in range(len(tableau_2D[0])):\n",
    "    ligne = [] \n",
    "    for j in range(len(tableau_2D)):\n",
    "      ligne.append(float(tableau_2D[j][i]))\n",
    "    tab.append(ligne)  \n",
    "  return tab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "def lire_fichier_csv(data,fichier):\n",
    "    resultat=[]\n",
    "    tableau=[]\n",
    "    for i in fichier:\n",
    "        tableau=lire_un_fichier_csv(os.path.join(data,i))\n",
    "        resultat.append(tableau)\n",
    "    return resultat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Shear_x001-x101_y008_Rot90.csv', 'Shear_x001-x101_y009_Rot90.csv', 'Shear_x001-x101_y010_Rot00.csv']\n"
     ]
    }
   ],
   "source": [
    "# Répertoire contenant les fichiers\n",
    "dossier = \"dataverse_files\\Dataset\\Shear_Wave_Rot00_CSV_Data\"\n",
    "fichiers_selectionnes=selection_fichier(dossier)\n",
    "print(fichiers_selectionnes)\n",
    "tableau_3D=lire_fichier_csv(dossier,fichiers_selectionnes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 119496 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "tableau_np = np.array(tableau_3D)\n",
    "\n",
    "# Sélectionner une tranche de tableau 3D pour l'affichage\n",
    "image = tableau_np[0,:,:]\n",
    "\n",
    "# Afficher l'image en utilisant imshow()\n",
    "plt.imshow(image, aspect='auto', origin='lower', cmap='jet')\n",
    "plt.colorbar()  # Ajouter une barre de couleur pour représenter l'échelle des intensités\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "Axes3D.plot_surface() missing 1 required positional argument: 'Z'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[177], line 4\u001b[0m\n\u001b[0;32m      2\u001b[0m ax \u001b[38;5;241m=\u001b[39m fig\u001b[38;5;241m.\u001b[39madd_subplot(\u001b[38;5;241m111\u001b[39m, projection\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m3d\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m      3\u001b[0m     \u001b[38;5;66;03m# Affichage de l'image 3D\u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m image \u001b[38;5;241m=\u001b[39m ax\u001b[38;5;241m.\u001b[39mplot_surface(image,image, cmap\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mviridis\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m      5\u001b[0m     \u001b[38;5;66;03m# Ajout de la barre de couleur\u001b[39;00m\n\u001b[0;32m      6\u001b[0m fig\u001b[38;5;241m.\u001b[39mcolorbar(image)\n",
      "\u001b[1;31mTypeError\u001b[0m: Axes3D.plot_surface() missing 1 required positional argument: 'Z'"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 64552 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111, projection='3d')\n",
    "    # Affichage de l'image 3D\n",
    "image = ax.plot_surface(image, cmap='viridis')\n",
    "    # Ajout de la barre de couleur\n",
    "fig.colorbar(image)\n",
    "\n",
    "    # Affichage du graphique\n",
    "plt.show()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
