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

View file

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

View file

@ -124,7 +124,7 @@ class Signal:
self.y,
)
def __sub__(self, other: float | Signal) -> Signal:
def __sub__(self, other: float | NDArray | Signal) -> Signal:
"""
Substract float or a signal to another
"""
@ -146,7 +146,7 @@ class Signal:
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
"""
@ -168,7 +168,7 @@ class Signal:
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
"""
@ -190,6 +190,28 @@ class Signal:
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:
"""
Convert to a numpy array