from src.steps.source_extraction import run_source_extraction as main_source_extraction
from src.steps.component_evaluation import run_component_evaluation as main_component_evaluation

#%%

# set working path
working_path = '/home/sebastian/Documents/Melisa/calcium_imaging_analysis/'
os.chdir(working_path)

## Open thw data base with all data
states_df = db.open_analysis_states_database()

##Select one specific row of the data base specified by mouse, session, trial, is_rest, decoding_v, cropping_v, etc.
## If one experimental parameters is not specifies, it chooses al previos one with same id
## If one analysis version is not specified it selects the latest one
selected_row = db.select('decoding', 56165, 1, 1)

##Select one row from selected_rows
row = selected_row.iloc[0]
##This gives an array with the experimental details and analysis version.
index = row.name

#%%
##run decoding on data specified by index (one row in the data base)
main_decoding(index, row)

#%%
## Define parameters from cropping the movie.
## paramenters is given to the funcion or can be retreived from the data base (I think)

parameters_cropping = {
Exemplo n.º 2
0
    'use_cuda': False,
    'nonneg_movie': True,
    'border_nan': 'copy'
}

#parameters for source extraction
gSig = 5
gSiz = 4 * gSig + 1
corr_limits = np.linspace(0.4, 0.6, 5)
pnr_limits = np.linspace(3, 7, 5)
cropping_v = np.zeros(5)
motion_correction_v = np.zeros(5)

selected_rows = db.select(states_df,
                          'cropping',
                          mouse=mouse,
                          session=session,
                          trial=trial,
                          is_rest=is_rest)
mouse_row = selected_rows.iloc[0]
for kk in range(4):
    cropping_interval = [
        x1_crops[kk], x2_crops[kk], y1_crops[kk], y2_crops[kk]
    ]
    parameters_cropping = {
        'crop_spatial': True,
        'cropping_points_spatial': cropping_interval,
        'crop_temporal': False,
        'cropping_points_temporal': []
    }
    mouse_row = main_cropping(mouse_row, parameters_cropping)
    cropping_v[kk] = mouse_row.name[5]
from src.steps.component_evaluation import run_component_evaluation as main_component_evaluation
import src.analysis_files_manipulation as fm
import src.analysis.metrics as metrics

#%%

# Paths
analysis_states_database_path = 'references/analysis/analysis_states_database.xlsx'
backup_path = 'references/analysis/backup/'
parameters_path = 'references/analysis/parameters_database.xlsx'

## Open thw data base with all data
states_df = db.open_analysis_states_database()
## Select all the data corresponding to a particular mouse. Ex: 56165

selected_rows = db.select('decoding', 56165)

parameters_cropping = {
    'crop_spatial': True,
    'cropping_points_spatial': [80, 450, 210, 680],
    'crop_temporal': False,
    'cropping_points_temporal': []
}

