Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. import argparse
  2. import math
  3.  
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. import pandas as pd
  7. from sklearn.metrics.pairwise import euclidean_distances
  8. from scipy.spatial import distance_matrix
  9. from scipy.spatial.distance import euclidean, pdist, squareform
  10. import csv
  11.  
  12.  
  13. parser = argparse.ArgumentParser()
  14. parser.add_argument('-a', "--anonymous", action='store_true', default=False, help='Hide axes')
  15. parser.add_argument('-t', "--truck", type=str, default=None, help='PLot one truck ID')
  16. parser.add_argument('-f', "--filename", type=str, default="Multi_P1FWM_turbo_failure_deviation_ano.csv",
  17. help='CSV filename')
  18. parser.add_argument('-n', "--normalise", action='store_true', default=False, help='Normalise')
  19. parser.add_argument("--max_pics", type=int, default=16, help='Max histograms on a plot')
  20. parser.add_argument("--cols", type=int, default=4, help='Number of histogram columns in plot')
  21. parser.add_argument("--rows", type=int, default=None, help='Number of rows to read from CSV file')
  22. parser.add_argument("--start", type=int, default=0, help='Start histogram')
  23. parser.add_argument("--trucks", type=str, default=None, help='Multiple chassis IDs, comma seperated')
  24. args = parser.parse_args()
  25. df = pd.read_csv("vehiclethree.csv", parse_dates=['Date'], header=0, index_col='Date')
  26. df.head()
  27. # df = pd.read_csv("vehiclethree.csv",parse_dates=[0])
  28. # print(df.shape)
  29. df = pd.DataFrame(df)
  30. # print(type(df))
  31. # print(df)
  32. # df['Date'] = pd.to_datetime(df['Date'])
  33. # df.set_index('Date')
  34. # title= df.iloc[:, 'Date']
  35. # title= pd.to_datetime(title)
  36. # title = title.dt.date
  37. # title = np.array(title)
  38.  
  39. two_week = df.resample('2W').mean()
  40. # print(two_week)
  41. # print(two_week.shape)
  42.  
  43. # title=two_week.loc[:, 'Date']
  44. # title= pd.to_datetime(title)
  45. # title = title.dt.date
  46. # title = np.array(title)
  47.  
  48. interpolated = two_week.interpolate(method='linear')
  49. # print(interpolated)
  50.  
  51. b = interpolated.iloc[:, 1:]
  52.  
  53. # print(b)
  54. # print(b.shape)
  55. d = b.diff(axis=0, periods=1)
  56. std_devi_diff = d.std(axis=1)
  57. print(std_devi_diff.shape)
  58. print(std_devi_diff)
  59. mean_diff = d.mean(axis=1)
  60. print(mean_diff)
  61. print(mean_diff.shape)
  62. print(mean_diff.values)
  63. fig = plt.figure()
  64. plt.plot(std_devi_diff.values)
  65. plt.tick_params(axis='both', which='major', labelsize=10)
  66. plt.tick_params(axis='both', which='minor', labelsize=8)
  67. plt.xlabel('Vehicle-3_biweekly',fontsize=18)
  68. plt.ylabel('standard deviation ',fontsize=16)
  69. fig.suptitle('standard deviation_rows',fontsize=20)
  70. plt.plot(mean_diff.values)
  71.  
  72. num_pics = d.shape[0]
  73. fig, axes = plt.subplots(nrows=1, ncols=d.shape[0])
  74. fig.set_figheight(20)
  75. fig.set_figwidth(20)
  76. cols = args.cols
  77. rows = int(num_pics/cols)+ 1*((num_pics % cols)!=0)
  78. sp=1
  79. pc=0
  80. i = 0
  81. fig = plt.figure(figsize=(cols*3, rows*3)) #plt.figure(figsize=(sz,sz))
  82. plt.subplots_adjust( hspace=0.7, wspace=0.5 )
  83.  
  84. for index, row in d.iterrows():
  85. ax = fig.add_subplot(rows, cols, sp)
  86. # print(type(row))
  87. xx = row.iloc[:19]
  88. yy = row.iloc[19:]
  89.  
  90. drop_reshape1 = row.values.reshape(20, 20)
  91. im = drop_reshape1
  92. print(im)
  93. # im = im.astype(int)
  94. # im = drop_reshape1.astype(int)
  95. im = np.flipud(im) # rot90(im) #flipud(im) #rot90()
  96. # print(im)
  97. # print("checking...")
  98.  
  99. if args.normalise:
  100. _min = 0
  101. _max = 1
  102. im += -(np.min(im))
  103. im /= np.max(im) / (_max - _min)
  104. # ax.append( fig.add_subplot(20, 20, index+1) )
  105.  
  106. im_masked = np.ma.masked_where(im == 0, im)
  107. plt.imshow(im_masked, interpolation='none')
  108.  
  109. ax.set_aspect('equal')
  110. ax.set_title('title')
  111. ax.get_xaxis().set_ticks([0, 19])
  112. ax.get_yaxis().set_ticks([])
  113. #
  114. ax.set_xticks(np.arange(-.5, 19, 1), minor=True);
  115. ax.set_yticks(np.arange(-.5, 19, 1), minor=True);
  116. ax.grid(which='minor', color='w', linestyle='-', linewidth=1)
  117. #
  118. if not args.anonymous:
  119. # ax.title.set_text(title[i])
  120. # i += 1
  121. ax.set_xlabel("engine speed")
  122. ax.set_ylabel("engine torque")
  123. # ax.title.set_text(B_new.SEND_DATETIME[row])
  124. plt.colorbar(orientation='vertical', ax=ax, format='%.1f', fraction=0.0408, pad=0.04)
  125. # plt.clim(0, 10);
  126. else:
  127. plt.colorbar(orientation='vertical', ax=ax, ticks=[])
  128. sp += 1
  129. if not args.anonymous:
  130. fig.suptitle('VEHICLE_ID' + ": " + str('SEND_DATETIME') + ' P1FWM') # Training data '+str(st)+" +"+str(nn) )
  131. # fn = "Sorted_title_" + str('SEND_DATETIME') + "_" + str(index) + "+" + str(pc)
  132. # if args.normalise:
  133. # fn += "_N"
  134. # fn += ".png"
  135. # print("Saving", fn)
  136. # if os.path.exists(fn):
  137. # os.remove(fn)
  138. # fig.savefig(fn, dpi=288)
  139.  
  140.  
  141. plt.show()
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. plt.show()
  149. #
  150.  
  151.  
  152.  
  153. ff= d.iloc[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement