Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import math
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- from sklearn.metrics.pairwise import euclidean_distances
- from scipy.spatial import distance_matrix
- from scipy.spatial.distance import euclidean, pdist, squareform
- import csv
- parser = argparse.ArgumentParser()
- parser.add_argument('-a', "--anonymous", action='store_true', default=False, help='Hide axes')
- parser.add_argument('-t', "--truck", type=str, default=None, help='PLot one truck ID')
- parser.add_argument('-f', "--filename", type=str, default="Multi_P1FWM_turbo_failure_deviation_ano.csv",
- help='CSV filename')
- parser.add_argument('-n', "--normalise", action='store_true', default=False, help='Normalise')
- parser.add_argument("--max_pics", type=int, default=16, help='Max histograms on a plot')
- parser.add_argument("--cols", type=int, default=4, help='Number of histogram columns in plot')
- parser.add_argument("--rows", type=int, default=None, help='Number of rows to read from CSV file')
- parser.add_argument("--start", type=int, default=0, help='Start histogram')
- parser.add_argument("--trucks", type=str, default=None, help='Multiple chassis IDs, comma seperated')
- args = parser.parse_args()
- df = pd.read_csv("vehiclethree.csv", parse_dates=['Date'], header=0, index_col='Date')
- df.head()
- # df = pd.read_csv("vehiclethree.csv",parse_dates=[0])
- # print(df.shape)
- df = pd.DataFrame(df)
- # print(type(df))
- # print(df)
- # df['Date'] = pd.to_datetime(df['Date'])
- # df.set_index('Date')
- # title= df.iloc[:, 'Date']
- # title= pd.to_datetime(title)
- # title = title.dt.date
- # title = np.array(title)
- two_week = df.resample('2W').mean()
- # print(two_week)
- # print(two_week.shape)
- # title=two_week.loc[:, 'Date']
- # title= pd.to_datetime(title)
- # title = title.dt.date
- # title = np.array(title)
- interpolated = two_week.interpolate(method='linear')
- # print(interpolated)
- b = interpolated.iloc[:, 1:]
- # print(b)
- # print(b.shape)
- d = b.diff(axis=0, periods=1)
- std_devi_diff = d.std(axis=1)
- print(std_devi_diff.shape)
- print(std_devi_diff)
- mean_diff = d.mean(axis=1)
- print(mean_diff)
- print(mean_diff.shape)
- print(mean_diff.values)
- fig = plt.figure()
- plt.plot(std_devi_diff.values)
- plt.tick_params(axis='both', which='major', labelsize=10)
- plt.tick_params(axis='both', which='minor', labelsize=8)
- plt.xlabel('Vehicle-3_biweekly',fontsize=18)
- plt.ylabel('standard deviation ',fontsize=16)
- fig.suptitle('standard deviation_rows',fontsize=20)
- plt.plot(mean_diff.values)
- num_pics = d.shape[0]
- fig, axes = plt.subplots(nrows=1, ncols=d.shape[0])
- fig.set_figheight(20)
- fig.set_figwidth(20)
- cols = args.cols
- rows = int(num_pics/cols)+ 1*((num_pics % cols)!=0)
- sp=1
- pc=0
- i = 0
- fig = plt.figure(figsize=(cols*3, rows*3)) #plt.figure(figsize=(sz,sz))
- plt.subplots_adjust( hspace=0.7, wspace=0.5 )
- for index, row in d.iterrows():
- ax = fig.add_subplot(rows, cols, sp)
- # print(type(row))
- xx = row.iloc[:19]
- yy = row.iloc[19:]
- drop_reshape1 = row.values.reshape(20, 20)
- im = drop_reshape1
- print(im)
- # im = im.astype(int)
- # im = drop_reshape1.astype(int)
- im = np.flipud(im) # rot90(im) #flipud(im) #rot90()
- # print(im)
- # print("checking...")
- if args.normalise:
- _min = 0
- _max = 1
- im += -(np.min(im))
- im /= np.max(im) / (_max - _min)
- # ax.append( fig.add_subplot(20, 20, index+1) )
- im_masked = np.ma.masked_where(im == 0, im)
- plt.imshow(im_masked, interpolation='none')
- ax.set_aspect('equal')
- ax.set_title('title')
- ax.get_xaxis().set_ticks([0, 19])
- ax.get_yaxis().set_ticks([])
- #
- ax.set_xticks(np.arange(-.5, 19, 1), minor=True);
- ax.set_yticks(np.arange(-.5, 19, 1), minor=True);
- ax.grid(which='minor', color='w', linestyle='-', linewidth=1)
- #
- if not args.anonymous:
- # ax.title.set_text(title[i])
- # i += 1
- ax.set_xlabel("engine speed")
- ax.set_ylabel("engine torque")
- # ax.title.set_text(B_new.SEND_DATETIME[row])
- plt.colorbar(orientation='vertical', ax=ax, format='%.1f', fraction=0.0408, pad=0.04)
- # plt.clim(0, 10);
- else:
- plt.colorbar(orientation='vertical', ax=ax, ticks=[])
- sp += 1
- if not args.anonymous:
- fig.suptitle('VEHICLE_ID' + ": " + str('SEND_DATETIME') + ' P1FWM') # Training data '+str(st)+" +"+str(nn) )
- # fn = "Sorted_title_" + str('SEND_DATETIME') + "_" + str(index) + "+" + str(pc)
- # if args.normalise:
- # fn += "_N"
- # fn += ".png"
- # print("Saving", fn)
- # if os.path.exists(fn):
- # os.remove(fn)
- # fig.savefig(fn, dpi=288)
- plt.show()
- plt.show()
- #
- ff= d.iloc[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement