# Drag Auto — Drag Force Analysis

Loads particle centroid tracking data, lets you interactively define movement regions, and computes drag force vs. displacement with a linear fit per particle and direction.

---

## Workflow Overview

1. **Load CSVs** — Reads all `*.csv` files from a folder (output from `Drag Force Particle Tracking Automatic.ipynb`). Automatically detects the number of particles from the column count (3 columns per particle: `cx`, `cy`, `r`).

2. **Set regions (slider cell)** — For each speed, an interactive plot shows the x-position traces for all particles over time. Use the three sliders to define:
   - **Stationary** — frames where the stage is not moving (baseline)
   - **Movement 1** — first direction of stage movement
   - **Movement 2** — second direction of stage movement (return)

   Click **Confirm All & Continue** when all speeds are set.

3. **Analyze** — Computes the mean displacement of each particle relative to its stationary baseline, and the expected Stokes drag force at each speed. Fits a linear spring constant `k` (pN/µm) per particle per direction through the origin.

---

## Key Parameters (Analysis Cell)

| Parameter | Description |
|---|---|
| `folder` | Path to folder containing `{speed} mms.csv` files |
| `PIXELS_PER_MICRON` | Pixel-to-micron conversion factor |
| `ETA` | Fluid viscosity (Pa·s); default: `0.001` (water) |
| `R` | Particle radius (m); default: `1e-6` (1 µm) |
| `TRIM` | Frames trimmed from each edge of a region to remove transients |

---

## Output Plot

- **Color = particle** (each particle gets a unique color)
- **Filled circles** = Direction 1 (Movement 1), **open circles** = Direction 2 (Movement 2)
- **Solid fit line** = Direction 1, **dotted fit line** = Direction 2
- Separate origin-constrained fit per particle per direction with 95% confidence interval shading
- Printed spring constant `k ± σ` (pN/µm) for each particle and direction

---

## Input File Format

CSV files must match the output of `Drag Force Particle Tracking Automatic.ipynb`:

- No header row
- Filename: `{speed} mms.csv` (e.g. `0.25 mms.csv`)
- Columns: `cx0, cy0, r0, cx1, cy1, r1, cx2, cy2, r2` (3 per particle, up to 3 particles)

---

## Dependencies

`numpy`, `pandas`, `scipy`, `matplotlib`, `ipywidgets`, `ipympl`

Install missing packages with `pip install <package>`.

---

## Tracking Data Source

Generate input CSVs using `Drag Force Particle Tracking Automatic.ipynb`.
