Advertisement
Guest User

Acceleration Project

a guest
Dec 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.59 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.    
  67.     vel_x=DoubleVar()
  68.     vel_y=DoubleVar()
  69.     vel_z=DoubleVar()
  70.     Entry(window,width=10,textvariable=vel_x).grid(row=1,column=1)
  71.     Entry(window,width=10,textvariable=vel_y).grid(row=2,column=1)
  72.     Entry(window,width=10,textvariable=vel_z).grid(row=3,column=1)
  73.     Label(window,text='',height=2,bg='#080104').grid(row=4,column=0)
  74.  
  75.     Label(window,text='Enter the inicial displacement on the x-axis in m',bg='#080104').grid(row=5,column=0)
  76.     Label(window,text='Enter the inicial displacement on the y-axis in m',bg='#080104').grid(row=6,column=0)
  77.     Label(window,text='Enter the inicial displacement on the z-axis in m',bg='#080104').grid(row=7,column=0)
  78.    
  79.     dis_x=DoubleVar()
  80.     dis_y=DoubleVar()
  81.     dis_z=DoubleVar()
  82.     Entry(window,width=10,textvariable=dis_x).grid(row=5,column=1)
  83.     Entry(window,width=10,textvariable=dis_y).grid(row=6,column=1)
  84.     Entry(window,width=10,textvariable=dis_z).grid(row=7,column=1)
  85.     Button(window,text='Next',command=window.quit).grid(row=8,column=2)
  86.    
  87.     velocity_x.append(vel_x)
  88.     velocity_x.append(vel_y)
  89.     velocity_x.append(vel_z)
  90.  
  91.     displacement_x.append(dis_x)
  92.     displacement_y.append(dis_y)
  93.     displacement_z.append(dis_z)
  94.  
  95.  
  96.  
  97. def Plot():
  98.     integral(time,acceleration_x,velocity_x)
  99.     integral(time,acceleration_y,velocity_y)
  100.     integral(time,acceleration_z,velocity_z)
  101.  
  102.     integral(time,velocity_x,displacement_x)
  103.     integral(time,velocity_y,displacement_y)
  104.     integral(time,velocity_z,displacement_z)
  105.  
  106.     force_x=[]
  107.     force_y=[]
  108.     force_z=[]
  109.     net_force=[]
  110.     fcalc(acceleration_x,mass,force_x)
  111.     fcalc(acceleration_y,mass,force_y)
  112.     fcalc(acceleration_z,mass,force_z)
  113.  
  114.     for i in range(0,len(force_x),1):
  115.         net_force.append(force_x[i]+force_y[i]+force_z[i])
  116.     #------------------Work-------------------
  117.     work_x=[]
  118.     work_y=[]
  119.     work_z=[]
  120.     calc(force_x,displacement_x,work_x)
  121.     calc(force_y,displacement_y,work_y)
  122.     calc(force_z,displacement_z,work_z)
  123.  
  124.     #-------------------Power-----------------
  125.     power_x=[]
  126.     power_y=[]
  127.     power_z=[]
  128.     calc(force_x,velocity_x,power_x)
  129.     calc(force_y,velocity_y,power_y)
  130.     calc(force_z,velocity_z,power_z)
  131.     #------------------Graphs----------------
  132.  
  133.     fig,ax=plt.subplots(nrows=6,sharex=True)
  134.     plt.subplots_adjust(hspace=0,wspace=0,top=0.95,right=0.98,bottom=0.06,left=0.06)
  135.     fig.suptitle('Acceleration Project',fontsize=16)
  136.  
  137.     ax[0].plot(time,acceleration_x,label='X-axis')
  138.     ax[0].plot(time,acceleration_y,label='Y-axis')
  139.     ax[0].plot(time,acceleration_z,label='Z-axis')
  140.     ax[0].legend(loc=2,prop={'size':10})
  141.     ax[0].set_ylabel('Acceleration')
  142.  
  143.     ax[1].plot(time,velocity_x,label='X-axis')
  144.     ax[1].plot(time,velocity_y,label='Y-axis')
  145.     ax[1].plot(time,velocity_z,label='Z-axis')
  146.     ax[1].legend(loc=2,prop={'size':10})
  147.     ax[1].set_ylabel('Velocity')
  148.  
  149.     ax[2].plot(time,displacement_x,label='X-axis')
  150.     ax[2].plot(time,displacement_y,label='Y-axis')
  151.     ax[2].plot(time,displacement_z,label='Z-axis')
  152.     ax[2].legend(loc=2,prop={'size':10})
  153.     ax[2].set_ylabel('Displacement')
  154.  
  155.     ax[3].plot(time,force_x,label='X-axis')
  156.     ax[3].plot(time,force_y,label='Y-axis')
  157.     ax[3].plot(time,force_z,label='Z-axis')
  158.     ax[3].plot(time,net_force,label='Net Force')
  159.     ax[3].legend(loc=2,prop={'size':10})
  160.     ax[3].set_ylabel('Force')
  161.  
  162.     ax[4].plot(time,work_x,label='X-axis')
  163.     ax[4].plot(time,work_y,label='Y-axis')
  164.     ax[4].plot(time,work_z,label='Z-axis')
  165.     ax[4].set_ylabel('Work')
  166.     ax[4].legend(loc=2,prop={'size':10})
  167.  
  168.     ax[5].plot(time,power_x,label='X-axis')
  169.     ax[5].plot(time,power_y,label='Y-axis')
  170.     ax[5].plot(time,power_z,label='Z-axis')
  171.     ax[5].set_ylabel('Power')
  172.     ax[5].legend(loc=2,prop={'size':10})
  173.  
  174.     plt.xlabel('Time')
  175.     plt.show()
  176.  
  177.  
  178. message="""
  179. UNIVERSIDAD DE PUERTO RICO
  180. Recinto de Mayagüez
  181.  
  182.  
  183. Welcome to the Acceleration Project
  184. [Stand Alone Version]
  185.  
  186. This version can be executed with just python 3.7 or above installed without the need of an IDE
  187.  
  188.     The Acceleration project will help you find the Velocity, Displacement, Force, Work, and Power on the x, y, and z axis.
  189. """
  190.  
  191.  
  192. logo=PhotoImage(file='D:/UPRM/Misc/UPRlogosmall.png')
  193. Label(image=logo,bg='#080104').grid(row=0,column=0)
  194.  
  195. introduction=Message(window,text=message,anchor="w",bg="#080104").grid(row=0,column=1)
  196.  
  197. openFile=Button(window,text='Open File',command=file).grid(row=0,column=2,sticky='w')
  198. Label(window,text='Enter the mass of the phone ',bg="#080104").grid(row=1,column=0,sticky='e')
  199.  
  200. mass_text=DoubleVar()
  201. Mass=Entry(window,width=10,textvariable=mass_text).grid(row=1,column=1,sticky='w')
  202. Run=Button(window,text='Run Program',command=run).grid(row=1,column=1)
  203. window.mainloop()
  204.  
  205. Plot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement