Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import filedialog, Text
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- window=Tk()
- window.geometry("600x300")
- window.title("Acceleration Project")
- window.resizable(False,False)
- window.configure(background="#080104")
- def integral(x,y,z):
- for k in range(1,len(y),1):
- z.append((y[k]+y[k-1])*(x[k]-x[k-1])*0.5+z[k-1])
- def calc(x,value,y):
- for i in range(0,len(x),1):
- y.append(x[i]*value[i])
- y=np.array(y)
- def fcalc(x,value,y):
- for i in range(0,len(x),1):
- y.append(x[i]*value)
- y=np.array(y)
- File=[0]
- velocity_x=[]
- velocity_y=[]
- velocity_z=[]
- displacement_x=[]
- displacement_y=[]
- displacement_z=[]
- def file():
- Name=filedialog.askopenfilename(initialdir="/",title='Select File',filetypes=(("CSV","*.csv"),("all files","*.*")))
- File[0]=Name
- for app in File:
- label=Label(window,text=Name,fg='green',bg='#080104',font=('menlo',10)).grid(row=0,column=2,sticky='n')
- def Next():
- for widget in window.winfo_children():
- widget.destroy()
- def run():
- mass=mass_text.get()
- name=File[0]
- time=pd.read_csv(name,usecols=[0],skiprows=0)
- acceleration_x=pd.read_csv(name,usecols=[1],skiprows=0)
- acceleration_y=pd.read_csv(name,usecols=[2],skiprows=0)
- acceleration_z=pd.read_csv(name,usecols=[3],skiprows=0)
- time=np.array(time)
- acceleration_x=np.array(acceleration_x)
- acceleration_y=np.array(acceleration_y)
- acceleration_z=np.array(acceleration_z)
- Next()
- Label(window,text='Enter the inicial velocity on the x-axis in m/s',bg='#080104').grid(row=1,column=0)
- Label(window,text='Enter the inicial velocity on the y-axis in m/s',bg='#080104').grid(row=2,column=0)
- Label(window,text='Enter the inicial velocity on the z-axis in m/s',bg='#080104').grid(row=3,column=0)
- vel_x=DoubleVar()
- vel_y=DoubleVar()
- vel_z=DoubleVar()
- Entry(window,width=10,textvariable=vel_x).grid(row=1,column=1)
- Entry(window,width=10,textvariable=vel_y).grid(row=2,column=1)
- Entry(window,width=10,textvariable=vel_z).grid(row=3,column=1)
- Label(window,text='',height=2,bg='#080104').grid(row=4,column=0)
- Label(window,text='Enter the inicial displacement on the x-axis in m',bg='#080104').grid(row=5,column=0)
- Label(window,text='Enter the inicial displacement on the y-axis in m',bg='#080104').grid(row=6,column=0)
- Label(window,text='Enter the inicial displacement on the z-axis in m',bg='#080104').grid(row=7,column=0)
- dis_x=DoubleVar()
- dis_y=DoubleVar()
- dis_z=DoubleVar()
- Entry(window,width=10,textvariable=dis_x).grid(row=5,column=1)
- Entry(window,width=10,textvariable=dis_y).grid(row=6,column=1)
- Entry(window,width=10,textvariable=dis_z).grid(row=7,column=1)
- Button(window,text='Next',command=window.quit).grid(row=8,column=2)
- velocity_x.append(vel_x.get())
- velocity_x.append(vel_y.get())
- velocity_x.append(vel_z.get())
- displacement_x.append(dis_x.get())
- displacement_y.append(dis_y.get())
- displacement_z.append(dis_z.get())
- integral(time,acceleration_x,velocity_x)
- integral(time,acceleration_y,velocity_y)
- integral(time,acceleration_z,velocity_z)
- integral(time,velocity_x,displacement_x)
- integral(time,velocity_y,displacement_y)
- integral(time,velocity_z,displacement_z)
- force_x=[]
- force_y=[]
- force_z=[]
- net_force=[]
- fcalc(acceleration_x,mass,force_x)
- fcalc(acceleration_y,mass,force_y)
- fcalc(acceleration_z,mass,force_z)
- for i in range(0,len(force_x),1):
- net_force.append(force_x[i]+force_y[i]+force_z[i])
- #------------------Work-------------------
- work_x=[]
- work_y=[]
- work_z=[]
- calc(force_x,displacement_x,work_x)
- calc(force_y,displacement_y,work_y)
- calc(force_z,displacement_z,work_z)
- #-------------------Power-----------------
- power_x=[]
- power_y=[]
- power_z=[]
- calc(force_x,velocity_x,power_x)
- calc(force_y,velocity_y,power_y)
- calc(force_z,velocity_z,power_z)
- #------------------Graphs----------------
- fig,ax=plt.subplots(nrows=6,sharex=True)
- plt.subplots_adjust(hspace=0,wspace=0,top=0.95,right=0.98,bottom=0.06,left=0.06)
- fig.suptitle('Acceleration Project',fontsize=16)
- ax[0].plot(time,acceleration_x,label='X-axis')
- ax[0].plot(time,acceleration_y,label='Y-axis')
- ax[0].plot(time,acceleration_z,label='Z-axis')
- ax[0].legend(loc=2,prop={'size':10})
- ax[0].set_ylabel('Acceleration')
- ax[1].plot(time,velocity_x,label='X-axis')
- ax[1].plot(time,velocity_y,label='Y-axis')
- ax[1].plot(time,velocity_z,label='Z-axis')
- ax[1].legend(loc=2,prop={'size':10})
- ax[1].set_ylabel('Velocity')
- ax[2].plot(time,displacement_x,label='X-axis')
- ax[2].plot(time,displacement_y,label='Y-axis')
- ax[2].plot(time,displacement_z,label='Z-axis')
- ax[2].legend(loc=2,prop={'size':10})
- ax[2].set_ylabel('Displacement')
- ax[3].plot(time,force_x,label='X-axis')
- ax[3].plot(time,force_y,label='Y-axis')
- ax[3].plot(time,force_z,label='Z-axis')
- ax[3].plot(time,net_force,label='Net Force')
- ax[3].legend(loc=2,prop={'size':10})
- ax[3].set_ylabel('Force')
- ax[4].plot(time,work_x,label='X-axis')
- ax[4].plot(time,work_y,label='Y-axis')
- ax[4].plot(time,work_z,label='Z-axis')
- ax[4].set_ylabel('Work')
- ax[4].legend(loc=2,prop={'size':10})
- ax[5].plot(time,power_x,label='X-axis')
- ax[5].plot(time,power_y,label='Y-axis')
- ax[5].plot(time,power_z,label='Z-axis')
- ax[5].set_ylabel('Power')
- ax[5].legend(loc=2,prop={'size':10})
- plt.xlabel('Time')
- plt.show()
- message="""
- UNIVERSIDAD DE PUERTO RICO
- Recinto de Mayagüez
- Welcome to the Acceleration Project
- [Stand Alone Version]
- This version can be executed with just python 3.7 or above installed without the need of an IDE
- The Acceleration project will help you find the Velocity, Displacement, Force, Work, and Power on the x, y, and z axis.
- """
- logo=PhotoImage(file='D:/UPRM/Misc/UPRlogosmall.png')
- Label(image=logo,bg='#080104').grid(row=0,column=0)
- introduction=Message(window,text=message,anchor="w",bg="#080104").grid(row=0,column=1)
- openFile=Button(window,text='Open File',command=file).grid(row=0,column=2,sticky='w')
- Label(window,text='Enter the mass of the phone ',bg="#080104").grid(row=1,column=0,sticky='e')
- mass_text=DoubleVar()
- Mass=Entry(window,width=10,textvariable=mass_text).grid(row=1,column=1,sticky='w')
- Run=Button(window,text='Run Program',command=run).grid(row=1,column=1)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement