Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions neuroglia/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,59 @@ def transform(self,X):
.reset_index()[['level_0','level_1']]
.rename(columns={'level_0':'time','level_1':'neuron'})
)


class Resampler(BaseEstimator, TransformerMixin):
"""Resample data

Parameters
----------
sample_times

Notes
-----

This estimator is stateless (besides constructor parameters), the
fit method does nothing but is useful when used in a pipeline.
"""

def __init__(self, sample_times=None):
self.sample_times = sample_times

def fit(self, X, y=None):
"""Do nothing and return the estimator unchanged

This method is here to implement the scikit-learn API and work in
scikit-learn pipelines.

Parameters
----------
X : array-like

Returns
-------
self

"""
return self

def transform(self, X):
"""Binarize each element of X

Parameters
----------
X : {array-like, sparse matrix}, shape [n_samples, n_features]
The data to binarize, element by element.
"""

if self.sample_times is None:
self.sample_times = X.index

splined_traces = running.apply(
lambda y: create_interpolator(X.index,y),
axis=0,
)

return splined_traces.apply(
lambda s: pd.Series(s(sample_times),index=sample_times)
).T
2 changes: 1 addition & 1 deletion neuroglia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def create_interpolator(t,y):
interpolator function that accepts a list of times

"""
interpolator = interpolate.InterpolatedUnivariateSpline(t, y)
interpolator = interpolate.interp1d(t, y, bounds_error=False)
return interpolator