Coverage for cli/src/xyfigure/functional_architecture.py: 73%
64 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-18 01:09 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-18 01:09 +0000
1# Functional Architecture
3from typing import NamedTuple, Tuple
5import matplotlib.pyplot as plt
6import numpy as np
7from pathlib import Path # stop using os.path, use pathlib instead
10class Database(NamedTuple):
11 filename: str = "filename.ext"
12 filetype: str = "ext"
13 filepath: str = "."
16class Csv(Database):
17 filetype: str = "csv"
20class Dsr(Database):
21 filetype: str = "dsr"
24class Cal(Database):
25 filetype: str = "cal"
28class Dat(Database):
29 filetype: str = "dat"
32class PairedLabels(NamedTuple):
33 x: str = "x-axis"
34 y: str = "y-axis"
35 # x: str
36 # y: str
39class PairedSeries(NamedTuple):
40 x: Tuple[float] = (0.0,)
41 y: Tuple[float] = (0.0,)
42 # x: Tuple[float]
43 # y: Tuple[float]
46class Figure(NamedTuple):
47 labels: PairedLabels = PairedLabels()
48 series: Tuple[PairedSeries] = (PairedSeries(),)
49 xmin: float = 0.0
50 xmax: float = 1.0
51 ymin: float = 0.0
52 ymax: float = 1.0
53 filename: str = "figure.pdf"
54 width: float = 8.0 # inches
55 height: float = 6.0 # inches
56 dpi: int = 150 # dots per inch, resolution
59def csv_data_labels(x: Csv) -> PairedLabels:
60 return PairedLabels()
63def csv_data(x: Csv) -> PairedSeries:
65 file_pathed = Path(x.filepath).joinpath(x.filename)
67 data = np.genfromtxt(
68 file_pathed, dtype="float", delimiter=",", skip_header=1, usecols=(0, 1)
69 )
70 return PairedSeries(x=tuple(data[:, 0]), y=tuple(data[:, 1]))
73def dsr_data_labels(x: Dsr) -> PairedLabels:
74 # return PairedLabels()
75 raise NotImplementedError
78def dsr_data(x: Dsr) -> PairedSeries:
79 # return PairedSeries()
80 raise NotImplementedError
83def caldat_data_labels(x0: Cal, x1: Dat) -> PairedLabels:
84 # return PairedLabels()
85 raise NotImplementedError
88def caldat_data(x0: Cal, x1: Dat) -> PairedSeries:
89 # return PairedSeries()
90 raise NotImplementedError
93# def integrate(x0: PairedSeries, inital_condition: float = 0.0) -> PairedSeries:
94def integrate(x0: PairedSeries, inital_condition: float) -> PairedSeries:
95 return PairedSeries()
98def differentiate(x: PairedSeries) -> PairedSeries:
99 return PairedSeries()
102# def butterworth_filter(
103# x0: PairedSeries, order: int = 4, type: str = "lowpass", cutoff: float = 1650.0
104# ) -> PairedSeries:
105def butterworth_filter(
106 x0: PairedSeries, order: int, type: str, cutoff: float
107) -> PairedSeries:
108 return PairedSeries()
111def figure_save(x: Figure) -> None:
112 fig, ax = plt.subplots(nrows=1, dpi=x.dpi)
113 fig.set_size_inches(w=x.width, h=x.height)
115 for item in x.series:
116 ax.plot(item.x, item.y)
118 ax.set_xlim([x.xmin, x.xmax])
119 ax.set_ylim([x.ymin, x.ymax])
121 ax.grid()
122 # ax.legend()
123 fig.savefig(x.filename, dpi=x.dpi, bbox_inches="tight")
124 print(f" Saved figure as {x.filename}")
127"""
128Copyright 2023 Sandia National Laboratories
130Notice: This computer software was prepared by National Technology and Engineering Solutions of
131Sandia, LLC, hereinafter the Contractor, under Contract DE-NA0003525 with the Department of Energy
132(DOE). All rights in the computer software are reserved by DOE on behalf of the United States
133Government and the Contractor as provided in the Contract. You are authorized to use this computer
134software for Governmental purposes but it is not to be released or distributed to the public.
135NEITHER THE U.S. GOVERNMENT NOR THE CONTRACTOR MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES
136ANY LIABILITY FOR THE USE OF THIS SOFTWARE. This notice including this sentence must appear on any
137copies of this computer software. Export of this data may require a license from the United States
138Government.
139"""