Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. # import pandas as pd
  2. # import numpy as np
  3. # from numpy import array
  4. # import matplotlib.pyplot as plt
  5. # data = pd.read_csv("Multi_P1FWM_turbo_failure_deviation_ano.csv", header=0)
  6. # train_data = data.iloc[:,5:405]
  7. # # print(train_data.head(2))
  8. # print(train_data.shape)
  9. # newdata = array(train_data)
  10. # print(newdata.shape)
  11. # newdata = newdata[1,:]
  12. # print(newdata.shape)
  13. # print(newdata)
  14. import numpy as np
  15. import pandas as pd
  16. from PIL import Image
  17. import plotly.plotly as py
  18. import plotly.figure_factory as ff
  19. from numpy import array
  20. import matplotlib.pyplot as plt
  21. import argparse
  22. parser = argparse.ArgumentParser()
  23. parser.add_argument( '-a', "--anonymous", action='store_true', default=False, help='Hide axes' )
  24. parser.add_argument( '-t', "--truck", type=str, default=None, help='PLot one truck ID' )
  25. parser.add_argument( '-f', "--filename", type=str, default="Multi_P1FWM_turbo_failure_deviation_ano.csv", help='CSV filename' )
  26. parser.add_argument( '-n', "--normalise", action='store_true', default=False, help='Normalise' )
  27. parser.add_argument( "--max_pics", type=int, default=16, help='Max histograms on a plot' )
  28. parser.add_argument( "--cols", type=int, default=4, help='Number of histogram columns in plot' )
  29. parser.add_argument( "--rows", type=int, default=None, help='Number of rows to read from CSV file' )
  30. parser.add_argument( "--start", type=int, default=0, help='Start histogram' )
  31. parser.add_argument( "--trucks", type=str, default=None, help='Multiple chassis IDs, comma seperated' )
  32. args = parser.parse_args()
  33. df = pd.read_csv("Multi_P1FWM_turbo_failure_deviation_ano.csv")
  34. vehicle_1 = df[df['VEHICLE_ID'] == 1]
  35. vehicle_2 = df[df['VEHICLE_ID'] == 2]
  36. vehicle_3 = df[df['VEHICLE_ID'] == 3]
  37. vehicle_4 = df[df['VEHICLE_ID'] == 4]
  38. vehicle_5 = df[df['VEHICLE_ID'] == 5]
  39. #print(vehicle_1)
  40. vehicle_1_time = vehicle_1.SEND_DATETIME
  41. vehicle_2_time = vehicle_2.SEND_DATETIME
  42. vehicle_3_time = vehicle_3.SEND_DATETIME
  43. vehicle_4_time = vehicle_4.SEND_DATETIME
  44. vehicle_5_time = vehicle_5.SEND_DATETIME
  45. #print(vehicle_1_time)
  46. new = df["SEND_DATETIME"].str.split(" ",n=1,expand=True)
  47. df["Date"] =new[0]
  48. df["Time"] =new[1]
  49. df.drop(columns=["SEND_DATETIME"], inplace= True)
  50. # df.dropna(inplace= True)
  51. # df = df.join(df['SEND_DATETIME'].str.split(',',expand=True).add_prefix('Time'))
  52. #print(df.shape)
  53. #print(df)
  54. data = array(df)
  55. # print(data)
  56. #print(type(data))
  57. #print(data[0,4:404])
  58. print('Rows: %d' %data.shape[0])
  59. print('Cols: %d' %data.shape[1])
  60. num_pics = data.shape[0]
  61. if num_pics > args.max_pics:
  62. st = num_pics - args.max_pics
  63. num_pics = args.max_pics
  64. print(num_pics)
  65. sp =1
  66. n = 3
  67. cols = args.cols
  68. rows = int(num_pics/cols)+ 1*((num_pics % cols)!=0)
  69. nn = rows * cols
  70. pc = 0
  71. fig = plt.figure(figsize=(cols*3, rows*3)) #plt.figure(figsize=(sz,sz))
  72. plt.subplots_adjust( hspace=0.7, wspace=0.5 )
  73. ax = fig.add_subplot(rows,cols,sp)
  74. im = data[13,4:404]
  75. im = np.reshape(im,(20,20))
  76. im = im.astype(int)
  77. # print(im.shape)
  78. im = np.flipud(im)
  79. # print(im)
  80. if args.normalise:
  81. _min = 0
  82. _max = 1
  83. im += -(np.min(im))
  84. im /= np.max(im) / (_max - _min)
  85. im_masked = np.ma.masked_where(im == 0 , im)
  86. plt.imshow(im_masked,interpolation='none',cmap="plasma")
  87. ax.set_aspect('equal')
  88. ax.get_xaxis().set_ticks([0,19])
  89. ax.get_yaxis().set_ticks([])
  90. ax.set_xticks(np.arange(-.5, 19, 1), minor=True);
  91. ax.set_yticks(np.arange(-.5, 19, 1), minor=True);
  92. ax.grid(which='minor', color='w', linestyle='-', linewidth=1)
  93. if not args.anonymous:
  94. ax.set_xlabel( "engine speed" )
  95. ax.set_ylabel( "engine torque" )
  96. plt.colorbar(orientation='vertical', ax=ax, format='%.1f', fraction=0.04)
  97. else:
  98. plt.colorbar(orientation='vertical', ax=ax, ticks=[])
  99.  
  100. plt.show()
  101.  
  102. #print(a)
  103. #print(a.shape)
  104. # a = a.reshape(20,20)
  105. # print(a.shape)
  106.  
  107. # plt.hist(a, 20, density=1,alpha=0.75)
  108. # plt.ylabel('engine torque')
  109. # plt.xlabel('engine speed')
  110. # # plt.title('vehicle_id')
  111. # # plt.grid(True)
  112. # # plt.show()
  113. # xx = a[:19]
  114. # yy = a[19:]
  115. # #plt.hist2d(xx,yy,bins=20,cmap=plt.cm.BuGn_r)
  116. # plt.figure(2)
  117. # plt.plot(xx,'bo',yy,'k')
  118. # plt.show()
  119. # nn = [go.Histogram2d(x=xx,y=yy)]
  120. # py.iplot(nn)
  121. # plt.show()
  122. # plt.figure(3)
  123. # # plt.hexbin(xx,yy,gridsize=(15,10),cmap='Blues')
  124. # # cb=plt.colorbar
  125. # # plt.show()
  126. # hist_data = [xx, yy]
  127. # group_labels=['a','b']
  128. # fig = ff.create_distplot(hist_data,group_labels,bin_size=.2)
  129. # py.iplot(fig)
  130.  
  131. # print(xx)
  132. # print(yy)
  133. # plt.hist(a,bins=20)
  134. # plt.show()
  135.  
  136. # newdata = df[:,5:]
  137. # print(newdata.shape)
  138. # print(newdata)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement