示例#1
0
def plot_clusters(raw, t, Z, N, name, labels, plot_all, plot_path):

    results = hierarchy.fcluster(Z, t=N, criterion='maxclust')
    s = pd.DataFrame(results)
    s.index = raw.columns
    s.columns = ['name']
    lbd = dict(zip(s.index, labels))
    tcns = {}
    for cluster in s['name'].unique():
        tcns[cluster] = s[s['name'] == cluster].index.tolist()

    if plot_all:
        plot_dendrograms(Z, name, labels, plot_path)
        r, c = sqfactors(N)
        fig, axs = subplots(r,
                            c,
                            sharey='all',
                            sharex='all',
                            num='_'.join([name, 'cluster']),
                            figsize=[6 * c, 6 * r])
        for i, cluster in enumerate(tcns.keys()):
            ax = axs[i]
            for tcn in tcns[cluster]:
                ax.plot(t, raw.loc[:, tcn], label=lbd[tcn])
            ax.legend(fontsize=8)
        plt.tight_layout()
        plt.savefig(plot_path + name + '_cluster.png')
        plt.close('all')

    return tcns
示例#2
0
for ch in chlist:
    print(ch)
    fulldata[ch] = check_and_clean(fulldata[ch],1)

table = tb.get('THOR')
table = table[table.TYPE.isin(['Frontale/Véhicule']) & table.VITESSE.isin([48,56])]
ok, slip = tb.tcns(tb.split(table, column='CBL_BELT', categories=['OK','SLIP']))

#%%
if 0:
    cd = style.colordict(chlist)
    titles = dict(zip(chlist, ['Upper Left', 'Upper Right', 'Lower Right', 'Lower Left']))

    plt.close('all')
    r, c = 2, 2
    fig, axs = style.subplots(r, c, sharex='all', sharey='all')
    ok_df = pd.DataFrame()
    slip_df = pd.DataFrame()
    for i, ch in enumerate(chlist):
        ax=axs[i]
        peaks, times = data.find_peak(data.smooth(fulldata[ch]), time)
        ok_df = pd.concat([ok_df, peaks.loc[ok].dropna().abs()], axis=1)
        slip_df = pd.concat([slip_df, peaks.loc[slip].dropna().abs()], axis=1)

        hist, bin_edges = np.histogram(np.array(peaks.loc[ok].dropna().abs()), bins=np.linspace(0,60,41), normed=True)
        ax.bar(bin_edges[1:], hist, 60/40, label=titles[ch]+' ok', color=cd[ch], alpha=0.25)
        hist, bin_edges = np.histogram(np.array(peaks.loc[slip].dropna().abs()), bins=np.linspace(0,60,41), normed=True)
        ax.bar(bin_edges[1:], -hist, 60/40, label=titles[ch]+' slip', color=cd[ch], alpha=0.75)

        ax.set_title(titles[ch])
        ax.set_xlabel('Displacement')
