backscattering-analyzer/src/backscattering_analyzer/display.py

70 lines
2.3 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from backscattering_analyzer import logger
from backscattering_analyzer.experiment import Experiment
def show_projection(
experiment: Experiment,
start_frequency: float | None = None,
end_frequency: float | None = None,
) -> None:
"""
Show projection data with matplotlib
"""
logger.debug(_("showing experiment result"))
from matplotlib.pyplot import (
loglog,
show,
legend,
close,
title,
xlabel,
ylabel,
xlim,
ylim,
grid,
)
reference = experiment.data.reference.sensibility.psd().sqrt()
try:
excited = experiment.data.excited.sensibility.psd().sqrt()
loglog(
experiment.projection_excited.x,
experiment.projection_excited.y,
label=_("projection with excitation"),
) # type: ignore[ReportUnusedCallResult]
loglog(
excited.x,
excited.y,
label=_("detected sensibility with excitation"),
) # type: ignore[ReportUnusedCallResult]
loglog(
(experiment.projection_excited + reference).x,
(experiment.projection_excited + reference).y,
label=_(
"sum: no excitation and projection with excitation"
),
) # type: ignore[ReportUnusedCallResult]
except AttributeError:
logger.debug(
_("no excited signal, will only show reference signal")
)
loglog(
experiment.projection_reference.x,
experiment.projection_reference.y,
label=_("projection without excitation"),
) # type: ignore[ReportUnunsedCallResult]
loglog(
reference.x,
reference.y,
label=_("detected sensibility without excitation"),
) # type: ignore[ReportUnusedCallResult]
legend() # type: ignore[ReportUnusedCallResult]
title(experiment.bench) #  type: ignore[ReportUnusedCallResult]
xlabel(_("frequencies (Hz)")) # type: ignore[ReportUnusedCallResult]
ylabel(_("sensibility ($\\frac{1} {\\sqrt {Hz}}$)")) #  type: ignore[ReportUnusedCallResult]
xlim(5, 100) # type: ignore[ReportUnusedCallResult]
ylim(10e-28, 10e-18) # type: ignore[ReportUnusedCallResult]
grid(True, "both") # type: ignore[ReportUnusedCallResult]
show()
close()
logger.debug(_("experiment result showed"))