Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added testing for processing module #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
16 changes: 15 additions & 1 deletion src/iblphotometry/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,29 @@ def fillnan_kde(y: np.ndarray, w: int = 25):


def remove_outliers(
F: pd.Series, w_size: int = 1000, alpha: float = 0.005, w: int = 25
F: pd.Series,
w_len: float = 60,
alpha: float = 0.005,
w: int = 25,
fs=None,
max_it=100,
):
y, t = F.values, F.index.values
fs = 1 / np.median(np.diff(t)) if fs is None else fs
w_size = int(w_len * fs)

y = copy(y)
outliers = detect_outliers(y, w_size=w_size, alpha=alpha)
j = 0
while len(outliers) > 0:
y[outliers] = np.nan
y = fillnan_kde(y, w=w)
outliers = detect_outliers(y, w_size=w_size, alpha=alpha)
if j > max_it:
break
else:
j += 1

return pd.Series(y, index=t)


Expand Down
8 changes: 4 additions & 4 deletions src/iblphotometry/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from iblphotometry.processing import make_sliding_window
from iblphotometry.pipelines import run_pipeline
from brainbox.io.one import SessionLoader

Check failure on line 13 in src/iblphotometry/qc.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/iblphotometry/qc.py:13:29: F401 `brainbox.io.one.SessionLoader` imported but unused

logger = logging.getLogger()

Expand Down Expand Up @@ -65,7 +65,7 @@
S = sliding_metric(
F, metric=metric, **sliding_kwargs, metric_kwargs=metric_kwargs
)
r, p = linregress(S.times(), S.values)[2:4]
r, p = linregress(S.index.values, S.values)[2:4]
else:
r = np.nan
p = np.nan
Expand Down Expand Up @@ -121,15 +121,15 @@

# get behavioral data
# TODO this should be provided
sl = SessionLoader(eid=eid, one=data_loader.one)
# sl = SessionLoader(eid=eid, one=data_loader.one)
# for caroline
# trials = sl.load_trials(
# collection='alf/task_00'
# ) # this is necessary fo caroline
trials = sl.load_trials() # should be good for all others
# trials = sl.load_trials() # should be good for all others

# the old way
# trials = data_loader.one.load_dataset(eid, '*trials.table.pqt')
trials = data_loader.one.load_dataset(eid, '*trials.table.pqt')

for band in signal_bands:
raw_tf = raw_dfs[band]
Expand Down
34 changes: 34 additions & 0 deletions src/iblphotometry_tests/test_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import iblphotometry.io as fio
import iblphotometry.processing as processing
import pandas as pd

from iblphotometry_tests.base_tests import PhotometryDataTestCase


class TestProcessing(PhotometryDataTestCase):
# think here about the possible use cases

def test_processing(self):
self.set_paths('alejandro')
# get data
raw_dfs = fio.from_ibl_pqt(
self.paths['photometry_signal_pqt'],
self.paths['photometryROI_locations_pqt'],
)
trials = pd.read_parquet(self.paths['trials_table_pqt'])

Check failure on line 18 in src/iblphotometry_tests/test_processing.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

src/iblphotometry_tests/test_processing.py:18:9: F841 Local variable `trials` is assigned to but never used
raw_df = raw_dfs['GCaMP']['DMS']

# bleach corrections
processing.lowpass_bleachcorrect(raw_df)
processing.exponential_bleachcorrect(raw_df)

# outlier removal
processing.remove_outliers(raw_df)
processing.remove_spikes(raw_df)

# other functions
processing.make_sliding_window(raw_df.values, 100, method='stride_tricks')
processing.make_sliding_window(raw_df.values, 100, method='window_generator')
processing.sliding_dFF(raw_df, w_len=60)
processing.sliding_z(raw_df, w_len=60)
processing.sliding_mad(raw_df, w_len=60)
Loading