def _shift_pt_trace(trace, offset):
    tr_type = type(trace)
    tr_new = tr_type(
                time=trace.time_pts + offset,
                data=trace.data_pts,)
    copy_trace_attrs(trace, tr_new, comment='+(Shifted %2.2f)' % offset)
    return tr_new
Ejemplo n.º 2
0
def _fixeddt_gradient(self, *args):
    # assert False, 'ToCheck'
    tr_new = TraceFixedDT(
        time=self.time_pts, data=np.gradient(self.data_pts_np, *args) * self.data_unit / self.get_dt_new()
    )
    copy_trace_attrs(self, tr_new, comment="+gradient")
    return tr_new
Ejemplo n.º 3
0
def _fixeddt_gradient(self, *args):
    # assert False, 'ToCheck'
    tr_new = TraceFixedDT(time=self.time_pts,
                          data=np.gradient(self.data_pts_np, *args) *
                          self.data_unit / self.get_dt_new())
    copy_trace_attrs(self, tr_new, comment="+gradient")
    return tr_new
def _shift_pt_trace(trace, offset):
    tr_type = type(trace)
    tr_new = tr_type(
        time=trace.time_pts + offset,
        data=trace.data_pts,
    )
    copy_trace_attrs(trace, tr_new, comment='+(Shifted %2.2f)' % offset)
    return tr_new
Ejemplo n.º 5
0
def _butterworthfilter(tr, filterorder, cutoff_frequency):
    cutoff_frequency.rescale('Hz')
    import scipy.signal
    frequency_hz = 1 / float(tr.get_dt_new().rescale('s'))
    n_frq_hz = frequency_hz / 2.0

    cuttoff_norm = cutoff_frequency / n_frq_hz
    (coeff_num, coeff_denom) = scipy.signal.filter_design.butter(filterorder, cuttoff_norm)
    filteredsignal = scipy.signal.lfilter(coeff_num, coeff_denom, tr.data_pts_np)

    tr_new = TraceFixedDT(time=tr.time_pts, data=filteredsignal * tr.data_unit,)
    copy_trace_attrs(tr, tr_new, comment="+(Butterworth Filtered)" )
    return tr_new
Ejemplo n.º 6
0
def _filterlowpassrc(tr, tau):
    import scipy.signal
    assert isinstance(tr, TraceFixedDT)
    dt = tr.get_dt_new()
    k = 1. / tau * dt
    k = float(k.rescale(pq.dimensionless))

    coeff_denom = np.array([1, k - 1])
    coeff_num = np.array([0, k])

    xp = scipy.signal.lfilter(coeff_num, coeff_denom, tr.data_pts_np)
    tr_new = TraceFixedDT(time=tr.time_pts,
                          data=xp * tr.data_unit,
                         )
    copy_trace_attrs(tr, tr_new, comment="+(LP RC Filtered)" )
    return tr_new
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------

from morphforge.traces.traceobjpluginctrl import copy_trace_attrs
from morphforge.traces.traceobjpluginctrl import TraceMethodCtrl
from morphforge.traces import TraceFixedDT
from morphforge.traces import TraceVariableDT
from morphforge.traces import TracePiecewise
from MMtrace_conversion import TraceConverter, TraceApproximator

# Conversion to: FixedDT:
#########################
TraceMethodCtrl.register(TraceFixedDT, 'convert_to_fixed', lambda tr, dt: copy_trace_attrs(tr_old=tr, tr_new=TraceConverter.rebase_to_fixed_dt(tr, dt)))
TraceMethodCtrl.register(TraceVariableDT, 'convert_to_fixed', lambda tr, dt: copy_trace_attrs(tr_old=tr, tr_new=TraceConverter.rebase_to_fixed_dt(tr, dt)))
TraceMethodCtrl.register(TracePiecewise, 'convert_to_fixed', lambda tr, dt: copy_trace_attrs(tr_old=tr, tr_new=TraceConverter.rebase_to_fixed_dt(tr, dt)))




# Conversion to VariableDT:
###########################
TraceMethodCtrl.register(
        TraceFixedDT,
        'convert_to_variable', 
        lambda tr, eps: copy_trace_attrs(tr_old=tr, tr_new=TraceConverter.reduce_to_variable_dt_trace(original_trace=tr, epsilon=eps)))

TraceMethodCtrl.register(
        TraceVariableDT,
Ejemplo n.º 8
0
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------

from morphforge.traces.traceobjpluginctrl import copy_trace_attrs
from morphforge.traces.traceobjpluginctrl import TraceMethodCtrl
from morphforge.traces import TraceFixedDT
from morphforge.traces import TraceVariableDT
from morphforge.traces import TracePiecewise
from MMtrace_conversion import TraceConverter, TraceApproximator

# Conversion to: FixedDT:
#########################
TraceMethodCtrl.register(
    TraceFixedDT, 'convert_to_fixed', lambda tr, dt: copy_trace_attrs(
        tr_old=tr, tr_new=TraceConverter.rebase_to_fixed_dt(tr, dt)))
TraceMethodCtrl.register(
    TraceVariableDT, 'convert_to_fixed', lambda tr, dt: copy_trace_attrs(
        tr_old=tr, tr_new=TraceConverter.rebase_to_fixed_dt(tr, dt)))
TraceMethodCtrl.register(
    TracePiecewise, 'convert_to_fixed', lambda tr, dt: copy_trace_attrs(
        tr_old=tr, tr_new=TraceConverter.rebase_to_fixed_dt(tr, dt)))

# Conversion to VariableDT:
###########################
TraceMethodCtrl.register(
    TraceFixedDT, 'convert_to_variable', lambda tr, eps: copy_trace_attrs(
        tr_old=tr,
        tr_new=TraceConverter.reduce_to_variable_dt_trace(original_trace=tr,
                                                          epsilon=eps)))
Ejemplo n.º 9
0
def _clone_piecewise(tr):
    tr_new = TracePiecewise(pieces = [copy.copy(piece) for piece in tr.pieces])
    copy_trace_attrs(tr, tr_new, comment='+(cloned)')
    return tr_new
Ejemplo n.º 10
0
def _clone_variable(tr):
    tr_new = TraceVariableDT(
            time = np.copy( tr.time_pts_np) * tr.time_units,
            data = np.copy( tr.data_pts_np) * tr.data_units )
    copy_trace_attrs(tr, tr_new, comment='+(cloned)')
    return tr_new