Small changes

This commit is contained in:
linarphy 2024-06-04 17:10:25 +02:00
parent 1e4dc0975b
commit 0db64c03ab
No known key found for this signature in database
GPG key ID: E61920135EFF2295
3 changed files with 79 additions and 30 deletions

View file

@ -16,7 +16,16 @@ def show_projection(
Show projection data with matplotlib
"""
logger.debug(_("showing experiment result"))
from matplotlib.pyplot import loglog, show, legend, close, vlines
from matplotlib.pyplot import (
loglog,
show,
legend,
close,
vlines,
title,
xlabel,
ylabel,
)
excited = experiment.signals["excited"].psd().sqrt()
reference = experiment.signals["reference"].psd().sqrt()
@ -25,13 +34,14 @@ def show_projection(
experiment.projection.y,
label="projection",
) # type: ignore[ReportUnusedCallResult]
loglog(excited.x, excited.y, label="excited bench") # type: ignore[ReportUnusedCallResult]
loglog(reference.x, reference.y, label="reference bench") # type: ignore[ReportUnusedCallResult]
loglog(excited.x, excited.y, label=_("excited bench")) # type: ignore[ReportUnusedCallResult]
loglog(reference.x, reference.y, label=_("reference bench")) # type: ignore[ReportUnusedCallResult]
loglog(
(experiment.projection + reference).x,
(experiment.projection + reference).y,
label="sum reference + excited",
label=_("sum reference + excited"),
) # type: ignore[ReportUnusedCallResult]
"""
if start_frequency is not None:
vlines(
[
@ -39,7 +49,7 @@ def show_projection(
],
min(experiment.projection.y),
max(experiment.projection.y),
color = 'k',
color="k",
) # type: ignore[ReportUnusedCallResult]
if end_frequency is not None:
vlines(
@ -48,9 +58,13 @@ def show_projection(
],
min(experiment.projection.y),
max(experiment.projection.y),
color = 'k',
color="k",
) # type: ignore[ReportUnusedCallResult]
"""
legend() # type: ignore[ReportUnusedCallResult]
title(experiment.bench) # type: ignore[ReportUnusedCallResult]
xlabel(_("frequency (Hz)")) # type: ignore[ReportUnusedCallResult]
ylabel(_("stray ($\\frac{1} {\\sqrt {Hz}}$)")) # type: ignore[ReportUnusedCallResult]
show()
close()
logger.debug(_("experiment result showed"))

View file

@ -90,6 +90,7 @@ def load_coupling(
date: str,
file: str,
powers: dict[str, float],
model_powers: dict[str, float],
) -> list[Signal]:
"""
Load and correct coupling date from modelisation
@ -141,21 +142,27 @@ def load_coupling(
)
)
if model_powers["laser"] != 0:
if bench in ["SDB1", "SDB2"]:
modelisation_signal[0] = (
modelisation_signal[0]
* (powers["laser"] / 40)
* (powers["dark_fringe"] / 5e-6) ** (1 / 2)
* (powers["laser"] / model_powers["laser"])
* (powers["dark_fringe"] / model_powers["dark_fringe"])
** (1 / 2)
) # radiation
modelisation_signal[1] = modelisation_signal[1] * (
powers["dark_fringe"] / 5e-6
powers["dark_fringe"] / model_powers["dark_fringe"]
) ** (1 / 2) # phase
elif bench in ["SWEB", "SNEB"]:
modelisation_signal[1] = (
modelisation_signal[1] * powers["laser"] / 40
modelisation_signal[1]
* powers["laser"]
/ model_powers["laser"]
) # radiation
elif bench in ["SIB2", "SPRB"]:
logger.info(
_("cannot fix projection power for SIB2 and SPRB coupling")
_(
"cannot fix projection power for SIB2 and SPRB coupling"
)
)
return modelisation_signal

View file

@ -1,10 +1,9 @@
from pathlib import Path
from tomllib import load
from numpy import argmin, float64, pi, log10
from numpy import argmin, pi, log10
from numpy.core.function_base import logspace
from numpy.core.multiarray import array
from numpy.typing import NDArray
from science_signal import interpolate
from science_signal.signal import Signal
from backscattering_analyzer import logger
@ -221,6 +220,36 @@ class Experiment:
)
logger.debug(_("movement processed"))
try:
correct_power = bool(values["dates"][date]["correct-power"])
if correct_power:
model_powers = {
"laser": values["dates"][date]["coupling"]["laser"],
"dark_fringe": values["dates"][date]["coupling"][
"dark_fringe"
],
}
else:
model_powers = {
"laser": 0,
"dark_fringe": 0,
}
except KeyError as error:
print(error)
logger.warning(
_(
"cannot find if coupling values should be "
+ "corrected due to the diff between power used in "
+ "model and the real one. No correction will be "
+ "applied"
)
)
correct_power = False
model_powers = {
"laser": 0,
"dark_fringe": 0,
}
try:
self.coupling = load_coupling(
data_folder,
@ -228,6 +257,7 @@ class Experiment:
date,
self.modelisation_file,
self.powers,
model_powers,
)
logger.debug(_("coupling signals successfully loaded"))
except OSError:
@ -316,9 +346,7 @@ class Experiment:
) = self.get_factors(start=start_frequency, end=end_frequency)
for index in range(precision):
logger.debug(
_("search for a local minimum")
)
logger.debug(_("search for a local minimum"))
x = logspace(log10(scatter_min), log10(scatter_max), 1000)