Commit 85bd97f1 authored by Stephen Thompson's avatar Stephen Thompson

Merge branch '8-frametype' into 'master'

Resolve "Return types for get_frame"

See merge request !1
parents a7e91c7e 945cc701
Pipeline #1720 passed with stages
in 14 minutes and 56 seconds
......@@ -36,7 +36,11 @@ Installing
Using
-----
Configuration is done using Python libraries. Tracking data is returned in NumPy arrays.
Configuration is done using Python libraries at instantiation. Invalid
configuration should raise exceptions. Tracking data is returned in a set of
lists, containing the port handles, timestamps, framenumbers, the tracking data
and a tracking quality metric. By default tracking data is returned as a 4x4 NumPy array,
though can be returned as a quaternion by changing the configuration.
::
......@@ -45,15 +49,16 @@ Configuration is done using Python libraries. Tracking data is returned in NumPy
"tracker type": "polaris",
"romfiles" : ["../data/8700339.rom"]
}
TRACKER = NDITracker()
TRACKER.connect(SETTINGS)
TRACKER = NDITracker(SETTINGS)
TRACKER.start_tracking()
print(TRACKER.get_frame()
port_handles, timestamps, framenumbers, tracking, quality = TRACKER.get_frame()
for t in tracking:
print (t)
TRACKER.stop_tracking()
TRACKER.close()
See example.py for a full example
See demo.py for a full example
Developing
----------
......
......@@ -7,7 +7,7 @@ Contents
:maxdepth: 1
requirements
pycharm
release_notes
Module Contents <modules>
* :ref:`modindex`
......
.. _pycharm:
Some Hints for Developing with PyCharm
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PyCharm is a popular python editor. This is a quickstart guide setting up
PyCharm for developing sksurgerynditracker.
This assumes you have PyCharm installed and configured to support virtual environments.
1. Start PyCharm
2. Select File > Open
3. Select the project's folder
4. Open in a new window
5. Open Preferences
6. Click on Project: [YourProject] and select Project Interpreter
7. At the right of the Project Interpreterm, click the cog
8. Select Add Local...
9. Select Virtual Environment
10. Choose a location for your virtual environment (for example, [YourHomeFolder]/VirtualEnvs/[YourProjectName])
11. Select a base interpreter (usually the latest version of Python 3).
12. Recommended settings: Do not inherit global site-packages, and do not make available to all projects.
13. Click OK
14. Click on Terminal
15. `pip install tox`
16. `tox`
17. Expand the project
18. Right-click on the Tests folder and choose "Run Unittests in tests". This will create a new configuration for running tests
19. Right-click on sksurgerynditracker and select Run sksurgerynditracker. This will create a new configuration for running the project.
20. Switch between the program and test configurations using the drop-down at the top of the screen, and the green arrow to run or the green bug to debug.
.. highlight:: shell
.. _release_notes:
==========================================
Release Notes for scikit-surgerynditracker
==========================================
+------------+--------------------------------------------------------+
| Release | Description |
+============+========================================================+
| 0.0.1 | First release (tested with Vega) |
+------------+--------------------------------------------------------+
| 0.0.2 | Tidied documentation |
+------------+--------------------------------------------------------+
| 0.0.3 | Added time stamp (adds extra column to return array) |
+------------+--------------------------------------------------------+
| 0.0.4 | No code changes. |
+------------+--------------------------------------------------------+
| 0.0.5 | Tested and works with multichannel Aurora trackers |
+------------+--------------------------------------------------------+
| 0.1.0 | Removed configure method, configuration now done at |
| | init. |
| | Changed return type of get_frame(). Not backwards |
| | compatible. Returns matrix for tracking, not |
| | quaternion. Timestamp, port handle, frame number |
| | and tracking quality all returned as separate lists. |
+------------+--------------------------------------------------------+
......@@ -13,32 +13,29 @@ checks whether the requirement is met.
Requirements
~~~~~~~~~~~~
+------------+--------------------------------------------------------+-------------------------------------+
| ID | Description | Test |
+============+========================================================+=====================================+
| 0000 | Module has a help page | pylint, see |
| | | tests/pylint.rc and tox.ini |
+------------+--------------------------------------------------------+-------------------------------------+
| 0001 | Functions are documented | pylint, see |
| | | tests/pylint.rc and tox.ini |
+------------+--------------------------------------------------------+-------------------------------------+
| 0002 | Package has a version number | No test yet, handled by git. |
+------------+--------------------------------------------------------+-------------------------------------+
| 0003 | Connects and configures, vega, polaris and aurora | |
+------------+--------------------------------------------------------+-------------------------------------+
| 0004 | Configures via a python dictionary | |
+------------+--------------------------------------------------------+-------------------------------------+
| 0005 | Provides get frame to get frame of tracking data | |
+------------+--------------------------------------------------------+-------------------------------------+
| 0006 | Get frame returns data as numpy array | |
+------------+--------------------------------------------------------+-------------------------------------+
| 0007 | Supports multiple tracked objects | |
+------------+--------------------------------------------------------+-------------------------------------+
| 0008 | Provides a method to stream data to file for later | |
| | use. | |
+------------+--------------------------------------------------------+-------------------------------------+
| 0009 | If no tracking available GetFrame Returns NaN | |
+------------+--------------------------------------------------------+-------------------------------------+
+----------+--------------------------------------------------------+-------------------------------------+
| ID | Description | Test |
+==========+========================================================+=====================================+
| 00 | Module has a help page | pylint, see |
| | | tests/pylint.rc and tox.ini |
+----------+--------------------------------------------------------+-------------------------------------+
| 01 | Functions are documented | pylint, see |
| | | tests/pylint.rc and tox.ini |
+----------+--------------------------------------------------------+-------------------------------------+
| 02 | Package has a version number | handled by versioneer |
+----------+--------------------------------------------------------+-------------------------------------+
| 03 | Connects and configures, vega, polaris and aurora | test_configure |
+----------+--------------------------------------------------------+-------------------------------------+
| 04 | Configures via a python dictionary | test_configure |
+----------+--------------------------------------------------------+-------------------------------------+
| 05 | Provides get frame to get frame of tracking data | test_get_frame |
+----------+--------------------------------------------------------+-------------------------------------+
| 06 | Get frame returns data as numpy array | test_get_frame |
+----------+--------------------------------------------------------+-------------------------------------+
| 07 | Supports multiple tracked objects | test_get_frame |
+----------+--------------------------------------------------------+-------------------------------------+
| 09 | If no tracking available GetFrame Returns NaN | - |
+----------+--------------------------------------------------------+-------------------------------------+
......
......@@ -54,10 +54,4 @@ setup(
'numpy>=1.11',
'ndicapi>=3.2.3',
],
entry_points={
'console_scripts': [
'sksurgerynditracker=sksurgerynditracker.__main__:main',
],
},
)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from sksurgerynditracker.ui.sksurgerynditracker_command_line import main
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
......@@ -36,8 +36,7 @@ def run():
"../data/8700339.rom",
"../data/something_else.rom"]
}
tracker = NDITracker()
tracker.connect(settings_vega)
tracker = NDITracker(settings_vega)
tracker.start_tracking()
......
This diff is collapsed.
......@@ -2,13 +2,18 @@
"""scikit-surgerynditracker tests"""
#what testing can we do with out being attached to a tracker?
#What testing can we do when we are attached to a tracker?
#We could build a fake ndi tracker, that listens on a port
#and responds appropriately.
import pytest
from sksurgerynditracker.nditracker import NDITracker
#configuration.
SETTINGS_VEGA = {
"tracker type": "vega",
"ip address" : "192.168.2.17",
"ip address" : "999.999.999.999",
"port" : 8765,
"romfiles" : [
"../data/something_else.rom",
......@@ -30,103 +35,104 @@ SETTINGS_DUMMY = {
"tracker type": "dummy",
}
def test_connect():
#what testing can we do with out being attached to a tracker?
#What testing can we do when we are attached to a tracker?
#We could build a fake ndi tracker, that listens on a port
#and responds appropriately.
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
"""
connects and configures ,
reqs: 03, 04
"""
tracker = NDITracker(SETTINGS_DUMMY)
tracker.close()
def test_connect_network():
tracker = NDITracker()
"""
connects and configures, throws error when no vega
reqs: 03, 04
"""
with pytest.raises(IOError):
tracker.connect(SETTINGS_VEGA)
with pytest.raises(ValueError):
tracker.close()
tracker = NDITracker(SETTINGS_VEGA)
del tracker
def test_connect_serial():
tracker = NDITracker()
"""
connects and configures, throws error when no serial
reqs: 03, 04
"""
tracker = None
with pytest.raises(IOError):
tracker.connect(SETTINGS_POLARIS)
with pytest.raises(ValueError):
tracker.close()
tracker = NDITracker(SETTINGS_POLARIS)
del tracker
def test_configure():
tracker = NDITracker()
"""
connects and configures, throws errors when when errors in dictionary
reqs: 03, 04
"""
no_rom = {
"tracker type": "polaris",
}
with pytest.raises(KeyError):
tracker._configure(no_rom)
tracker = NDITracker(no_rom)
del tracker
bad_tracker = {
"tracker type": "optotrack",
}
with pytest.raises(ValueError):
tracker._configure(bad_tracker)
tracker = NDITracker(bad_tracker)
del tracker
no_ip = {
"tracker type": "vega",
"romfiles": "[rom]"
}
with pytest.raises(KeyError):
tracker._configure(no_ip)
tracker = NDITracker(no_ip)
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
no_port = {
"tracker type": "vega",
"ip address": "tracker",
"romfiles": "[rom]"
}
tracker = NDITracker(no_port)
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
aurora = {"tracker type": "aurora"}
tracker = NDITracker(aurora)
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
aurora_sp = {"tracker type": "aurora",
"serial_port": "1"}
tracker = NDITracker(aurora_sp)
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
aurora_np = {"tracker type": "aurora",
"ports to probe": "50"}
tracker = NDITracker(aurora_np)
del tracker
no_port = {
"tracker type": "vega",
"ip address": "tracker",
"romfiles": "[rom]"
}
tracker._configure(no_port)
aurora = { "tracker type": "aurora" }
tracker._configure(aurora)
aurora_sp = { "tracker type": "aurora",
"serial_port": "1" }
tracker._configure(aurora_sp)
aurora_np = { "tracker type": "aurora",
"ports to probe": "50" }
tracker._configure(aurora_np)
def test_close():
with pytest.raises(ValueError):
tracker = NDITracker()
tracker.close()
def test_read_sroms_from_file():
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker._read_sroms_from_file()
tracker.close()
def test_initialise_ports():
tracker = NDITracker()
tracker._device = None
with pytest.raises(ValueError):
tracker._initialise_ports()
with pytest.raises(ValueError):
tracker.close()
def test_enable_tools():
tracker = NDITracker()
tracker._device = None
with pytest.raises(ValueError):
tracker._enable_tools()
with pytest.raises(ValueError):
tracker.close()
def test_get_frame():
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
data = tracker.get_frame()
assert data.shape == (0,11)
assert data.dtype == 'float64'
"""
test get frame returns numpy array
reqs:05, 06
"""
tracker = NDITracker(SETTINGS_DUMMY)
_port_handles, _timestamps, _framenumbers, \
tracking, _tracking_quality = tracker.get_frame()
assert not tracking
del tracker
dummy_two_rom = {
"tracker type": "dummy",
"romfiles" : [
......@@ -134,16 +140,23 @@ def test_get_frame():
"../data/8700339.rom"]
}
tracker.connect(dummy_two_rom)
data = tracker.get_frame()
assert data.shape == (2,11)
assert data.dtype == 'float64'
tracker = NDITracker(dummy_two_rom)
_port_handles, _timestamps, _framenumbers, \
tracking, _tracking_quality = tracker.get_frame()
assert len(tracking) == 2
assert tracking[0].shape == (4, 4)
assert tracking[0].dtype == 'float64'
def test_get_tool_descriptions():
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
descriptions = tracker.get_tool_descriptions()
assert len(descriptions) == 0
"""
test get tool descriptions
reqs:05, 06
"""
tracker = NDITracker(SETTINGS_DUMMY)
_port_handles, descriptions = tracker.get_tool_descriptions()
assert not descriptions
del tracker
dummy_two_rom = {
"tracker type": "dummy",
......@@ -152,28 +165,28 @@ def test_get_tool_descriptions():
"../data/8700339.rom"]
}
tracker.connect(dummy_two_rom)
descriptions = tracker.get_tool_descriptions()
tracker = NDITracker(dummy_two_rom)
_port_handles, descriptions = tracker.get_tool_descriptions()
assert len(descriptions) == 2
def test_start_tracking():
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
"""
test start tracking
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker.start_tracking()
tracker.close()
def test_stop_tracking():
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
"""
test stop tracking
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker.stop_tracking()
tracker.close()
def test_check_for_errors():
tracker = NDITracker()
tracker.connect(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker._check_for_errors("dummy error")
tracker.close()
......@@ -13,14 +13,14 @@ deps=-rrequirements-dev.txt
whitelist_externals=coverage,pip
# See .coveragerc for list of omitted files
commands = coverage erase
coverage run -a --source ./sksurgerynditracker -m pytest
coverage run -a --source ./sksurgerynditracker -m pytest -s -v
coverage report -m
[testenv:lint]
basepython=python3.6
deps=pylint
{[testenv]deps}
commands=pylint --rcfile=tests/pylintrc sksurgerynditracker
commands=pylint --rcfile=tests/pylintrc sksurgerynditracker tests
[testenv:docs]
basepython=python3.6
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment