Skip to content

Commit

Permalink
Move analysis to pre-process data file
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Aug 7, 2023
1 parent 20bd64c commit 966229d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
40 changes: 39 additions & 1 deletion rsp_vision/analysis/preprocess_data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import logging

import allensdk.brain_observatory.dff as dff_module
import numpy as np
from allensdk.brain_observatory.r_neuropil import NeuropilSubtract

from rsp_vision.load.load_raw_suite2p_data import read_numpy_output_of_suite2p
from rsp_vision.load.load_stimulus_info import how_many_days_in_dataset


def pipeline_for_processing_raw_suite2p_data(folder_naming, config):
n_days = how_many_days_in_dataset(folder_naming)
data = read_numpy_output_of_suite2p(folder_naming, n_days)
n_roi = len(data[1]["F"])

# now handling only the case of one day. Need to extend to multiple
# days using registers2p

dff, r = neuropil_subtraction(
data[1]["F"],
data[1]["Fneu"],
)

len_session = config["len-session"]
n_sessions = config["n-sessions"]
dff = dff[:, :, np.newaxis]
dff = dff.reshape(n_sessions, n_roi, len_session)

is_cell = data[1]["iscell"]
day = {"stimulus": [1] * n_roi}

return {
"f": dff,
"is_cell": is_cell,
"day": day,
"r_neu": r,
"imaging": ["suite2p"],
"stim": ["TODO"],
"trig": ["TODO"],
}


def neuropil_subtraction(f, f_neu):
# for every ROI
# if fluorescence type is allen_df
logging.info("Performing neuropil subtraction...")

# use default parameters for all methods
neuropil_subtraction = NeuropilSubtract()
Expand Down
16 changes: 8 additions & 8 deletions rsp_vision/load/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import h5py
import yaml

from rsp_vision.load.load_raw_suite2p_data import read_numpy_output_of_suite2p
from rsp_vision.load.load_stimulus_info import (
check_how_many_sessions_in_dataset,
how_many_days_in_dataset,
from rsp_vision.analysis.preprocess_data import (

Check warning on line 8 in rsp_vision/load/load_data.py

View check run for this annotation

Codecov / codecov/patch

rsp_vision/load/load_data.py#L8

Added line #L8 was not covered by tests
pipeline_for_processing_raw_suite2p_data,
)

from ..objects.data_raw import DataRaw
Expand Down Expand Up @@ -65,10 +63,12 @@ def load_data_from_filename(
"Only sf_tf analysis is implemented for summary data"
)
else:
n_days = how_many_days_in_dataset(folder_naming)
check_how_many_sessions_in_dataset(folder_naming, n_days)
data = read_numpy_output_of_suite2p(folder_naming, n_days)
return DataRaw(data)
logging.info("Loading raw data from suite2p output")
data_dict = pipeline_for_processing_raw_suite2p_data(

Check warning on line 67 in rsp_vision/load/load_data.py

View check run for this annotation

Codecov / codecov/patch

rsp_vision/load/load_data.py#L66-L67

Added lines #L66 - L67 were not covered by tests
folder_naming, config
)

return DataRaw(data_dict, is_summary_data=False)

Check warning on line 71 in rsp_vision/load/load_data.py

View check run for this annotation

Codecov / codecov/patch

rsp_vision/load/load_data.py#L71

Added line #L71 was not covered by tests


def read_config_file(config_path: Path) -> dict:
Expand Down
2 changes: 2 additions & 0 deletions setup_for_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"drift_order": 2,
"fps_two_photon": 30,
"fps_tree_photon": 6.74,
"len-session": 11400,
"n-sessions": 18,
"spatial_frequencies": [0.01, 0.02, 0.04, 0.08, 0.16, 0.32],
"temporal_frequencies": [0.5, 1, 2, 4, 8, 16],
"directions": [0, 45, 90, 135, 180, 225, 270, 315],
Expand Down

0 comments on commit 966229d

Please sign in to comment.