def C_analysis_pdf(datafile, iprotocol=0, Nmax=1000000, roi=0):

    data = MultimodalData(datafile)

    if not os.path.isdir(summary_pdf_folder(datafile)):
        os.mkdir(summary_pdf_folder(datafile))

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-gratings-analysis.pdf' % data.protocols[iprotocol])

    if roi == 0:
        ROIs = np.arange(data.iscell.sum())[:Nmax]
    else:
        ROIs = [roi]

    CELL_RESPS = []
    with PdfPages(pdf_filename) as pdf:

        for roi in ROIs:

            fig, cell_resp = C_ROI_analysis(data,
                                            roiIndex=roi,
                                            iprotocol=iprotocol)
            CELL_RESPS.append(cell_resp)

            pdf.savefig(fig)  # saves the current figure into a pdf page
            plt.close(fig)

        fig = summary_fig(CELL_RESPS)

        pdf.savefig(fig)
        plt.close(fig)

    print('[ok] moving dot analysis saved as: "%s" ' % pdf_filename)
def DS_analysis_pdf(datafile, iprotocol=0, Nmax=1000000):

    data = MultimodalData(datafile)

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-direction_selectivity.pdf' % data.protocols[iprotocol])

    Nresp, SIs = 0, []
    with PdfPages(pdf_filename) as pdf:

        for roi in np.arange(data.iscell.sum())[:Nmax]:

            print('   - direction-selectivity analysis for ROI #%i / %i' %
                  (roi + 1, data.iscell.sum()))
            fig, SI, responsive = DS_ROI_analysis(data,
                                                  roiIndex=roi,
                                                  iprotocol=iprotocol)
            pdf.savefig()  # saves the current figure into a pdf page
            plt.close()

            if responsive:
                Nresp += 1
                SIs.append(SI)

        summary_fig2(Nresp,
                     data.iscell.sum(),
                     SIs,
                     label='Direct. Select. Index')
        pdf.savefig()  # saves the current figure into a pdf page
        plt.close()

    print('[ok] direction selectivity analysis saved as: "%s" ' % pdf_filename)
Example #3
0
def analysis_pdf(datafile, iprotocol=0, Nmax=1000000):

    data = Data(datafile)

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-behavioral-modulation.pdf' % data.protocols[iprotocol])

    full_resp = compute_population_resp(datafile,
                                        protocol_id=iprotocol,
                                        Nmax=Nmax)

    with PdfPages(pdf_filename) as pdf:
        # print('   - behavioral-modulation analysis for ROI #%i / %i' % (roi+1, data.iscell.sum()))
        fig = population_tuning_fig(full_resp)
        pdf.savefig(fig)  # saves the current figure into a pdf page
        plt.close()
        fig1, fig2 = behavior_mod_population_tuning_fig(
            full_resp, running_speed_threshold=0.1, pupil_threshold=2.5)

        pdf.savefig(fig1)  # saves the current figure into a pdf page
        plt.close(fig1)
        pdf.savefig(fig2)  # saves the current figure into a pdf page
        plt.close(fig2)

    print('[ok] behavioral-modulation analysis saved as: "%s" ' % pdf_filename)
Example #4
0
def analysis_pdf(datafile, iprotocol=0, Nmax=1000000):

    data = MultimodalData(datafile)

    pdf_filename = os.path.join(summary_pdf_folder(datafile), '%s-secondary_RF.pdf' % data.protocols[iprotocol])

    # find center and surround
    icenter = np.argwhere([('center' in p) for p in data.protocols])[0][0]
    isurround = np.argwhere([('surround' in p) for p in data.protocols])[0][0]
    
    curves, results = [], {'Ntot':data.iscell.sum()}
    with PdfPages(pdf_filename) as pdf:

        for roi in np.arange(data.iscell.sum())[:Nmax]:

            print('   - secondary-RF analysis for ROI #%i / %i' % (roi+1, data.iscell.sum()))
            # fig, fig2, radii, max_response_curve, imax_response_curve, full_resp = ROI_analysis(data, roiIndex=roi,
            #                                                                                     iprotocol_center=icenter,
            #                                                                                     iprotocol_surround=isurround)
            FIGS = ROI_analysis(data, roiIndex=roi,
                                iprotocol_center=icenter,
                                iprotocol_surround=isurround)
            for fig in FIGS:
                pdf.savefig(fig)
                plt.close(fig)
            
        #     pdf.savefig(fig2)
        #     plt.close(fig2)

        #     if max_response_curve is not None:
        #         curves.append(max_response_curve)

        #     # initialize if not done
        #     for key in full_resp:
        #         if ('-bins' in key) and (key not in results):
        #             results[key] = full_resp[key]
        #         elif (key not in results):
        #             results[key] = []
                    
        #     significant_cond = (full_resp['significant']==True)
        #     if np.sum(significant_cond)>0:
        #         imax = np.argmax(full_resp['value'][significant_cond])
        #         for key in full_resp:
        #             if ('-bins' not in key):
        #                 results[key].append(full_resp[key][significant_cond][imax])

        # if len(results['value'])>0:
            
        #     fig = SS_summary_fig(results)
        #     pdf.savefig(fig)
        #     plt.close(fig)

        #     fig = summary_fig(radii, curves, data.iscell.sum())
        #     pdf.savefig(fig)
        #     plt.close(fig)

    print('[ok] secondary RF analysis saved as: "%s" ' % pdf_filename)
def analysis_pdf(datafile,
                 iprotocol=0,
                 response_significance_threshold=0.01,
                 roi=0,
                 Nmax=1000000):

    data = MultimodalData(datafile)

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-moving-dots_selectivity.pdf' % data.protocols[iprotocol])

    if roi == 0:
        ROIs = np.arange(data.iscell.sum())[:Nmax]
    else:
        ROIs = [roi]

    CELL_RESPS = []
    with PdfPages(pdf_filename) as pdf:

        for roi in ROIs:

            fig, cell_resp = ROI_analysis(
                data,
                roiIndex=roi,
                iprotocol=iprotocol,
                response_significance_threshold=response_significance_threshold
            )
            CELL_RESPS.append(cell_resp)

            pdf.savefig(fig)  # saves the current figure into a pdf page
            plt.close(fig)

        fig = summary_fig(CELL_RESPS)

        pdf.savefig(fig)
        plt.close(fig)
        np.save(
            os.path.join(summary_pdf_folder(datafile),
                         'summary-moving-dot.npy'), CELL_RESPS)

    print('[ok] moving dot analysis saved as: "%s" ' % pdf_filename)
Example #6
0
def analysis_pdf(datafile, iprotocol=0, Nmax=1000000):

    data = MultimodalData(datafile)

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-surround_suppression.pdf' % data.protocols[iprotocol])

    curves, results = [], {'Ntot': data.iscell.sum()}
    with PdfPages(pdf_filename) as pdf:

        for roi in np.arange(data.iscell.sum())[:Nmax]:

            print('   - surround-suppression analysis for ROI #%i / %i' %
                  (roi + 1, data.iscell.sum()))
            fig, fig2, radii, max_response_curve, imax_response_curve, full_resp = ROI_analysis(
                data, roiIndex=roi, iprotocol=iprotocol)
            pdf.savefig(fig)
            pdf.savefig(fig2)
            plt.close(fig)
            plt.close(fig2)

            if max_response_curve is not None:
                curves.append(max_response_curve)

            # initialize if not done
            for key in full_resp:
                if ('-bins' in key) and (key not in results):
                    results[key] = full_resp[key]
                elif (key not in results):
                    results[key] = []

            significant_cond = (full_resp['significant'] == True)
            if np.sum(significant_cond) > 0:
                imax = np.argmax(full_resp['value'][significant_cond])
                for key in full_resp:
                    if ('-bins' not in key):
                        results[key].append(
                            full_resp[key][significant_cond][imax])

        if len(results['value']) > 0:

            fig = SS_summary_fig(results)
            pdf.savefig(fig)
            plt.close(fig)

            fig = summary_fig(radii, curves, data.iscell.sum())
            pdf.savefig(fig)
            plt.close(fig)

    print('[ok] direction selectivity analysis saved as: "%s" ' % pdf_filename)
