Commit df2e03d8 authored by Kamal Nasser's avatar Kamal Nasser

things

parent 6a04ad67
<component name="ProjectDictionaryState">
<dictionary name="nativ">
<words>
<w>detun</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="E303" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="R User Library">
<CLASSES />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (PyoPlayer_Project)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/rtscs - codebase1.iml" filepath="$PROJECT_DIR$/.idea/rtscs - codebase1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 2.7 (PyoPlayer_Project)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="R User Library" level="project" />
<orderEntry type="library" name="R Skeletons" level="application" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
......@@ -12,10 +12,12 @@ class PyoHandler:
self.s = pyo.Server(sr=48000, nchnls=2, buffersize=512, duplex=0, winhost="asio").boot()
self.s.start()
# each synth is a sin sound wave
self.synth = pyo.Sine(.4, mul=0.5, add=0.5)
self.synth2 = pyo.Sine(.4, mul=0.5, add=0.5).out(2)
self.synth3 = pyo.Sine(.4, mul=0.5, add=0.5).out(3)
self.synth4 = pyo.Sine(.4, mul=0.5, add=0.5).out(4)
#self.synth = pyo.SuperSaw()
self.synth = pyo.Sine()
self.synth2 = pyo.Sine(.2, mul=0.5, add=0.5).out(2)
self.synth3 = pyo.Sine(.2, mul=0.5, add=0.5).out(3)
#self.synth4 = pyo.Sine(.2, mul=0.5, add=0.5).out(4)
self.synth4 = pyo.SuperSaw()
def change_pyo(self, fr, bal, mul):
# change the pyo parameters:
......@@ -27,7 +29,7 @@ class PyoHandler:
self.synth.setFreq(fr)
self.synth.setMul(mul)
# adding more sin waves for the Y axis
self.synth2.setFreq(fr * 5 / 3)
self.synth2.setFreq(fr * 15 / 3)
self.synth3.setFreq(fr * 1.25)
self.synth4.setFreq(fr * 7 / 2)
# changing the amplitude of the waves according to position in Y axis
......
......@@ -7,9 +7,9 @@ import optirx_utils
DEFAULT_NOTE_DURATION_PRECISION = 0.125
# rh roll implemented for future use
DEFAULT_OPTITRACK_RANGES_DICT = {'x': (-3, 3), 'y': (1, 1.9), 'z': (-1, 1.7), 'rh_roll': (-80, 100)}
DEFAULT_RTSCS_PARAM_RANGES_DICT = {'frequency': (0, 1000), 'sins': (0, 0.5),
'amplitude': (0, 1), 'numerical_hint': (0, 1)}
DEFAULT_OPTITRACK_RANGES_DICT = {'x': (-1.5, 1.3), 'y': (0.0, 2.0), 'z': (-1.5, 1.7), 'rh_roll': (-180, 180)}
DEFAULT_RTSCS_PARAM_RANGES_DICT = {'frequency': (0, 600), 'sins': (0, 0.5),
'amplitude': (0.1, 1), 'numerical_hint': (0, 1)}
class OptitrackParamReceiver(BaseRtscsParamReceiver):
......
......@@ -2,6 +2,7 @@
A utility to help determine the desired bounding box of the space in which the system operator will be working,
and the extreme angles of rotation that the operator hand can be held and at which it is still detected by the cameras.
"""
from tabulate import tabulate
import time
import math
from rtscs_param_receivers.optitrack_param_receiver.optitrack_packet_receiver import OptitrackPacketReceiver
......@@ -11,6 +12,15 @@ import sys
minint = -sys.maxint - 1
maxint = sys.maxint
fns = {
"min": min,
"max": max,
}
totalNumbers = {
"max": [minint, minint, minint, minint],
"min": [maxint, maxint, maxint, maxint],
}
if __name__ == '__main__':
optritrack_packet_recv = OptitrackPacketReceiver('127.0.0.1') # adjust OptriTrack server IP if needed
optritrack_packet_recv.start()
......@@ -19,22 +29,18 @@ if __name__ == '__main__':
#print packet
rh = optirx_utils.get_first_rigid_body(packet)
totalNumbers = {
"min": [minint, minint, minint, minint],
"max": [maxint, maxint, maxint, maxint],
}
if rh is not None:
# mul by -1 to fix flipped coordinates if not fully compatible Motive calibration square
rh_position = rh.position
#rh_position = map(lambda coordinate: -1 * coordinate, rh.position)
rh_roll = math.degrees(optirx_utils.orientation2radians(rh.orientation)[0])
currentNumbers = rh_position + [rh_roll]
currentNumbers = list(rh_position) + [rh_roll]
for method in ["min", "max"]:
for idx, value in enumerate(currentNumbers, start=1):
totalNumbers[method][idx] = globals()[method](value, currentNumbers[idx])
for idx, value in enumerate(currentNumbers, start=0):
totalNumbers[method][idx] = fns[method](totalNumbers[method][idx], value)
print currentNumbers
print totalNumbers
#print(totalNumbers)
print '\n' * 20
print tabulate([totalNumbers["min"], totalNumbers["max"], currentNumbers], headers=["x", "y", "z", "roll"])
time.sleep(0.05)
# init for sext package
""" Setuptools extensions
nibabel uses these routines, and houses them, and installs them. nipy-proper
and dipy use them.
"""
""" distutils utilities for porting to python 3 within 2-compatible tree """
from __future__ import division, print_function, absolute_import
import sys
import re
try:
from distutils.command.build_py import build_py_2to3
except ImportError:
# 2.x - no parsing of code
from distutils.command.build_py import build_py
else: # Python 3
# Command to also apply 2to3 to doctests
from distutils import log
class build_py(build_py_2to3):
def run_2to3(self, files):
# Add doctest parsing; this stuff copied from distutils.utils in
# python 3.2 source
if not files:
return
fixer_names, options, explicit = (self.fixer_names,
self.options,
self.explicit)
# Make this class local, to delay import of 2to3
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
class DistutilsRefactoringTool(RefactoringTool):
def log_error(self, msg, *args, **kw):
log.error(msg, *args)
def log_message(self, msg, *args):
log.info(msg, *args)
def log_debug(self, msg, *args):
log.debug(msg, *args)
if fixer_names is None:
fixer_names = get_fixers_from_package('lib2to3.fixes')
r = DistutilsRefactoringTool(fixer_names, options=options)
r.refactor(files, write=True)
# Then doctests
r.refactor(files, write=True, doctests_only=True)
This diff is collapsed.
This diff is collapsed.
""" Tests for nisexts.sexts module
"""
import sys
import types
from ..sexts import package_check
from nose.tools import assert_true, assert_false, assert_equal, assert_raises
FAKE_NAME = 'nisext_improbable'
assert FAKE_NAME not in sys.modules
FAKE_MODULE = types.ModuleType('nisext_fake')
def test_package_check():
# Try to use a required package - raise error
assert_raises(RuntimeError, package_check, FAKE_NAME)
# Optional, log.warn
package_check(FAKE_NAME, optional=True)
# Can also pass a string
package_check(FAKE_NAME, optional='some-package')
try:
# Make a package
sys.modules[FAKE_NAME] = FAKE_MODULE
# Now it passes if we don't check the version
package_check(FAKE_NAME)
# A fake version
FAKE_MODULE.__version__ = '0.2'
package_check(FAKE_NAME, version='0.2')
# fails when version not good enough
assert_raises(RuntimeError, package_check, FAKE_NAME, '0.3')
# Unless optional in which case log.warns
package_check(FAKE_NAME, version='0.3', optional=True)
# Might do custom version check
package_check(FAKE_NAME, version='0.2', version_getter=lambda x: '0.2')
finally:
del sys.modules[FAKE_NAME]
def test_package_check_setuptools():
# If setuptools arg not None, missing package just adds it to arg
assert_raises(RuntimeError, package_check, FAKE_NAME, setuptools_args=None)
def pkg_chk_sta(*args, **kwargs):
st_args = {}
package_check(*args, setuptools_args=st_args, **kwargs)
return st_args
assert_equal(pkg_chk_sta(FAKE_NAME),
{'install_requires': ['nisext_improbable']})
# Check that this gets appended to existing value
old_sta = {'install_requires': ['something']}
package_check(FAKE_NAME, setuptools_args=old_sta)
assert_equal(old_sta,
{'install_requires': ['something', 'nisext_improbable']})
# That existing value as string gets converted to a list
old_sta = {'install_requires': 'something'}
package_check(FAKE_NAME, setuptools_args=old_sta)
assert_equal(old_sta,
{'install_requires': ['something', 'nisext_improbable']})
# Optional, add to extras_require
assert_equal(pkg_chk_sta(FAKE_NAME, optional='something'),
{'extras_require': {'something': ['nisext_improbable']}})
# Check that this gets appended to existing value
old_sta = {'extras_require': {'something': ['amodule']}}
package_check(FAKE_NAME, optional='something', setuptools_args=old_sta)
assert_equal(old_sta,
{'extras_require':
{'something': ['amodule', 'nisext_improbable']}})
# That string gets converted to a list here too
old_sta = {'extras_require': {'something': 'amodule'}}
package_check(FAKE_NAME, optional='something', setuptools_args=old_sta)
assert_equal(old_sta,
{'extras_require':
{'something': ['amodule', 'nisext_improbable']}})
# But optional has to be a string if not empty and setuptools_args defined
assert_raises(RuntimeError,
package_check, FAKE_NAME, optional=True, setuptools_args={})
try:
# Make a package
sys.modules[FAKE_NAME] = FAKE_MODULE
# No install_requires because we already have it
assert_equal(pkg_chk_sta(FAKE_NAME), {})
# A fake version still works
FAKE_MODULE.__version__ = '0.2'
assert_equal(pkg_chk_sta(FAKE_NAME, version='0.2'), {})
# goes into install requires when version not good enough
exp_spec = [FAKE_NAME + '>=0.3']
assert_equal(pkg_chk_sta(FAKE_NAME, version='0.3'),
{'install_requires': exp_spec})
# Unless optional in which case goes into extras_require
package_check(FAKE_NAME, version='0.2', version_getter=lambda x: '0.2')
assert_equal(
pkg_chk_sta(FAKE_NAME, version='0.3', optional='afeature'),
{'extras_require': {'afeature': exp_spec}})
# Might do custom version check
assert_equal(
pkg_chk_sta(FAKE_NAME,
version='0.2',
version_getter=lambda x: '0.2'),
{})
# If the version check fails, put into requires
bad_getter = lambda x: x.not_an_attribute
exp_spec = [FAKE_NAME + '>=0.2']
assert_equal(
pkg_chk_sta(FAKE_NAME,
version='0.2',
version_getter=bad_getter),
{'install_requires': exp_spec})
# Likewise for optional dependency
assert_equal(
pkg_chk_sta(FAKE_NAME,
version='0.2',
optional='afeature',
version_getter=bad_getter),
{'extras_require': {'afeature': [FAKE_NAME + '>=0.2']}})
finally:
del sys.modules[FAKE_NAME]
""" Tests for testers
"""
from __future__ import division, print_function
import os
from os.path import dirname, pathsep
from ..testers import back_tick, run_mod_cmd, PYTHON
from nose.tools import assert_true, assert_equal, assert_raises
def test_back_tick():
cmd = '{0} -c "print(\'Hello\')"'.format(PYTHON)
assert_equal(back_tick(cmd), "Hello")
assert_equal(back_tick(cmd, ret_err=True), ("Hello", ""))
assert_equal(back_tick(cmd, True, False), (b"Hello", b""))
cmd = '{0} -c "raise ValueError()"'.format(PYTHON)
assert_raises(RuntimeError, back_tick, cmd)
def test_run_mod_cmd():
mod = 'os'
mod_dir = dirname(os.__file__)
assert_equal(run_mod_cmd(mod, mod_dir, "print('Hello')", None, False),
("Hello", ""))
sout, serr = run_mod_cmd(mod, mod_dir, "print('Hello again')")
assert_equal(serr, '')
mod_file, out_str = [s.strip() for s in sout.split('\n')]
assert_true(mod_file.startswith(mod_dir))
assert_equal(out_str, 'Hello again')
sout, serr = run_mod_cmd(mod,
mod_dir,
"print(os.environ['PATH'])",
None,
False)
assert_equal(serr, '')
sout2, serr = run_mod_cmd(mod,
mod_dir,
"print(os.environ['PATH'])",
'pth2',
False)
assert_equal(serr, '')
assert_equal(sout2, '"pth2"' + pathsep + sout)
This source diff could not be displayed because it is too large. You can view the blob instead.
# encoding: utf-8
"""
Copyright 2009-2015 Olivier Belanger
This file is part of pyo, a python module to help digital signal
processing script creation.
pyo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
pyo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with pyo. If not, see <http://www.gnu.org/licenses/>.
"""
from math import pow, log10
######################################################################
### Map -> rescale values from sliders
######################################################################
class Map(object):
"""
Converts value between 0 and 1 on various scales.
Base class for Map objects.
:Args:
min: int or float
Lowest value of the range.
max: int or float
Highest value of the range.
scale: string {'lin', 'log'}
Method used to scale the input value on the specified range.
>>> m = Map(20., 20000., 'log')
>>> print(m.get(.5))
632.455532034
>>> print(m.set(12000))
0.926050416795
"""
def __init__(self, min, max, scale):
self._min, self._max, self._scale = float(min), float(max), scale
def get(self, x):
"""
Takes `x` between 0 and 1 and returns scaled value.
"""
if x < 0:
x = 0.0
elif x > 1:
x = 1.0
if self._scale == 'log':
return pow(10, x * log10(self._max / self._min) + log10(self._min))
else:
return (self._max - self._min) * x + self._min
def set(self, x):
"""
Takes `x` in the real range and returns value unscaled
(between 0 and 1).
"""
if self._scale == 'log':
return log10(x / self._min) / log10(self._max / self._min)
else:
return (x - self._min) / (self._max - self._min)
def setMin(self, x):
"""
Replace the `min` attribute.
:Args:
x: float
New `min` attribute.
"""
self._min = x
def setMax(self, x):
"""
Replace the `max` attribute.
:Args:
x: float
New `max` attribute.
"""
self._max = x
def setScale(self, x):
"""
Replace the `scale` attribute.
:Args:
x: string
New `scale` attribute.
"""
self._scale = x
@property
def min(self):
"""int or float. Lowest value of the range."""
return self._min
@min.setter
def min(self, x):
self.setMin(x)
@property
def max(self):
"""int or float. Highest value of the range."""
return self._max
@max.setter
def max(self, x):
self.setMax(x)
@property
def scale(self):
"""string. Method used to scale the input value."""
return self._scale
@scale.setter
def scale(self, x):
self.setScale(x)
class SLMap(Map):
"""
Base Map class used to manage control sliders.
Derived from Map class, a few parameters are added for sliders
initialization.
:Parent: :py:class:`Map`
:Args:
min: int or float
Smallest value of the range.
max: int or float
Highest value of the range.
scale: string {'lin', 'log'}
Method used to scale the input value on the specified range.
name: string
Name of the attributes the slider is affected to.
init: int or float
Initial value. Specified in the real range, not between 0 and 1.
Use `set` method to retreive the normalized corresponding value.