Update typing

This commit is contained in:
linarphy 2024-05-23 15:49:40 +02:00
parent e1d0585ac4
commit 01d23573e4
No known key found for this signature in database
GPG key ID: E61920135EFF2295
6 changed files with 57 additions and 45 deletions

View file

@ -39,3 +39,6 @@ line-length = 72
quote-style = "double"
indent-style = "space"
docstring-code-format = true
[tool.basedpyright]
typeCheckingMode = "all"

View file

@ -1,16 +1,17 @@
from __future__ import annotations
from typing import Any
from numpy.typing import NDArray
from numpy import arange
from numpy import arange, float64
def interpolate_abciss(signals: tuple[Signal, ...]) -> NDArray:
def interpolate_abciss(signals: tuple[Signal, ...]) -> NDArray[float64]:
"""
return the axis that would be used by the interpolate function
"""
rates = [signal.rate for signal in signals]
rates: list[float] = [signal.rate for signal in signals]
start = max([signal.x[0] for signal in signals])
end = min([signal.x[-1] for signal in signals])
start: float = max([signal.x[0] for signal in signals])
end: float = min([signal.x[-1] for signal in signals])
return arange(start, end, 1 / max(rates))

View file

@ -1,5 +1,5 @@
# utils
from sys import argv as options
from sys import argv
from backscattering_analyzer.settings import Settings
from backscattering_analyzer.signal import Signal
from backscattering_analyzer import interpolate, interpolate_abciss
@ -15,10 +15,17 @@ class Analyzer:
Utility class to study backscattering light in VIRGO
"""
def __init__(self, arguments: list = []) -> None:
self.settings = Settings(options[1:] + arguments)
def __init__(self, arguments: None | list[str] | str = None) -> None:
if arguments is None:
options = []
elif isinstance(arguments, str):
options = arguments.split(" ")
else:
options = arguments
self.settings = Settings(argv[1:] + options)
self.load()
self.process_movement()
self.compute_light()
def load(self):
"""
@ -126,7 +133,7 @@ class Analyzer:
.low_pass_filter(5 * self.settings.vibration_frequency)
)
def compute_light(self):
def compute_light(self) -> None:
"""
Compute psd of the computed projection with current bench
excitation
@ -169,7 +176,6 @@ class Analyzer:
self.projection = Signal(
frequencies,
sqrt(sum(results)),
sum(results),
self.settings,
)
return self.projection

View file

@ -7,7 +7,7 @@ from rich.traceback import install as traceback_install
class Settings:
def __init__(self, options: list):
def __init__(self, options: list[str]) -> None:
self.theme = Theme(
{
"main": "white bold",
@ -17,7 +17,7 @@ class Settings:
}
)
self.console = Console(theme=self.theme)
traceback_install(console=self.console, show_locals=True)
_ = traceback_install(console=self.console, show_locals=True)
self.version = "0.1.0"
self.help = (
"[main]display[/main] [option]\\[options][/option]"
@ -35,7 +35,7 @@ class Settings:
values = load(file)
self.folder = Path(values["general"]["data_folder"])
self.wavelength = values["interferometer"]["wavelength"]
self.wavelength: float = values["interferometer"]["wavelength"]
index = 0
while index < len(options):
@ -125,25 +125,27 @@ class Settings:
pass
index += 1
if not self.bench in values["benches"].keys():
if self.bench not in values["benches"].keys():
raise ValueError("unknow bench {}".format(self.bench))
self.calib_mirror = values["benches"][self.bench]["calib"][
"mirror"
]
self.calib_bench = values["benches"][self.bench]["calib"][
"bench"
]
self.scattering_factor = values["benches"][self.bench][
"scatter_factor"
]
self.calib_mirror: float = values["benches"][self.bench][
"calib"
]["mirror"]
self.calib_bench: float = values["benches"][self.bench][
"calib"
]["bench"]
self.scattering_factor: list[float] = values["benches"][
self.bench
]["scatter_factor"]
if not self.date in values["dates"].keys():
if self.date not in values["dates"].keys():
raise ValueError("unknow date {}".format(self.date))
self.power_in = values["dates"][self.date]["power_in"]
self.power_out = values["dates"][self.date]["power_out"]
self.modelisation = values["dates"][self.date]["modelisation"]
self.power_in: float = values["dates"][self.date]["power_in"]
self.power_out: float = values["dates"][self.date]["power_out"]
self.modelisation: str = values["dates"][self.date][
"modelisation"
]
self.vibration_frequency = 0.2
@ -185,6 +187,6 @@ class Settings:
def coupling_name(self) -> str:
return "{bench}coupling".format(bench=self.bench)
def log(self, message) -> None:
def log(self, message: str) -> None:
if self.verbose:
self.console.log(message, _stack_offset=2)

View file

@ -1,12 +1,12 @@
from __future__ import annotations
from numpy.typing import NDArray
from numpy.typing import ArrayLike, NDArray
from backscattering_analyzer.settings import Settings
from backscattering_analyzer import interpolate
from scipy.signal import welch, detrend
from scipy.fft import irfft, rfft, rfftfreq
from scipy.interpolate import CubicSpline
from numpy import where, sin, cos, array, sqrt
from numpy import where, sin, cos, array, sqrt, float64
class Signal:
@ -15,7 +15,7 @@ class Signal:
"""
def __init__(
self, x: NDArray, value: NDArray, settings: Settings
self, x: NDArray[float64], value: NDArray[float64], settings: Settings
) -> None:
if x.shape != value.shape:
raise Exception("x and y does not have the same dimension")
@ -63,7 +63,7 @@ class Signal:
self.settings,
)
def low_pass_filter(self, cutoff):
def low_pass_filter(self, cutoff: float) -> Signal:
"""
Cut higher frequencies than cutoff for this signal
"""
@ -124,7 +124,7 @@ class Signal:
self.y,
)
def __sub__(self, other: float | NDArray | Signal) -> Signal:
def __sub__(self, other: ArrayLike | Signal) -> Signal:
"""
Substract float or a signal to another
"""
@ -146,7 +146,7 @@ class Signal:
self.settings,
)
def __add__(self, other: float | NDArray | Signal) -> Signal:
def __add__(self, other: ArrayLike | Signal) -> Signal:
"""
Add a float or a signal to another
"""
@ -168,7 +168,7 @@ class Signal:
self.settings,
)
def __mul__(self, other: float | NDArray | Signal) -> Signal:
def __mul__(self, other: ArrayLike | Signal) -> Signal:
"""
Multiply a signal by a value or another signal
"""
@ -190,7 +190,7 @@ class Signal:
self.settings,
)
def __truediv__(self, other) -> Signal:
def __truediv__(self, other: ArrayLike | Signal) -> Signal:
"""
Divide a signal by a value
"""
@ -212,7 +212,7 @@ class Signal:
self.settings,
)
def __array__(self) -> NDArray:
def __array__(self) -> NDArray[float64]:
"""
Convert to a numpy array
"""
@ -233,7 +233,7 @@ class Signal:
self.settings,
)
def __getitem__(self, key) -> NDArray:
def __getitem__(self, key: int) -> float64:
"""
Get an element of the signal
"""
@ -245,7 +245,7 @@ class Signal:
"""
return len(self.x)
def __pow__(self, other) -> Signal:
def __pow__(self, other: float | int) -> Signal:
"""
Signal put to power
"""

View file

@ -4,23 +4,23 @@
wavelength = 1.064e-6
[benches]
[benches.SDB1]
scatter_factor = [1.3e-4, 0]
scatter_factor = [1.5e-9, 0]
[benches.SDB1.calib]
bench = 1.15
mirror = 1.15
[benches.SDB2]
scatter_factor = [6e-6, 0]
scatter_factor = [2.4e-11, 0]
[benches.SDB2.calib]
bench = 1.3
mirror = 1.3
[benches.SIB2]
scatter_factor = [1e-3, 0]
scatter_factor = [0, 0]
[benches.SIB2.calib]
bench = 1.0
mirror = 1.0
[benches.SNEB]
scatter_factor = [8e-3, 0]
scatter_factor = [9.5e-9, 0]
[benches.SNEB.calib]
bench = 1.01
mirror = 1.101
@ -30,7 +30,7 @@
bench = 1.0
mirror = 1.0
[benches.SWEB]
scatter_factor = [4e-3, 0]
scatter_factor = [4.7e-9, 0]
[benches.SWEB.calib]
bench = -0.98
mirror = 0.98