Example #7
0
def analysis_pdf(datafile, iprotocol=0, Nmax=1000000):

    data = MultimodalData(datafile, with_visual_stim=True)

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-RF_mapping.pdf' % data.protocols[iprotocol])

    curves, results = [], {'Ntot': data.iscell.sum()}
    with PdfPages(pdf_filename) as pdf:

        for roi in np.arange(data.iscell.sum())[:Nmax]:

            print('   - RF mapping analysis for ROI #%i / %i' %
                  (roi + 1, data.iscell.sum()))
            fig = ROI_analysis(data, roiIndex=roi, iprotocol=iprotocol)
            pdf.savefig(fig)
            plt.close(fig)

    print('[ok] RF mapping analysis saved as: "%s" ' % pdf_filename)
def analysis_pdf(datafile, iprotocol=0, Nmax=1000000):

    data = MultimodalData(datafile)

    pdf_filename = os.path.join(
        summary_pdf_folder(datafile),
        '%s-contrast_curves.pdf' % data.protocols[iprotocol])

    if data.metadata['CaImaging']:

        results = {'Ntot': data.iscell.sum()}

        with PdfPages(pdf_filename) as pdf:

            CURVES = []
            for roi in np.arange(data.iscell.sum())[:Nmax]:
                print('   - contrast-curves analysis for ROI #%i / %i' %
                      (roi + 1, data.iscell.sum()))
                fig, contrasts, max_response_curve = ROI_analysis(
                    data, roiIndex=roi, iprotocol=iprotocol)
                pdf.savefig(fig)
                plt.close(fig)
                if np.max(max_response_curve) > 0:
                    CURVES.append(max_response_curve)
            #
            fig = summary_fig(contrasts, CURVES, data.iscell.sum())
            pdf.savefig(fig)
            plt.close(fig)

    elif data.metadata['Electrophy']:
        with PdfPages(pdf_filename) as pdf:
            fig, fig2 = Ephys_analysis(data, iprotocol=iprotocol)
            pdf.savefig(fig)
            plt.close(fig)
            pdf.savefig(fig2)
            plt.close(fig2)

    print('[ok] contrast-curves analysis saved as: "%s" ' % pdf_filename)
def analysis_pdf(datafile,
                 iprotocol=-1,
                 Nmax=2,
                 verbose=False):

    data = MultimodalData(datafile)

    if iprotocol<0:
        iprotocol = np.argwhere([('gaussian-blobs' in p) for p in data.protocols])[0][0]
        print('gaussian-blob analysis for protocol #', iprotocol)
    
    pdf_filename = os.path.join(summary_pdf_folder(datafile), '%s-flashes.pdf' % data.protocols[iprotocol])
    
    
    if data.metadata['CaImaging']:

        # results = {'Ntot':data.iscell.sum()}
    
        with PdfPages(pdf_filename) as pdf:
            
            fig = Ophys_analysis(data,
                                 Nmax=Nmax,
                                 verbose=verbose)
            
            pdf.savefig(fig)
            plt.close(fig)

            
    elif data.metadata['Electrophy']:
        with PdfPages(pdf_filename) as pdf:
            fig, fig2 = Ephys_analysis(data, iprotocol=iprotocol)
            pdf.savefig(fig)
            plt.close(fig)
            pdf.savefig(fig2)
            plt.close(fig2)
            

    print('[ok] gaussian-blobs analysis saved as: "%s" ' % pdf_filename)
