Skip to content
Snippets Groups Projects
Commit a04da788 authored by Mouhcine's avatar Mouhcine
Browse files

Ajout de l'export des fiigures pour le rapport

parent a3d36997
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,8 @@ import joblib
from hyperopt import fmin, hp, tpe, Trials, space_eval, STATUS_OK, anneal
import plotly.graph_objects as go
import plotly.express as px
import plotly.io as pio
import streamlit as st
st.set_option('deprecation.showPyplotGlobalUse', False)
Report/figures/Elbow.png

22.3 KiB

Report/figures/Influence_plot.png

28.9 KiB

Report/figures/Spectra_Plot.png

177 KiB

Report/figures/graphe.png

32.1 KiB

Report/figures/graphe_hotelling.png

30.3 KiB

Report/figures/graphe_loadings.png

60.6 KiB

Report/figures/scores_plot_2d_axis1_axis2.png

51.4 KiB

Report/figures/scores_plot_2d_axis1_axis3.png

52.2 KiB

Report/figures/scores_plot_2d_axis2_axis3.png

50.8 KiB

......@@ -6,6 +6,16 @@ from Modules import *
from Class_Mod.DATA_HANDLING import *
# HTML pour le bandeau "CEFE - CNRS"
bandeau_html = """
<div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;">
<h1 style="text-align: center; color: white;">CEFE - CNRS</h1>
</div>
"""
# Injecter le code HTML du bandeau
st.markdown(bandeau_html, unsafe_allow_html=True)
# # TOC menu on the left
show_pages(
[Page("app.py", "Home"),
......@@ -18,6 +28,7 @@ hide_pages("Samples Selection")
hide_pages("Models Creation")
hide_pages("Predictions")
with st.sidebar:
interface = st.selectbox(label="Interface", options=['simple', 'advanced'], key='interface')
st.page_link('pages\\1-samples_selection.py')
......@@ -35,17 +46,35 @@ with st.sidebar:
st.page_link('pages\\2-model_creation.py')
st.page_link('pages\\3-prediction.py')
# Page header
with st.container():
st.subheader("Plateforme d'Analyses Chimiques pour l'Ecologie-PACE :goat:")
st.title("NIRS Utils")
st.write("Samples selection (PCA, [UMAP](https://umap-learn.readthedocs.io/en/latest/how_umap_works.html), ...), Predictive Modelling ([Pinard](https://github.com/GBeurier/pinard), [LWPLSR](https://doi.org/10.1002/cem.3209), ...), and Predictions using your data (CSV or DX files) and/or PACE NIRS Database.")
#st.image(img_general)
st.markdown("### We could add documentation here ###")
# Centrer les boutons
st.markdown(
"""
<style>
.stButton>button {
display: block;
margin: 0 auto;
width: 200px;
height: 50px;
font-size: 16px;
}
</style>
""",
unsafe_allow_html=True
)
header1, header2, header3 = st.columns(3)
if header1.button("Samples Selection"):
st.switch_page('pages\\1-samples_selection.py')
if header2.button("Model Creation"):
st.switch_page('pages\\2-model_creation.py')
if header3.button("Predictions"):
st.switch_page('pages\\3-prediction.py')
\ No newline at end of file
st.switch_page('pages\\3-prediction.py')
st.subheader("Plateforme d'Analyses Chimiques pour l'Ecologie-PACE :goat:")
st.title("NIRS Utils")
st.write("Samples selection (PCA, [UMAP](https://umap-learn.readthedocs.io/en/latest/how_umap_works.html), ...), Predictive Modelling ([Pinard](https://github.com/GBeurier/pinard), [LWPLSR](https://doi.org/10.1002/cem.3209), ...), and Predictions using your data (CSV or DX files) and/or PACE NIRS Database.")
#st.image(img_general)
st.markdown("### We could add documentation here ###")
\ No newline at end of file
......@@ -3,6 +3,19 @@ st.set_page_config(page_title="NIRS Utils", page_icon=":goat:", layout="wide")
from Modules import *
from Class_Mod.DATA_HANDLING import *
# HTML pour le bandeau "CEFE - CNRS"
bandeau_html = """
<div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;">
<h1 style="text-align: center; color: white;">CEFE - CNRS</h1>
</div>
"""
# Injecter le code HTML du bandeau
st.markdown(bandeau_html, unsafe_allow_html=True)
st.session_state["interface"] = st.session_state.get('interface')
if st.session_state["interface"] == 'simple':
hide_pages("Predictions")
......@@ -54,13 +67,12 @@ if data_file:
st.success("The data have been loaded successfully", icon="")
os.unlink(tmp_path)
## Visualize spectra
if not spectra.empty:
with col2:
fig = plot_spectra(spectra)
st.pyplot(fig)
fig.savefig("./Report/figures/Spectra_Plot.png")
############################## Exploratory data analysis ###############################
container2 = st.container(border=True)
......@@ -102,8 +114,13 @@ if not t.empty:
if clus_method == cluster_methods[1]:
ncluster = scores.number_input(min_value=2, max_value=30, value=3, label = 'Select the desired number of clusters')
cl_model = Sk_Kmeans(tcr, max_clusters = 30)
fig2 = px.scatter(cl_model.inertia_.T, y = 'inertia')
fig2 = px.scatter(cl_model.inertia_.T, y = 'inertia')
scores.plotly_chart(fig2)
img = pio.to_image(fig2, format="png")
with open("./Report/figures/Elbow.png", "wb") as f:
f.write(img)
data, labels = cl_model.fit_optimal(nclusters = ncluster)
elif clus_method == cluster_methods[2]:
......@@ -119,7 +136,7 @@ if not t.empty:
# scores plot with clustering
if list(labels) and meta_data.empty:
fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = labels)
# scores plot with metadata
elif len(list(labels)) == 0 and not meta_data.empty:
filter = meta_data.columns[1:]
......@@ -151,26 +168,63 @@ if not t.empty:
st.plotly_chart(fig)
## Export en 2d Axe1..Axe3
if not t.empty:
if dim_red_method == dim_red_methods[1]:
# nombre de clusters
num_clusters = len(np.unique(labels))
# Une couleur par cluster
custom_color_palette = px.colors.qualitative.Plotly[:num_clusters]
# Graphique pour les dimensions (axis1, axis2)
fig_2d_axis1_axis2 = px.scatter(t, x=axis1, y=axis2, color=labels, color_discrete_sequence=custom_color_palette)
img_2d_axis1_axis2 = pio.to_image(fig_2d_axis1_axis2, format="png")
with open("./Report/figures/scores_plot_2d_axis1_axis2.png", "wb") as f:
f.write(img_2d_axis1_axis2)
# Graphique pour les dimensions (axis1, axis3)
fig_2d_axis1_axis3 = px.scatter(t, x=axis1, y=axis3, color=labels, color_discrete_sequence=custom_color_palette)
img_2d_axis1_axis3 = pio.to_image(fig_2d_axis1_axis3, format="png")
with open("./Report/figures/scores_plot_2d_axis1_axis3.png", "wb") as f:
f.write(img_2d_axis1_axis3)
# Graphique pour les dimensions (axis2, axis3)
fig_2d_axis2_axis3 = px.scatter(t, x=axis2, y=axis3, color=labels, color_discrete_sequence=custom_color_palette)
img_2d_axis2_axis3 = pio.to_image(fig_2d_axis2_axis3, format="png")
with open("./Report/figures/scores_plot_2d_axis2_axis3.png", "wb") as f:
f.write(img_2d_axis2_axis3)
if not spectra.empty:
if dim_red_method == dim_red_methods[1]:
with loadings:
st.write('Loadings plot')
p = dr_model.loadings_
pp = pd.concat([p, pd.DataFrame(np.arange(p.shape[0]), index=p.index, columns=['wl'])], axis =1)
pp = pd.concat([p, pd.DataFrame(np.arange(p.shape[0]), index=p.index, columns=['wl'])], axis=1)
df1 = pp.melt(id_vars="wl")
fig = px.line(df1, x = 'wl', y = 'value', color='variable')
fig.update_layout(legend=dict(x=1, y=0,font=dict(family="Courier", size=12, color="black"),
bordercolor="Black", borderwidth=2))
st.plotly_chart(fig, use_container_width = True)
fig = px.line(df1, x='wl', y='value', color='variable', color_discrete_sequence=px.colors.qualitative.Plotly)
fig.update_layout(legend=dict(x=1, y=0, font=dict(family="Courier", size=12, color="black"),
bordercolor="black", borderwidth=2))
st.plotly_chart(fig, use_container_width=True)
# Export du graphique
img = pio.to_image(fig, format="png")
with open("./Report/figures/graphe_loadings.png", "wb") as f:
f.write(img)
with influence:
st.write('Influence plot')
ax1 = st.selectbox("Component", options=dr_model.scores_.columns, index=3)
leverage = dr_model.leverage_
residuals = dr_model.residuals_
fig = px.scatter(x=leverage[ax1], y=residuals[ax1], color = leverage[ax1]*residuals[ax1]).update_layout(xaxis_title="Leverage",yaxis_title="Residuals")
fig = px.scatter(x=leverage[ax1], y=residuals[ax1], color=leverage[ax1]*residuals[ax1], color_continuous_scale='Blues')
fig.update_layout(xaxis_title="Leverage", yaxis_title="Residuals")
st.plotly_chart(fig)
img = pio.to_image(fig, format="png")
with open("./Report/figures/Influence_plot.png", "wb") as f:
f.write(img)
with hotelling:
st.write('T²-Hotelling vs Q residuals plot')
......@@ -179,4 +233,5 @@ if not spectra.empty:
hotelling = dr_model.hotelling_
fig = px.scatter(t, x=hotelling[ax2], y=residuals[ax2]).update_layout(xaxis_title="",yaxis_title="Residuals")
st.plotly_chart(fig)
\ No newline at end of file
st.plotly_chart(fig)
fig.write_image("./Report/figures/graphe_hotelling.png", format="png")
......@@ -2,7 +2,15 @@ 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 *
# HTML pour le bandeau "CEFE - CNRS"
bandeau_html = """
<div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;">
<h1 style="text-align: center; color: white;">CEFE - CNRS</h1>
</div>
"""
# Injecter le code HTML du bandeau
st.markdown(bandeau_html, unsafe_allow_html=True)
st.session_state["interface"] = st.session_state.get('interface')
if st.session_state["interface"] == 'simple':
......
......@@ -2,7 +2,15 @@ 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 *
# HTML pour le bandeau "CEFE - CNRS"
bandeau_html = """
<div style="width: 100%; background-color: #4682B4; padding: 10px; margin-bottom: 10px;">
<h1 style="text-align: center; color: white;">CEFE - CNRS</h1>
</div>
"""
# Injecter le code HTML du bandeau
st.markdown(bandeau_html, unsafe_allow_html=True)
st.session_state["interface"] = st.session_state.get('interface')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment