Exemplo n.º 1
0
#%% Belt Score Distribution
plt.close('all')
from GitHub.COM import plotstyle as style

t = t.rename(columns = {'Toward':'Difference'})
groupA = t.loc[t.Group == 'A',['Group','LBS','Chest','Pelvis','Difference']].dropna(axis=0)
#groupB = t.loc[t.Group == 'B',['Group','LBS','Chest','Pelvis','Difference']].dropna(axis=0)
groupC = t.loc[t.Group == 'C',['Group','LBS','Chest','Pelvis','Difference']].dropna(axis=0)
groups = pd.concat([groupA,groupC],axis=0)
position = pd.DataFrame(list(zip([0,1],['A','C'])), columns=['X','Group'])

#plotdata = pd.merge(position, groups, on='Group', how='outer')
plotdata = groups

axs = style.subplots(1, 2, sharey='all', visible=False)

#ax1 = plotdata.plot.scatter('X','LBS')
#for column in ['LBS','Chest','Pelvis','Difference']:
#plotdata.boxplot(ax=ax, column=['Chest','Pelvis','Difference'], by='Group', grid=False)
plotdata[plotdata.Group == 'A'].boxplot(ax=axs[0], column=['Chest','Pelvis','Difference'], grid=False)
plotdata[plotdata.Group == 'C'].boxplot(ax=axs[1], column=['Chest','Pelvis','Difference'], grid=False)

axs[0].set_xlabel('Group \'A\'')
axs[1].set_xlabel('Group \'C\'')
axs[0].set_ylabel('Acceleration X [g]')
plt.subplots_adjust(wspace=.0)
#%%
    
groupA = t.loc[t.Group == 'A',['Group','LBS','Chest','Pelvis','Difference']]
#groupB = t.loc[t.Group == 'B',['Group','LBS','Chest','Pelvis','Difference']]
Exemplo n.º 2
0
                           index_col=0,
                           skiprows=[1, 2])

#data = dict(zip(['TC18-011','TC18-018'],[MifoldData,TakataData]))
time = MifoldData['T_10000_0']
channels = ['12CHST0000Y7ACXC', '12PELV0000Y7ACXA']
colors = dict(zip(channels, ['tab:orange', 'tab:blue']))
name = dict(zip(channels, ['Chest', 'Pelvis']))
#%%
plt.close('all')
#plt.figure(figsize=(4.8,4.8))
#ax1 = plt.subplot(211)
#ax2 = plt.subplot(212)
axs = style.subplots(2,
                     1,
                     sharex='all',
                     sharey='all',
                     visible=True,
                     figsize=(4.8, 4.8))
ax1, ax2 = axs.flatten()

for ch in channels:
    ax1.plot(time * 1000, MifoldData[ch], color=colors[ch], label=name[ch])
    ax2.plot(time * 1000, TakataData[ch], color=colors[ch], label=name[ch])

for ax in [ax1, ax2]:
    ax.set_xlabel('Time [ms]')
    ax.set_ylabel('Acceleration X [g]')
    ax.set_ylim((-80, 15))
    ax.set_xlim((0, 200))

    h, l = ax.get_legend_handles_labels()
Exemplo n.º 3
0
savedir = os.fspath('P:/AHEC/Plots/')

subdir = 'test/'
tcns = None
#chlist = ['10SIMELE00INACXD', '10SIMERI00INACXD', '10CVEHCG0000ACXD']

time, data = ob.openbook(readdir)

left = data['10SIMELE00INACXD']
center = data['10CVEHCG0000ACXD']
right = data['10SIMERI00INACXD']

plt.close('all')

r, c = style.sqfactors(len(center.columns[:9]))
fig, axs = style.subplots(r, c, sharey='all', figsize=(10 * c, 6.25 * r))
ylim = style.ylim_no_outliers([center - right, center, right])

for i, tcn in enumerate(center.columns[:9]):
    ax = axs[i]
    try:
        ax.plot(time, center.loc[:, tcn] - right.loc[:, tcn], color='k')
        ax.plot(time, center.loc[:, tcn], color='tab:red')
        ax.plot(time, right.loc[:, tcn], color='tab:blue')
        ax.plot(time, left.loc[:, tcn], color='tab:purple')
    except KeyError:
        pass
    ax.set_title(tcn)
    ax.set_xlim(-0.01, 0.3)
    ax.set_ylim(*ylim)
    ax.set_ylabel('Acceleration [g]')
Exemplo n.º 4
0
def plotbook(subdir, chlist, tcns=None):
    #if 1==1:
    """
    Docsting for basic plotting routine
    """
    import os
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    from GitHub.COM import openbook as ob
    from GitHub.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]]

    time, cibdict, beldict, pairs = ob.cibbel(readdir)

    xlim = (0, 0.3)
    xlabel = 'Time [s]'
    colors = {'cib': '', 'bel': ''}
    #%% FIGURE 1 - all pairs plotted individually

    plt.close('all')

    for channel in chlist:
        if tcns is None:
            cib = cibdict[channel]
            bel = beldict[channel]
            pairs = ob.lookup_pairs(cib.columns, project='AHEC')
#            pairs = ob.lookup_pairs(cib.columns.tolist(), project='AHEC')
#            pairs = ob.lookup_pairs(project='AHEC') #move out of if with tcns arg
        else:
            cib = cibdict[channel].loc[:, tcns].dropna(axis=1)
            bel = beldict[channel].loc[:, tcns].dropna(axis=1)
            pairs = ob.lookup_pairs(tcns, project='AHEC')

        if cib.shape[0] == 0:
            continue

        plotframes = [cib, bel]
        ylim = style.ylim_no_outliers(plotframes)
        if (channel[2:6] == 'SIME') or (channel[2:6] == 'CVEH'
                                        and channel[14:15] == 'X'):
            ylim = (-60, 30)
        ylabel = style.ylabel(channel[12:14], channel[14:15])

        #        pairs = ob.lookup_pairs(cib.columns.tolist(), project='AHEC')
        #        pairs = ob.lookup_pairs(tcns, project='AHEC')
        #        pairs = pairs.set_index('CIBLE')
        r, c = style.sqfactors(pairs.shape[0])
        fig, axs = style.subplots(r,
                                  c,
                                  sharex='all',
                                  sharey='all',
                                  visible=True,
                                  num='All Pairs: ' + channel,
                                  figsize=(5 * c, 3.125 * r))
        fig.suptitle(
            '{sbdir} - Frontal Offset Crash Test at {speed} km/h\n{ch} - {desc}'
            .format(sbdir=subdir[:-4],
                    speed=subdir[-3:-1],
                    ch=channel,
                    desc=description.get(channel, 'Description Unavailable')))

        #        for i, (cib_tcn, bel_tcn) in enumerate(zip(cib.columns, bel.columns)):
        for i, (cib_tcn, bel_tcn) in enumerate(zip(pairs.CIBLE, pairs.BELIER)):
            ax = axs[i]

            pair = pairs[pairs.CIBLE == cib_tcn]
            #            bool1 = pairs.loc[cib_tcn,'SUBSET'] == 'HEV vs ICE'
            bool1 = pair.SUBSET.item() == 'HEV vs ICE'
            #            bool2 = not pairs.loc[cib_tcn,'SUBSET'] == 'General'
            bool2 = not pair.SUBSET.item() == 'General'
            colors['cib'] = (
                'tab:blue' if bool1 else 'tab:purple') if bool2 else 'tab:pink'
            colors['bel'] = ('tab:orange' if bool1 else
                             'tab:green') if bool2 else 'tab:grey'

            #            ax.plot(time, cib.loc[:, cib_tcn], color=colors['cib'], label=cib_tcn)
            #            ax.plot(time, bel.loc[:, bel_tcn], color=colors['bel'], label=bel_tcn)
            ax.plot(time,
                    cib.get(cib_tcn, default=time * np.nan),
                    color=colors['cib'],
                    label=cib_tcn)
            ax.plot(time,
                    bel.get(bel_tcn, default=time * np.nan),
                    color=colors['bel'],
                    label=bel_tcn)
            ax.set_xlim(*xlim)
            ax.set_ylim(*ylim)
            title = '{} vs {}: {} vs {}'.format(
                cib_tcn, pair.BELIER.to_string(index=False),
                pair.CBL_MODELE.to_string(index=False),
                pair.BLR_MODELE.to_string(index=False))
            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_' + channel + '.png',
                    dpi=200)
        plt.close('all')

    #%% FIGURE 3 - Vehicle groups

    pairs = ob.lookup_pairs(tcns, project='AHEC')
    popdict = ob.populations(readdir, pairs)

    NULLDF = pd.DataFrame(columns=tcns)
    NULL = {'CIBLE': NULLDF, 'BELIER': NULLDF}

    plt.close('all')
    for channel in chlist:
        HEV = popdict[channel].get('HEV vs ICE', NULL)['CIBLE']
        ICE = popdict[channel].get('HEV vs ICE', NULL)['BELIER']
        OLD = popdict[channel].get('Old vs New', NULL)['CIBLE']
        NEW = popdict[channel].get('Old vs New', NULL)['BELIER']
        CIB = popdict[channel].get('General', NULL)['CIBLE']
        BEL = popdict[channel].get('General', NULL)['BELIER']

        if tcns is not None:
            HEV = pd.DataFrame(HEV, columns=tcns).dropna(axis=1)
            ICE = pd.DataFrame(ICE, columns=tcns).dropna(axis=1)
            OLD = pd.DataFrame(OLD, columns=tcns).dropna(axis=1)
            NEW = pd.DataFrame(NEW, columns=tcns).dropna(axis=1)
            CIB = pd.DataFrame(CIB, columns=tcns).dropna(axis=1)
            BEL = pd.DataFrame(BEL, columns=tcns).dropna(axis=1)

#        HEVstats = popdict['HEV vs ICE']['CIBLE'][channel+'_stats']
#        ICEstats = popdict['HEV vs ICE']['BELIER'][channel+'_stats']
#        OLDstats = popdict['Old vs New']['CIBLE'][channel+'_stats']
#        NEWstats = popdict['Old vs New']['BELIER'][channel+'_stats']
#        CIBstats = popdict['General']['CIBLE'][channel+'_stats']
#        BELstats = popdict['General']['BELIER'][channel+'_stats']

        fig = plt.figure('Groups: ' + channel, figsize=(20, 12.5))
        fig.suptitle(
            '{sbdir} - Frontal Offset Crash Test at {speed} km/h\n{ch} - {desc}'
            .format(sbdir=subdir[:-4],
                    speed=subdir[-3:-1],
                    ch=channel,
                    desc=description.get(channel, 'Description Unavailable')))

        plotframes = [CIB, BEL, HEV, ICE, OLD, NEW]
        ylim = style.ylim_no_outliers(plotframes)
        ylabel = style.ylabel(channel[12:14], channel[14:15])

        if not CIB.empty:
            #FIRST SUBPLOT - 'CIBLE' Group full data set
            ax = plt.subplot(2, 3, 1)
            plt.plot(time,
                     CIB,
                     '.',
                     color='tab:pink',
                     markersize=0.5,
                     label='n = {}'.format(CIB.shape[1]))
            plt.xlim(*xlim)
            plt.ylim(*ylim)
            plt.title('Cible Vehicle Data')
            plt.ylabel(ylabel)
            plt.xlabel(xlabel)
            style.legend(ax=plt.gca(), loc=4)

        if not BEL.empty:
            #SECOND SUBPLOT - 'BELIER' Group full data set
            plt.subplot(2, 3, 4, sharey=ax)
            plt.plot(time,
                     BEL,
                     '.',
                     color='tab:gray',
                     markersize=0.5,
                     label='n = {}'.format(BEL.shape[1]))
            plt.xlim(*xlim)
            plt.ylim(*ylim)
            plt.title('Belier Vehicle Data')
            plt.ylabel(ylabel)
            plt.xlabel(xlabel)
            style.legend(ax=plt.gca(), loc=4)

        if not HEV.empty:
            # HEV
            plt.subplot(2, 3, 2, sharey=ax)
            plt.plot(time,
                     HEV,
                     '.',
                     color='tab:blue',
                     markersize=0.5,
                     label='n = {}'.format(HEV.shape[1]))
            plt.xlim(*xlim)
            plt.ylim(*ylim)
            plt.title('HEV Vehicle Data')
            plt.ylabel(ylabel)
            plt.xlabel(xlabel)
            style.legend(ax=plt.gca(), loc=4)

        if not ICE.empty:
            # ICE
            plt.subplot(2, 3, 5, sharey=ax)
            plt.plot(time,
                     ICE,
                     '.',
                     color='tab:orange',
                     markersize=0.5,
                     label='n = {}'.format(ICE.shape[1]))
            plt.xlim(*xlim)
            plt.ylim(*ylim)
            plt.title('ICE Vehicle Data')
            plt.ylabel(ylabel)
            plt.xlabel(xlabel)
            style.legend(ax=plt.gca(), loc=4)

        if not NEW.empty:
            # NEW
            plt.subplot(2, 3, 3, sharey=ax)
            plt.plot(time,
                     NEW,
                     '.',
                     color='tab:green',
                     markersize=0.5,
                     label='n = {}'.format(NEW.shape[1]))
            plt.xlim(*xlim)
            plt.ylim(*ylim)
            plt.title('New Vehicle Data')
            plt.ylabel(ylabel)
            plt.xlabel(xlabel)
            style.legend(ax=plt.gca(), loc=4)

        if not OLD.empty:
            # OLD
            plt.subplot(2, 3, 6, sharey=ax)
            plt.plot(time,
                     OLD,
                     '.',
                     color='tab:purple',
                     markersize=0.5,
                     label='n = {}'.format(OLD.shape[1]))
            plt.xlim(*xlim)
            plt.ylim(*ylim)
            plt.title('Old Vehicle Data')
            plt.ylabel(ylabel)
            plt.xlabel(xlabel)
            style.legend(ax=plt.gca(), loc=4)

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

    #%% FIGURE 4 - all pairs plotted individually

    plt.close('all')

    table = pd.read_excel('P:/AHEC/ahectable.xlsx')
    table = table.dropna(axis=0, how='all').dropna(axis=1, thresh=2)

    for channel in chlist:
        if tcns is None:
            cib = cibdict[channel]
            bel = beldict[channel]
            table2 = table[table.loc[:, ['CIBLE', 'BELIER']].isin(
                cib.columns).any(axis=1)]
        else:
            cib = cibdict[channel].loc[:, tcns].dropna(axis=1)
            bel = beldict[channel].loc[:, tcns].dropna(axis=1)
            table2 = table[table.loc[:, ['CIBLE', 'BELIER']].isin(tcns).any(
                axis=1)]

        pairs = table2.loc[:, [
            'CIBLE', 'BELIER', 'VITESSE', 'CBL_MODELE', 'BLR_MODELE', 'SUBSET',
            'CBL_POIDS', 'BLR_POIDS'
        ]]
        pairs['Mass Gap'] = pairs['CBL_POIDS'] - pairs['BLR_POIDS']
        pairs = pairs.sort_values(by=['Mass Gap'])

        if cib.shape[0] == 0:
            continue

        plotframes = [cib, bel]
        ylim = style.ylim_no_outliers(plotframes)
        if (channel[2:6] == 'SIME') or (channel[2:6] == 'CVEH'
                                        and channel[14:15] == 'X'):
            ylim = (-60, 30)
        ylabel = style.ylabel(channel[12:14], channel[14:15])

        r, c = style.sqfactors(pairs.shape[0])
        fig, axs = style.subplots(r,
                                  c,
                                  sharex='all',
                                  sharey='all',
                                  visible=True,
                                  num='Mass: ' + channel,
                                  figsize=(5 * c, 3.125 * r))
        fig.suptitle(
            '{sbdir} - Frontal Offset Crash Test at {speed} km/h\n{ch} - {desc}'
            .format(sbdir=subdir[:-4],
                    speed=subdir[-3:-1],
                    ch=channel,
                    desc=description.get(channel, 'Description Unavailable')))

        for i, (cib_tcn, bel_tcn) in enumerate(zip(pairs.CIBLE, pairs.BELIER)):
            ax = axs[i]

            pair = pairs[pairs.CIBLE == cib_tcn]
            bool1 = pair.SUBSET.item() == 'HEV vs ICE'
            bool2 = not pair.SUBSET.item() == 'General'
            colors['cib'] = (
                'tab:blue' if bool1 else 'tab:purple') if bool2 else 'tab:pink'
            colors['bel'] = ('tab:orange' if bool1 else
                             'tab:green') if bool2 else 'tab:grey'

            ax.plot(time,
                    cib.get(cib_tcn, default=time * np.nan),
                    color=colors['cib'],
                    label=cib_tcn)
            ax.plot(time,
                    bel.get(bel_tcn, default=time * np.nan),
                    color=colors['bel'],
                    label=bel_tcn)
            ax.set_xlim(*xlim)
            ax.set_ylim(*ylim)
            title = '{} vs {}: {} vs {}\n({} lbs)'.format(
                cib_tcn, pair.BELIER.to_string(index=False),
                pair.CBL_MODELE.to_string(index=False),
                pair.BLR_MODELE.to_string(index=False),
                pair['Mass Gap'].to_string(index=False))
            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 + 'Mass_' + channel + '.png', dpi=200)
        plt.close('all')
Exemplo n.º 5
0
plt.close('all')
for vitesse in [40, 48, 56]:
    tcnlist = list(table[table['Vitesse'] == vitesse].index)
    peakdata = {}
    lbs = {}
    for channel in fulldata:
        peakdata[channel] = pd.DataFrame(columns=['t0', 'tp', 'start', 'peak'])
        for tcn in fulldata[channel].columns.intersection(tcnlist):
            peakdata[channel].loc[tcn] = gp.get_peak(time,
                                                     fulldata[channel][tcn])
            mask = scoretable.Modele == table.loc[tcn].Modele
            lbs[tcn] = scoretable[mask].iloc[0, -4:]

    axs = style.subplots(3,
                         4,
                         num='Lap Belt Scores %s' % vitesse,
                         sharex=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 11, 12],
                         sharey=[1, 1, 3, 3, 5, 5, 3, 3, 9, 10, 11, 12])

    xlabel = 'Lap Belt Score'

    for channel, subloc in subplot_peak.items():
        ax = axs[subloc - 1]

        for tcn in peakdata[channel].index:
            ax.plot(lbs[tcn]['D3'],
                    peakdata[channel].loc[tcn, 'peak'],
                    '.',
                    color='tab:orange',
                    label='C3')
            ax.plot(lbs[tcn]['D4'],
Exemplo n.º 6
0
        table = pd.concat([table, table2], axis=0)

    sets = set(table[column].sort_values())
    sub = {}
    for set_item in sets:
        sub[set_item] = table[table[column] == set_item]['CIBLE'].tolist()

    for channel in chlist:

        ch = channel[0] if isinstance(channel, list) else channel
        ylabel = style.ylabel(ch[12:14], ch[14:15])

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

        chdata = pd.concat([data[ch] for ch in channel], axis=1) if isinstance(
            channel, list) else data[channel]
        ylim = style.ylim_no_outliers(chdata)

        for i, set_item in enumerate(sub):
            ax = axs[i]
            try:
                df = chdata.loc[:, sub[set_item]]
Exemplo n.º 7
0
#for group in groupdict:
#    for channel in groupdict[group]:
#        temp = style.explode(groupdict[group][channel],[])
#        dvdf = pd.concat(temp, axis=1)
#        groupdict[group][channel] = dvdf

#groupA = groupdict['A']
#groupC = groupdict['C']
chm = [channel+'m' for channel in channels]
colors = dict(zip(channels+chm, ['tab:orange','tab:blue','tab:red','tab:blue']))
name = dict(zip(channels, ['Chest','Pelvis']))
al = dict(zip(channels, [0.25,0.25]))
#%% Group A and C for Offset, Wall
plt.close('all')

axs = style.subplots(2,2,sharex='all',sharey='all',visible=True,figsize=(9,6))

for i, config in enumerate(['offset','mur']):
    
    for ch in channels:
        axs[i].plot(time*1000, groupdict['A'][ch][config], color = colors[ch], alpha=al[ch], label = name[ch])
        axs[i+2].plot(time*1000, groupdict['C'][ch][config], color = colors[ch], alpha=al[ch], label = name[ch])
        
        axs[i].plot(time*1000, groupdict['A'][ch][config].mean(axis=1), color = colors[ch+'m'], label = name[ch]+' Mean')
        axs[i+2].plot(time*1000, groupdict['C'][ch][config].mean(axis=1), color = colors[ch+'m'], label = name[ch]+' Mean')
        
    for group in ['A','C']:
        ax = axs[i] if group == 'A' else axs[i+2]
        
        ax.set_xlabel('Time [ms]')
        ax.set_ylabel('Acceleration X [g]')