parameters_motion_correction = {
    'motion_correct': True,
    'pw_rigid': True,
    'save_movie_rig': False,
    'gSig_filt': (7, 7),
    'max_shifts': (25, 25),
    'niter_rig': 1,
## Open thw data base with all data
states_df = db.open_analysis_states_database()
## Select all the data corresponding to a particular mouse. Ex: 56165

#selected_rows = db.select('decoding',56165)

mouse_number = 56165
session = 1
init_trial = 6
end_trial = 11
is_rest = 1

selected_rows = db.select(states_df,'source_extraction',mouse = mouse_number, session = session, is_rest = is_rest,
                          decoding_v= None,
                          cropping_v = 1,
                          motion_correction_v=1,
                          source_extraction_v = 1, alignment_v= 0, max_version= False)
selected_rows = selected_rows.query('trial > 5')

corr_mean_array = []
pnr_mean_array = []
corr_std_array = []
pnr_std_array = []
trial_name_array = []

corr_mean_array_is_rest = []
pnr_mean_array_is_rest = []
corr_std_array_is_rest = []
pnr_std_array_is_rest = []
trial_name_array_is_rest = []
analysis_states_database_path = 'references/analysis/analysis_states_database.xlsx'
backup_path = 'references/analysis/backup/'
parameters_path = 'references/analysis/parameters_database.xlsx'

## Open the data base with all data
states_df = db.open_analysis_states_database()

#selection of data to crop. Take into account that cropping is more or less the same for every session in one mouse.
mouse = 32364
session = None
trial = None
is_rest = None
# CROPPING
# Select the rows for cropping
selected_rows = db.select(states_df,'cropping',mouse=mouse,session=session, trial= trial, is_rest=is_rest)
mouse_row = selected_rows.iloc[0]
#shows one frame of the movie so the cropping region can be choosen.
plot_movie_frame(mouse_row)

#%%
#manualy load the cropping region of interest
parameters_cropping = cropping_interval() #check whether it is better to do it like this or to use the functions get
# and set parameters from the data_base_manipulation file

mouse_row = main_cropping(mouse_row, parameters_cropping) #run cropping

plot_movie_frame_cropped(mouse_row) # verify that the cropping is the desired one
# Now cropping parameters had been selected. Next step is selection version analysis.

states_df = db.append_to_or_merge_with_states_df(states_df, mouse_row) #merge the new state with the previous data base
backup_path = 'references/analysis/backup/'

## Open the data base with all data
states_df = db.open_analysis_states_database()
#detail the selected mouse
mouse = 32364
session = 1
trial = 1
is_rest = 1
cropping_version = 1

# Select rows from the data base fo the next analysis step motion correction
selected_rows = db.select(states_df,
                          'motion_correction',
                          mouse=mouse,
                          session=session,
                          trial=trial,
                          is_rest=is_rest,
                          cropping_v=cropping_version)

#For visualization: plot different filter sizes
mouse_row = selected_rows.iloc[0]
gSig_filters = 2 * np.arange(0, 5) + 3
get_fig_gSig_filt_vals(mouse_row, gSig_filters)

#start a cluster
n_processes = psutil.cpu_count()
cm.cluster.stop_server()
# Start a new cluster
c, dview, n_processes = cm.cluster.setup_cluster(
    backend='local',
#%% COMPONENT EVALUATION RUNNING ON MULTIPLE VERSIONS AND PARAMETERS

source_extraction_v_array = np.arange(1,30) # (this par shoul related to the length of the general selection of source extracted
#files)

min_SNR_array =np.arange(1,7,1)
r_values_min_array = [0.75,0.80,0.85,0.90,0.95]

#%%
for kk in range(len(source_extraction_v_array)):
    for ii in range(len(min_SNR_array)):
        for jj in range(len(r_values_min_array)):
            min_SNR = min_SNR_array[ii]
            r_values_min = r_values_min_array[jj]
            selected_row= db.select(states_df, 'component_evaluation', mouse = mouse, session = session, trial = trial,
                                    is_rest = is_rest, cropping_v=cropping_version, motion_correction_v=motion_correction_version,
                                 source_extraction_v= source_extraction_v_array[kk])
            mouse_row = selected_row.iloc[0]
            parameters_component_evaluation = {'min_SNR': min_SNR,
                                               'rval_thr': r_values_min,
                                               'use_cnn': False}
            mouse_row_new = main_component_evaluation(mouse_row, parameters_component_evaluation)
            states_df = db.append_to_or_merge_with_states_df(states_df, mouse_row_new)
            db.save_analysis_states_database(states_df, path=analysis_states_database_path, backup_path = backup_path)



#%% Plotting the result of selected and unselected cells for each parameter selection (contours and traces)

component_evaluation_v_array = np.arange(0,len(min_SNR_array)*len(r_values_min_array))
Exemplo n.º 8
0
import src.analysis.metrics as metrics
from caiman.source_extraction.cnmf.cnmf import load_CNMF

# Paths
analysis_states_database_path = os.environ[
    'PROJECT_DIR'] + 'references/analysis/analysis_states_database.xlsx'
backup_path = os.environ['PROJECT_DIR'] + 'references/analysis/backup/'
#parameters_path = 'references/analysis/parameters_database.xlsx'

## Open thw data base with all data
states_df = db.open_analysis_states_database()

#%% DECODING
# Select all the data corresponding to a particular mouse. Ex: 56165.

selected_rows = db.select(states_df, 'decoding', 56165)
mouse_row = selected_rows.iloc[0]
mouse_row = main_decoding(mouse_row)
states_df = db.append_to_or_merge_with_states_df(states_df, mouse_row)
db.save_analysis_states_database(states_df, analysis_states_database_path,
                                 backup_path)

#%% CROPPING
# Select the rows for cropping
selected_rows = db.select(states_df, 'cropping', 56165)

mouse_row = selected_rows.iloc[0]
plot_movie_frame(mouse_row)
#%%
parameters_cropping = cropping_interval(
)  #check whether it is better to do it like this or to use the functions get
# Paths
analysis_states_database_path = 'references/analysis/analysis_states_database.xlsx'
backup_path = 'references/analysis/backup/'

states_df = db.open_analysis_states_database()

mouse_number = 56165
session = 1
init_trial = 6
end_trial = 11
is_rest = None

#%% Select first data
selected_rows = db.select(states_df,
                          'decoding',
                          mouse=mouse_number,
                          session=session,
                          is_rest=is_rest)
mouse_row = selected_rows.iloc[0]
mouse_row = main_decoding(mouse_row)
plot_movie_frame(mouse_row)

#%% select cropping parameters
parameters_cropping = cropping_interval(
)  #check whether it is better to do it like this or to use the functions get
# and set parameters from the data_base_manipulation file

#%% Run decoding for group of data tha have the same cropping parameters (same mouse)

for i in range(init_trial, end_trial):
    selection = selected_rows.query('(trial ==' + f'{i}' + ')')