def gabor_sequence_diffs_sess123(sessions,
                                 analyspar,
                                 sesspar,
                                 stimpar,
                                 basepar,
                                 permpar,
                                 figpar,
                                 seed=None,
                                 parallel=False):
    """
    gabor_sequence_diffs_sess123(sessions, analyspar, sesspar, stimpar, 
                                 basepar, permpar, figpar)

    Retrieves differences in ROI responses to Gabor sequences from 
    sessions 1 to 3.
        
    Saves results and parameters relevant to analysis in a dictionary.

    Required args:
        - sessions (list): 
            Session objects
        - analyspar (AnalysPar): 
            named tuple containing analysis parameters
        - sesspar (SessPar): 
            named tuple containing session parameters
        - stimpar (StimPar): 
            named tuple containing stimulus parameters
        - basepar (BasePar): 
            named tuple containing baseline parameters
        - permpar (PermPar): 
            named tuple containing permutation parameters
        - figpar (dict): 
            dictionary containing figure parameters
    
    Optional args:
        - seed (int): 
            seed value to use. (-1 treated as None)
            default: None
        - parallel (bool): 
            if True, some of the analysis is run in parallel across CPU cores 
            default: False
    """

    logger.info("Compiling Gabor sequence differences from session 1 to 3.",
                extra={"spacing": "\n"})

    # calculate multiple comparisons
    dummy_df = misc_analys.get_check_sess_df(
        sessions, None,
        analyspar).drop_duplicates(subset=["lines", "planes", "sess_ns"])
    permpar = misc_analys.set_multcomp(permpar, sess_df=dummy_df)

    split = "by_exp"
    diffs_df = seq_analys.get_sess_grped_diffs_df(
        sessions,
        analyspar=analyspar,
        stimpar=stimpar,
        basepar=basepar,
        permpar=permpar,
        split=split,
        randst=seed,
        parallel=parallel,
    )

    extrapar = {
        "split": split,
        "seed": seed,
    }

    info = {
        "analyspar": analyspar._asdict(),
        "sesspar": sesspar._asdict(),
        "stimpar": stimpar._asdict(),
        "basepar": basepar._asdict(),
        "permpar": permpar._asdict(),
        "extrapar": extrapar,
        "diffs_df": diffs_df.to_dict()
    }

    helper_fcts.plot_save_all(info, figpar)
def visual_flow_rel_resp_sess123(sessions,
                                 analyspar,
                                 sesspar,
                                 stimpar,
                                 permpar,
                                 figpar,
                                 seed=None,
                                 parallel=False):
    """
    visual_flow_rel_resp_sess123(sessions, analyspar, sesspar, stimpar, 
                                 permpar, figpar)

    Retrieves ROI responses to expected and unexpected visual flow, relative 
    to session 1.
        
    Saves results and parameters relevant to analysis in a dictionary.

    Required args:
        - sessions (list): 
            Session objects
        - analyspar (AnalysPar): 
            named tuple containing analysis parameters
        - sesspar (SessPar): 
            named tuple containing session parameters
        - stimpar (StimPar): 
            named tuple containing stimulus parameters
        - permpar (PermPar): 
            named tuple containing permutation parameters
        - figpar (dict): 
            dictionary containing figure parameters
    
    Optional args:
        - seed (int): 
            seed value to use. (-1 treated as None)
            default: None
        - parallel (bool): 
            if True, some of the analysis is run in parallel across CPU cores 
            default: False
    """

    logger.info("Compiling ROI visual flow responses relative to session 1.",
                extra={"spacing": "\n"})

    if analyspar.scale:
        raise ValueError("analyspar.scale should be set to False.")

    # calculate multiple comparisons
    dummy_df = misc_analys.get_check_sess_df(
        sessions, None,
        analyspar).drop_duplicates(subset=["lines", "planes", "sess_ns"])
    permpar = misc_analys.set_multcomp(permpar,
                                       sess_df=dummy_df,
                                       CIs=False,
                                       factor=2)

    rel_sess = 1
    rel_resp_df = seq_analys.get_rel_resp_stats_df(
        sessions,
        analyspar=analyspar,
        stimpar=stimpar,
        permpar=permpar,
        rel_sess=rel_sess,
        randst=seed,
        parallel=parallel,
    )

    extrapar = {
        "rel_sess": rel_sess,
        "seed": seed,
    }

    info = {
        "analyspar": analyspar._asdict(),
        "sesspar": sesspar._asdict(),
        "stimpar": stimpar._asdict(),
        "permpar": permpar._asdict(),
        "extrapar": extrapar,
        "rel_resp_df": rel_resp_df.to_dict(),
    }

    helper_fcts.plot_save_all(info, figpar)
Exemple #3
0
def visual_flow_tracked_roi_abs_usi_means_sess123(
        sessions, analyspar, sesspar, stimpar, basepar, idxpar, permpar, 
        figpar, seed=None, parallel=False):
    """
    visual_flow_tracked_roi_abs_usi_means_sess123(
        sessions, analyspar, sesspar, stimpar, basepar, idxpar, permpar, 
        figpar)

    Retrieves mean absolute for tracked ROI visual flow USIs for session 1 to 3.
        
    Saves results and parameters relevant to analysis in a dictionary.

    Required args:
        - sessions (list): 
            Session objects
        - analyspar (AnalysPar): 
            named tuple containing analysis parameters
        - sesspar (SessPar): 
            named tuple containing session parameters
        - stimpar (StimPar): 
            named tuple containing stimulus parameters
        - basepar (BasePar): 
            named tuple containing baseline parameters
        - idxpar (IdxPar): 
            named tuple containing index parameters
        - permpar (PermPar): 
            named tuple containing permutation parameters
        - figpar (dict): 
            dictionary containing figure parameters
    
    Optional args:
        - seed (int): 
            seed value to use. (-1 treated as None)
            default: None
        - parallel (bool): 
            if True, some of the analysis is run in parallel across CPU cores 
            default: False
    """

    logger.info(
        ("Compiling absolute means of tracked ROI Gabor USIs for "
        "sessions 1 to 3."), 
        extra={"spacing": "\n"})

    if not analyspar.tracked:
        raise ValueError("analyspar.tracked should be set to True.")

    # remove incomplete session series and warn
    sessions = misc_analys.check_sessions_complete(sessions)

    # calculate multiple comparisons
    dummy_df = misc_analys.get_check_sess_df(
        sessions, None, analyspar).drop_duplicates(
            subset=["lines", "planes", "sess_ns"])

    permpar = misc_analys.set_multcomp(permpar, sess_df=dummy_df, CIs=False)

    absolute = True
    by_mouse = False
    idx_stats_df = usi_analys.get_idx_stats_df(
        sessions, 
        analyspar=analyspar, 
        stimpar=stimpar, 
        basepar=basepar, 
        idxpar=idxpar, 
        permpar=permpar, 
        absolute=absolute, 
        by_mouse=by_mouse, 
        randst=seed,
        parallel=parallel, 
        )

    extrapar = {
        "absolute": absolute,
        "by_mouse": by_mouse,
        "seed": seed,
        }

    info = {"analyspar"   : analyspar._asdict(),
            "sesspar"     : sesspar._asdict(),
            "stimpar"     : stimpar._asdict(),
            "basepar"     : basepar._asdict(),
            "idxpar"      : idxpar._asdict(),
            "permpar"     : permpar._asdict(),
            "extrapar"    : extrapar,
            "idx_stats_df": idx_stats_df.to_dict()
            }

    helper_fcts.plot_save_all(info, figpar)
