-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractJSON.py
More file actions
105 lines (80 loc) · 3.37 KB
/
Copy pathextractJSON.py
File metadata and controls
105 lines (80 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import json
import matplotlib.pyplot as plt
import pandas as pd
import PorousMedia
from matplotlib.colors import ListedColormap, BoundaryNorm
def all_data(path_json):
with open(path_json, 'r') as f:
data = json.load(f)
# === Nombres adimensionnels ===
adim_raw = data["adimensional_numbers"]
if "With u" in adim_raw and "With u_Darcy" in adim_raw:
adim_dict = {
name: {
"With u": val_u,
"With u_Darcy": val_darcy
}
for name, val_u, val_darcy in zip(adim_raw["Number"], adim_raw["With u"], adim_raw["With u_Darcy"])
}
else:
col_name = [key for key in adim_raw.keys() if key != "Number"][0]
adim_dict = {
name: value
for name, value in zip(adim_raw["Number"], adim_raw[col_name])
}
# === Paramètres LB-WBS ===
LB_raw = data["LB_WBS_parameters"]
LB_dict = {
model: {
"s_v": sv,
"alpha": alpha,
"s_j": sj
}
for model, sv, alpha, sj in zip(LB_raw["LB-WBS model"], LB_raw["s_v"], LB_raw["alpha"], LB_raw["s_j"])
}
# === Paramètres physiques, références et adimensionnés ===
phys_raw = data["physicals"]
variables = phys_raw["Variables"]
phys_dict = {var: val for var, val in zip(variables, phys_raw["Physical"])}
ref_dict = {var: val for var, val in zip(variables, phys_raw["Reference"])}
adi_dict = {var: val for var, val in zip(variables, phys_raw["No dimension"])}
return adim_dict, LB_dict, phys_dict, ref_dict, adi_dict
def multi_model(paths_json, view_table=False):
"""Extract all data in the list of JSON path
pathsJSON : liste of paths [exemple1.json, exemple2.json]
option view-table : if True, allows to visualize into the terminal the value of the data """
resultats = []
for path in paths_json:
try:
adim, LB, phys, ref, adi = all_data(path)
# ✅ Si le fichier contient 'impermeable', on force les valeurs
if 'impermeable' in path.lower():
LB.setdefault("Selected", {})
LB["Selected"]["alpha"] = 0
LB["Selected"]["s_v"] = 2
LB["Selected"]["s_j"] = 2
fichier_data = {
"fichier": path,
"adimensionnels": adim,
"LB_parameters": LB,
"physical": phys,
"reference": ref,
"adimensionne": adi
}
resultats.append(fichier_data)
if view_table:
print(f"\n📁 Fichier : {path}")
print("📐 Nombres adimensionnels :")
print(pd.DataFrame(adim).T)
print("\n⚙️ Paramètres LB-WBS :")
print(pd.DataFrame(LB).T)
print("\n🔬 Paramètres physiques :")
print(pd.DataFrame(phys.items(), columns=["Variable", "Valeur"]))
# print("\n📏 Paramètres de référence :")
# print(pd.DataFrame(ref.items(), columns=["Variable", "Valeur"]))
print("\n📐 Paramètres adimensionnés :")
print(pd.DataFrame(adi.items(), columns=["Variable", "Valeur"]))
print("\n" + "=" * 70)
except Exception as e:
print(f"❌ Erreur lors du traitement de {path} : {e}")
return resultats