28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""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()
|