from PMG.COM.openbook import openHDF5 import PMG.COM.data as data from PMG.COM.data import check_and_clean import PMG.COM.plotstyle as style import PMG.COM.table as tb THOR = os.fspath('P:/AHEC/Data/THOR/') chlist = ['11CHSTLEUPTHDSXB', '11CHSTRIUPTHDSXB', '11CHSTRILOTHDSXB', '11CHSTLELOTHDSXB'] time, fulldata = openHDF5(THOR, chlist) 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]
# -*- coding: utf-8 -*- """ Created on Thu Apr 19 11:14:43 2018 @author: giguerf """ import matplotlib.pyplot as plt from PMG.COM.openbook import openHDF5 from PMG.COM import table as tb from matplotlib.animation import FuncAnimation from matplotlib.widgets import Slider import matplotlib.gridspec as gridspec table = tb.get('SLED') SLED = 'P:/SLED/Data/' chlist = [ '12HEAD0000Y7ACXA', '12HEAD0000Y2ACXA', '12CHST0000Y7ACXC', '12CHST0000Y2ACXC', '12PELV0000Y7ACXA', '12PELV0000Y2ACXA' ] time, fulldata = openHDF5(SLED, chlist) raw = fulldata['12PELV0000Y7ACXA'].iloc[:, 0] #%% Animation fig, ax = plt.subplots(figsize=(5, 3)) #ax.set(xlim=(-3, 3), ylim=(-1, 1)) ax.plot(raw, 'k')
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')
ax.plot(t, raw) ax2 = plt.twinx(ax=ax) ax2.plot(t, df, ':') return clusters, df ### Run the main function unless imported if __name__ == '__main__': from PMG.COM import table as tb path = os.fspath('P:/AHEC/DATA/Full Sample/48/') project = 'AHEC' plot_path = 'P:/AHEC/Plots/Clustering/THOR/' table = tb.get(project) tcns = table[table.SUBSET.isin(['HEV vs ICE']) & table.VITESSE.isin([48])].CIBLE.tolist() + table[ table.SUBSET.isin(['HEV vs ICE']) & table.VITESSE.isin([48])].BELIER.tolist() # tcns = None time, raw = import_data(path, '10CVEHCG0000ACXD', tcns, sl=slice(100, 1600)) labels = make_labels(raw, project) clusters, data = cluster(time, raw, labels,
import pandas as pd import matplotlib.pyplot as plt #from PMG.COM.openbook import openHDF5 import PMG.COM.plotstyle as style import PMG.COM.table as tb #THOR = os.fspath('P:/AHEC/Data/THOR/') chlist = [ '11NECKLO00THFOXA', '11CHSTLEUPTHDSXB', '11PELV0000THACXA', '11FEMRLE00THFOZB' ] #chlist = ['11CHST0000THACXC', '11CHSTLEUPTHDSXB', '11CLAVLEINTHFOZA', '11CLAVRIINTHFOZA'] 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')