def run_analysis_and_save_figs(datafile, suffix='', folder='./', Ybar=0.1):

    pdf_filename = os.path.join(summary_pdf_folder(datafile),
                                'motion-contour-interaction.pdf')

    data = MCI_data(datafile)

    if len(data.episode_static_patch.varied_parameters.keys()) == 2:
        contour_key = [
            k for k in data.episode_static_patch.varied_parameters.keys()
        ][0]
    elif len(data.episode_static_patch.varied_parameters.keys()) == 1:
        contour_key = ''
    else:
        print(
            '\n\n /!\ MORE THAN ONE CONTOUR KEY /!\ \n    --> needs special analysis   \n\n '
        )

    if len(data.episode_moving_dots.varied_parameters.keys()) == 2:
        motion_key = [
            k for k in data.episode_moving_dots.varied_parameters.keys()
        ][0]
    elif len(data.episode_moving_dots.varied_parameters.keys()) == 1:
        motion_key = ''
    else:
        print(
            '\n\n /!\ MORE THAN ONE MOTION KEY /!\ \n    --> needs special analysis   \n\n '
        )

    if 'patch-delay' in data.episode_mixed.varied_parameters.keys():
        mixed_only_key = 'patch-delay'
    else:
        mixed_only_key = ''

    with PdfPages(pdf_filename) as pdf:
        # static patches
        fig, AX = data.episode_static_patch.plot_trial_average(
            roiIndices='mean',
            column_key=contour_key,
            with_annotation=True,
            with_std=False,
            ybar=Ybar,
            ybarlabel='%.1fdF/F' % Ybar,
            xbar=1,
            xbarlabel='1s')
        fig.suptitle('static patches\n\n', fontsize=9)
        pdf.savefig(fig)
        plt.close(fig)

        # moving dots
        fig, AX = data.episode_moving_dots.plot_trial_average(
            roiIndices='mean',
            column_key=motion_key,
            with_annotation=True,
            with_std=False,
            ybar=Ybar,
            ybarlabel='%.1fdF/F' % Ybar,
            xbar=1,
            xbarlabel='1s')
        fig.suptitle('moving dots\n\n', fontsize=9)
        pdf.savefig(fig)
        plt.close(fig)

        # mixed stimuli
        fig, AX = data.episode_mixed.plot_trial_average(
            roiIndices='mean',
            column_key=mixed_only_key,
            row_key=motion_key,
            color_key=('patch-%s' % contour_key if
                       (contour_key != '') else ''),
            with_annotation=True,
            with_std=False,
            ybar=Ybar,
            ybarlabel='%.1fdF/F' % Ybar,
            xbar=1,
            xbarlabel='1s')
        fig.suptitle('mixed static-patch + moving-dots\n\n', fontsize=9)
        pdf.savefig(fig)
        plt.close(fig)

        if data.episode_random_dots is not None:
            fig, AX = data.episode_random_dots.plot_trial_average(
                roiIndices='mean',
                column_key=motion_key,
                with_annotation=True,
                with_std=False,
                ybar=Ybar,
                ybarlabel='%.1fdF/F' % Ybar,
                xbar=1,
                xbarlabel='1s')
            fig.suptitle('random line moving-dots\n\n', fontsize=9)
            pdf.savefig(fig)
            plt.close(fig)

        if data.episode_mixed_random_dots is not None:
            fig, AX = data.episode_mixed_random_dots.plot_trial_average(
                roiIndices='mean',
                column_key=motion_key,
                color_key=('patch-%s' % contour_key if
                           (contour_key != '') else ''),
                with_annotation=True,
                with_std=False,
                ybar=Ybar,
                ybarlabel='%.1fdF/F' % Ybar,
                xbar=1,
                xbarlabel='1s')
            fig.suptitle('mixed static-patch + random line moving-dots\n\n',
                         fontsize=9)
            pdf.savefig(fig)
            plt.close(fig)

        ## Focusing on cells responding to contour features

        rois_of_interest_contour = find_responsive_cells(
            data.episode_static_patch,
            param_key=contour_key,
            interval_pre=[-1, 0],
            interval_post=[0.5, 1.5])

        rois_of_interest_motion = find_responsive_cells(
            data.episode_moving_dots,
            param_key=motion_key,
            interval_pre=[-2, 0],
            interval_post=[1, 3])

        rois_of_interest_contour_only = exclude_motion_sensitive_cells(
            rois_of_interest_contour, rois_of_interest_motion)

        fig, ax = make_proportion_fig(data, rois_of_interest_contour,
                                      rois_of_interest_motion,
                                      rois_of_interest_contour_only)
        pdf.savefig(fig)
        plt.close(fig)

        for key in [
                key for key in rois_of_interest_contour_only
                if 'resp' not in key
        ]:

            print('- %s patch --> %i significantly modulated cells (%.1f%%) ' %
                  (key, len(rois_of_interest_contour_only[key]),
                   100 * len(rois_of_interest_contour_only[key]) / data.nROIs))

            if len(rois_of_interest_contour_only[key]) > 0:

                fig, AX = data.episode_static_patch.plot_trial_average(
                    roiIndices=rois_of_interest_contour_only[key],
                    column_key=contour_key,
                    with_annotation=True,
                    with_std=False,
                    ybar=Ybar,
                    ybarlabel='%.1fdF/F' % Ybar,
                    xbar=1,
                    xbarlabel='1s')
                fig.suptitle('static patches --> cells resp. to %s\n\n\n' %
                             key,
                             fontsize=8)
                pdf.savefig(fig)
                plt.close(fig)

                fig, AX = data.episode_moving_dots.plot_trial_average(
                    roiIndices=rois_of_interest_contour_only[key],
                    column_key=motion_key,
                    with_annotation=True,
                    with_std=False,
                    ybar=Ybar,
                    ybarlabel='%.1fdF/F' % Ybar,
                    xbar=1,
                    xbarlabel='1s')
                fig.suptitle('moving-dots --> cells resp. to %s\n\n\n' % key,
                             fontsize=8)
                pdf.savefig(fig)
                plt.close(fig)
                fig, AX = data.episode_mixed.plot_trial_average(
                    roiIndices=rois_of_interest_contour_only[key],
                    column_key=mixed_only_key,
                    row_key=motion_key,
                    color_key=('patch-%s' % contour_key if
                               (contour_key != '') else ''),
                    with_annotation=True,
                    with_std=False,
                    ybar=Ybar,
                    ybarlabel='%.1fdF/F' % Ybar,
                    xbar=1,
                    xbarlabel='1s')
                fig.suptitle('mixed-stim --> cells resp. to %s\n\n\n' % key,
                             fontsize=8)
                pdf.savefig(fig)
                plt.close(fig)

                for contour_index in range(
                        len(data.episode_static_patch.
                            varied_parameters[contour_key])):
                    for motion_index in range(
                            len(data.episode_moving_dots.
                                varied_parameters[motion_key])):
                        for mixed_index in range(
                                len(data.episode_mixed.
                                    varied_parameters[mixed_only_key])):
                            mixed_indices = [
                                motion_index, contour_index, mixed_index
                            ]
                            mixed_keys = [
                                motion_key,
                                'patch-%s' % contour_key, mixed_only_key
                            ]
                            fig, _, _ = interaction_fig(
                                data.get_responses(
                                    data.episode_static_patch.
                                    find_episode_cond(contour_key,
                                                      contour_index),
                                    data.episode_moving_dots.find_episode_cond(
                                        motion_key, motion_index),
                                    data.episode_mixed.find_episode_cond(
                                        mixed_keys, mixed_indices),
                                    roiIndices=rois_of_interest_contour_only[
                                        key]),
                                static_patch_label='patch\n (%s=%i)' %
                                (contour_key[:3], data.episode_static_patch.
                                 varied_parameters[contour_key][contour_index]
                                 ),
                                moving_dots_label='mv-dots\n (%s=%i)' %
                                (motion_key[:3], data.episode_moving_dots.
                                 varied_parameters[motion_key][motion_index]),
                                mixed_label='mixed\n (%s=%i)' %
                                (mixed_only_key.replace('patch-', '')[:3],
                                 data.episode_mixed.varied_parameters[
                                     mixed_only_key][mixed_index]),
                                Ybar=Ybar)
                            pdf.savefig(fig)
                            plt.close(fig)

        print('[ok] motion-contour-interaction analysis saved as: "%s" ' %
              pdf_filename)
