# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] colab_type="text" id="kPFD7mlSFqlG"
# # Visualisation des données
# -

# %reset -f

import numpy as np
import pandas as pd
import ast
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

# %matplotlib nbagg

# +
N = len(pd.read_csv("../../data/case_1_spatial.csv"))
step_count = len(pd.read_csv("../../data/case_1_temporal.csv"))

print("Taille du maillage :", N)
print("Nombre d'iterations:", step_count)

# +
# elements a visualiser
e = np.empty(shape=(step_count, N), dtype=float)
f = np.empty(shape=(step_count, N), dtype=float)
tm = np.empty(shape=(step_count, N), dtype=float)
tr = np.empty(shape=(step_count, N), dtype=float)

for i in range(step_count):
    file_name = "../../data/anim/animation." + str(i) + ".csv";
    df = pd.read_csv(file_name)
    e[i] = np.array(df['E'])
    f[i] = np.array(df['F'])
    tm[i] = np.array(df['T'])
    tr[i] = np.array(df['Tr'])
    
x = np.array(df['x'])
rho = np.array(df['rho'])

# au temps final
display(df[:5])
# -

fig, ax = plt.subplots(1,1,figsize=(4,3))
ax.plot(x, rho, '--', label="densité", color='tab:purple')
plt.legend()
plt.show()

# +
fig, ax = plt.subplots(1,2,figsize=(8,3))

# initialisation
im1 = [axis.plot([],[])[0] for axis in ax]
im2 = [axis.plot([],[])[0] for axis in ax]

# subplot 1 -  energy et flux
im1[0] = ax[0].plot([],[], 'b', label="énergie", lw=3)[0]
im2[0] = ax[0].plot([],[], 'y-', label="flux", lw=3)[0]

ax[0].set_xlim([0, 1])
ax[0].set_ylim([-3.25, 15.75])

# subplot 2 -  temperature matiere et radiative
im1[1] = ax[1].plot([],[], 'g-', label="température matière", lw=1)[0]
im2[1] = ax[1].plot([],[], 'r--', label="température radiative", lw=1)[0]

ax[1].set_xlim([0, 1])
ax[1].set_ylim([4.5, 6.5])

# legende sur tous les subplots
legs = [axis.legend(loc=2, prop={'size': 6})  for axis in ax]
plt.tight_layout()

def update(i):
    # subplot 1
    im1[0].set_data(x, e[i])
    im2[0].set_data(x, f[i])

    # subplot 2
    im1[1].set_data(x, tm[i])
    im2[1].set_data(x, tr[i])

    return im1 + im2

anim = FuncAnimation(fig, update, frames=step_count, interval=10, repeat=False, blit=True)
plt.show()

# +
# anim.save('animation.mp4', writer='ffmpeg', fps=75)

StarcoderdataJupyterScriptsDedupFiltered