# Q-1: Run your first cell and change one number

Data-Driven Athletics tutorial · Week 1 · Chapter 1 · about 10 min · workflow steps: Gather, Statistics

Web page: https://apopt.com/course/tutorials/q01-first-cell/ · Data: https://apopt.com/data/tutorials/q01-first-cell/

## The decision

An athlete films a jump and wants a height. Before trusting any app, you should be able to
repeat its arithmetic yourself and know which input the answer is most sensitive to.

## The raw data

- `raw/results_jump2_120fps.md`: the jump app's text result for the course's example clip, a slow-motion jump filmed at 120 frames per second and stored at 30 Written by the jump app at apopt.com (its own results-file code, run on the clip for Chapter 1 of the book, Section 1.3).

### A cell is a calculator you can rerun

A code cell holds a few lines of Python. Press **Run** and the page runs them and prints the
result underneath. Nothing is installed and nothing leaves your browser.

The first calculation of the course is the height of a jump from its **flight time**, the time
the feet are off the ground. The body rises for half the flight and falls for the other half,
so the rise is h = g t² / 8, where g is the acceleration of gravity (Section 1.3.2). Maya filmed
her jump at 60 frames per second and counted 32 frames in the air.

*Predict first:* 32 frames at 60 frames per second is a flight of 0.533 s. How high did Maya rise, in centimeters?

```python
g = 9.80665        # m/s², the standard gravity the jump app uses
frames = 32        # frames counted in the air
fps = 60           # frames per second the camera recorded
t = frames / fps   # flight time, s
h = g * t**2 / 8   # rise from takeoff to the top, m
print(f"flight {t:.3f} s -> height {100 * h:.1f} cm")
```

Output:

```
flight 0.533 s -> height 34.9 cm
```

### Change one number

Now edit the cell below: it is the same calculation with one more frame in the air. Change the
`33` to any count you like and press Run again. Watch how fast the height moves.

*Predict first:* One extra frame is about 3% more flight time. Will the height rise by about 3%, 6%, or 12%?

```python
frames = 33
t2 = frames / fps
h2 = g * t2**2 / 8
print(f"flight {t2:.3f} s -> height {100 * h2:.1f} cm")
print(f"flight {100 * (t2 / t - 1):+.1f}%, height {100 * (h2 / h - 1):+.1f}%")
```

Output:

```
flight 0.550 s -> height 37.1 cm
flight +3.1%, height +6.3%
```

The flight grew by 3.1% and the height by 6.3%, about twice as much, because the time is
squared. One frame at 60 frames per second is worth about 2 cm of height. That is the
**resolution** of a 60-frame-per-second count (Section 1.4).

### The same formula on a real app file

The jump app at apopt.com writes a text file of its results. Open the one it wrote for the
course's example clip, find the flight time, and repeat the app's arithmetic. The clip was filmed
in slow motion at 120 frames per second but stored as a 30-frame-per-second file, so the cell also
shows what happens if you divide by the wrong rate.

```python
text = open("raw/results_jump2_120fps.md").read()
for line in text.splitlines():
    if line.startswith("- Flight time:"):
        print(line)
        ms = float(line.split(":")[1].split("ms")[0])
t_app = ms / 1000
print(f"app's flight {t_app:.3f} s -> {100 * g * t_app**2 / 8:.1f} cm")
t_wrong = t_app * 120 / 30          # the same frames divided by the file's rate
print(f"read at 30 fps by mistake: {t_wrong:.3f} s -> {100 * g * t_wrong**2 / 8:.0f} cm")
```

Output:

```
- Flight time: 367 ms | 16.5 cm derived | 26.6 cm from the pixel-scaled height
app's flight 0.367 s -> 16.5 cm
read at 30 fps by mistake: 1.468 s -> 264 cm
```

The arithmetic matches the app: 0.367 s gives 16.5 cm. Divided by the file's 30 frames per
second instead of the camera's 120, the flight is four times too long and the "height" sixteen
times too large, 264 cm, higher than a basketball rim. Always divide by the rate the camera
recorded at.

### One chart

Draw the formula as a curve and mark the three flights you have met. Change `t_list` to add your
own.

```python
import numpy as np
import matplotlib.pyplot as plt

tt = np.linspace(0.2, 0.7, 101)
t_list = [t_app, t, t2]
names = ["example clip (app)", "Maya, 32 frames", "Maya, 33 frames"]
fig, ax = plt.subplots(figsize=(6.4, 3.6))
ax.plot(tt, 100 * g * tt**2 / 8, "k-", label="h = g t² / 8")
for ti, name, m in zip(t_list, names, ["o", "s", "^"]):
    ax.plot(ti, 100 * g * ti**2 / 8, m, ms=8, label=name)
ax.set(xlabel="flight time (s)", ylabel="jump height (cm)")
ax.legend()
plt.tight_layout()
print("a 0.6 s flight is", round(100 * g * 0.6**2 / 8, 1), "cm")
```

Output:

```
a 0.6 s flight is 44.1 cm
```

![A rising curve of jump height in centimeters against flight time in seconds from 0.2 to 0.7 s, with three marked points: the app's example clip at 0.367 s and 16.5 cm, and Maya's 32- and 33-frame counts near 35 and 37 cm.](https://apopt.com/course/tutorials/q01-first-cell/c07-1.png)

The curve bends upward: each extra hundredth of a second of flight is worth more height than
the one before. Notice that the formula only ever sees the time. Get the frame count or the frame
rate wrong and the height is wrong, however careful the arithmetic.

**For the athlete:** "Your flight time was 0.37 s, which works out to a 16.5 cm rise; next time
film at a known frame rate and we can compare jumps to within about a centimeter."

## With your own data

Film one jump of your own from the side at 60 frames per second, step through it frame by frame
(Q-2), count the frames in the air, and put your count and your camera's rate into the first cell.

## Action card

- **Finding:** The app's flight time of 0.367 s gives a 16.5 cm rise, and the arithmetic checks out.
- **Evidence:** h = g t² / 8 with g = 9.80665 m/s² reproduces the app's number; one more frame at 60 frames per second adds about 2 cm.
- **Sure:** High for the arithmetic; the height is only as good as the frame count and the frame rate behind it.
- **Action:** Film every test jump at a known frame rate and write that rate down with the result.
- **Retest:** Recompute any app height you are given before you compare two of them.

## References

- *Data-Driven Athletics*, Chapter 1, A First Measurement (Section 1.3) and What a Number Is Worth (Section 1.4).

---
Text CC BY 4.0, code MIT. IRSRI Sports Research Institute.
