# Path: src/markwrite/markwrite/sigproc/sample_filter.py
# def filter_pen_sample_series(series):
#     """
#     Given the pen samples ndarray in series, perform filtering on the
#     x, y, and pressure values, updating the associated 'filter_X' fields
#     with the filter results.
#     :param series: markwrite sample ndarray for the series to be filtered.
#     :return:
#     """
# 
#     if SETTINGS['filter_imported_pen_data'] is False:
#         series['x_filtered'] = series['x']
#         series['y_filtered'] = series['y']
#         series['pressure_filtered'] = series['pressure']
#         return
# 
#     # Initial filter will use scipy.signal.savgol_filter, commonly used in
#     # eye tracking data, as it does not phase shift the data and does
#     # a good job of smoothing out noise while maintaining signal.
#     # See http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter
#     if len(series)> window_length*2:
#         series['x_filtered'] = savgol_filter(series['x'], window_length, polyorder)
#         series['y_filtered'] = savgol_filter(series['y'], window_length, polyorder)
#         series['pressure_filtered'] =  savgol_filter(series['pressure'], window_length, polyorder)
#         series['pressure_filtered'][series['pressure_filtered'] < 0.0] = 0.0
#     elif len(series) > 10:
#         series['x_filtered'] = savgol_filter(series['x'], 5, 3)
#         series['y_filtered'] = savgol_filter(series['y'], 5, 3)
#         series['pressure_filtered'] =  savgol_filter(series['pressure'], 5, 3)
#         series['pressure_filtered'][series['pressure_filtered'] < 0.0] = 0.0
#     else:
#         series['x_filtered'] = series['x']
#         series['y_filtered'] = series['y']
#         series['pressure_filtered'] =  series['pressure']
# 
# Path: src/markwrite/markwrite/sigproc/sample_va.py
# def calculate_velocity(series):
#     """
#     Given the pen samples ndarray in series, calculate velocity for x and y
#     fields, updating the associated '*_velocity' fields
#     with the calculated result.
#     :param series: markwrite sample ndarray.
#     :return:
#     """
# 
#     # Calculate velocity using 1st deriv scipy.signal.savgol_filter,
#     # as it does not phase shift the data and does a good job of
#     # smoothing out noise with minimal signal distortion.
#     # See http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter
#     if len(series)==1:
#         # nothing to do
#         return
# 
#     dx = series['x_filtered'][1:]-series['x_filtered'][0:-1]
#     dy = series['y_filtered'][1:]-series['y_filtered'][0:-1]
#     xy_velocity = np.hypot(dx, dy)
# 
#     wlength = 0
#     polyo = 0
#     if len(series)> window_length:
#         wlength = window_length
#         polyo = polyorder
#     elif len(series) > 10:
#         wlength = 5
#         polyo = 3
# 
#     if wlength > 0:
#         series['x_velocity'] = savgol_filter(series['x'], wlength, polyo,
#                                          deriv=1, delta=1.0)
#         series['y_velocity'] = savgol_filter(series['y'], wlength, polyo,
#                                          deriv=1, delta=1.0)
#         #series['xy_velocity'][1:] = savgol_filter(xy_velocity, wlength, polyo)
#         #series['xy_velocity'][0] = series['xy_velocity'][1]
#         #series['xy_acceleration'] = savgol_filter(series['xy_velocity'],
#         #                                           wlength, polyo,
#         #                                           deriv=1, delta=1.0)
# 
#     else:
#         series['x_velocity'][1:] = dx
#         series['y_velocity'][1:] = dy
#         series['x_velocity'][0] = series['x_velocity'][1]
#         series['y_velocity'][0] = series['y_velocity'][1]
# 
#     series['xy_velocity'][1:] = xy_velocity
#     series['xy_velocity'][0] = series['xy_velocity'][1]
# 
#     series['xy_acceleration'][1:] = series['xy_velocity'][1:]-series['xy_velocity'][:-1]
#     series['xy_acceleration'][0] = series['xy_acceleration'][1]


from weakref import proxy, ProxyType
from pyqtgraph import OrderedDict
from file_io import EyePenDataImporter, XmlDataImporter, HubDatastoreImporter
from file_io import TabDelimitedDataImporter, readPickle, writePickle
from file_io import SAMPLE_STATES
from segment import PenDataSegment, PenDataSegmentCategory
from util import contiguous_regions, getFilteredStringList
from gui.projectsettings import SETTINGS
from .sigproc import filter_pen_sample_series, calculate_velocity
            from gui.dialogs import DlgFromDict
            from .sigproc import parse_velocity_and_curvature
            from .sigproc import parse_using_sample_field
import os
import glob
import codecs
import numpy as np
import pyqtgraph as pg
        import datetime
                    import traceback
        self.project._mwapp._penDataSpatialViewWidget.zoomToPenData(
            self.selectedpendata)

    def lineMoved(self):
        if self.blockLineSignal:
            return
        pg.LinearRegionItem.lineMoved(self)
        if self.project._mwapp._segmenttree.doNotSetActiveObject is False:
            self.project._mwapp.setActiveObject(self)

    def lineMoveFinished(self):
        pg.LinearRegionItem.lineMoveFinished(self)
        if self.project._mwapp._segmenttree.doNotSetActiveObject is False:
            self.project._mwapp.setActiveObject(self)

    def getBounds(self):
        return self.lines[0].maxRange

    @property
    def project(self):
        return self._project

    @project.setter
    def project(self, p):
        if p is None:
            self._project = proxy(p)
            self.setBounds(bounds=(0, 0))
            self.setRegion([0, 0])
        else:
            if isinstance(p, ProxyType):

# Path: src/markwrite/markwrite/sigproc/sample_filter.py
# def filter_pen_sample_series(series):
#     """
#     Given the pen samples ndarray in series, perform filtering on the
#     x, y, and pressure values, updating the associated 'filter_X' fields
#     with the filter results.
#     :param series: markwrite sample ndarray for the series to be filtered.
#     :return:
#     """
# 
#     if SETTINGS['filter_imported_pen_data'] is False:
#         series['x_filtered'] = series['x']
#         series['y_filtered'] = series['y']
#         series['pressure_filtered'] = series['pressure']
#         return
# 
#     # Initial filter will use scipy.signal.savgol_filter, commonly used in
#     # eye tracking data, as it does not phase shift the data and does
#     # a good job of smoothing out noise while maintaining signal.
#     # See http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter
#     if len(series)> window_length*2:
#         series['x_filtered'] = savgol_filter(series['x'], window_length, polyorder)
#         series['y_filtered'] = savgol_filter(series['y'], window_length, polyorder)
#         series['pressure_filtered'] =  savgol_filter(series['pressure'], window_length, polyorder)
#         series['pressure_filtered'][series['pressure_filtered'] < 0.0] = 0.0
#     elif len(series) > 10:
#         series['x_filtered'] = savgol_filter(series['x'], 5, 3)
#         series['y_filtered'] = savgol_filter(series['y'], 5, 3)
#         series['pressure_filtered'] =  savgol_filter(series['pressure'], 5, 3)
#         series['pressure_filtered'][series['pressure_filtered'] < 0.0] = 0.0
#     else:
#         series['x_filtered'] = series['x']
#         series['y_filtered'] = series['y']
#         series['pressure_filtered'] =  series['pressure']
# 
# Path: src/markwrite/markwrite/sigproc/sample_va.py
# def calculate_velocity(series):
#     """
#     Given the pen samples ndarray in series, calculate velocity for x and y
#     fields, updating the associated '*_velocity' fields
#     with the calculated result.
#     :param series: markwrite sample ndarray.
#     :return:
#     """
# 
#     # Calculate velocity using 1st deriv scipy.signal.savgol_filter,
#     # as it does not phase shift the data and does a good job of
#     # smoothing out noise with minimal signal distortion.
#     # See http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter
#     if len(series)==1:
#         # nothing to do
#         return
# 
#     dx = series['x_filtered'][1:]-series['x_filtered'][0:-1]
#     dy = series['y_filtered'][1:]-series['y_filtered'][0:-1]
#     xy_velocity = np.hypot(dx, dy)
# 
#     wlength = 0
#     polyo = 0
#     if len(series)> window_length:
#         wlength = window_length
#         polyo = polyorder
#     elif len(series) > 10:
#         wlength = 5
#         polyo = 3
# 
#     if wlength > 0:
#         series['x_velocity'] = savgol_filter(series['x'], wlength, polyo,
#                                          deriv=1, delta=1.0)
#         series['y_velocity'] = savgol_filter(series['y'], wlength, polyo,
#                                          deriv=1, delta=1.0)
#         #series['xy_velocity'][1:] = savgol_filter(xy_velocity, wlength, polyo)
#         #series['xy_velocity'][0] = series['xy_velocity'][1]
#         #series['xy_acceleration'] = savgol_filter(series['xy_velocity'],
#         #                                           wlength, polyo,
#         #                                           deriv=1, delta=1.0)
# 
#     else:
#         series['x_velocity'][1:] = dx
#         series['y_velocity'][1:] = dy
#         series['x_velocity'][0] = series['x_velocity'][1]
#         series['y_velocity'][0] = series['y_velocity'][1]
# 
#     series['xy_velocity'][1:] = xy_velocity
#     series['xy_velocity'][0] = series['xy_velocity'][1]
# 
#     series['xy_acceleration'][1:] = series['xy_velocity'][1:]-series['xy_velocity'][:-1]
#     series['xy_acceleration'][0] = series['xy_acceleration'][1]


# Path: src/markwrite/markwrite/project.py
from weakref import proxy, ProxyType
from pyqtgraph import OrderedDict
from file_io import EyePenDataImporter, XmlDataImporter, HubDatastoreImporter
from file_io import TabDelimitedDataImporter, readPickle, writePickle
from file_io import SAMPLE_STATES
from segment import PenDataSegment, PenDataSegmentCategory
from util import contiguous_regions, getFilteredStringList
from gui.projectsettings import SETTINGS
from .sigproc import filter_pen_sample_series, calculate_velocity
            from gui.dialogs import DlgFromDict
            from .sigproc import parse_velocity_and_curvature
            from .sigproc import parse_using_sample_field
import os
import glob
import codecs
import numpy as np
import pyqtgraph as pg
        import datetime
                    import traceback

        self.project._mwapp._penDataSpatialViewWidget.zoomToPenData(
            self.selectedpendata)

    def lineMoved(self):
        if self.blockLineSignal:
            return
        pg.LinearRegionItem.lineMoved(self)
        if self.project._mwapp._segmenttree.doNotSetActiveObject is False:
            self.project._mwapp.setActiveObject(self)

    def lineMoveFinished(self):
        pg.LinearRegionItem.lineMoveFinished(self)
        if self.project._mwapp._segmenttree.doNotSetActiveObject is False:
            self.project._mwapp.setActiveObject(self)

    def getBounds(self):
        return self.lines[0].maxRange

    @property
    def project(self):
        return self._project

    @project.setter
    def project(self, p):
        if p is None:
            self._project = proxy(p)
            self.setBounds(bounds=(0, 0))
            self.setRegion([0, 0])
        else:
            if isinstance(p, ProxyType):

                self._project = p