def analysis_pdf(datafile, Nmax=1000000):

    data = MultimodalData(datafile)

    stim_duration = data.metadata['Protocol-1-presentation-duration']
    interval_post = [1. / 2. * stim_duration, stim_duration]
    interval_pre = [interval_post[0] - interval_post[1], 0]

    try:
        # find the protocol with the many-standards
        iprotocol_MS = np.argwhere([('many-standards' in p)
                                    for p in data.protocols])[0][0]
        # find the protocol with the oddball-1
        iprotocol_O1 = np.argwhere([('oddball-1' in p)
                                    for p in data.protocols])[0][0]
        # find the protocol with the oddball-2
        iprotocol_O2 = np.argwhere([('oddball-2' in p)
                                    for p in data.protocols])[0][0]

        # mismatch negativity angles
        MM_angles = [
            data.metadata['Protocol-%i-angle-redundant (deg)' %
                          (1 + iprotocol_O1)],
            data.metadata['Protocol-%i-angle-deviant (deg)' %
                          (1 + iprotocol_O1)]
        ]
        #
        DATA = {'stim_duration': stim_duration}
        DATA[str(int(MM_angles[0]))] = {
            'iprotocol_control': iprotocol_MS,
            'control': [],
            'redundant': [],
            'deviant': [],
            'responsive': []
        }
        DATA[str(int(MM_angles[1]))] = {
            'iprotocol_control': iprotocol_MS,
            'control': [],
            'redundant': [],
            'deviant': [],
            'responsive': []
        }
        DATA[str(
            int(data.metadata[
                'Protocol-%i-angle-redundant (deg)' %
                (1 + iprotocol_O1)]))]['iprotocol_redundant'] = iprotocol_O1
        DATA[str(
            int(data.metadata[
                'Protocol-%i-angle-deviant (deg)' %
                (1 + iprotocol_O1)]))]['iprotocol_deviant'] = iprotocol_O1
        DATA[str(
            int(data.metadata[
                'Protocol-%i-angle-redundant (deg)' %
                (1 + iprotocol_O2)]))]['iprotocol_redundant'] = iprotocol_O2
        DATA[str(
            int(data.metadata[
                'Protocol-%i-angle-deviant (deg)' %
                (1 + iprotocol_O2)]))]['iprotocol_deviant'] = iprotocol_O2

        # find the angle for the redundant and deviant conditions
        print(data.metadata['Protocol-3-angle-redundant (deg)'],
              data.metadata['Protocol-3-angle-deviant (deg)'])

        Nresp, Nresp_selective, SIs = 0, 0, []

        pdf_OS = PdfPages(
            os.path.join(
                summary_pdf_folder(datafile),
                '%s-orientation_selectivity.pdf' %
                data.protocols[iprotocol_MS]))
        pdf_MSO = PdfPages(
            os.path.join(
                summary_pdf_folder(datafile),
                '%s-mismatch_selective_only.pdf' %
                data.protocols[iprotocol_MS]))
        pdf_MA = PdfPages(
            os.path.join(summary_pdf_folder(datafile),
                         '%s-mismatch_all.pdf' % data.protocols[iprotocol_MS]))

        for roi in np.arange(data.iscell.sum())[:Nmax]:

            print('   - MMN analysis for ROI #%i / %i' %
                  (roi + 1, data.iscell.sum()))
            ## ORIENTATION SELECTIVITY ANALYSIS
            fig, SI, responsive, responsive_angles = ODS.OS_ROI_analysis(
                data,
                roiIndex=roi,
                iprotocol=iprotocol_MS,
                stat_test_props=dict(interval_pre=interval_pre,
                                     interval_post=interval_post,
                                     test='wilcoxon',
                                     positive=True),
                with_responsive_angles=True)
            pdf_OS.savefig()  # saves the current figure into a pdf page
            plt.close()

            if responsive:
                Nresp += 1
                SIs.append(SI)

            EPISODES = EpisodeResponse(
                data,
                protocol_id=None,  # means all
                quantity='CaImaging',
                subquantity='dF/F',
                roiIndex=roi)

            fig, AX = ge.figure(axes=(2, 1), wspace=3., right=10.)
            responsive_for_at_least_one = False
            ge.annotate(fig, 'ROI #%i' % (roi + 1), (0.02, 0.98), va='top')

            for angle, ax in zip(MM_angles, AX):

                DATA[str(int(angle))]['responsive'].append(
                    False)  # False by default

                ge.title(ax, '$\\theta$=%.1f$^{o}$' % angle)
                for ik, key, color in zip(range(3),
                                          ['control', 'redundant', 'deviant'],
                                          ['k', ge.blue, ge.red]):
                    cond = data.get_stimulus_conditions([
                        np.array(DATA[str(int(angle))]['iprotocol_%s' % key]),
                        np.array([float(angle)])
                    ], ['protocol_id', 'angle'], None)[0]
                    ge.plot(EPISODES.t,
                            EPISODES.resp[cond, :].mean(axis=0),
                            sy=EPISODES.resp[cond, :].std(axis=0),
                            color=color,
                            ax=ax,
                            no_set=True)
                    ge.annotate(ax,
                                ik * '\n' + '%s, n=%i' % (key, np.sum(cond)),
                                (0.98, 1.),
                                color=color,
                                va='top',
                                size='small')

                    # storing for population analysis:
                    DATA[str(int(angle))][key].append(
                        EPISODES.resp[cond, :].mean(axis=0))
                    if angle in responsive_angles:
                        responsive_for_at_least_one = True
                        DATA[str(int(
                            angle))]['responsive'][-1] = True  # shift to True

                ge.set_plot(ax, xlabel='time (s)', ylabel='dF/F')

            pdf_MA.savefig()
            if responsive_for_at_least_one:
                pdf_MSO.savefig()
            plt.close()

        for angle in MM_angles:
            fig, AX = modulation_summary_panel(EPISODES.t,
                                               DATA[str(int(angle))],
                                               title='$\\theta$=%.1f$^{o}$' %
                                               angle)
            pdf_MA.savefig()
            plt.close()
            fig, AX = modulation_summary_panel(EPISODES.t,
                                               DATA[str(int(angle))],
                                               title='$\\theta$=%.1f$^{o}$' %
                                               angle,
                                               responsive_only=True)
            pdf_MSO.savefig()
            plt.close()

        # orientation selectivity summary
        ODS.summary_fig(Nresp,
                        data.iscell.sum(),
                        SIs,
                        label='Orient. Select. Index')
        pdf_OS.savefig()  # saves the current figure into a pdf page
        plt.close()

        # modulation summary

        for pdf in [pdf_OS, pdf_MSO, pdf_MA]:
            pdf.close()

        print('[ok] mismatch negativity analysis saved in: "%s" ' %
              summary_pdf_folder(datafile))

    except BaseException as be:
        print('\n', be)
        print('---------------------------------------')
        print(' /!\ Pb with mismatch negativity analysis /!\  ')