def gabor_decoding_sess123(sessions,
                           analyspar,
                           sesspar,
                           stimpar,
                           logregpar,
                           permpar,
                           figpar,
                           seed=None,
                           parallel=False):
    """
    gabor_decoding_sess123(sessions, analyspar, sesspar, stimpar, logregpar, 
                           permpar, figpar)

    Runs decoding analyses (D and U orientations).
        
    Saves results and parameters relevant to analysis in a dictionary.

    Required args:
        - sessions (list): 
            Session objects
        - analyspar (AnalysPar): 
            named tuple containing analysis parameters
        - sesspar (SessPar): 
            named tuple containing session parameters
        - stimpar (StimPar): 
            named tuple containing stimulus parameters
        - logregpar (LogRegPar): 
            named tuple containing logistic regression parameters
        - permpar (PermPar): 
            named tuple containing permutation parameters
        - figpar (dict): 
            dictionary containing figure parameters
    
    Optional args:
        - seed (int): 
            seed value to use. (-1 treated as None)
            default: None
        - parallel (bool): 
            if True, some of the analysis is run in parallel across CPU cores 
            default: False
    """

    comp_str = logregpar.comp.replace("ori", " orientation")

    logger.info(
        f"Compiling Gabor {comp_str} decoder performances for sessions 1 to 3.",
        extra={"spacing": "\n"})

    if not analyspar.scale:
        raise ValueError("analyspar.scale should be True.")

    # calculate multiple comparisons
    dummy_df = misc_analys.get_check_sess_df(
        sessions, None,
        analyspar).drop_duplicates(subset=["lines", "planes", "sess_ns"])
    permpar = misc_analys.set_multcomp(permpar,
                                       sess_df=dummy_df,
                                       pairs=False,
                                       factor=2)

    n_splits = 100
    score_df = decoding_analys.run_sess_logregs(
        sessions,
        analyspar=analyspar,
        stimpar=stimpar,
        logregpar=logregpar,
        permpar=permpar,
        n_splits=n_splits,
        seed=seed,
        parallel=parallel,
    )

    extrapar = {
        "n_splits": n_splits,
        "seed": seed,
    }

    info = {
        "analyspar": analyspar._asdict(),
        "sesspar": sesspar._asdict(),
        "stimpar": stimpar._asdict(),
        "logregpar": logregpar._asdict(),
        "permpar": permpar._asdict(),
        "extrapar": extrapar,
        "scores_df": score_df.to_dict(),
    }

    helper_fcts.plot_save_all(info, figpar)
Exemple #5
0
def gabor_roi_usi_sig_by_mouse(sessions, analyspar, sesspar, stimpar, basepar, 
                               idxpar, permpar, figpar, seed=None, 
                               parallel=False):
    """
    gabor_roi_usi_sig_by_mouse(sessions, analyspar, sesspar, stimpar, basepar, 
                               idxpar, permpar, figpar)

    Retrieves percentage of signifiant ROI Gabor USIs by mouse.
        
    Saves results and parameters relevant to analysis in a dictionary.

    Required args:
        - sessions (list): 
            Session objects
        - analyspar (AnalysPar): 
            named tuple containing analysis parameters
        - sesspar (SessPar): 
            named tuple containing session parameters
        - stimpar (StimPar): 
            named tuple containing stimulus parameters
        - basepar (BasePar): 
            named tuple containing baseline parameters
        - idxpar (IdxPar): 
            named tuple containing index parameters
        - permpar (PermPar): 
            named tuple containing permutation parameters
        - figpar (dict): 
            dictionary containing figure parameters
    
    Optional args:
        - seed (int): 
            seed value to use. (-1 treated as None)
            default: None
        - parallel (bool): 
            if True, some of the analysis is run in parallel across CPU cores 
            default: False
    """

    logger.info(
        f"Compiling percentages of significant Gabor USIs by mouse.", 
        extra={"spacing": "\n"}
        )

    by_mouse = True
    idx_df = usi_analys.get_idx_df(
        sessions, 
        analyspar=analyspar, 
        stimpar=stimpar, 
        basepar=basepar, 
        idxpar=idxpar, 
        permpar=permpar, 
        by_mouse=by_mouse,
        randst=seed, 
        parallel=parallel,
        )

    permpar = misc_analys.set_multcomp(
        permpar, sess_df=idx_df, pairs=False, factor=2
        )
    
    perc_sig_df = usi_analys.get_perc_sig_df(idx_df, analyspar, permpar, seed)

    extrapar = {
        "by_mouse": by_mouse,
        "seed"    : seed,
        }

    info = {"analyspar"  : analyspar._asdict(),
            "sesspar"    : sesspar._asdict(),
            "stimpar"    : stimpar._asdict(),
            "basepar"    : basepar._asdict(),
            "idxpar"     : idxpar._asdict(),
            "permpar"    : permpar._asdict(),
            "extrapar"   : extrapar,
            "perc_sig_df": perc_sig_df.to_dict()
            }

    helper_fcts.plot_save_all(info, figpar)