SHARE
TWEET

Untitled

a guest Mar 19th, 2019 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import matplotlib
  2. matplotlib.use('TkAgg')
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  6. from matplotlib.figure import Figure
  7. from tkinter import *
  8. from tkinter import filedialog as FD
  9. from scipy import stats
  10.  
  11.  
  12. filename = FD.askopenfilename()
  13. print(filename)
  14. #opening *into an object* file to read
  15. file = open(filename, "r")
  16.  
  17. #file.readline = reading the file line by line (.read is everything)
  18. title = file.readline()
  19. #assign title to substring
  20. title = title[7:]
  21.  
  22. file.readline()
  23. #read date
  24. date = file.readline()
  25. date = date[16:]
  26.  
  27. file.readline()
  28. file.readline()
  29. file.readline()
  30.  
  31. print(title)
  32. print(date)
  33.  
  34. #make blank list, (read)
  35. blanks = []
  36.  
  37. keep_going = True
  38. current_line = file.readline()
  39.  
  40. while keep_going == True:
  41.     if current_line == "\n":
  42.         keep_going = False
  43.     else:
  44.         blanks.append(float(current_line))
  45.         current_line = file.readline()
  46.  
  47. print(blanks)
  48.  
  49.  
  50. #reads the blanks
  51. file.readline()
  52. file.readline()
  53.  
  54. keep_going = True
  55. current_line = file.readline()
  56.  
  57.  
  58. ##print(blanks)
  59. print("blank deviation=", np.std(blanks))
  60. print("LOD = ", np.std(blanks)*3)
  61. while keep_going == True:
  62.     if current_line[x] == "Concentration    Readings\n" or i >= j:
  63.         break
  64.     i+=1
  65. i+=1
  66. xArray = []
  67. yArray = []
  68. while len(current_line)>i:
  69.     pts = current_line[i].split("\t")
  70.     #print(pts)
  71.     m=0
  72.     while m<3:
  73.         xArray.append(pts[0])
  74.         yArray.append(pts[m+2].strip("\n"))
  75.         m+=1
  76.     i+=1
  77. print("xArray: ",xArray)
  78. print("yArray: ",yArray)
  79. x = np.array(xArray, dtype=np.float64)
  80. y = np.array(yArray, dtype=np.float64)
  81. def best_fit_slope_and_intercept(xArray, yArray):
  82.     m = (((mean(xArray) * mean(yArray)) - mean(yArray * xArray)) /
  83.          ((mean(xArray) * mean(xArray)) - mean(xArray * xArray)))
  84.  
  85.     b = mean(yArray) - m * mean(xArray)
  86.  
  87.     return m, b
  88. print("best_fit result: ", best_fit_slope_and_intercept(x, y))
  89. m,b=best_fit_slope_and_intercept(x, y)
  90.  
  91. Fit_line = [(m*xpt)+b for xpt in x]
  92. plt.scatter(x,y,color='#003F72')
  93. plt.plot(x, Fit_line)
  94. print (blanks)
  95. print("LOD = ",np.std(blanks))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top