Guest User

Untitled

a guest
Jul 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Jul 9 10:30:15 2018
  5.  
  6. @author: cad6
  7. """
  8.  
  9. def tc9010percent():
  10. #%% extracts the channel, temperature and resistance from .csv file (must be given the path)
  11. csvFile = input('File Path? ')
  12. import numpy as np
  13. import matplotlib.pyplot as plt
  14. raw = np.loadtxt(open(csvFile,"rb"), delimiter=",", skiprows=1)
  15. channel = raw[:, 1][0]
  16. temperatureRaw = raw[:, 2]
  17. resistanceRaw = raw[:, 3]
  18.  
  19. #%% establishes the tuples which hol/home/linaro/Tc Data and Curve Code/2018_07_02/Channel_5_2018_07_02_13_28_42.csvd contextualized data
  20. resTuple = tuple(resistanceRaw)
  21. tempTuple = tuple(temperatureRaw)
  22.  
  23. #%%Tc50
  24. resList = list(resistanceRaw)
  25. tempList = list(temperatureRaw)
  26. resList.sort()
  27. tempList.sort()
  28.  
  29.  
  30. temperatureRange = tempList[-1] - tempList[0]
  31. rangeVariable = int(len(resistanceRaw)*(.5/temperatureRange))
  32. maxRes = []
  33. minRes = []
  34. for i in range(-rangeVariable , 0) :
  35. maxRes.append(resList[i])
  36.  
  37. for j in range(0, rangeVariable):
  38. minRes.append(resList[j])
  39.  
  40. upperRes = int(np.mean(maxRes))
  41. lowerRes = int(np.mean(minRes))
  42. aveRes = .5*(upperRes + lowerRes)
  43.  
  44.  
  45. upperBound = .25*aveRes + aveRes
  46. lowerBound = -.25*aveRes + aveRes
  47.  
  48. newArray = []
  49. resVals = []
  50. tempVals = []
  51.  
  52. for x in range(0, len(resList)):
  53. newArray.append(upperBound>resList[x]>lowerBound)
  54.  
  55. for r in range(0, len(newArray)):
  56. if newArray[r] == True:
  57. resVals.append(resList[r])
  58.  
  59. tupleIndex = []
  60. for h in range(0, len(resVals)) :
  61. tupleIndex.append(resTuple.index(resVals[h]))
  62.  
  63.  
  64. for g in range(0, len(tupleIndex)):
  65. tempVals.append(tempTuple[tupleIndex[g]])
  66.  
  67. if len(tempVals) %2 == 0:
  68. tempVals.append(tempVals[-1])
  69.  
  70. Tc50 = np.median(tempVals)
  71.  
  72. #%%make list without top 10 and bottom 10 percent of values
  73. largestMinRes = minRes[-1]
  74. smallestMaxRes = maxRes[0]
  75. newArray1 = []
  76. applicableValues1 = []
  77. for x in range(0, len(resList)):
  78. newArray1.append(smallestMaxRes>resList[x]>largestMinRes)
  79.  
  80. for r in range(0, len(newArray1)):
  81. if newArray1[r] == True:
  82. applicableValues1.append(resList[r])
  83.  
  84. tupleIndex1 = []
  85. for h in range(0, len(applicableValues1)):
  86. tupleIndex1.append(resTuple.index(applicableValues1[h]))
  87.  
  88. tempVals = []
  89. for g in range(0, len(tupleIndex1)):
  90. tempVals.append(tempTuple[tupleIndex1[g]])
  91.  
  92. #extact temperature vals close to 10%
  93. approxResAtTc10 = np.median(maxRes)*.1
  94. number = .75
  95. resTc10 = [x for x in resList if approxResAtTc10 -number*approxResAtTc10 <= x <= approxResAtTc10 + number*approxResAtTc10]
  96. if resTc10 == []:
  97. number = 2*number
  98. resTc10 = [x for x in resList if approxResAtTc10 -number*approxResAtTc10 <= x <= approxResAtTc10 + number*approxResAtTc10]
  99. tempTc10 = []
  100. for j in range(0, len(resTc10)):
  101. tempTc10.append(tempTuple[resTuple.index(resTc10[j])])
  102. if len(tempTc10) %2 == 0:
  103. tempTc10.append(tempTc10[-1])
  104. resRangeTc10 = []
  105. for h in range(0, len(tempTc10)):
  106. resRangeTc10.append(resTuple[tempTuple.index(tempTc10[h])])
  107. Tc10 = max(tempTc10)
  108.  
  109. #extract temperature vals close to 90%
  110. approxResAtTc90 = np.median(maxRes)*.9
  111. resTc90 = [x for x in resList if approxResAtTc90 -.75<= x <= approxResAtTc90 +.75 ]
  112. tempTc90 = []
  113. for i in range(0, len(resTc90)):
  114. tempTc90.append(tempTuple[resTuple.index(resTc90[i])])
  115. if len(tempTc90) %2 == 0:
  116. tempTc90.append(tempTc90[-1])
  117. resRangeTc90 = []
  118. for h in range(0, len(tempTc90)):
  119. resRangeTc90.append(resTuple[tempTuple.index(tempTc90[h])])
  120. Tc90 = np.median(tempTc90)
  121. #calculate ΔTc
  122. ΔTc = Tc90-Tc10
  123. print('Critical Temperature (10 Percent Measurement) of Channel %d is %f' %(channel, Tc10))
  124. print('Critical Temperature (90 Percent Measurement) of Channel %d is %f' %(channel, Tc90))
  125. print('ΔTc of Channel %d is %f' %(channel, ΔTc))
  126.  
  127. #%% extreme error check
  128. if ΔTc<= 0.1 or ΔTc > 1:
  129. print('ΔTc seems off, error suspected')
  130.  
  131. #%%plotting
  132. plt.title('Resistance vs Temperature for Channel %d' %channel)
  133. plt.xlabel('Temperature(K)')
  134. plt.ylabel('Resistance(Ω)')
  135. plt.axis([Tc10-.5, Tc90+.5, -1, approxResAtTc90+20])
  136. plt.plot(tempTuple,resTuple, 'k')
  137. plt.axvline(x= Tc10, color = 'r', label = 'Tc10')
  138. plt.axvline(x=Tc90, color = 'b', label = 'Tc90')
  139. plt.axhline(y= .5*(resTuple[tempTuple.index(Tc10)]+resTuple[tempTuple.index(Tc90)]), color = 'g', linestyle = '-.', label = '50% Res')
  140. plt.axhline(y=resTuple[tempTuple.index(Tc10)], color = 'r', linestyle = '-.', label = 'Res at Tc10')
  141. plt.axhline(y=resTuple[tempTuple.index(Tc90)], color = 'b', linestyle = '-.', label = 'Res at Tc90')
  142. plt.legend()
  143. return;
Add Comment
Please, Sign In to add comment