Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Mon Jul 9 10:30:15 2018
- @author: cad6
- """
- def tc9010percent():
- #%% extracts the channel, temperature and resistance from .csv file (must be given the path)
- csvFile = input('File Path? ')
- import numpy as np
- import matplotlib.pyplot as plt
- raw = np.loadtxt(open(csvFile,"rb"), delimiter=",", skiprows=1)
- channel = raw[:, 1][0]
- temperatureRaw = raw[:, 2]
- resistanceRaw = raw[:, 3]
- #%% 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
- resTuple = tuple(resistanceRaw)
- tempTuple = tuple(temperatureRaw)
- #%%Tc50
- resList = list(resistanceRaw)
- tempList = list(temperatureRaw)
- resList.sort()
- tempList.sort()
- temperatureRange = tempList[-1] - tempList[0]
- rangeVariable = int(len(resistanceRaw)*(.5/temperatureRange))
- maxRes = []
- minRes = []
- for i in range(-rangeVariable , 0) :
- maxRes.append(resList[i])
- for j in range(0, rangeVariable):
- minRes.append(resList[j])
- upperRes = int(np.mean(maxRes))
- lowerRes = int(np.mean(minRes))
- aveRes = .5*(upperRes + lowerRes)
- upperBound = .25*aveRes + aveRes
- lowerBound = -.25*aveRes + aveRes
- newArray = []
- resVals = []
- tempVals = []
- for x in range(0, len(resList)):
- newArray.append(upperBound>resList[x]>lowerBound)
- for r in range(0, len(newArray)):
- if newArray[r] == True:
- resVals.append(resList[r])
- tupleIndex = []
- for h in range(0, len(resVals)) :
- tupleIndex.append(resTuple.index(resVals[h]))
- for g in range(0, len(tupleIndex)):
- tempVals.append(tempTuple[tupleIndex[g]])
- if len(tempVals) %2 == 0:
- tempVals.append(tempVals[-1])
- Tc50 = np.median(tempVals)
- #%%make list without top 10 and bottom 10 percent of values
- largestMinRes = minRes[-1]
- smallestMaxRes = maxRes[0]
- newArray1 = []
- applicableValues1 = []
- for x in range(0, len(resList)):
- newArray1.append(smallestMaxRes>resList[x]>largestMinRes)
- for r in range(0, len(newArray1)):
- if newArray1[r] == True:
- applicableValues1.append(resList[r])
- tupleIndex1 = []
- for h in range(0, len(applicableValues1)):
- tupleIndex1.append(resTuple.index(applicableValues1[h]))
- tempVals = []
- for g in range(0, len(tupleIndex1)):
- tempVals.append(tempTuple[tupleIndex1[g]])
- #extact temperature vals close to 10%
- approxResAtTc10 = np.median(maxRes)*.1
- number = .75
- resTc10 = [x for x in resList if approxResAtTc10 -number*approxResAtTc10 <= x <= approxResAtTc10 + number*approxResAtTc10]
- if resTc10 == []:
- number = 2*number
- resTc10 = [x for x in resList if approxResAtTc10 -number*approxResAtTc10 <= x <= approxResAtTc10 + number*approxResAtTc10]
- tempTc10 = []
- for j in range(0, len(resTc10)):
- tempTc10.append(tempTuple[resTuple.index(resTc10[j])])
- if len(tempTc10) %2 == 0:
- tempTc10.append(tempTc10[-1])
- resRangeTc10 = []
- for h in range(0, len(tempTc10)):
- resRangeTc10.append(resTuple[tempTuple.index(tempTc10[h])])
- Tc10 = max(tempTc10)
- #extract temperature vals close to 90%
- approxResAtTc90 = np.median(maxRes)*.9
- resTc90 = [x for x in resList if approxResAtTc90 -.75<= x <= approxResAtTc90 +.75 ]
- tempTc90 = []
- for i in range(0, len(resTc90)):
- tempTc90.append(tempTuple[resTuple.index(resTc90[i])])
- if len(tempTc90) %2 == 0:
- tempTc90.append(tempTc90[-1])
- resRangeTc90 = []
- for h in range(0, len(tempTc90)):
- resRangeTc90.append(resTuple[tempTuple.index(tempTc90[h])])
- Tc90 = np.median(tempTc90)
- #calculate ΔTc
- ΔTc = Tc90-Tc10
- print('Critical Temperature (10 Percent Measurement) of Channel %d is %f' %(channel, Tc10))
- print('Critical Temperature (90 Percent Measurement) of Channel %d is %f' %(channel, Tc90))
- print('ΔTc of Channel %d is %f' %(channel, ΔTc))
- #%% extreme error check
- if ΔTc<= 0.1 or ΔTc > 1:
- print('ΔTc seems off, error suspected')
- #%%plotting
- plt.title('Resistance vs Temperature for Channel %d' %channel)
- plt.xlabel('Temperature(K)')
- plt.ylabel('Resistance(Ω)')
- plt.axis([Tc10-.5, Tc90+.5, -1, approxResAtTc90+20])
- plt.plot(tempTuple,resTuple, 'k')
- plt.axvline(x= Tc10, color = 'r', label = 'Tc10')
- plt.axvline(x=Tc90, color = 'b', label = 'Tc90')
- plt.axhline(y= .5*(resTuple[tempTuple.index(Tc10)]+resTuple[tempTuple.index(Tc90)]), color = 'g', linestyle = '-.', label = '50% Res')
- plt.axhline(y=resTuple[tempTuple.index(Tc10)], color = 'r', linestyle = '-.', label = 'Res at Tc10')
- plt.axhline(y=resTuple[tempTuple.index(Tc90)], color = 'b', linestyle = '-.', label = 'Res at Tc90')
- plt.legend()
- return;
Add Comment
Please, Sign In to add comment