Skip to content

Commit

Permalink
added optimize function to DataProcessing
Browse files Browse the repository at this point in the history
  • Loading branch information
Stas committed Jun 20, 2019
1 parent e1949d3 commit 5390039
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 75 deletions.
41 changes: 22 additions & 19 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Introduction

This software works on a pipeline basis.

To install use: pip install submovements

Input
~~~~~~~~~~~~~~~
The input is a directory of trials which are saved as CSV files with the following file names:
Expand Down
82 changes: 41 additions & 41 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
"""The setup script."""

from setuptools import setup, find_packages

with open('README.rst') as readme_file:
readme = readme_file.read()

with open('HISTORY.rst') as history_file:
history = history_file.read()

requirements = [ ]

setup_requirements = ['pytest-runner', ]

test_requirements = ['pytest', ]

setup(
author="Stas Steinberg, Liz Izakson, Meyrav Dayan",
author_email='stanislavs1@mail.tau.ac.il, lizizakson@mail.tau.ac.il, meyravdayan@mail.tau.ac.il',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3.7',
],
description="Our goal is to detect sub-movements from motion data.",
install_requires=requirements,
license="MIT license",
long_description=readme + '\n\n' + history,
include_package_data=True,
keywords='submovements',
name='submovements',
packages=find_packages(include=['submovements']),
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/sstbrg/submovements',
version='0.1.1',
zip_safe=False,
)
"""The setup script."""

from setuptools import setup, find_packages

with open('README.rst') as readme_file:
readme = readme_file.read()

with open('HISTORY.rst') as history_file:
history = history_file.read()

requirements = [ ]

setup_requirements = ['pytest-runner', ]

test_requirements = ['pytest', ]

setup(
author="Stas Steinberg, Liz Izakson, Meyrav Dayan",
author_email='stanislavs1@mail.tau.ac.il, lizizakson@mail.tau.ac.il, meyravdayan@mail.tau.ac.il',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3.7',
],
description='Our goal is to detect submovements from motion data',
install_requires=requirements,
license="MIT license",
long_description='',
include_package_data=True,
keywords='submovements',
name='submovements',
packages=find_packages(include=['submovements']),
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/sstbrg/submovements',
version='0.1.1',
zip_safe=False,
)
5 changes: 5 additions & 0 deletions submovements/DataProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from scipy.signal import butter, filtfilt
from pathlib import Path
import seaborn as sns
from fit_submovements import *

sns.set()

Expand Down Expand Up @@ -184,6 +185,10 @@ class Preprocessor():
raw_headers = attr.ib(default=['SampleNum', 'x', 'y', 'z',
'phi', 'theta', 'psi', 'Time', 'Event'])

def do_fit(self, trial):
fit_result = optimize_jerk(trial)
return fit_result

def load_df_from_directory_gen(self, dir_path, cols=('x', 'y')):
###
# This is a generator which takes csv
Expand Down
28 changes: 13 additions & 15 deletions submovements/fit_submovements.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def func(t, *params):
return Y


def optimize_jerk(trial, plot_fit):
def optimize_jerk(trial):
###
# Creates the cost jerk function for x and y
# TODO: add support for all dimensions (currently fits only X data
Expand All @@ -49,30 +49,28 @@ def optimize_jerk(trial, plot_fit):

n = 3

guess_x = [0, 0.9, 180]
guess_vx = [0, 0.9, 180]
for n in range(1,n):
guess_x += [t0, D/n, 180]
guess_vx += [t0, D/n, 180]

guess_vy = [0, 0.9, 180]
for n in range(1,n):
guess_vy += [t0, D/n, 180]

# TODO: calculate bounds
# bounds_low = [0, 0.1, -50, -50]
# bounds_high = [t.max(), t.max()-t.min(), 200, 200]

popt_x, pcov_x = curve_fit(func, t, Vx, p0=guess_x)
perr_x = np.sqrt(np.diag(pcov_x))

print(popt_x)
print(perr_x)

fit = func(t, *popt_x)
popt_vx, pcov_vx = curve_fit(func, t, Vx, p0=guess_vx)
perr_vx = np.sqrt(np.diag(pcov_vx))

if plot_fit:
plt.plot(t, Vx)
plt.plot(t, fit, 'r-')
plt.show()
popt_vy, pcov_vy = curve_fit(func, t, Vy, p0=guess_vy)
perr_vy = np.sqrt(np.diag(pcov_vy))

fit_vx = func(t, *popt_vx)
fit_vy = func(t, *popt_vy)

return fit, popt_x, perr_x
return fit_vx, fit_vy, popt_vx, perr_vx, popt_vy, perr_vy

if __name__ == '__main__':
path_to_raw_data = '..\\data\\results\\simonvisual\\1'
Expand Down

0 comments on commit 5390039

Please sign in to comment.