def plotbook(subdir, tcns=None):
    """
    Docsting for basic plotting routine
    """
    import os
    #    import pandas as pd
    import matplotlib.pyplot as plt
    from PMG.COM import openbook as ob
    from PMG.COM import plotstyle as style

    readdir = os.fspath('P:/AHEC/SAI/')
    savedir = os.fspath('P:/AHEC/Plots/')

    time, slipdict, slidedict, okdict, singles, pairs = ob.thor(readdir, tcns)
    colors = ['tab:blue', 'tab:green', 'tab:orange', 'tab:purple']
    lines = {
        'TC11-008': [0.016, 0.062, 0.080, 0.093],
        'TC12-218': [0.030, 0.063, 0.082, 0.083],
        'TC14-035': [0.042, 0.070, 0.081, 0.088],
        'TC15-162': [0.013, 0.077, 0.088, 0.095],
        'TC15-163': [0.000, 0.000, 0.000, 0.092],
        'TC17-031': [0.030, 0.060, 0.076, 0.083],
        'TC17-201': [0.030, 0.056, 0.076, 0.084],
        'TC17-212': [0.031, 0.060, 0.080, 0.090]
    }

    #%% FIGURE 1 - all pairs plotted individually

    xlim = (0, 0.15)
    xlabel = 'Time [s]'
    #
    plt.close('all')

    r, c = style.sqfactors(len(tcns))
    fig, axs = style.subplots(r,
                              c,
                              sharex='all',
                              sharey='all',
                              visible=True,
                              num='SEBE-NECK',
                              figsize=(5 * c, 3.125 * r))

    for i, tcn in enumerate(tcns):
        ax = axs[i]

        slip_cols = []
        for channel in slipdict:
            slip_cols.extend(slipdict[channel].columns)
        slip_cols = list(set(slip_cols))
        slip = tcn in slip_cols
        ax.plot(time,
                slipdict['11SEBE0000B3FO0D'][tcn]
                if slip else okdict['11SEBE0000B3FO0D'][tcn],
                color='tab:blue')
        ax2 = plt.twinx(ax)
        ax2.plot(time,
                 slipdict['11NECKLO00THFOXA'][tcn]
                 if slip else okdict['11NECKLO00THFOXA'][tcn],
                 color='tab:green')
        ax2.plot(time,
                 slipdict['11NECKLO00THFOYA'][tcn]
                 if slip else okdict['11NECKLO00THFOYA'][tcn],
                 color='tab:green')
        ax3 = plt.twinx(ax)
        ax3.plot(time,
                 slipdict['11CLAVLEINTHFOZA'][tcn]
                 if slip else okdict['11CLAVLEINTHFOZA'][tcn],
                 color='tab:orange')
        ax3.plot(time,
                 slipdict['11CLAVRIOUTHFOZA'][tcn]
                 if slip else okdict['11CLAVRIOUTHFOZA'][tcn],
                 color='tab:purple')
        for line, color in zip(lines.get(tcn, [-1] * 4), colors):
            ax.axvline(line, color=color)
        ax.set_xlim(*xlim)
        ax.set_ylim(-6000, 6000)
        ax2.set_ylim(-2000, 2000)
        ax3.set_ylim(-1000, 1000)

        title = tcn
        ax.set_title(title)
        ax.set_ylabel('Seat Belt Tension [N]')
        ax2.set_ylabel('Neck Force [N]')
        ax.set_xlabel(xlabel)
        ax.legend(loc=4)

    plt.tight_layout(rect=[0, 0, 1, 0.92])
    plt.savefig(savedir + subdir + 'SEBE-NECK.png', dpi=200)
    plt.close('all')

    #%% FIGURE 2 - Vehicle groups and means

    plt.close('all')
    plt.figure('SEBE-NECK Groups', figsize=(20, 12.5))

    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(2, 3, 1)
    plt.plot(time,
             slipdict['11SEBE0000B3FO0D'],
             '.',
             color='tab:blue',
             markersize=0.5,
             label='inner n = {}'.format(len(slipdict['11SEBE0000B3FO0D'])))
    plt.xlim(*xlim)
    ax.set_ylim(-6000, 6000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('Slip SEBE')
    plt.ylabel('Seat Belt Tension [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(2, 3, 2)
    plt.plot(time,
             slipdict['11NECKLO00THFOXA'],
             '.',
             color='tab:orange',
             markersize=0.5,
             label='inner n = {}'.format(len(slipdict['11NECKLO00THFOXA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('Slip NECK X')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(2, 3, 3)
    plt.plot(time,
             slipdict['11NECKLO00THFOYA'],
             '.',
             color='tab:purple',
             markersize=0.5,
             label='inner n = {}'.format(len(slipdict['11NECKLO00THFOYA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('Slip NECK Y')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(2, 3, 4)
    plt.plot(time,
             okdict['11SEBE0000B3FO0D'],
             '.',
             color='tab:blue',
             markersize=0.5,
             label='inner n = {}'.format(len(okdict['11SEBE0000B3FO0D'])))
    plt.xlim(*xlim)
    ax.set_ylim(-6000, 6000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('OK SEBE')
    plt.ylabel('Seat Belt Tension [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(2, 3, 5)
    plt.plot(time,
             okdict['11NECKLO00THFOXA'],
             '.',
             color='tab:orange',
             markersize=0.5,
             label='inner n = {}'.format(len(okdict['11NECKLO00THFOXA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('OK NECK X')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(2, 3, 6)
    plt.plot(time,
             okdict['11NECKLO00THFOYA'],
             '.',
             color='tab:purple',
             markersize=0.5,
             label='inner n = {}'.format(len(okdict['11NECKLO00THFOYA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('OK NECK Y')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)

    plt.subplots_adjust(top=0.893,
                        bottom=0.060,
                        left=0.048,
                        right=0.974,
                        hspace=0.222,
                        wspace=0.128)
    plt.savefig(savedir + subdir + 'SEBE-NECK_stats.png', dpi=200)
    plt.close('all')
    #%% FIGURE 2 - Vehicle groups and means

    plt.close('all')
    plt.figure('SEBE-NECK Groups', figsize=(20, 12.5))

    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(3, 2, 1)
    plt.plot(time,
             slipdict['11SEBE0000B3FO0D'],
             '.',
             color='tab:blue',
             markersize=0.5,
             label='inner n = {}'.format(len(slipdict['11SEBE0000B3FO0D'])))
    plt.xlim(*xlim)
    ax.set_ylim(-6000, 6000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('Slip SEBE')
    plt.ylabel('Seat Belt Tension [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(3, 2, 3)
    plt.plot(time,
             slipdict['11NECKLO00THFOXA'],
             '.',
             color='tab:orange',
             markersize=0.5,
             label='inner n = {}'.format(len(slipdict['11NECKLO00THFOXA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('Slip NECK X')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(3, 2, 5)
    plt.plot(time,
             slipdict['11NECKLO00THFOYA'],
             '.',
             color='tab:purple',
             markersize=0.5,
             label='inner n = {}'.format(len(slipdict['11NECKLO00THFOYA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('Slip NECK Y')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(3, 2, 2)
    plt.plot(time,
             okdict['11SEBE0000B3FO0D'],
             '.',
             color='tab:blue',
             markersize=0.5,
             label='inner n = {}'.format(len(okdict['11SEBE0000B3FO0D'])))
    plt.xlim(*xlim)
    ax.set_ylim(-6000, 6000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('OK SEBE')
    plt.ylabel('Seat Belt Tension [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(3, 2, 4)
    plt.plot(time,
             okdict['11NECKLO00THFOXA'],
             '.',
             color='tab:orange',
             markersize=0.5,
             label='inner n = {}'.format(len(okdict['11NECKLO00THFOXA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('OK NECK X')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)
    #FIRST SUBPLOT - 'SLIP' Group full data set
    ax = plt.subplot(3, 2, 6)
    plt.plot(time,
             okdict['11NECKLO00THFOYA'],
             '.',
             color='tab:purple',
             markersize=0.5,
             label='inner n = {}'.format(len(okdict['11NECKLO00THFOYA'])))
    plt.xlim(*xlim)
    ax.set_ylim(-2000, 2000)
    ax.axvline(0.055)
    ax.axvline(0.080)
    ax.axvline(0.090)
    plt.title('OK NECK Y')
    plt.ylabel('Neck Force [N]')
    plt.xlabel(xlabel)
    style.legend(ax=plt.gca(), loc=4)

    plt.subplots_adjust(top=0.893,
                        bottom=0.060,
                        left=0.048,
                        right=0.974,
                        hspace=0.222,
                        wspace=0.128)
    plt.savefig(savedir + subdir + 'SEBE-NECK_stats2.png', dpi=200)
    plt.close('all')
示例#4
0
for ch in chlist:
    data[ch] = pair_data.loc[:, ch + 'ICE'] - pair_data.loc[:, ch + 'EV']

data2 = {}
for ch in th_chs:
    data2[ch] = pair_data_2.loc[:, ch + 'ICE'] - pair_data_2.loc[:, ch + 'EV']

#%% Figure 1 - Boxplot with scatter/jitter
H3_color = '#1b9e77'
TH_color = '#d95f02'
TH2_color = '#7570b3'

plt.close('all')
fig, axs = style.subplots(2,
                          3,
                          sharex='col',
                          sharey='all',
                          figsize=(6.5, 5),
                          visible=False)
axs = list(axs)
ax2 = axs[2].twinx()  #secondary axis for neck force

for i, (h3, th, name) in enumerate(zip(h3_chs, th_chs, chname)):
    if i == 2:
        ax = ax2
    else:
        ax = axs[i]

#    H3_array = np.arange(-5,1,1)
#    TH_array = np.arange(5,11,1)
#    TH2_array = np.arange(-3,8,1)
    H3_array = data[h3].dropna().values
示例#5
0
#%%
table = table[table.BACK.isin(['HB', 'LB']) & table.DATA.isin(['YES'])]
colors = style.colordict(
    ['HBold_accel', 'LBold_accel', 'HBnew_accel', 'LBnew_accel'])
labels = dict(
    zip(['HBold_accel', 'LBold_accel', 'HBnew_accel', 'LBnew_accel'],
        ['Highback Old', 'Lowback Old', 'Highback New', 'Lowback New']))

channels = ['12HEAD0000Y7ACXA', '12CHST0000Y7ACXC', '12PELV0000Y7ACXA']
chname = dict(zip(channels, ['Head', 'Chest', 'Pelvis']))

plt.close('all')
for ch in channels:

    fig, axs = style.subplots(2, 2, sharex='all', sharey='all')
    for i, (back, sled, ax) in enumerate(
            zip(['HB', 'HB', 'LB', 'LB'],
                ['old_accel', 'new_accel', 'old_accel', 'new_accel'], axs)):
        SEs = table[table.BACK.isin([back])
                    & table.SLED.isin([sled])].SE.tolist()
        data = fulldata[ch].loc[:, SEs].rolling(20,
                                                0,
                                                center=True,
                                                win_type='triang').mean()
        ax.plot(time,
                data,
                color=colors[back + sled],
                label=labels[back + sled])
        style.legend(ax, loc='lower right')
    ax.set_xlim(0, 0.12)
def plotbook(subdir, tcns=None):
    """
    Docsting for basic plotting routine
    """
    import os
    import pandas as pd
    import matplotlib.pyplot as plt
    from PMG.COM import openbook as ob
    from PMG.COM import plotstyle as style

    readdir = os.fspath('P:/AHEC/SAI/')
    savedir = os.fspath('P:/AHEC/Plots/')

    descriptions = pd.read_excel('P:/AHEC/Descriptions.xlsx', index_col = 0)
    description = descriptions.to_dict()[descriptions.columns[0]]

    tcns = ['TC09-027', 'TC13-007', 'TC17-201', 'TC17-212', 'TC15-163', 'TC11-008', 'TC14-035', 'TC12-003', 'TC15-162', 'TC17-209', 'TC14-220', 'TC17-211', 'TC17-025', 'TC12-217', 'TC12-501', 'TC14-139', 'TC16-013', 'TC14-180', 'TC16-129', 'TC17-208']

#    REPLACE THE BELOW WITH HDF5 VERSION
#    time, slipdict, slidedict, okdict, singles, pairs = ob.thor(readdir, tcns)

    #%% FIGURE 1 - all pairs plotted individually

    xlim = (0, 0.3)
    xlabel = 'Time [s]'
#
    plt.close('all')
    for outer, inner in  [['11CLAVRIOUTHFOXA', '11CLAVRIINTHFOXA'],
                          ['11CLAVRIOUTHFOZA', '11CLAVRIINTHFOZA'],
                          ['11CLAVLEOUTHFOXA', '11CLAVLEINTHFOXA'],
                          ['11CLAVLEOUTHFOZA', '11CLAVLEINTHFOZA']]:

        slipinner = slipdict[inner]
        slipouter = slipdict[outer]
        okinner = okdict[inner]
        okouter = okdict[outer]
        plotinner = pd.concat([slipinner, okinner], axis=1).dropna(axis=1)
        plotouter = pd.concat([slipouter, okouter], axis=1).dropna(axis=1)
        plotinner = plotinner.loc[:,tcns] if tcns is not None else plotinner
        plotouter = plotouter.loc[:,tcns] if tcns is not None else plotouter
        if plotinner.shape[0] == 0:
            continue
        ylim = style.ylim_no_outliers(pd.concat([plotinner, plotouter], axis=1))
        ylabel = style.ylabel(inner[12:14], inner[14:15])

        r, c = style.sqfactors(len(plotinner.columns.tolist()))
        fig, axs = style.subplots(r, c, sharex='all', sharey='all', visible=True,
                                  num='All Pairs: '+inner, figsize=(5*c, 3.125*r))
        fig.suptitle('{ch} - {desc}'.format(ch = inner,
                     desc = description.get(inner, 'Description Unavailable')))

        for i, tcn in enumerate(plotinner.columns.tolist()):
            ax = axs[i]

            bool1 = tcn in slipinner.columns
            ax.plot(time, plotinner.loc[:, tcn], color = 'tab:blue' if bool1 else 'tab:orange', label = 'inner')
            ax.plot(time, plotouter.loc[:, tcn], color = 'tab:green' if bool1 else 'tab:purple', label = 'outer')
            ax.set_xlim(*xlim)
            ax.set_ylim(*ylim)

            title = tcn
            ax.set_title(title)
            ax.set_ylabel(ylabel)
            ax.set_xlabel(xlabel)
            ax.legend(loc=4)

        plt.tight_layout(rect=[0,0,1,0.92])
        plt.savefig(savedir+subdir+'All_Pairs_'+inner+'_combo.png', dpi=200)
        plt.close('all')

    #%% FIGURE 2 - Vehicle groups and means

    plt.close('all')
    for outer, inner in  [['11CLAVRIOUTHFOXA', '11CLAVRIINTHFOXA'],
                          ['11CLAVRIOUTHFOZA', '11CLAVRIINTHFOZA'],
                          ['11CLAVLEOUTHFOXA', '11CLAVLEINTHFOXA'],
                          ['11CLAVLEOUTHFOZA', '11CLAVLEINTHFOZA']]:

        slipinner = slipdict[inner]
        slipouter = slipdict[outer]
        okinner = okdict[inner]
        okouter = okdict[outer]
        plotinner = pd.concat([slipinner, okinner], axis=1).dropna(axis=1)
        plotouter = pd.concat([slipouter, okouter], axis=1).dropna(axis=1)
        plotinner = plotinner.loc[:,tcns] if tcns is not None else plotinner
        plotouter = plotouter.loc[:,tcns] if tcns is not None else plotouter

        ylim = style.ylim_no_outliers(pd.concat([plotinner, plotouter], axis=1))
        ylabel = style.ylabel(inner[12:14], inner[14:15])

        fig = plt.figure('Groups: '+inner, figsize=(20, 12.5))
        fig.suptitle('{ch} - {desc}'.format(ch = inner,
                     desc = description.get(inner, 'Description Unavailable')))

        #FIRST SUBPLOT - 'SLIP' Group full data set
        ax = plt.subplot(2,1,1)
        plt.plot(time, slipinner, '.', color = 'tab:blue', markersize=0.5, label = 'inner n = {}'.format(slipinner.shape[1]))
        plt.plot(time, slipouter, '.', color = 'tab:green', markersize=0.5, label = 'outer n = {}'.format(slipouter.shape[1]))
        plt.xlim(*xlim)
        ax.set_ylim(*ylim)
        plt.title('Slipping Belts')
        plt.ylabel(ylabel)
        plt.xlabel(xlabel)
        style.legend(ax=plt.gca(), loc=4)

        #THIRD SUBPLOT - 'OK' Group full data set
        plt.subplot(2,1,2, sharey = ax)
        plt.plot(time, okinner, '.', color = 'tab:orange', markersize=0.5, label = 'inner n = {}'.format(okinner.shape[1]))
        plt.plot(time, okouter, '.', color = 'tab:purple', markersize=0.5, label = 'outer n = {}'.format(okouter.shape[1]))
        plt.xlim(*xlim)
        ax.set_ylim(*ylim)
        plt.title('Ok Belts')
        plt.ylabel(ylabel)
        plt.xlabel(xlabel)
        style.legend(ax=plt.gca(), loc=4)

        plt.subplots_adjust(top=0.893, bottom=0.060, left=0.048, right=0.974, hspace=0.222, wspace=0.128)
        plt.savefig(savedir+subdir+'Belt_'+inner+'_combo.png', dpi=200)
        plt.close('all')
示例#7
0
def plotbook(savedir, chlist, tcns=None):
    """
    Plot THOR-related basic overview plots. All pairs by channels and both
    groups with means/intervals by channels.
    """
    import pandas as pd
    import matplotlib.pyplot as plt
    from PMG.COM import plotstyle as style, data, table as tb

    descriptions = pd.read_excel('P:/AHEC/Descriptions.xlsx', index_col=0)
    description = descriptions.to_dict()[descriptions.columns[0]]

    time, fulldata = data.import_data('P:/AHEC/DATA/THOR/',
                                      chlist,
                                      tcns,
                                      check=False)
    #    for k,v in fulldata.items():
    #        fulldata[k] = data.check_and_clean(v, stage=2)

    table = tb.get('THOR')
    table = table[table.CIBLE.isin(tcns)]
    slips = table[table.CBL_BELT.isin(['SLIP'])].CIBLE.tolist()
    oks = table[table.CBL_BELT.isin(['OK'])].CIBLE.tolist()
    table = table[table.CIBLE.isin(slips + oks)]

    #%% FIGURE 1 - all pairs plotted individually

    xlim = (0, 0.3)
    xlabel = 'Time [s]'

    plt.close('all')
    for channel in chlist:
        slipdf = fulldata[channel].loc[:, slips]
        okdf = fulldata[channel].loc[:, oks]
        plotdata = pd.concat([slipdf, okdf], axis=1)

        if plotdata.empty:
            continue

        ylabel = style.ylabel(channel[12:14], channel[14:15])

        r, c = style.sqfactors(len(plotdata.columns.tolist()))
        fig, axs = style.subplots(r,
                                  c,
                                  sharex='all',
                                  sharey='all',
                                  visible=True,
                                  num='All Pairs: ' + channel)
        fig.suptitle('{ch} - {desc}'.format(ch=channel,
                                            desc=description.get(
                                                channel,
                                                'Description Unavailable')))

        for i, tcn in enumerate(table.CIBLE):
            ax = axs[i]
            ax.plot(time, plotdata.loc[:, tcn], color='tab:green', label=tcn)
            ax.set_xlim(*xlim)

            title = ' '.join(
                [tcn, table[table.CIBLE == tcn].CBL_MODELE.tolist()[0]])
            ax.set_title(title)
            ax.set_ylabel(ylabel)
            ax.set_xlabel(xlabel)
            ax.legend(loc=4)

        plt.tight_layout(rect=[0, 0, 1, 0.92])
        plt.savefig(savedir + 'All_Pairs_' + channel + '.png', dpi=200)
        plt.close('all')

    #%% FIGURE 2 - Vehicle groups and means

    plt.close('all')
    for channel in chlist:

        slipdf = fulldata[channel].loc[:, slips]
        okdf = fulldata[channel].loc[:, oks]

        ylabel = style.ylabel(channel[12:14], channel[14:15])

        fig, axs = style.subplots(2,
                                  2,
                                  sharex='all',
                                  sharey='all',
                                  num='Belt: ' + channel,
                                  figsize=(20, 12.5))
        fig.suptitle('{ch} - {desc}'.format(ch=channel,
                                            desc=description.get(
                                                channel,
                                                'Description Unavailable')))

        #FIRST SUBPLOT - 'SLIP' Group full data set
        ax = axs[0]
        ax.plot(time,
                slipdf,
                lw=1,
                color='tab:blue',
                label='n = {}'.format(slipdf.shape[1]))
        ax.set_title('Slipping Belts')
        ax.set_ylabel(ylabel)
        ax.set_xlabel(xlabel)
        style.legend(ax, loc=4)

        #THIRD SUBPLOT - 'OK' Group full data set
        ax = axs[2]
        ax.plot(time,
                okdf,
                lw=1,
                color='tab:orange',
                label='n = {}'.format(okdf.shape[1]))
        ax.set_title('Ok Belts')
        ax.set_ylabel(ylabel)
        ax.set_xlabel(xlabel)
        style.legend(ax, loc=4)

        #SECOND SUBPLOT - 'CIBLE' vs 'BELIER' Groups (median and intervals)
        ax = axs[1]
        data.tolerance(ax, time, slipdf, 'tab:blue')
        data.tolerance(ax, time, okdf, 'tab:orange')

        ax.set_title('All Belts (Mean and Intervals)')
        ax.set_ylabel(ylabel)
        ax.set_xlabel(xlabel)
        ax.legend(loc=4)

        ax.set_xlim(*xlim)
        #%%
        plt.subplots_adjust(top=0.893,
                            bottom=0.060,
                            left=0.048,
                            right=0.974,
                            hspace=0.222,
                            wspace=0.128)
        plt.savefig(savedir + 'Belt_' + channel + '.png', dpi=200)
        plt.close('all')
示例#8
0
time, fulldata = openHDF5(THOR, chlist)

ok, slip = tb.split(tb.get('THOR'), 'CBL_BELT', ['OK', 'SLIP']).values()
slip = slip[~slip.T1.isnull() & ~slip.T1.isin(['?'])]

bin1 = slip[(0.060 <= slip.T1) & (slip.T1 < 0.075)]
#bin2 = slip[(0.075<=slip.T1) & (slip.T1<0.090)]
#bin3 = slip[(0.090<=slip.T1) & (slip.T1<0.115)]
#%%
ok, slip = tb.split(table, 'CBL_BELT', ['OK', 'SLIP']).values()
slip = slip[~slip.T1.isnull() & ~slip.T1.isin(['?'])]
bin1 = slip[(0.060 <= slip.T1) & (slip.T1 < 0.075)]

r, c = 2, 2
plt.close('all')
fig, axs = style.subplots(r, c, sharex='all', sharey='col', figsize=(6.5, 6.5))

ind = pd.concat([time, pd.Series(time.index)], axis=1).set_index('Time')
chname = dict(zip(chlist, ['Lower Neck $F_x$', 'Upper Left Chest $D_x$']))
alltcns = bin1.CIBLE.tolist() + ok.CIBLE.tolist()

for c, (ch, group) in enumerate(
        zip([
            '11NECKLO00THFOXA', '11CHSTLEUPTHDSXB', '11NECKLO00THFOXA',
            '11CHSTLEUPTHDSXB'
        ], [bin1, bin1, ok, ok])):

    ax = axs[c]
    tcns = group.CIBLE.tolist()
    df = fulldata[ch].loc[:, tcns]
    if c in [0, 2]:
示例#9
0
xfmt.set_powerlimits((-3,4))
#xloc = matplotlib.ticker.MaxNLocator(nbins='auto', steps=[1, 1.5, 2, 2.5, 3, 4, 5, 10],
#                                     prune=None, min_n_ticks=4)

if 1:
    plt.close('all')
    chlist = ['11NECKLO00THFOXA','11NECKLO00THFOYA','11CHSTLEUPTHDSXB','11CHSTRIUPTHDSXB','11CHSTLELOTHDSXB','11CHSTRILOTHDSXB']
    labels = ['Lower Neck $\mathregular{F_x}$ [N]',
              'Lower Neck $\mathregular{F_y}$ [N]',
              'Upper Left Chest $\mathregular{D_x}$ [mm]',
              'Upper Right Chest $\mathregular{D_x}$ [mm]',
              'Lower Left Chest $\mathregular{D_x}$ [mm]',
              'Lower Right Chest $\mathregular{D_x}$ [mm]']
    ylabel = dict(zip(chlist, labels))

    fig, axs = style.subplots(3, 2, sharex='all', sharey=[1,2,3,3,3,3], figsize=(7,6.5))

    for i, channel in enumerate(chlist):
        df = fulldata[channel].dropna(axis=0).dropna(axis=1)
#        df = df.loc[:,slips+oks]
        df.reindex(slips+oks, axis=1)
        df_slip = df.reindex(slips, axis=1)
        df_ok = df.reindex(oks, axis=1)

        window = 100
        alpha = 0.10
        slip_median = df_slip.median(axis=1).rolling(window,0,center=True,win_type='triang').mean()
        ok_median = df_ok.median(axis=1).rolling(window,0,center=True,win_type='triang').mean()
        slip_high = df_slip.quantile(1-alpha/2, axis=1).rolling(window,0,center=True,win_type='triang').mean()
        slip_low = df_slip.quantile(alpha/2, axis=1).rolling(window,0,center=True,win_type='triang').mean()
        ok_high = df_ok.quantile(1-alpha/2, axis=1).rolling(window,0,center=True,win_type='triang').mean()