'''
The code in this cell opens up the file skydiver_time_velocities.csv 
and extracts two 1D numpy arrays of equal length.  One array is
of the velocity data taken by the radar gun, and the second is
the times that the data is taken.
'''

import numpy as np

skydiver_time, skydiver_velocity = np.loadtxt("skydiver_time_velocities.csv",
                                              delimiter=',',skiprows=1,unpack=True)


'''
This is a piece of example code that shows you how to get the 
velocity at any time you want using the Numpy interp() method.  
This requires you to pick a time where you want the velocity
as an input parameter to the method, as well as the time and 
velocity arrays that you will interpolate from.
'''

time = 7.2  # time in seconds
vel = np.interp(time,skydiver_time,skydiver_velocity)
print("velocity at time {:.3f} s is {:.3f} m/s".format(time,vel))

# put your code here!




"""
Explanation: What's the terminal velocity of a skydiver?
Names of group members
// put your names here!
Goals of this assignment
The main goal of this assignment is to use numerical integration and differentiation to study the behavior of a skydiver.  You're going to use the numerical integration and differentiation techniques that you learned in the pre-class assignment.
Some background knowledge that we need for this model
Position, velocity, and acceleration
In physics, three important properties of a moving object are its position ($\vec{x}$), velocity ($\vec{v}$), and acceleration ($\vec{a}$).  These are vector quantities, meaning that they have both a magnitude and a direction, and are related in the following way:
$\vec{v} = \frac{d\vec{x}}{dt}$ 
$\vec{a} = \frac{d\vec{v}}{dt}$ - i.e., acceleration is the rate of change of velocity (units of meters per second$^2$)
In words, velocity is the rate of change of position with time (and having units of length per time) and acceleration is the rate of change of velocity with time (and having units of length per time$^2$).  Given this, the fundamental theorem of calculus tells us that we can relate these quantities by integration as well.  Expressed mathematically:
$\vec{x} = \vec{x}_0 + \int_0^t \vec{v}(t) dt$
$\vec{v} = \vec{v}_0 + \int_0^t \vec{a}(t) dt$
So, we can get the position at any time by starting at the initial position and integrating the velocity over time, and can get the velocity at any time by starting with the initial velocity and integrating the acceleration over time.
Terminal velocity
An object moving through a fluid like air or water experiences a force of friction - just think about what happens if you stick your hand out of the window of a moving car!  This is why airplanes need to run their engines constantly while in flight; when traveling at a constant speed, the force exerted by the engines just balances the force exerted by the air friction.  This force of friction always points in the opposite direction of the object's motion (in other words, in the opposite direction of its velocity).
A similar thing happens to a falling object.  As an object falls downward faster and faster, the force of gravity pulling downward is eventually perfectly balanced by the upward force from air resistance (upward because the direction of motion is down).  When these forces perfectly balance, the object experiences zero acceleration, and thus its velocity becomes constant.  We call this the terminal velocity.
The challenge
Your professor happens to mention that he went skydiving last weekend.  He jumped from a stationary helicopter that was hovering 2,000 meters above the ground, and opened the parachute at the last possible moment.  In the interests of science, he had a friend stand on the ground with a radar gun and measure his velocity as a function of time.  This file, skydiver_time_velocities.csv, has been provided to you to examine.  You are asked to do the following:

Calculate and plot the position, velocity, and acceleration as a function of time.
If you start the clock when your professor steps out of the helicopter (i.e., $t=0$), at what time does he land on the ground?
At what time, and at what height above ground, does he reach terminal velocity?

In the cells below, we have provided two pieces of code: one that reads the data you want from the file into two Numpy arrays, and a second piece of code that can provide you with the velocity at any time.
End of explanation
"""


# put your code here!




"""
Explanation: The second part of the challenge
In addition to your professor, a mouse and an elephant have also chosen to go skydiving.  (Choice may have had less to do with it than a tired physics professor trying to make a point; work with me here.)  Their speeds were recorded as well, in the files mouse_time_velocities.csv and elephant_time_velocities.csv.  Read the data in for these two unfortunate creatures and store them in their own arrays. (Don't worry, they had parachutes too, they're just not very happy about the whole situation!)  Then, do the same calculations as before and plot the position, velocity, and acceleration as a function of time for all three individuals on the same set of graphs.  Do the mouse and/or elephant reach terminal velocity?  If so, at what time, and at what height above the ground?  
put your answer here!
End of explanation
"""


from IPython.display import HTML
HTML(
"""
<iframe 
	src="https://goo.gl/forms/XvxmPrGnDOD3UZcI2?embedded=true" 
	width="80%" 
	height="1200px" 
	frameborder="0" 
	marginheight="0" 
	marginwidth="0">
	Loading...
</iframe>
"""
)

"""
Explanation: Assignment wrapup
Please fill out the form that appears when you run the code below.  You must completely fill this out in order to receive credit for the assignment!
End of explanation
"""


