-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user/acwikla/refactor_position_and_tests (#197)
- Loading branch information
1 parent
d5f623e
commit d91e5a1
Showing
12 changed files
with
101 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class LfPosition: | ||
|
||
def __init__(self, position_data, timestamps): | ||
self.position_data = position_data | ||
self.timestamps = timestamps |
8 changes: 8 additions & 0 deletions
8
src/datamigration/nwb/components/position/lf_position_builder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from src.datamigration.nwb.components.position.lf_position import LfPosition | ||
|
||
|
||
class LfPositionBuilder: | ||
|
||
@staticmethod | ||
def build(position_data, timestamps): | ||
return LfPosition(position_data, timestamps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/datamigration/nwb/components/position/lf_position_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from src.datamigration.nwb.components.position.lf_position_builder import LfPositionBuilder | ||
from src.datamigration.nwb.components.position.position_creator import PositionCreator | ||
from src.datamigration.nwb.components.position.lf_position_extractor import LfPositionExtractor | ||
|
||
|
||
class LfPositionManager: | ||
def __init__(self, datasets): | ||
self.lf_position_extractor = LfPositionExtractor(datasets) | ||
self.lf_position_builder = LfPositionBuilder() | ||
|
||
def get_lf_position(self): | ||
position_data = self.lf_position_extractor.get_position() | ||
timestamps = self.lf_position_extractor.get_timestamps() | ||
return self.lf_position_builder.build(position_data, timestamps) | ||
|
14 changes: 0 additions & 14 deletions
14
src/datamigration/nwb/components/position/position_builder.py
This file was deleted.
Oops, something went wrong.
11 changes: 8 additions & 3 deletions
11
src/datamigration/nwb/components/position/position_creator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
from pynwb.behavior import Position | ||
|
||
from src.datamigration.tools.validate_input_parameters import validate_input_parameters | ||
|
||
|
||
class PositionCreator: | ||
|
||
@staticmethod | ||
def create_position(position_data, timestamps): | ||
def create(lf_position): | ||
validate_input_parameters(__name__, lf_position) | ||
validate_input_parameters(__name__, lf_position.position_data, lf_position.timestamps) | ||
|
||
position = Position() | ||
position.create_spatial_series( | ||
name='series', | ||
data=position_data, | ||
data=lf_position.position_data, | ||
reference_frame='Description defining what the zero-position is', | ||
timestamps=timestamps | ||
timestamps=lf_position.timestamps | ||
) | ||
return position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import unittest | ||
|
||
from testfixtures import should_raise | ||
|
||
from src.datamigration.exceptions.none_param_in_init_exception import NoneParamInInitException | ||
from src.datamigration.nwb.components.position.lf_position_manager import LfPositionManager | ||
from src.datamigration.nwb.components.position.position_creator import PositionCreator | ||
from src.datamigration.tools.file_scanner import Dataset | ||
|
||
path = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
@unittest.skip("test requires continuoustime.dat file and can't be used on travis") | ||
class TestPositionExtraction(unittest.TestCase): | ||
|
||
@staticmethod | ||
def create_test_dataset(): | ||
dataset = Dataset('test_dataset') | ||
dataset.add_data_to_dataset(path + '/../datamigration/res/pos_test/', 'pos') | ||
dataset.add_data_to_dataset(path + '/../test_data/beans/preprocessing/20190718/20190718_beans_01_s1.time/', | ||
'time') | ||
return dataset | ||
|
||
def test_position_extractor_reading_data_successfully(self): | ||
dataset = self.create_test_dataset() | ||
|
||
lf_position_manager = LfPositionManager(datasets=[dataset, ]) | ||
position_creator = PositionCreator() | ||
|
||
lf_position = lf_position_manager.get_lf_position() | ||
position = position_creator.create(lf_position) | ||
|
||
self.assertIsNotNone(position) | ||
self.assertEqual([32658, 4], position['Fields'].data.shape, | ||
'Shape should be [32658, 4]') | ||
self.assertEqual((32658,), position['Fields'].timestamps.shape, | ||
'Shape should be (32658,)') | ||
|
||
@should_raise(NoneParamInInitException) | ||
def test_position_extractor_fails_reading_data_due_to_None_datasets(self): | ||
lf_position_manager = LfPositionManager(datasets=None) | ||
position_creator = PositionCreator() | ||
|
||
lf_position = lf_position_manager.get_lf_position() | ||
position_creator.create(lf_position) |