From f920a27c6fcb18c08ebd6bb1598400295b91f68f Mon Sep 17 00:00:00 2001
From: Nicolas Barthes <nicolas.barthes@cnrs.fr>
Date: Wed, 5 Jun 2024 11:12:44 +0200
Subject: [PATCH] cleaning of import functions

---
 src/Modules.py                |  2 +-
 src/Packages.py               |  8 +++++++-
 src/Report/figures/.gitkeep   |  0
 src/Report/report.py          | 15 ++++++---------
 src/pages/2-model_creation.py | 29 ++++++-----------------------
 5 files changed, 20 insertions(+), 34 deletions(-)
 delete mode 100644 src/Report/figures/.gitkeep

diff --git a/src/Modules.py b/src/Modules.py
index db36ca7..da66759 100644
--- a/src/Modules.py
+++ b/src/Modules.py
@@ -6,7 +6,7 @@ from Class_Mod.Miscellaneous import prediction, download_results, plot_spectra,
 from style.header import add_header
 from Report import report
 css_file = Path("style/")
-
+from config.config import pdflatex_path
 local_css(css_file / "style.css")
 
 # path = os.path.dirname(os.path.abspath(__file__)).replace('\\','/')
diff --git a/src/Packages.py b/src/Packages.py
index b090edf..7b80d48 100644
--- a/src/Packages.py
+++ b/src/Packages.py
@@ -10,7 +10,9 @@ import random
 import datetime
 import numpy as np
 import pandas as pd
+import zipfile
 from matplotlib import colors
+from matplotlib.colors import Normalize
 from abc import ABC,abstractmethod
 from typing import Optional, List
 from sklearn.preprocessing import StandardScaler, MinMaxScaler, LabelEncoder
@@ -22,6 +24,10 @@ import kennard_stone as ks
 ### Exploratory data analysis-Dimensionality reduction
 from umap.umap_ import UMAP
 from sklearn.decomposition import PCA, NMF
+from pandas.api.types import is_float_dtype
+from plotly.subplots import make_subplots
+from matplotlib.cm import ScalarMappable
+import streamlit.components.v1 as components
 
 # Clustering
 from sklearn.cluster import KMeans, HDBSCAN,AffinityPropagation
@@ -47,7 +53,7 @@ from PIL import Image
 import plotly.express as px
 import plotly.graph_objects as go
 import plotly.io as pio
-import matplotlib.pyplot as plt
+import matplotlib.pyplot as plt, mpld3
 import seaborn as sns
 import matplotlib
 
diff --git a/src/Report/figures/.gitkeep b/src/Report/figures/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/src/Report/report.py b/src/Report/report.py
index ddd647e..5d58bf8 100644
--- a/src/Report/report.py
+++ b/src/Report/report.py
@@ -2,6 +2,8 @@ import subprocess
 from pathlib import Path
 import os
 import pandas as pd
+from config.config import pdflatex_path
+import zipfile
 
 def report(*args):
     to_report=[]
@@ -423,11 +425,8 @@ def report(*args):
 # latex_report = report('sample', 'predict',)
 
 def compile_latex():
-    # path to pdflatex
-    pdflatex_path = Path("C:/Users/diane/AppData/Local/Programs/MiKTeX/miktex/bin/x64/")
-    # pdflatex_path = Path("C:/Users/maimouni/AppData/Local/Programs/MiKTeX/miktex/bin/x64/")
-    from config.config import pdflatex_path
-    import os
+    # path to pdflatex imported from config/config.py
+
     filename_path = Path("Report/")
     filename = 'report.tex'
     # run pdflatex with bibtex compilation (2nd run)
@@ -444,10 +443,8 @@ def compile_latex():
     for ext in extensions:
         os.unlink(str(filename_path / filename[:-4]) + ext)
     # open the report
-    proc = subprocess.Popen([str(filename[:-4]) + '.pdf'], cwd = filename_path / 'figures', shell=True)
-    proc.communicate()
-    import os
-    import zipfile
+    # proc = subprocess.Popen([str(filename[:-4]) + '.pdf'], cwd = filename_path / 'figures', shell=True)
+    # proc.communicate()
 
     folder_path = Path('Report/figures')
     zip_path = Path('Report/')
diff --git a/src/pages/2-model_creation.py b/src/pages/2-model_creation.py
index 49a680f..96dd22a 100644
--- a/src/pages/2-model_creation.py
+++ b/src/pages/2-model_creation.py
@@ -1,36 +1,21 @@
-import streamlit
+# import streamlit
 from Packages import *
 st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide")
 from Modules import *
 from Class_Mod.DATA_HANDLING import *
-from pandas.api.types import is_float_dtype
 from Class_Mod.Miscellaneous import desc_stats
-from plotly.subplots import make_subplots
-import plotly.graph_objects as go
-from matplotlib.cm import ScalarMappable
 add_header()
 
-import matplotlib.pyplot as plt, mpld3
-import streamlit.components.v1 as components
-
-repertoire_a_vider = 'D:/Mouhcine/nirs_workflow/src/Report/figures'
-import shutil
+repertoire_a_vider = Path('Report/figures')
 if os.path.exists(repertoire_a_vider):
     for fichier in os.listdir(repertoire_a_vider):
-        chemin_fichier = os.path.join(repertoire_a_vider, fichier)
+        chemin_fichier = repertoire_a_vider / fichier
         if os.path.isfile(chemin_fichier) or os.path.islink(chemin_fichier):
             os.unlink(chemin_fichier)
         elif os.path.isdir(chemin_fichier):
-            shutil.rmtree(chemin_fichier)
-# HTML pour le bandeau "CEFE - CNRS"
-
-json_sp=pd.DataFrame()
-
-
-
-
-
+            os.rmdir(chemin_fichier)
 
+json_sp = pd.DataFrame()
 
 st.session_state["interface"] = st.session_state.get('interface')
 if st.session_state["interface"] == 'simple':
@@ -268,9 +253,7 @@ if not spectra.empty and not y.empty:
         # rr.columns = ['y values', 'x_axis', 'y_axis']
         # fig = px.scatter(rr, x = 'x_axis', y = 'y_axis', color_continuous_scale=px.colors.sequential.Viridis, color = 'y values')
         # M3.plotly_chart(fig)
-        
-        
-        from matplotlib.colors import Normalize
+
         color_variable = y_train
         norm = Normalize(vmin=color_variable.min(), vmax= color_variable.max())
         cmap = plt.get_cmap('viridis')
-- 
GitLab