Skip to content

Commit

Permalink
Tests for loading v0.1 data and new sensor data
Browse files Browse the repository at this point in the history
  • Loading branch information
caiw committed Dec 7, 2023
1 parent 18dd464 commit 64e31af
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Possible default location for downloaded data
kymata_data/
kymata-toolbox-data/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
6 changes: 4 additions & 2 deletions kymata/io/nkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def file_version(from_path_or_file: path_type | file_type) -> version.Version:


def load_expression_set(from_path_or_file: path_type | file_type) -> ExpressionSet:
version, data_dict = _load_data(from_path_or_file)
_v, data_dict = _load_data(from_path_or_file)

type_identifier = data_dict[_Keys.expressionset_type]

Expand All @@ -78,7 +78,7 @@ def load_expression_set(from_path_or_file: path_type | file_type) -> ExpressionS
functions=data_dict[_Keys.functions],
sensors=[SensorDType(c) for c in data_dict[_Keys.channels]],
latencies=data_dict[_Keys.latencies],
data=[data_dict[LAYER_SCALP][:, :, i]
data=[data_dict[_Keys.data][LAYER_SCALP][:, :, i]
for i in range(len(data_dict[_Keys.functions]))],
)

Expand Down Expand Up @@ -151,6 +151,7 @@ def _load_data(from_path_or_file: path_type | file_type) -> tuple[version.Versio
return v, return_dict


# noinspection DuplicatedCode
def _load_data_current(from_path_or_file: path_type | file_type) -> dict[str, Any]:
"""
Load data from current version
Expand Down Expand Up @@ -187,6 +188,7 @@ def _load_data_current(from_path_or_file: path_type | file_type) -> dict[str, An
return return_dict


# noinspection DuplicatedCode
def _load_data_0_1(from_path_or_file: path_type | file_type) -> dict[str, Any]:
"""
This is a function which loads data format 0.1.
Expand Down
Binary file added tests/test-data/sensor.nkg
Binary file not shown.
Binary file added tests/test-data/version_0_1.nkg
Binary file not shown.
23 changes: 22 additions & 1 deletion tests/test_saveload_nkg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from tempfile import NamedTemporaryFile

from kymata.entities.expression import ExpressionSet
from kymata.entities.expression import HexelExpressionSet, SensorExpressionSet
from kymata.io.nkg import save_expression_set, load_expression_set


Expand All @@ -21,3 +22,23 @@ def test_save_and_load_is_equal():
delete_dataset(sample_dataset)

assert es_loaded_from_source == ed_saved_and_reloaded


def test_load_v0_1_nkg():
es = load_expression_set(Path(Path(__file__).parent, "test-data", "version_0_1.nkg"))
assert isinstance(es, HexelExpressionSet)
assert len(es.functions) == 1
assert es.functions == ["test function"]
assert len(es.latencies) == 10
assert len(es.hexels) == 100
assert es.left.shape == es.right.shape == (100, 10, 1)


def test_load_sensor_nkg():
es = load_expression_set(Path(Path(__file__).parent, "test-data", "sensor.nkg"))
assert isinstance(es, SensorExpressionSet)
assert len(es.functions) == 1
assert es.functions == ["test function"]
assert len(es.latencies) == 10
assert len(es.sensors) == 305
assert es.scalp.shape == (305, 10, 1)

0 comments on commit 64e31af

Please sign in to comment.