Files
templates/python/examples/plot_processing.py

28 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Sparse sine reconstruction using the public contract, independent of a GUI."""
import argparse
import math
from pathlib import Path
from set_devices.plot_processing import Axis, Series, Snapshot, prepare, process, write_csv
from set_devices.signal_reconstruction import METHODS
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--method", choices=METHODS, default="spline")
parser.add_argument("--degree", type=int, default=3)
parser.add_argument("--points", type=int, default=201)
parser.add_argument("--output", type=Path, default=Path("curve.csv"))
args = parser.parse_args()
samples = [(i * 125, math.sin(i * math.pi / 4)) for i in range(9)]
snapshot = Snapshot((Series("sine", "Синусоида: 9 отсчётов", samples, y_unit="В"),),
Axis("Время", "мс"), "sparse-sine")
curve = process(prepare(snapshot, "sine", args.method, args.points, args.degree))
with args.output.open("w", encoding="utf-8-sig", newline="") as stream:
write_csv(curve, stream)
print(f"{args.output}: {curve.input_count} -> {len(curve.points)}; RMSE={curve.rmse:.6g}")
if __name__ == "__main__":
main()