Advertisement
Guest User

Acceleration Project 2

a guest
Dec 9th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.60 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import filedialog, Text
  3. import numpy as np
  4. import pandas as pd
  5. import matplotlib.pyplot as plt
  6.  
  7. window=Tk()
  8. window.geometry("600x300")
  9. window.title("Acceleration Project")
  10. window.resizable(False,False)
  11. window.configure(background="#080104")
  12.  
  13. def integral(x,y,z):
  14.     for k in range(1,len(y),1):
  15.         z.append((y[k]+y[k-1])*(x[k]-x[k-1])*0.5+z[k-1])
  16.  
  17. def calc(x,value,y):
  18.     for i in range(0,len(x),1):
  19.         y.append(x[i]*value[i])
  20.     y=np.array(y)
  21.    
  22. def fcalc(x,value,y):
  23.     for i in range(0,len(x),1):
  24.         y.append(x[i]*value)
  25.     y=np.array(y)
  26.  
  27. File=[0]
  28.  
  29. velocity_x=[]
  30. velocity_y=[]
  31. velocity_z=[]
  32.  
  33. displacement_x=[]
  34. displacement_y=[]
  35. displacement_z=[]
  36.  
  37. def file():
  38.     Name=filedialog.askopenfilename(initialdir="/",title='Select File',filetypes=(("CSV","*.csv"),("all files","*.*")))
  39.     File[0]=Name
  40.     for app in File:
  41.         label=Label(window,text=Name,fg='green',bg='#080104',font=('menlo',10)).grid(row=0,column=2,sticky='n')
  42.  
  43.  
  44.    
  45.  
  46. def Next():
  47.         for widget in window.winfo_children():
  48.             widget.destroy()
  49.  
  50.  
  51. def run():
  52.     mass=mass_text.get()
  53.     name=File[0]
  54.     time=pd.read_csv(name,usecols=[0],skiprows=0)
  55.     acceleration_x=pd.read_csv(name,usecols=[1],skiprows=0)
  56.     acceleration_y=pd.read_csv(name,usecols=[2],skiprows=0)
  57.     acceleration_z=pd.read_csv(name,usecols=[3],skiprows=0)
  58.     time=np.array(time)
  59.     acceleration_x=np.array(acceleration_x)
  60.     acceleration_y=np.array(acceleration_y)
  61.     acceleration_z=np.array(acceleration_z)
  62.     Next()
  63.     Label(window,text='Enter the inicial velocity on the x-axis in m/s',bg='#080104').grid(row=1,column=0)
  64.     Label(window,text='Enter the inicial velocity on the y-axis in m/s',bg='#080104').grid(row=2,column=0)
  65.     Label(window,text='Enter the inicial velocity on the z-axis in m/s',bg='#080104').grid(row=3,column=0)
  66.     vel_x=DoubleVar()
  67.     vel_y=DoubleVar()
  68.     vel_z=DoubleVar()
  69.     Entry(window,width=10,textvariable=vel_x).grid(row=1,column=1)
  70.     Entry(window,width=10,textvariable=vel_y).grid(row=2,column=1)
  71.     Entry(window,width=10,textvariable=vel_z).grid(row=3,column=1)
  72.     Label(window,text='',height=2,bg='#080104').grid(row=4,column=0)
  73.  
  74.     Label(window,text='Enter the inicial displacement on the x-axis in m',bg='#080104').grid(row=5,column=0)
  75.     Label(window,text='Enter the inicial displacement on the y-axis in m',bg='#080104').grid(row=6,column=0)
  76.     Label(window,text='Enter the inicial displacement on the z-axis in m',bg='#080104').grid(row=7,column=0)
  77.    
  78.     dis_x=DoubleVar()
  79.     dis_y=DoubleVar()
  80.     dis_z=DoubleVar()
  81.     Entry(window,width=10,textvariable=dis_x).grid(row=5,column=1)
  82.     Entry(window,width=10,textvariable=dis_y).grid(row=6,column=1)
  83.     Entry(window,width=10,textvariable=dis_z).grid(row=7,column=1)
  84.     Button(window,text='Next',command=window.quit).grid(row=8,column=2)
  85.    
  86.     velocity_x.append(vel_x.get())
  87.     velocity_x.append(vel_y.get())
  88.     velocity_x.append(vel_z.get())
  89.  
  90.     displacement_x.append(dis_x.get())
  91.     displacement_y.append(dis_y.get())
  92.     displacement_z.append(dis_z.get())
  93.  
  94.     integral(time,acceleration_x,velocity_x)
  95.     integral(time,acceleration_y,velocity_y)
  96.     integral(time,acceleration_z,velocity_z)
  97.  
  98.     integral(time,velocity_x,displacement_x)
  99.     integral(time,velocity_y,displacement_y)
  100.     integral(time,velocity_z,displacement_z)
  101.  
  102.     force_x=[]
  103.     force_y=[]
  104.     force_z=[]
  105.     net_force=[]
  106.     fcalc(acceleration_x,mass,force_x)
  107.     fcalc(acceleration_y,mass,force_y)
  108.     fcalc(acceleration_z,mass,force_z)
  109.  
  110.     for i in range(0,len(force_x),1):
  111.         net_force.append(force_x[i]+force_y[i]+force_z[i])
  112.     #------------------Work-------------------
  113.     work_x=[]
  114.     work_y=[]
  115.     work_z=[]
  116.     calc(force_x,displacement_x,work_x)
  117.     calc(force_y,displacement_y,work_y)
  118.     calc(force_z,displacement_z,work_z)
  119.  
  120.     #-------------------Power-----------------
  121.     power_x=[]
  122.     power_y=[]
  123.     power_z=[]
  124.     calc(force_x,velocity_x,power_x)
  125.     calc(force_y,velocity_y,power_y)
  126.     calc(force_z,velocity_z,power_z)
  127.     #------------------Graphs----------------
  128.  
  129.     fig,ax=plt.subplots(nrows=6,sharex=True)
  130.     plt.subplots_adjust(hspace=0,wspace=0,top=0.95,right=0.98,bottom=0.06,left=0.06)
  131.     fig.suptitle('Acceleration Project',fontsize=16)
  132.  
  133.     ax[0].plot(time,acceleration_x,label='X-axis')
  134.     ax[0].plot(time,acceleration_y,label='Y-axis')
  135.     ax[0].plot(time,acceleration_z,label='Z-axis')
  136.     ax[0].legend(loc=2,prop={'size':10})
  137.     ax[0].set_ylabel('Acceleration')
  138.  
  139.     ax[1].plot(time,velocity_x,label='X-axis')
  140.     ax[1].plot(time,velocity_y,label='Y-axis')
  141.     ax[1].plot(time,velocity_z,label='Z-axis')
  142.     ax[1].legend(loc=2,prop={'size':10})
  143.     ax[1].set_ylabel('Velocity')
  144.  
  145.     ax[2].plot(time,displacement_x,label='X-axis')
  146.     ax[2].plot(time,displacement_y,label='Y-axis')
  147.     ax[2].plot(time,displacement_z,label='Z-axis')
  148.     ax[2].legend(loc=2,prop={'size':10})
  149.     ax[2].set_ylabel('Displacement')
  150.  
  151.     ax[3].plot(time,force_x,label='X-axis')
  152.     ax[3].plot(time,force_y,label='Y-axis')
  153.     ax[3].plot(time,force_z,label='Z-axis')
  154.     ax[3].plot(time,net_force,label='Net Force')
  155.     ax[3].legend(loc=2,prop={'size':10})
  156.     ax[3].set_ylabel('Force')
  157.  
  158.     ax[4].plot(time,work_x,label='X-axis')
  159.     ax[4].plot(time,work_y,label='Y-axis')
  160.     ax[4].plot(time,work_z,label='Z-axis')
  161.     ax[4].set_ylabel('Work')
  162.     ax[4].legend(loc=2,prop={'size':10})
  163.  
  164.     ax[5].plot(time,power_x,label='X-axis')
  165.     ax[5].plot(time,power_y,label='Y-axis')
  166.     ax[5].plot(time,power_z,label='Z-axis')
  167.     ax[5].set_ylabel('Power')
  168.     ax[5].legend(loc=2,prop={'size':10})
  169.  
  170.     plt.xlabel('Time')
  171.     plt.show()
  172.  
  173.  
  174. message="""
  175. UNIVERSIDAD DE PUERTO RICO
  176. Recinto de Mayagüez
  177.  
  178.  
  179. Welcome to the Acceleration Project
  180. [Stand Alone Version]
  181.  
  182. This version can be executed with just python 3.7 or above installed without the need of an IDE
  183.  
  184.     The Acceleration project will help you find the Velocity, Displacement, Force, Work, and Power on the x, y, and z axis.
  185. """
  186.  
  187.  
  188. logo=PhotoImage(file='D:/UPRM/Misc/UPRlogosmall.png')
  189. Label(image=logo,bg='#080104').grid(row=0,column=0)
  190.  
  191. introduction=Message(window,text=message,anchor="w",bg="#080104").grid(row=0,column=1)
  192.  
  193. openFile=Button(window,text='Open File',command=file).grid(row=0,column=2,sticky='w')
  194. Label(window,text='Enter the mass of the phone ',bg="#080104").grid(row=1,column=0,sticky='e')
  195.  
  196. mass_text=DoubleVar()
  197. Mass=Entry(window,width=10,textvariable=mass_text).grid(row=1,column=1,sticky='w')
  198. Run=Button(window,text='Run Program',command=run).grid(row=1,column=1)
  199.  
  200. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement