-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_experiment_file.py
97 lines (71 loc) · 2.65 KB
/
test_experiment_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# SPDX-FileCopyrightText: 2021-2022 Constantine Evans <const@costi.eu>
# SPDX-License-Identifier: AGPL-3.0-only
from pathlib import Path
import numpy as np
import pytest
from qslib import Experiment
from qslib.normalization import NormToMaxPerWell, NormToMeanPerWell
@pytest.fixture(scope="module")
def exp() -> Experiment:
exp = Experiment.from_file("tests/test.eds")
# We need better sample arrangements:
exp.sample_wells["Sample 1"] = ["A7", "A8"]
exp.sample_wells["Sample 2"] = ["A9", "A10"]
exp.sample_wells["othersample"] = ["B7"]
return exp
@pytest.fixture(scope="module")
def exp_reloaded(
exp: Experiment, tmp_path_factory: pytest.TempPathFactory
) -> Experiment:
tmp_path = tmp_path_factory.mktemp("exp")
exp.save_file(tmp_path / "test_loaded.eds")
return Experiment.from_file(tmp_path / "test_loaded.eds")
def test_props(exp: Experiment, exp_reloaded: Experiment):
assert exp.name == "2020-02-20_170706"
assert exp.info() == str(exp) == exp.summary()
def test_reload(exp: Experiment, exp_reloaded: Experiment):
assert (exp.welldata == exp_reloaded.welldata).all().all()
assert exp.name == exp_reloaded.name
assert exp.protocol == exp_reloaded.protocol
assert exp.plate_setup == exp_reloaded.plate_setup
def test_plots(exp: Experiment):
axf, axt = exp.plot_over_time(
legend=False, figure_kw={"constrained_layout": False}, annotate_stage_lines=True
)
# +2 here is for stage lines
assert len(axf.get_lines()) == 5 * len(exp.all_filters) + 2
assert np.allclose(axf.get_xlim(), (-0.004326652778519521, 0.09085970834891001))
with pytest.raises(ValueError, match="Samples not found"):
exp.plot_over_time("Sampl(e|a)")
with pytest.raises(ValueError, match="Samples not found"):
exp.plot_anneal_melt("Sampl(e|a)")
import matplotlib.pyplot as plt
_, ax = plt.subplots()
axs = exp.plot_over_time(
"Sample .*",
"x1-m1",
stages=2,
temperatures=False,
stage_lines=False,
ax=ax,
marker=".",
legend=False,
)
axs2 = exp.plot_over_time(
["Sample 1", "Sample 2"],
"x1-m1",
stages=2,
temperatures=False,
stage_lines="fluorescence",
annotate_stage_lines=("fluorescence", 0.1),
marker=".",
legend=True,
)
assert len(axs) == 1 == len(axs2)
assert len(axs[0].get_lines()) == 4 == len(axs2[0].get_lines()) - 2
axs = exp.plot_over_time("Sample .*")
exp.plot_anneal_melt(samples="Sample 1")
ax1 = exp.protocol.plot_protocol()
ax2 = exp.plot_protocol()
def test_rawquant(exp: Experiment):
exp.rawdata.loc[:, :]