LongitudinalAssessment.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sun Apr 28 15:50:58 2019
  4. @author: aemdlabs
  5. """
  6. import deepdish as dd
  7. import matplotlib.pyplot as plt
  8. from glob import glob
  9. import os
  10. import numpy as np
  11. import matplotlib.colors as colors
  12. import matplotlib as mpl
  13. import csv
  14. from matplotlib.colors import LinearSegmentedColormap
  15. MCSMapI={'SE1':'Ch03',
  16. 'SE2':'Ch05',
  17. 'SE3':'Ch01',
  18. 'SE4':'Ch02',
  19. 'SE5':'Ch22',
  20. 'SE6':'Ch06',
  21. 'SE7':'Ch16',
  22. 'SE8':'Ch37',
  23. 'SE9':'Ch20',
  24. 'SE10':'Ch10',
  25. 'SE11':'Ch24',
  26. 'SE12':'Ch08',
  27. 'SE13':'Ch14',
  28. 'SE14':'Ch04',
  29. 'SE15':'Ch18',
  30. 'SE16':'Ch33',
  31. 'SE17':'Ch34',
  32. 'SE18':'Ch60',
  33. 'SE19':'Ch38',
  34. 'SE20':'Ch64',
  35. 'SE21':'Ch40',
  36. 'SE22':'Ch56',
  37. 'SE23':'Ch42',
  38. 'SE24':'Ch70',
  39. 'SE25':'Ch66',
  40. 'SE26':'Ch65',
  41. 'SE27':'Ch68',
  42. 'SE28':'Ch67',
  43. 'SE29':'Ch55',
  44. 'SE30':'Ch62',
  45. 'SE31':'Ch58',
  46. 'SE32':'Ch69',
  47. 'ME1':'Ch57',
  48. 'ME2':'Ch61',
  49. 'ME3':'Ch53',
  50. 'ME4':'Ch63',
  51. 'ME5':'Ch52',
  52. 'ME6':'Ch41',
  53. 'ME7':'Ch49',
  54. 'ME8':'Ch51',
  55. 'ME9':'Ch46',
  56. 'ME10':'Ch45',
  57. 'ME11':'Ch44',
  58. 'ME12':'Ch39',
  59. 'ME13':'Ch54',
  60. 'ME14':'Ch43',
  61. 'ME15':'Ch50',
  62. 'ME16':'Ch47',
  63. 'ME17':'Ch32',
  64. 'ME18':'Ch27',
  65. 'ME19':'Ch30',
  66. 'ME20':'Ch29',
  67. 'ME21':'Ch28',
  68. 'ME22':'Ch25',
  69. 'ME23':'Ch26',
  70. 'ME24':'Ch07',
  71. 'ME25':'Ch21',
  72. 'ME26':'Ch11',
  73. 'ME27':'Ch17',
  74. 'ME28':'Ch15',
  75. 'ME29':'Ch13',
  76. 'ME30':'Ch31',
  77. 'ME31':'Ch19',
  78. 'ME32':'Ch09'}
  79. #Col, Row
  80. MCSMapFacingDown={'Ch58':(0,1),
  81. 'Ch57':(0,2),
  82. 'Ch56':(0,3),
  83. 'Ch55':(0,4),
  84. 'Ch54':(0,5),
  85. 'Ch53':(0,6),
  86. 'Ch52':(0,7),
  87. 'Ch51':(0,8),
  88. 'Ch50':(0,9),
  89. 'Ch49':(0,10),
  90. 'Ch60':(1,0),
  91. 'Ch61':(1,1),
  92. 'Ch62':(1,2),
  93. 'Ch63':(1,3),
  94. 'Ch64':(1,4),
  95. 'Ch65':(1,5),
  96. 'Ch43':(1,6),
  97. 'Ch44':(1,7),
  98. 'Ch45':(1,8),
  99. 'Ch46':(1,9),
  100. 'Ch47':(1,10),
  101. 'Ch70':(2,0),
  102. 'Ch69':(2,1),
  103. 'Ch68':(2,2),
  104. 'Ch67':(2,3),
  105. 'Ch66':(2,4),
  106. 'Ch42':(2,5),
  107. 'Ch41':(2,6),
  108. 'Ch40':(2,7),
  109. 'Ch39':(2,8),
  110. 'Ch38':(2,9),
  111. 'Ch37':(2,10),
  112. 'Ch01':(3,0),
  113. 'Ch02':(3,1),
  114. 'Ch03':(3,2),
  115. 'Ch04':(3,3),
  116. 'Ch05':(3,4),
  117. 'Ch06':(3,5),
  118. 'Ch30':(3,6),
  119. 'Ch31':(3,7),
  120. 'Ch32':(3,8),
  121. 'Ch33':(3,9),
  122. 'Ch34':(3,10),
  123. 'Ch11':(4,0),
  124. 'Ch10':(4,1),
  125. 'Ch09':(4,2),
  126. 'Ch08':(4,3),
  127. 'Ch07':(4,4),
  128. 'Ch29':(4,5),
  129. 'Ch28':(4,6),
  130. 'Ch27':(4,7),
  131. 'Ch26':(4,8),
  132. 'Ch25':(4,9),
  133. 'Ch24':(4,10),
  134. 'Ch12':None,
  135. 'Ch59':None,
  136. 'Ch13':(5,1),
  137. 'Ch14':(5,2),
  138. 'Ch15':(5,3),
  139. 'Ch16':(5,4),
  140. 'Ch17':(5,5),
  141. 'Ch18':(5,6),
  142. 'Ch19':(5,7),
  143. 'Ch20':(5,8),
  144. 'Ch21':(5,9),
  145. 'Ch22':(5,10)}
  146. def MeanStd(Data):
  147. Arr = np.zeros([len(Data.keys()),len(Data[Data.keys()[0]])])
  148. for iT,TrtName in enumerate(Data.keys()):
  149. Arr[iT,:] = Data[TrtName]
  150. return np.mean(Arr,0), np.std(Arr,0)
  151. def MeanStdCNP(Data):
  152. MeanCNP = np.array([])
  153. StdCNP = np.array([])
  154. for iT,TrtName in enumerate(Data.keys()):
  155. Mean = np.mean(Data[TrtName])
  156. Std = np.std(Data[TrtName])
  157. MeanCNP = np.append(MeanCNP, Mean)
  158. StdCNP = np.append(StdCNP, Std)
  159. return MeanCNP, StdCNP
  160. plt.close('all')
  161. #%% DC charact plotting
  162. plt.close('all')
  163. Files = [
  164. 'IV-charact/IV-Day1-2/20190731_033840 Current vs Vgs_5sStep.txt',
  165. 'IV-charact/IV-Day1-2/20190801_031608 Current vs Vgs5s-afterRec6-highRange.txt',
  166. 'IV-charact/IV-Day2/20190802_115002 Current vs Vgs-24h2-PostRec7.txt',
  167. 'IV-charact/IV-Day4/20190803_031630 Current vs Vgs-PostRec12.txt',
  168. 'IV-charact/IV-Day6/20190805_113528 Current vs Vgs-PreRec1.txt',
  169. 'IV-charact/IV-Day12/20190811_090313 Current vs Vgs-PostRec1.txt',
  170. 'IV-charact/IV-Day26/20190825_080628 Current vs Vgs.txt']
  171. color = ['r','orange','g','b','purple','m','cyan']
  172. cmap = mpl.cm.rainbow
  173. legend= ['Day 1','Day 2','Day 3','Day 5','Day 7','Day 12','Day 28']
  174. time = [1,2,3,4,6,12,26]
  175. CNPDict = {}
  176. GMDict = {}
  177. GMforSN = {}
  178. counter = -1
  179. for iFile, File in enumerate(Files):
  180. Fin = open(File)
  181. plt.figure(1)
  182. reader = csv.reader(Fin, delimiter='\t')
  183. lenVgs = 1000
  184. Vgs = np.zeros(lenVgs)
  185. Ids = np.zeros([lenVgs,8])
  186. GMforSN[iFile] = {}
  187. reader = csv.reader(Fin, delimiter='\t')
  188. for il, e in enumerate(reader):
  189. if il == 0:
  190. continue
  191. print(e)
  192. vg = e[0]
  193. vg = vg.replace(',','.')
  194. Vgs[il-1] = float(vg)
  195. for iids, ids in enumerate(e[1:]):
  196. ids = ids.replace(',','.')
  197. Ids[il-1,iids] = float(ids)
  198. CNP = np.array([])
  199. GM = np.array([])
  200. IdsTrim = {}
  201. for i in range(8):
  202. if i == 2:
  203. continue
  204. IdsTrim[i] = np.trim_zeros(Ids[:,i])
  205. if i == 0:
  206. Vgs = np.append(Vgs[0:2],np.trim_zeros(Vgs[2:]))
  207. plt.plot(Vgs,IdsTrim[i],color = cmap(iFile / float(len(Files))), label = legend[iFile])
  208. plt.legend()
  209. else:
  210. Vgs = np.append(Vgs[0:2],np.trim_zeros(Vgs[2:]))
  211. plt.plot(Vgs,IdsTrim[i],color =cmap(iFile / float(len(Files))))
  212. VgsFit = np.linspace(Vgs[0],Vgs[-1],100)
  213. fitVal=np.polyval(np.polyfit(Vgs,IdsTrim[i],9),VgsFit)
  214. cnp = VgsFit[np.where(fitVal==np.min(fitVal))]
  215. CNP = np.append(CNP,cnp)
  216. gm = np.max(abs(np.polyval(np.polyder(np.polyfit(Vgs,IdsTrim[i],9)),np.linspace(cnp-0.18, cnp,100))))*1e-2 #mS/V
  217. GMforSN[iFile][i] = gm
  218. GM = np.append(GM,gm)
  219. CNPDict[iFile] = CNP
  220. GMDict[iFile] = GM
  221. #### Calculate Gm
  222. if iFile not in [0,2,4,5,6]:
  223. continue
  224. counter += 1
  225. plt.figure(2)
  226. MeanIds, StdIds = MeanStd(IdsTrim)
  227. plt.plot(Vgs,MeanIds, color =color[counter], label = legend[iFile])
  228. plt.fill_between(Vgs,MeanIds+StdIds,MeanIds-StdIds, color =color[counter], alpha=0.3)
  229. plt.legend(bbox_to_anchor=(0.0, 0.36, 0.7, 0.0),fontsize=13)
  230. plt.xlabel('V$_{gs}$ (V)',fontsize=15)
  231. plt.ylabel('I$_{ds}$ ($\mu$A)',fontsize=15)
  232. plt.xticks(fontsize=13)
  233. plt.yticks(fontsize=13)
  234. MeanCNP, StdCNP = MeanStdCNP(CNPDict)
  235. CNPArray = np.zeros([len(Files),7])
  236. GMArray = np.zeros([len(Files),7])
  237. w = 0.1
  238. width = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)
  239. for ikey,key in enumerate(CNPDict.keys()):
  240. CNPArray[ikey,:] = CNPDict[key].T
  241. GMArray[ikey,:] = GMDict[key].T
  242. plt.figure()
  243. plt.boxplot(CNPArray.T, positions = time, widths = width(time,w))
  244. plt.xlabel('time (days)')
  245. plt.ylabel('CNP (V)')
  246. width = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)
  247. plt.figure()
  248. plt.boxplot(GMArray.T, positions = time, widths = width(time,w))
  249. plt.xlabel('time(h)')
  250. plt.ylabel('Gm (mS/V)')
  251. plt.xscale('log')
  252. #%% Noise Plotting
  253. dates = [
  254. 'Day1-2',
  255. 'Day2',
  256. 'Day4',
  257. 'Day6',
  258. 'Day12',
  259. 'Day26'
  260. ]
  261. cmap = mpl.cm.rainbow
  262. DCch = ['ME5','ME7','ME29','ME31','SE5','SE7','SE29','SE31']
  263. Directory = 'PSD-charact/{}/'.format(dates[0])
  264. ImportNoise = dd.io.load(Directory+'Power200Hz5')
  265. noise = np.ones((len(dates),len(ImportNoise)))*(-10000)
  266. GmDCNoise = np.zeros((len(dates),len(DCch)))
  267. GMDC = np.zeros((len(dates),len(DCch)))
  268. days = [1,2,3,6,11,29]
  269. NoiseMin = 2.5e-10
  270. GmMin = 1.5e-9
  271. DayNum = days
  272. figN,axN =plt.subplots()
  273. #axN = axS.twinx()
  274. for iday, day in enumerate(dates):
  275. Directory = 'PSD-charact/{}/'.format(day)
  276. ImportNoise = dd.io.load(Directory+'Power200Hz5')
  277. print(day)
  278. for ikey, key in enumerate(ImportNoise.keys()):
  279. print(iday,key,ikey)
  280. if key in DCch:
  281. if DCch.index(key) == 2:
  282. continue
  283. GmDCNoise[iday,DCch.index(key)] = 1e6*np.sqrt(ImportNoise[key]*200*np.log(10/1)/np.sqrt(2))/(GMforSN[iday][DCch.index(key)]*1e-4)
  284. GMDC[iday,DCch.index(key)] = (GMforSN[iday][DCch.index(key)])
  285. Aparam = np.sqrt(ImportNoise[key]*200)
  286. if Aparam >= NoiseMin:
  287. noise[iday,ikey] = Aparam
  288. else:
  289. noise[iday,ikey] = -100000
  290. print('{} damaged -Trt{}'.format(iday,key))
  291. figN
  292. w = 0.04
  293. width = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)
  294. axN.semilogy(np.random.normal(iday+1, w, size=1)-6*w, Aparam, 'k*',markersize=2)
  295. axN.set_xlabel('Time(days)')
  296. axN.set_ylabel('Estimate Irms(A) @1Hz')
  297. figN
  298. w = 0.035
  299. width = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)
  300. PropS = {}
  301. PropS['markeredgecolor'] = 'r'
  302. N = axN.boxplot(noise.T,widths = 4*w)#,positions = np.array(days)+1.7*width(days,w),widths=width(days,w))
  303. axN.set_xticklabels(days,)
  304. #axN.set_xscale("log")
  305. axN.set_xlabel('time (days)')
  306. axN.set_ylabel('Estimate I$_{ds-rms}$ (A) @1Hz')
  307. plt.legend()
  308. for element in ['boxes', 'whiskers', 'fliers', 'means', 'medians', 'caps']:
  309. plt.setp(N[element], color='k',markersize=2)
  310. for patch in N['boxes']:
  311. patch.set(color='k')
  312. fig2,ax2 = plt.subplots()
  313. w = 0.1
  314. width = lambda p, w: 10**(np.log10(p)+w/2.)-10**(np.log10(p)-w/2.)
  315. bp = ax2.boxplot(GmDCNoise.T)#,positions = days, widths=width(days,w))
  316. ax2.set_xticklabels(days,)
  317. for element in ['boxes', 'whiskers', 'fliers', 'means', 'medians', 'caps']:
  318. plt.setp(bp[element], color='k')
  319. for patch in bp['boxes']:
  320. patch.set(color='k')
  321. plt.xlabel('time (days)')
  322. plt.ylabel('V$_{gs-rms}$ ($\mu$V)')