153 lines
5.8 KiB
Python
153 lines
5.8 KiB
Python
from pathlib import Path
|
||
from pylatex import (Document, Section, Subsection, Command, Figure,
|
||
Tabular, Math, NoEscape, Package)
|
||
from pylatex.utils import bold
|
||
|
||
BASE = Path(__file__).parent
|
||
|
||
INDUTTORI = [
|
||
{
|
||
"nome": "Induttore 1",
|
||
"intervallo": "110.81 – 111.56 s",
|
||
"t0": "110.81",
|
||
"t_end": "111.56",
|
||
"n_punti": "5",
|
||
"zona_exc": None,
|
||
"A": "87.3140",
|
||
"A_err": "0.0260",
|
||
"tau": "15.7231",
|
||
"tau_err": "0.2021",
|
||
"r2": "0.999505",
|
||
"png": BASE / "induttore1" / "induttore1.png",
|
||
},
|
||
{
|
||
"nome": "Induttore 2",
|
||
"intervallo": "112.02 – 113.95 s",
|
||
"t0": "112.02",
|
||
"t_end": "113.95",
|
||
"n_punti": "13",
|
||
"zona_exc": None,
|
||
"A": "158.3430",
|
||
"A_err": "0.2088",
|
||
"tau": "13.2844",
|
||
"tau_err": "0.2183",
|
||
"r2": "0.997314",
|
||
"png": BASE / "induttore2" / "induttore2.png",
|
||
},
|
||
{
|
||
"nome": "Induttore 3",
|
||
"intervallo": "115.0 – 133.7 s",
|
||
"t0": "115.0",
|
||
"t_end": "133.7",
|
||
"n_punti": "125",
|
||
"zona_exc": "115.9 – 117.2 s",
|
||
"A": "185.1847",
|
||
"A_err": "0.2706",
|
||
"tau": "16.2654",
|
||
"tau_err": "0.0464",
|
||
"r2": "0.993827",
|
||
"png": BASE / "induttore3" / "induttore3.png",
|
||
},
|
||
]
|
||
|
||
def build_doc():
|
||
doc = Document(geometry_options={"margin": "2.5cm"})
|
||
|
||
doc.packages.append(Package("booktabs"))
|
||
doc.packages.append(Package("graphicx"))
|
||
doc.packages.append(Package("amsmath"))
|
||
doc.packages.append(Package("float"))
|
||
doc.packages.append(Package("caption"))
|
||
doc.packages.append(Package("inputenc", options="utf8"))
|
||
|
||
# Titolo
|
||
doc.preamble.append(Command("title", "Report Analisi Termica Forno"))
|
||
doc.preamble.append(Command("author", "Analisi IR -- Cevolani"))
|
||
doc.preamble.append(Command("date", NoEscape(r"\today")))
|
||
doc.append(NoEscape(r"\maketitle"))
|
||
|
||
# Introduzione
|
||
with doc.create(Section("Modello di fitting")):
|
||
doc.append(
|
||
"Ogni intervallo è interpolato con il modello di raffreddamento di Newton:"
|
||
)
|
||
doc.append(Math(data=[NoEscape(
|
||
r"T(t) = T_\infty + A \cdot e^{-(t - t_0)/\tau}"
|
||
)], escape=False))
|
||
doc.append(NoEscape(
|
||
r"dove $T_\infty = 22.99\,^\circ\mathrm{C}$ è la temperatura ambiente media ponderata. "
|
||
r"La regressione non lineare usa il metodo \textit{Trust Region Reflective} (TRF) "
|
||
r"di \texttt{scipy.optimize.curve\_fit}."
|
||
))
|
||
|
||
# Sezione per ogni induttore
|
||
for ind in INDUTTORI:
|
||
with doc.create(Section(ind["nome"])):
|
||
|
||
with doc.create(Subsection("Intervallo di campionamento")):
|
||
with doc.create(Tabular("|l|l|")) as tab:
|
||
tab.add_hline()
|
||
tab.add_row([bold("Parametro"), bold("Valore")])
|
||
tab.add_hline()
|
||
tab.add_row(["Inizio", f"{ind['t0']} s"])
|
||
tab.add_row(["Fine", f"{ind['t_end']} s"])
|
||
tab.add_row(["Numero di punti", ind["n_punti"]])
|
||
if ind["zona_exc"]:
|
||
tab.add_row(["Zona esclusa (peso = 0)", ind["zona_exc"]])
|
||
tab.add_hline()
|
||
|
||
with doc.create(Subsection("Equazione trovata")):
|
||
t0 = ind["t0"]
|
||
A = ind["A"]
|
||
tau = ind["tau"]
|
||
doc.append(Math(data=[NoEscape(
|
||
rf"T(t) = 22.99 + {A} \cdot e^{{-(t - {t0}) / {tau}}}"
|
||
)], escape=False))
|
||
|
||
doc.append(NoEscape(r"\vspace{4pt}"))
|
||
with doc.create(Tabular("|l|l|l|")) as tab:
|
||
tab.add_hline()
|
||
tab.add_row([bold("Parametro"), bold("Valore"), bold("Incertezza (1σ)")])
|
||
tab.add_hline()
|
||
tab.add_row(["A",
|
||
NoEscape(rf"${ind['A']}\,^\circ\mathrm{{C}}$"),
|
||
NoEscape(rf"$\pm\,{ind['A_err']}\,^\circ\mathrm{{C}}$")])
|
||
tab.add_row([NoEscape(r"$\tau$"),
|
||
NoEscape(rf"${ind['tau']}\,\mathrm{{s}}$"),
|
||
NoEscape(rf"$\pm\,{ind['tau_err']}\,\mathrm{{s}}$")])
|
||
tab.add_hline()
|
||
|
||
doc.append(NoEscape(r"\vspace{4pt}"))
|
||
doc.append(NoEscape(rf"$R^2 = {ind['r2']}$"))
|
||
|
||
with doc.create(Subsection("Grafico")):
|
||
with doc.create(Figure(position="H")) as fig:
|
||
fig.add_image(str(ind["png"]), width=NoEscape(r"0.9\textwidth"))
|
||
fig.add_caption(f"Fit esponenziale — {ind['nome']} [{ind['intervallo']}]")
|
||
|
||
# Tabella riepilogativa
|
||
with doc.create(Section("Riepilogo")):
|
||
with doc.create(Tabular("|l|l|l|l|l|")) as tab:
|
||
tab.add_hline()
|
||
tab.add_row([bold("Induttore"), bold("Intervallo [s]"),
|
||
bold("A [°C]"), bold(NoEscape(r"$\tau$ [s]")), bold(NoEscape(r"$R^2$"))])
|
||
tab.add_hline()
|
||
for ind in INDUTTORI:
|
||
tab.add_row([ind["nome"], ind["intervallo"],
|
||
ind["A"], ind["tau"], ind["r2"]])
|
||
tab.add_hline()
|
||
|
||
out = BASE / "report_completo"
|
||
doc.generate_tex(str(out))
|
||
print(f"report_completo.tex generato.")
|
||
|
||
try:
|
||
doc.generate_pdf(str(out), clean_tex=False, compiler="pdflatex")
|
||
print("report_completo.pdf generato.")
|
||
except Exception as e:
|
||
print(f"Compilazione PDF non disponibile ({e}).")
|
||
print("Installa MikTeX o TeX Live per generare il PDF da report_completo.tex.")
|
||
|
||
if __name__ == "__main__":
|
||
build_doc()
|