|
|
@ -112,7 +112,7 @@ def test_guess_decimal_separator_rewinds_handle(): |
|
|
|
from sensospot_data.parser import _guess_decimal_separator |
|
|
|
from sensospot_data.parser import _guess_decimal_separator |
|
|
|
from io import StringIO |
|
|
|
from io import StringIO |
|
|
|
|
|
|
|
|
|
|
|
handle = StringIO(f"header\n{input}\n") |
|
|
|
handle = StringIO("\n".join(["header", "data_line"])) |
|
|
|
_guess_decimal_separator(handle) |
|
|
|
_guess_decimal_separator(handle) |
|
|
|
|
|
|
|
|
|
|
|
assert next(handle) == "header\n" |
|
|
|
assert next(handle) == "header\n" |
|
|
@ -196,14 +196,14 @@ def test_parse_file(example_file): |
|
|
|
"Pos.Nom.X", |
|
|
|
"Pos.Nom.X", |
|
|
|
"Pos.Nom.Y", |
|
|
|
"Pos.Nom.Y", |
|
|
|
"Spot.Diameter", |
|
|
|
"Spot.Diameter", |
|
|
|
"Field.Row", |
|
|
|
"Well.Row", |
|
|
|
"Field.Column", |
|
|
|
"Well.Column", |
|
|
|
"Exposure.Id", |
|
|
|
"Exposure.Id", |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert set(result.columns) == columns |
|
|
|
assert set(result.columns) == columns |
|
|
|
assert result["Field.Row"][0] == "A" |
|
|
|
assert result["Well.Row"][0] == "A" |
|
|
|
assert result["Field.Column"][0] == 1 |
|
|
|
assert result["Well.Column"][0] == 1 |
|
|
|
assert result["Exposure.Id"][0] == 1 |
|
|
|
assert result["Exposure.Id"][0] == 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -264,8 +264,8 @@ def test_parse_folder(example_dir): |
|
|
|
data_frame = parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
data_frame = parse_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
assert len(data_frame) == 36 * 3 * 100 |
|
|
|
assert len(data_frame) == 36 * 3 * 100 |
|
|
|
assert len(data_frame["Field.Row"].unique()) == 3 |
|
|
|
assert len(data_frame["Well.Row"].unique()) == 3 |
|
|
|
assert len(data_frame["Field.Column"].unique()) == 12 |
|
|
|
assert len(data_frame["Well.Column"].unique()) == 12 |
|
|
|
assert len(data_frame["Exposure.Id"].unique()) == 3 |
|
|
|
assert len(data_frame["Exposure.Id"].unique()) == 3 |
|
|
|
assert len(data_frame["Pos.Id"].unique()) == 100 |
|
|
|
assert len(data_frame["Pos.Id"].unique()) == 100 |
|
|
|
|
|
|
|
|
|
|
@ -308,161 +308,6 @@ def test_sanity_check_raises_value_error(example_dir): |
|
|
|
_sanity_check(data_frame) |
|
|
|
_sanity_check(data_frame) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_search_channel_info_file_ok(example_dir): |
|
|
|
|
|
|
|
from sensospot_data.parser import _search_channel_info_file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _search_channel_info_file(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result.suffix == ".svexp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_search_channel_info_file_no_parameters_folder(example_dir): |
|
|
|
|
|
|
|
from sensospot_data.parser import _search_channel_info_file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _search_channel_info_file(example_dir / EXAMPLE_DIR_WO_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result is None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_search_channel_info_file_no_parameters_file(tmpdir): |
|
|
|
|
|
|
|
from sensospot_data.parser import _search_channel_info_file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params_dir = tmpdir / "Parameters" |
|
|
|
|
|
|
|
params_dir.mkdir() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _search_channel_info_file(tmpdir) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result is None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_channel_info(example_dir): |
|
|
|
|
|
|
|
from sensospot_data.parser import ( |
|
|
|
|
|
|
|
_search_channel_info_file, |
|
|
|
|
|
|
|
_parse_channel_info, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params = _search_channel_info_file(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
|
|
|
|
result = _parse_channel_info(params) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert set(result.keys()) == {1, 2, 3} |
|
|
|
|
|
|
|
assert result[1] == ("green", 100) |
|
|
|
|
|
|
|
assert result[2] == ("red", 150) |
|
|
|
|
|
|
|
assert result[3] == ("red", 15) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_valid_exposure_map_provided_ok(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parser import ( |
|
|
|
|
|
|
|
_get_valid_exposure_map, |
|
|
|
|
|
|
|
ExposureInfo, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dummy_value = ExposureInfo(None, None) |
|
|
|
|
|
|
|
exposure_map = {1: dummy_value, 2: dummy_value, 3: dummy_value} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _get_valid_exposure_map( |
|
|
|
|
|
|
|
"/nonexistent", exposure_df, exposure_map=exposure_map |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result == exposure_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_valid_exposure_map_provided_not_ok(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parser import _get_valid_exposure_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exposure_map = {1: None, 2: None} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _get_valid_exposure_map( |
|
|
|
|
|
|
|
"/nonexistent", exposure_df, exposure_map=exposure_map |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert set(result.keys()) == {1, 2, 3} |
|
|
|
|
|
|
|
assert all(v == (None, None) for v in result.values()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_valid_exposure_map_info_from_file_ok(example_dir, exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parser import _get_valid_exposure_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _get_valid_exposure_map( |
|
|
|
|
|
|
|
example_dir / EXAMPLE_DIR_WITH_PARAMS, exposure_df, exposure_map=None |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert set(result.keys()) == {1, 2, 3} |
|
|
|
|
|
|
|
assert result[1] == ("green", 100) |
|
|
|
|
|
|
|
assert result[2] == ("red", 150) |
|
|
|
|
|
|
|
assert result[3] == ("red", 15) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_valid_exposure_map_info_from_file_not_ok( |
|
|
|
|
|
|
|
example_dir, exposure_df |
|
|
|
|
|
|
|
): |
|
|
|
|
|
|
|
from sensospot_data.parser import _get_valid_exposure_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data_frame = exposure_df.drop(exposure_df.index[1]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _get_valid_exposure_map( |
|
|
|
|
|
|
|
example_dir / EXAMPLE_DIR_WITH_PARAMS, data_frame, exposure_map=None |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert set(result.keys()) == {1, 3} |
|
|
|
|
|
|
|
assert all(v == (None, None) for v in result.values()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_augment_exposure_map(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parser import ( |
|
|
|
|
|
|
|
_augment_exposure_map, |
|
|
|
|
|
|
|
ExposureInfo, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exposure_map = { |
|
|
|
|
|
|
|
1: ExposureInfo("red", 10), |
|
|
|
|
|
|
|
2: ExposureInfo("green", 20), |
|
|
|
|
|
|
|
3: ExposureInfo("blue", 50), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _augment_exposure_map(exposure_df, exposure_map) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result["Exposure.Id"][0] == 1 |
|
|
|
|
|
|
|
assert result["Exposure.Channel"][0] == "red" |
|
|
|
|
|
|
|
assert result["Exposure.Time"][0] == 10 |
|
|
|
|
|
|
|
assert result["Exposure.Id"][1] == 2 |
|
|
|
|
|
|
|
assert result["Exposure.Channel"][1] == "green" |
|
|
|
|
|
|
|
assert result["Exposure.Time"][1] == 20 |
|
|
|
|
|
|
|
assert result["Exposure.Id"][2] == 3 |
|
|
|
|
|
|
|
assert result["Exposure.Channel"][2] == "blue" |
|
|
|
|
|
|
|
assert result["Exposure.Time"][2] == 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_process_folder_with_exposure_map(example_dir): |
|
|
|
|
|
|
|
from sensospot_data.parser import _process_folder |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _process_folder(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert len(result) == 36 * 100 * 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected = [(1, "green", 100), (2, "red", 150), (3, "red", 15)] |
|
|
|
|
|
|
|
for exposure_id, channel, time in expected: |
|
|
|
|
|
|
|
mask = result["Exposure.Id"] == exposure_id |
|
|
|
|
|
|
|
example_row = result.loc[mask].iloc[1] |
|
|
|
|
|
|
|
assert example_row["Exposure.Channel"] == channel |
|
|
|
|
|
|
|
assert example_row["Exposure.Time"] == time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_process_folder_without_exposure_map(example_dir): |
|
|
|
|
|
|
|
from sensospot_data.parser import _process_folder |
|
|
|
|
|
|
|
from pandas import isnull |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _process_folder(example_dir / EXAMPLE_DIR_WO_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert len(result) == 96 * 100 * 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for exposure_id in range(1, 4): |
|
|
|
|
|
|
|
mask = result["Exposure.Id"] == exposure_id |
|
|
|
|
|
|
|
example_row = result.loc[mask].iloc[1] |
|
|
|
|
|
|
|
print(type(example_row["Exposure.Channel"])) |
|
|
|
|
|
|
|
assert isnull(example_row["Exposure.Channel"]) |
|
|
|
|
|
|
|
assert isnull(example_row["Exposure.Time"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_process_folder_creates_cache(dir_for_caching): |
|
|
|
def test_process_folder_creates_cache(dir_for_caching): |
|
|
|
from sensospot_data.parser import ( |
|
|
|
from sensospot_data.parser import ( |
|
|
|
process_folder, |
|
|
|
process_folder, |
|
|
@ -503,7 +348,7 @@ def test_process_folder_read_cache_fails_silently( |
|
|
|
|
|
|
|
|
|
|
|
result = process_folder(dir_for_caching) |
|
|
|
result = process_folder(dir_for_caching) |
|
|
|
|
|
|
|
|
|
|
|
assert result["Field.Row"][0] == "A" |
|
|
|
assert result["Well.Row"][0] == "A" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_cache_table_name(): |
|
|
|
def test_get_cache_table_name(): |
|
|
@ -528,7 +373,7 @@ def test_process_folder_read_cache_no_cache_arg(dir_for_caching, exposure_df): |
|
|
|
|
|
|
|
|
|
|
|
result = process_folder(dir_for_caching, use_cache=False) |
|
|
|
result = process_folder(dir_for_caching, use_cache=False) |
|
|
|
|
|
|
|
|
|
|
|
assert result["Field.Row"][0] == "A" |
|
|
|
assert result["Well.Row"][0] == "A" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_process_folder_writes_cache(dir_for_caching): |
|
|
|
def test_process_folder_writes_cache(dir_for_caching): |
|
|
|