Skip to content

run_caiman.py

run_caiman(file_paths, parameters, sampling_rate, output_dir, is3D)

Runs the standard caiman analysis pipeline (CNMF.fit_file method).

Parameters:

Name Type Description Default
file_paths list

Image (full) paths

required
parameters dict

Caiman parameters

required
sampling_rate float

Image sampling rate (Hz)

required
output_dir str

Output directory

required
is3D bool

the data is 3D

required
Source code in element_interface/run_caiman.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def run_caiman(
    file_paths: list,
    parameters: dict,
    sampling_rate: float,
    output_dir: str,
    is3D: bool,
):
    """
    Runs the standard caiman analysis pipeline (CNMF.fit_file method).

    Args:
        file_paths (list): Image (full) paths
        parameters (dict): Caiman parameters
        sampling_rate (float): Image sampling rate (Hz)
        output_dir (str): Output directory
        is3D (bool):  the data is 3D
    """
    parameters["is3D"] = is3D
    parameters["fnames"] = file_paths
    parameters["fr"] = sampling_rate

    opts = params.CNMFParams(params_dict=parameters)

    c, dview, n_processes = cm.cluster.setup_cluster(
        backend="local", n_processes=None, single_thread=False
    )

    cnm = CNMF(n_processes, params=opts, dview=dview)
    cnmf_output, mc_output = cnm.fit_file(
        motion_correct=True, include_eval=True, output_dir=output_dir, return_mc=True
    )

    cm.stop_server(dview=dview)

    cnmf_output_file = pathlib.Path(cnmf_output.mmap_file[:-4] + "hdf5")
    assert cnmf_output_file.exists()
    assert cnmf_output_file.parent == pathlib.Path(output_dir)

    _save_mc(mc_output, cnmf_output_file.as_posix(), parameters["is3D"])