179 lines
5.8 KiB
Python
Executable file
179 lines
5.8 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
from gettext import install
|
|
from backscattering_analyzer.display import show_projection # type: ignore[reportMissingTypeStubs]
|
|
from backscattering_analyzer.experiment import Experiment # type: ignore[reportMissingTypeStubs]
|
|
from logging import basicConfig, getLogger
|
|
from rich.console import Console
|
|
from rich.theme import Theme
|
|
from rich.logging import RichHandler
|
|
from warnings import filterwarnings
|
|
from command_parser.flag import Flag # type: ignore[reportMissingTypeStubs]
|
|
from command_parser.value import Value # type: ignore[reportMissingTypeStubs]
|
|
from command_parser.parser import parse # type: ignore[reportMissingTypeStubs]
|
|
from sys import argv
|
|
from importlib.metadata import version
|
|
|
|
install(__name__)
|
|
|
|
filterwarnings("error")
|
|
|
|
flags = [
|
|
Flag("help"),
|
|
Flag("version", single_char="V"),
|
|
Flag("verbose"),
|
|
Flag("full"),
|
|
]
|
|
values = [
|
|
Value("date", "2023_03_24"),
|
|
Value("bench", "SDB1"),
|
|
Value("file", "values.toml", single_char="F"),
|
|
Value("vibration-frequency", "0.2"),
|
|
]
|
|
parse(" ".join(argv[1:]), flags, values)
|
|
|
|
if flags[0].value:
|
|
theme = Theme(
|
|
{
|
|
"main": "white bold",
|
|
"option": "grey50 italic",
|
|
"argument": "red",
|
|
"description": "green italic",
|
|
}
|
|
)
|
|
console = Console(theme=theme)
|
|
help = (
|
|
"[main]display[/main] [option]\\[options][/option]"
|
|
"\n [argument]-b --bench[/argument] [description]bench of the experiment[/description]"
|
|
"\n [argument]-d --date[/argument] [description]date of the experiment[/description]"
|
|
"\n [argument]-h --help[/argument] [description]print this help and exit[/description]"
|
|
"\n [argument]-f --full[/argument] [description]run experiment with all benches with all dates[/description]"
|
|
"\n [argument]-F --file[/argument] [description]file containing all the parameters values (toml file)[/decription]"
|
|
"\n [argument]-v --verbose[/argument] [description]be verbose[/description]"
|
|
"\n [argument]-V --version[/argument] [description]print version number and exit[/description]"
|
|
)
|
|
console.print(help)
|
|
exit(0)
|
|
|
|
if flags[1].value:
|
|
version = (
|
|
"Versions\n"
|
|
"numpy {numpy}\n"
|
|
"scipy {scipy}\n"
|
|
"matplotlib {matplotlib}\n"
|
|
"science_signal {science_signal}\n"
|
|
"backscattering_analyzer {backscattering_analyzer}\n"
|
|
"command_parser {command_parser}\n"
|
|
"script 0.1.0\n"
|
|
).format(
|
|
numpy=version("numpy"),
|
|
scipy=version("scipy"),
|
|
matplotlib=version("matplotlib"),
|
|
science_signal=version("science_signal"),
|
|
backscattering_analyzer=version("backscattering_analyzer"),
|
|
command_parser=version("command_parser"),
|
|
)
|
|
console = Console()
|
|
console.print(version)
|
|
exit(0)
|
|
|
|
if flags[2].value:
|
|
level = "DEBUG"
|
|
else:
|
|
level = "INFO"
|
|
|
|
|
|
basicConfig(
|
|
level=level,
|
|
format="%(message)s",
|
|
datefmt="[%X]",
|
|
handlers=[RichHandler()],
|
|
)
|
|
|
|
logger = getLogger(__name__)
|
|
|
|
if flags[3].value:
|
|
logger.debug(_("loading every experiments"))
|
|
experiments: list[Experiment] = []
|
|
results: dict[str, float | None] = dict({})
|
|
for bench in ["SDB1", "SDB2", "SNEB", "SWEB"]:
|
|
if bench in ["SDB1", "SDB2"]:
|
|
experiment = Experiment(
|
|
bench,
|
|
"2023_03_24",
|
|
values[2].value,
|
|
float(values[3].value),
|
|
)
|
|
if bench == "SDB1":
|
|
start_frequency, end_frequency = 12.5, 30
|
|
else:
|
|
start_frequency, end_frequency = 40, 50
|
|
experiment.factors = experiment.fit_factors(
|
|
start_frequency=start_frequency,
|
|
end_frequency=end_frequency,
|
|
)
|
|
results[
|
|
"{bench}-{date}".format(
|
|
bench=bench,
|
|
date="2023_03_24",
|
|
)
|
|
] = experiment.factors["true"]
|
|
elif bench == "SNEB":
|
|
for date in ["2023_03_24", "2024_01_21"]:
|
|
experiment = Experiment(
|
|
bench,
|
|
date,
|
|
values[2].value,
|
|
float(values[3].value),
|
|
)
|
|
experiment.factors = experiment.fit_factors(
|
|
start_frequency = 15,
|
|
end_frequency = 100,
|
|
)
|
|
results[
|
|
"{bench}-{date}".format(
|
|
bench=bench,
|
|
date=date
|
|
)
|
|
] = experiment.factors["true"]
|
|
else: # bench == SWEB
|
|
for date in ["2023_03_24", "2023_12_20"]:
|
|
experiment = Experiment(
|
|
bench,
|
|
date,
|
|
values[2].value,
|
|
float(values[3].value),
|
|
)
|
|
experiment.factors = experiment.fit_factors(
|
|
start_frequency = 15,
|
|
end_frequency = 100,
|
|
)
|
|
results[
|
|
"{bench}-{date}".format(
|
|
bench=bench,
|
|
date=date
|
|
)
|
|
] = experiment.factors["true"]
|
|
console = Console()
|
|
console.print(results)
|
|
|
|
else:
|
|
experiment = Experiment(
|
|
values[1].value, values[0].value, values[2].value, float(values[3].value)
|
|
)
|
|
|
|
if experiment.bench == "SDB1":
|
|
start_frequency, end_frequency = 12.5, 30
|
|
elif experiment.bench == "SDB2":
|
|
start_frequency, end_frequency = 40, 50
|
|
else:
|
|
start_frequency, end_frequency = 15, 100
|
|
|
|
experiment.factors = experiment.fit_factors(
|
|
start_frequency=start_frequency,
|
|
end_frequency=end_frequency,
|
|
)
|
|
|
|
show_projection(experiment, start_frequency, end_frequency)
|
|
|
|
exit(0)
|