示例#1
0
def load_and_plot(df_files, write_dir='', plot_on=True):
    '''Loads and plots the csv files in df_files. Optionally saves pdf.
    Labels are used as the title'''
    for i in df_files.index:
        row = df_files.ix[i]
        df = fop.load_emg(row.Path)
        title = str(row.tolist())
        fig, _ = viz.plot_emg(df, title=title)

        if write_dir:
            try: os.mkdir(write_dir)
            except: pass
            fig.savefig(os.path.join(write_dir, str(i) + '.pdf'))
            if not plot_on:
                viz.plt.close()
示例#2
0
文件: calcs.py 项目: Saynah/AthosPy
def quality(csv_path):
    '''Calculate basic quality metrics for csv file.
    * number of rows - to find files that are too short or long enough to sample multiple times
    * max value across all channels (below 15,000) - magnitude of the signal
    * median value across all channels - find files with signals that are too low
    * number of spikes to 65535 - files where sensor was freaking out
    * max fraction of zero values across channels - possibly dead sensors?
    * max fraction of consecutive non-zero values - files with temporal binning issues
    '''
    df = fop.load_emg(csv_path)
    len_df = len(df)

    quality = {
        "Length": len_df,
        "Max": df[df < 15000].unstack().max(),
        "Median": df.unstack().median(),
        "N_spikes": (df > 65000).sum().sum(),
        "MaxFrac_zero": max((df == 0).sum().divide(len_df) * 100),
        # "MaxFrac_repeat": max(((df != 0) & (df.diff() == 0)).sum().divide(len_df) * 100)
        "MaxFrac_repeat": max(((df > 100) & (df.diff() == 0)).sum().divide(len_df) * 100)
    }
    return quality