You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.9 KiB
88 lines
2.9 KiB
from collections import namedtuple |
|
|
|
import pytest |
|
|
|
ExposureSetting = namedtuple("ExposureSetting", ["channel", "time"]) |
|
|
|
|
|
def test_split_data_frame(data_frame_with_params): |
|
from sensospot_data.utils import split_data_frame |
|
|
|
result = split_data_frame(data_frame_with_params, "Well.Row") |
|
|
|
assert set(result.keys()) == set("ABC") |
|
for key, value_df in result.items(): |
|
assert set(value_df["Well.Row"].unique()) == {key} |
|
|
|
|
|
def test_infer_exposure_from_parameters(data_frame_with_params): |
|
from sensospot_data.utils import _set_exposure_data_from_parameters |
|
|
|
result = _set_exposure_data_from_parameters(data_frame_with_params) |
|
|
|
assert all(result["Exposure.Channel"] == result["Parameters.Channel"]) |
|
assert all(result["Exposure.Time"] == result["Parameters.Time"]) |
|
|
|
|
|
def test_infer_exposure_from_parameters_raises_error( |
|
data_frame_without_params, |
|
): |
|
from sensospot_data.utils import _set_exposure_data_from_parameters |
|
|
|
with pytest.raises(ValueError) as excinfo: |
|
_set_exposure_data_from_parameters(data_frame_without_params) |
|
|
|
assert str(excinfo.value).startswith("Exposure Map: measurement") |
|
|
|
|
|
def test_apply_exposure_map(data_frame_with_params): |
|
from sensospot_data.utils import apply_exposure_map |
|
|
|
exposure_map = { |
|
1: ExposureSetting("Cy3", 100), |
|
2: ExposureSetting("Cy5", 15), |
|
3: ExposureSetting("Cy5", 150), |
|
} |
|
|
|
result = apply_exposure_map(data_frame_with_params, exposure_map) |
|
|
|
for key, value in exposure_map.items(): |
|
mask = result["Exposure.Id"] == key |
|
partial = result.loc[mask] |
|
assert set(partial["Exposure.Channel"].unique()) == {value.channel} |
|
assert set(partial["Exposure.Time"].unique()) == {value.time} |
|
|
|
|
|
def test_apply_exposure_map_raises_error(data_frame_with_params): |
|
from sensospot_data.utils import apply_exposure_map |
|
|
|
exposure_map = { |
|
1: ExposureSetting("Cy3", 100), |
|
2: ExposureSetting("Cy5", 15), |
|
"X": ExposureSetting("Cy5", 150), |
|
} |
|
|
|
with pytest.raises(ValueError) as excinfo: |
|
apply_exposure_map(data_frame_with_params, exposure_map) |
|
|
|
assert str(excinfo.value).startswith("Exposure Map differs") |
|
|
|
|
|
def test_apply_exposure_map_from_parameters(data_frame_with_params): |
|
from sensospot_data.utils import apply_exposure_map |
|
|
|
result = apply_exposure_map(data_frame_with_params, None) |
|
|
|
assert all(result["Exposure.Channel"] == result["Parameters.Channel"]) |
|
assert all(result["Exposure.Time"] == result["Parameters.Time"]) |
|
|
|
|
|
def test_apply_exposure_map_from_parameters_raises_error( |
|
data_frame_without_params, |
|
): |
|
from sensospot_data.utils import apply_exposure_map |
|
|
|
with pytest.raises(ValueError) as excinfo: |
|
apply_exposure_map(data_frame_without_params, None) |
|
|
|
assert str(excinfo.value).startswith("Exposure Map: measurement")
|
|
|