Add config file and fix movement unit

This commit is contained in:
linarphy 2024-05-23 13:27:25 +02:00
parent 74cce86cef
commit e1d0585ac4
No known key found for this signature in database
GPG key ID: E61920135EFF2295
3 changed files with 58 additions and 44 deletions

View file

@ -42,9 +42,9 @@ class Analyzer:
self.settings.log("loading bench movement") self.settings.log("loading bench movement")
try: try:
data = loadtxt(file).T data = loadtxt(file).T
self.bench_movement = Signal( self.bench_movement = (
data[0], data[1], self.settings Signal(data[0], data[1], self.settings) * 1e-6
) ) # um
except OSError: except OSError:
raise Exception("{file} does not exist".format(file=file)) raise Exception("{file} does not exist".format(file=file))
@ -56,8 +56,8 @@ class Analyzer:
self.settings.log("loading mirror movement") self.settings.log("loading mirror movement")
try: try:
data = loadtxt(file).T data = loadtxt(file).T
self.mirror_movement = Signal( self.mirror_movement = (
data[0], data[1], self.settings Signal(data[0], data[1], self.settings) * 1e-6
) )
except OSError: except OSError:
raise Exception("{file} does not exist".format(file=file)) raise Exception("{file} does not exist".format(file=file))
@ -146,10 +146,7 @@ class Analyzer:
frequencies = zeros(results.shape[1]) frequencies = zeros(results.shape[1])
for index in range(len(self.coupling)): for index in range(len(self.coupling)):
phase = ( phase = (index + 1) * 4 * pi / self.settings.wavelength
(index + 1) * 4 * pi / (self.settings.wavelength * 1e6)
# * 1e6 sinon la courbe n'est plus du tout la même
)
factor_n = (self.movement * phase).sin().psd().sqrt() factor_n = (self.movement * phase).sin().psd().sqrt()
coupling_n = self.coupling[0].abs() coupling_n = self.coupling[0].abs()
@ -163,22 +160,12 @@ class Analyzer:
# no need to redefine it each time but simpler here # no need to redefine it each time but simpler here
frequencies = factor_n.x frequencies = factor_n.x
""" # from theoric equation
results[index] = ( results[index] = (
sqrt(self.settings.scattering_factor[index]) sqrt(self.settings.scattering_factor[index])
* self.settings.power_in * self.settings.power_in
/ self.settings.power_out / self.settings.power_out
* (coupling_n * factor_n + coupling_d * factor_d).y * (coupling_n * factor_n + coupling_d * factor_d).y
) )
"""
results[index] = ( # from matlab
sqrt(self.settings.scattering_factor[index])
* self.settings.wavelength
/ (4 * pi)
* (coupling_n**2 * factor_n + coupling_d**2 * factor_d)
.sqrt()
.y
) ** 2
self.projection = Signal( self.projection = Signal(
frequencies, frequencies,

View file

@ -1,4 +1,5 @@
from pathlib import Path from pathlib import Path
from tomllib import load
from rich.console import Console from rich.console import Console
from rich.theme import Theme from rich.theme import Theme
@ -29,13 +30,12 @@ class Settings:
self.verbose = False self.verbose = False
self.bench = "SDB1" self.bench = "SDB1"
self.date = "2023_03_24" self.date = "2023_03_24"
self.folder = Path("/home/demagny/data")
self.wavelength = 1.064e-6 # m
self.calib_bench = 1.15 with open("values.toml", "rb") as file:
self.calib_mirror = 1.15 values = load(file)
self.scattering_factor = [1.3e-4, 1e-16] # parameter to change
self.vibration_frequency = 0.2 self.folder = Path(values["general"]["data_folder"])
self.wavelength = values["interferometer"]["wavelength"]
index = 0 index = 0
while index < len(options): while index < len(options):
@ -125,22 +125,27 @@ class Settings:
pass pass
index += 1 index += 1
if self.date == "2023_03_24": if not self.bench in values["benches"].keys():
self.modelisation = "scatterCouplingO4.mat" raise ValueError("unknow bench {}".format(self.bench))
self.power_in = 23 # W
self.power_out = 8e-3 # W self.calib_mirror = values["benches"][self.bench]["calib"][
elif self.date == "2023_12_21": "mirror"
self.modelisation = "scatterCouplingMisalignSR.mat" ]
self.power_in = 12.1 # W self.calib_bench = values["benches"][self.bench]["calib"][
self.power_out = 8e-3 # W "bench"
elif self.date == "2024_01_21": ]
self.modelisation = "scatterCouplingMisalignSR.mat" self.scattering_factor = values["benches"][self.bench][
self.power_in = 12.1 # W "scatter_factor"
self.power_out = 8e-3 # W ]
else:
self.modelisation = "scatterCouplingO4.mat" if not self.date in values["dates"].keys():
self.power_in = 23 # W raise ValueError("unknow date {}".format(self.date))
self.power_out = 8e-3 # W
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.vibration_frequency = 0.2
def bench_file(self) -> Path: def bench_file(self) -> Path:
return self.folder / ( return self.folder / (

View file

@ -124,7 +124,7 @@ class Signal:
self.y, self.y,
) )
def __sub__(self, other: float | Signal) -> Signal: def __sub__(self, other: float | NDArray | Signal) -> Signal:
""" """
Substract float or a signal to another Substract float or a signal to another
""" """
@ -146,7 +146,7 @@ class Signal:
self.settings, self.settings,
) )
def __add__(self, other: float | Signal) -> Signal: def __add__(self, other: float | NDArray | Signal) -> Signal:
""" """
Add a float or a signal to another Add a float or a signal to another
""" """
@ -168,7 +168,7 @@ class Signal:
self.settings, self.settings,
) )
def __mul__(self, other: float | Signal) -> Signal: def __mul__(self, other: float | NDArray | Signal) -> Signal:
""" """
Multiply a signal by a value or another signal Multiply a signal by a value or another signal
""" """
@ -190,6 +190,28 @@ class Signal:
self.settings, self.settings,
) )
def __truediv__(self, other) -> Signal:
"""
Divide a signal by a value
"""
if isinstance(other, Signal):
if len(other) != len(self):
signal_1, signal_2 = interpolate((self, other))
else:
signal_1, signal_2 = self, other
return Signal(
signal_1.frequencies,
signal_1.y / signal_2.y,
self.settings,
)
else:
return Signal(
self.x,
self.y / other,
self.settings,
)
def __array__(self) -> NDArray: def __array__(self) -> NDArray:
""" """
Convert to a numpy array Convert to a numpy array