|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
|
|
import pandas |
|
|
|
from .conftest import EXAMPLE_DIR_WO_PARAMS, EXAMPLE_DIR_WITH_PARAMS |
|
|
|
from .conftest import EXAMPLE_DIR_WO_PARAMS, EXAMPLE_DIR_WITH_PARAMS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,10 +44,13 @@ def test_parse_channel_info(example_dir): |
|
|
|
) |
|
|
|
) |
|
|
|
result = _parse_measurement_params(params) |
|
|
|
result = _parse_measurement_params(params) |
|
|
|
|
|
|
|
|
|
|
|
assert set(result.keys()) == {1, 2, 3} |
|
|
|
expected = pandas.DataFrame({ |
|
|
|
assert result[1] == ("green", 100) |
|
|
|
"Exposure.Id": [1,2,3], |
|
|
|
assert result[2] == ("red", 150) |
|
|
|
"Parameters.Channel": ["green", "red", "red"], |
|
|
|
assert result[3] == ("red", 15) |
|
|
|
"Parameters.Time" : [100.0, 150.0, 15.0] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result.equals(expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_measurement_params_file_found(example_dir): |
|
|
|
def test_get_measurement_params_file_found(example_dir): |
|
|
@ -54,10 +58,13 @@ def test_get_measurement_params_file_found(example_dir): |
|
|
|
|
|
|
|
|
|
|
|
result = get_measurement_params(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
result = get_measurement_params(example_dir / EXAMPLE_DIR_WITH_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
assert set(result.keys()) == {1, 2, 3} |
|
|
|
expected = pandas.DataFrame({ |
|
|
|
assert result[1] == ("green", 100) |
|
|
|
"Exposure.Id": [1,2,3], |
|
|
|
assert result[2] == ("red", 150) |
|
|
|
"Parameters.Channel": ["green", "red", "red"], |
|
|
|
assert result[3] == ("red", 15) |
|
|
|
"Parameters.Time" : [100.0, 150.0, 15.0] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result.equals(expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_measurement_params_file_not_found(example_dir): |
|
|
|
def test_get_measurement_params_file_not_found(example_dir): |
|
|
@ -68,28 +75,6 @@ def test_get_measurement_params_file_not_found(example_dir): |
|
|
|
assert result is None |
|
|
|
assert result is None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_measurement_params(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parameters import ExposureInfo, _add_measurement_params |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params = { |
|
|
|
|
|
|
|
1: ExposureInfo("red", 10), |
|
|
|
|
|
|
|
2: ExposureInfo("green", 20), |
|
|
|
|
|
|
|
3: ExposureInfo("blue", 50), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _add_measurement_params(exposure_df, params) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result["Exposure.Id"][0] == 1 |
|
|
|
|
|
|
|
assert result["Parameters.Channel"][0] == "red" |
|
|
|
|
|
|
|
assert result["Parameters.Time"][0] == 10 |
|
|
|
|
|
|
|
assert result["Exposure.Id"][1] == 2 |
|
|
|
|
|
|
|
assert result["Parameters.Channel"][1] == "green" |
|
|
|
|
|
|
|
assert result["Parameters.Time"][1] == 20 |
|
|
|
|
|
|
|
assert result["Exposure.Id"][2] == 3 |
|
|
|
|
|
|
|
assert result["Parameters.Channel"][2] == "blue" |
|
|
|
|
|
|
|
assert result["Parameters.Time"][2] == 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_optional_measurement_parameters_with_params_file( |
|
|
|
def test_add_optional_measurement_parameters_with_params_file( |
|
|
|
exposure_df, example_dir |
|
|
|
exposure_df, example_dir |
|
|
|
): |
|
|
|
): |
|
|
@ -121,60 +106,3 @@ def test_add_optional_measurement_parameters_without_params_file( |
|
|
|
assert one_exposure_data_frame["Parameters.Time"].hasnans |
|
|
|
assert one_exposure_data_frame["Parameters.Time"].hasnans |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apply_map(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parameters import _apply_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map = { |
|
|
|
|
|
|
|
1: {"SomeColumn": "A", "OtherColumn": 9}, |
|
|
|
|
|
|
|
2: {"SomeColumn": "B", "OtherColumn": 8}, |
|
|
|
|
|
|
|
3: {"SomeColumn": "C", "OtherColumn": 7}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _apply_map(exposure_df, map, "Exposure.Id") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key, value in map.items(): |
|
|
|
|
|
|
|
mask = result["Exposure.Id"] == key |
|
|
|
|
|
|
|
partial = result.loc[mask] |
|
|
|
|
|
|
|
assert set(partial["SomeColumn"].unique()) == {value["SomeColumn"]} |
|
|
|
|
|
|
|
assert set(partial["OtherColumn"].unique()) == {value["OtherColumn"]} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apply_map_keys_not_in_df(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parameters import _apply_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map = { |
|
|
|
|
|
|
|
1: {"some_col": "A", "other_col": 9}, |
|
|
|
|
|
|
|
2: {"some_col": "B", "other_col": 8}, |
|
|
|
|
|
|
|
3: {"some_col": "C", "other_col": 7}, |
|
|
|
|
|
|
|
4: {"some_col": "D", "other_col": 6}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _apply_map(exposure_df, map, "Exposure.Id") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for key in (1, 2, 3): |
|
|
|
|
|
|
|
value = map[key] |
|
|
|
|
|
|
|
mask = result["Exposure.Id"] == key |
|
|
|
|
|
|
|
partial = result.loc[mask] |
|
|
|
|
|
|
|
assert set(partial["some_col"].unique()) == {value["some_col"]} |
|
|
|
|
|
|
|
assert set(partial["other_col"].unique()) == {value["other_col"]} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert "D" not in set(result["some_col"].unique()) |
|
|
|
|
|
|
|
assert "6" not in set(result["other_col"].unique()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apply_map_not_all_keys_map_to_df(exposure_df): |
|
|
|
|
|
|
|
from sensospot_data.parameters import _apply_map |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map = { |
|
|
|
|
|
|
|
1: {"some_col": "A", "other_col": 9}, |
|
|
|
|
|
|
|
3: {"some_col": "C", "other_col": 7}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = _apply_map(exposure_df, map, "Exposure.Id") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert not result.iloc[0].hasnans |
|
|
|
|
|
|
|
assert result.iloc[1].hasnans |
|
|
|
|
|
|
|
assert not result.iloc[2].hasnans |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert result["some_col"].hasnans |
|
|
|
|
|
|
|
assert result["other_col"].hasnans |
|
|
|
|
|
|
|