trace_save
Builtin index · Signal processing
trace_save(path, trace)
Input: path, trace · Output: no output
What it is
Writes a trace (a record of real vectors or a table of numeric columns, all the same length) to path. The extension selects the format: .csv is plain CSV with a header row, readable by read_csv and any spreadsheet; .npz is a NumPy archive of float64 arrays, readable by read_npz and numpy.load. Both reuse the existing writers (write_csv, write_npz); what this adds is the trace contract: one call for a record or a table, the same file for the same signals (no timestamps, signals in the order given), and an error instead of a file for signals of unequal length, a non-numeric field, a duplicate name or a name a CSV header cannot hold. Every finite value, both zeros and both infinities are read back bit for bit from either format; a NaN is read back as a NaN, and only .npz keeps its sign and payload.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
trace_save(path, trace) | path vectornot documented yettrace vectornot documented yet | no output | The extension selects the format: .csv is plain CSV with a header row, readable by read_csv and any spreadsheet; .npz is a NumPy archive of float64 arrays, readable by read_npz and numpy.load. Every finite value, both zeros and both infinities are read back bit for bit from either format; a NaN is read back as a NaN, and only .npz keeps its sign and payload. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
function sho(t, y)
return [y[1], -y[0]]
end function
te = linspace(0, 5, 51)
r = ode45("sho", [0, 5], [1, 0], t_eval=te, rtol=1e-10, atol=1e-12)
trace_save("reference.npz", {t = r.t, y = r.y[:, 0]})
ref = trace_load("reference.npz")
c = ode23("sho", [0, 5], [1, 0], t_eval=te) # the run under test
d = trace_diff(ref, {t = c.t, y = c.y[:, 0]}, rtol=1e-6, atol=1e-6)
print(d.ok) # false
print(d.worst_signal) # y
print(d.max_abs) # 2.652263e-6, at sample d.worst_index (32)
false y 2.652263e-6
from signal-processing