Skip to content
weecologyPublic

About

Annotation workflow for reviewing time-series drone imagery and labeling possible bird nest locations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

97 Commits

Folders and files

Repository files navigation

NestTrack

English | Português

NestTrack is a CIS4914 Senior Design project advised by Dr. Ethan White.

It's a tool for reviewing time-series drone imagery of Everglades bird colonies. An annotator opens one spot, steps through every flight date of the season, sees the model's predicted boxes, and marks what's really a bird or a nest. The goal is cleaner labeled data for the lab's future analysis and modeling.

Team

  • Jolina Jasperson
  • Noel Mendez
  • Alvaro Flores
  • Yi Su

How it fits together

Browser  ──>  React app (localhost:5173)  ──>  Flask API (localhost:5000)  ──>  Dropbox ("Nest Track" folder)
  • React app (react/): the annotator UI. Built with React Router, Vite, and Tailwind.
  • Flask API (api/): lists sequences, serves sequence data, hands out image links, saves annotations.
  • Dropbox: holds the sequences and images in a shared folder owned by the NestTrack Dropbox account. The API reaches it after someone clicks Connect Dropbox in the app.

You run two servers on your machine, the API and the React app, each in its own terminal.


Getting started

Follow these in order the first time. Every command runs from the repo root (the NestTrack folder that holds api/ and react/) unless a step says otherwise.

Commands are shown for Windows PowerShell and macOS / Linux. Where they're the same, there's just one.

Step 1. Install the tools

You need three things. Check whether you already have them first.

Tool Version Check with
Git any recent git --version
Python 3.12 (see .python-version) python --version
Node.js 22.22 or newer node --version

If something is missing or too old:

React Router needs Node 22.22.0 or newer. An older Node 22 (like 22.14) prints a warning and the app may not load. Run nvm install 22 again to get the latest 22.x.

Close and reopen your terminal after installing anything, so it picks up the new PATH.

Step 2. Get the code

git clone https://github.com/JolinaJ/NestTrack.git
cd NestTrack

If you already cloned it, update instead:

git checkout main
git pull

Step 3. Set up the Python environment (API)

A virtual environment ("venv") keeps this project's Python packages separate from everything else on your machine. We keep it at api/venv/, which is gitignored.

3a. Create the venv. You only do this once.

Windows PowerShell:

python -m venv api/venv

macOS / Linux:

python3 -m venv api/venv

3b. Activate it. Do this every time you open a new terminal for the API.

Windows PowerShell:

api\venv\Scripts\Activate.ps1

macOS / Linux:

source api/venv/bin/activate

Your prompt now starts with (venv). That's how you know it's active.

Windows: "running scripts is disabled on this system"? Run this once, then try activating again:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

3c. Install the packages.

pip install -r api/requirements-dev.txt
pip install -r api/requirements-import.txt

The first line installs Flask, the Dropbox SDK, and pytest. The second installs the libraries the lab-data import uses (rasterio, Pillow). It takes a minute or two the first time.

3d. Check it worked.

python -c "import flask, dropbox, rasterio; print('ok')"

It should print ok.

Step 4. Create your api/.env file

The API reads its settings and secrets from api/.env. That file is gitignored and never committed, so everyone makes their own from the template.

4a. Copy the template.

Windows PowerShell:

Copy-Item api/.env.example api/.env

macOS / Linux:

cp api/.env.example api/.env

4b. Fill in the values. Open api/.env in your editor. It looks like this:

DROPBOX_APP_KEY=your_app_key_here
DROPBOX_APP_SECRET=your_app_secret_here
DROPBOX_SCOPED_FOLDER=Nest Track
DROPBOX_REDIRECT_URI=http://localhost:5000/auth/dropbox/callback
FRONTEND_ORIGIN=http://localhost:5173
FLASK_SECRET_KEY=change_me
Key What to put Where it comes from
DROPBOX_APP_KEY The Dropbox app's key From the Dropbox App Console. Ask whoever owns the Dropbox app
DROPBOX_APP_SECRET The Dropbox app's secret Same as above
FLASK_SECRET_KEY A long random string Generate your own, see 4c
DROPBOX_SCOPED_FOLDER Leave as Nest Track
DROPBOX_REDIRECT_URI Leave as is for local development
FRONTEND_ORIGIN Leave as is for local development

4c. Generate your FLASK_SECRET_KEY. With the venv active:

python -c "import secrets; print(secrets.token_hex(32))"

Copy the printed string over change_me. Every teammate uses their own. It signs the cookie that protects the Dropbox login, so it just has to be random and private.

Never paste api/.env anywhere public. If a secret leaks, whoever owns the Dropbox app can rotate it in the App Console.

Step 5. Start the API

In a terminal with the venv active (Step 3b), from the repo root:

flask --app api/app.py run --port 5000 --debug

You should see:

 * Running on http://127.0.0.1:5000
 * Debugger is active!

--debug restarts the server whenever you save a Python file. Leave this terminal open, since closing it stops the API.

Check it from your browser: open http://localhost:5000/api/dropbox/status. You should see:

{"account": null, "connected": false}

connected: false is expected. You'll connect Dropbox in Step 7.

Step 6. Start the React app

Open a second terminal and go into the react folder:

cd react
npm install
npm run dev
  • npm install downloads the frontend packages into react/node_modules/. Run it the first time, and again whenever react/package.json changes.
  • npm run dev starts the dev server. You should see:
  ➜  Local:   http://localhost:5173/

Leave this terminal open too.

Step 7. Open the app and connect Dropbox

  1. Go to http://localhost:5173/annotate.
  2. The sidebar shows a blue Connect Dropbox button. Click it.
  3. A popup opens on Dropbox's sign-in page. Sign in with the NestTrack Dropbox account (ask whoever owns it for the login). Don't use your personal Dropbox.
  4. Click Allow.
  5. The popup closes by itself. The sidebar now shows NestTrack Project and the list of sequences under Sequences/sites.

You only do this once per machine. The connection survives restarts.

Then type your name in the Your name box under the Dropbox card and click Set name. It goes on every save you make, and your own saves are the ones that open, so use the same name every time. The browser remembers it.

Step 8. Use it

  • Click a sequence in the sidebar, like 6thBridge_2023_10. The image for its first flight date opens, with the Timeline of every date along the bottom.
  • Keep your place: the address bar tracks the sequence and date, like /annotate?sequence=6thBridge_2023_10&date=2023-02-17. A refresh or a pasted link lands on the same photo, and the browser's Back button goes to the sequence you had open before.
  • Save: your changes stay in the browser while you work, so a refresh or a crash doesn't lose them. They only get to Dropbox when you click Save. A sequence with unsaved changes has an orange dot in the sidebar, and Discard goes back to your last save.
  • Change dates: click a date in the timeline, use the ‹ / › buttons at its ends, or press ← / →. Home and End jump to the first and last date.
  • Select several dates: Shift-click selects a range, Ctrl-click adds or removes one date. The × chip at the top of the timeline clears the selection.
  • Zoom and pan: scroll or use the + / − buttons (or ↑ / ↓) to zoom, and drag to pan. The crosshair button under them recenters the image.
  • Hide panels: the Sequences and Timeline toggles at the top show or hide the sidebar and the timeline.
  • On the timeline, red counts are the model's predicted boxes on that date and pink counts are saved annotations.

That's it. You're running NestTrack.


Everyday use

Once everything's set up, starting work is two terminals:

Terminal 1, the API (from the repo root):

Windows PowerShell:

api\venv\Scripts\Activate.ps1
flask --app api/app.py run --port 5000 --debug

macOS / Linux:

source api/venv/bin/activate
flask --app api/app.py run --port 5000 --debug

Terminal 2, the React app:

cd react
npm run dev

Then open http://localhost:5173/annotate.

Stop either server with Ctrl+C in its terminal.

After you pull new changes

Other people's changes can add packages. After git pull, re-run both installs. They're quick when nothing changed.

pip install -r api/requirements-dev.txt -r api/requirements-import.txt   # venv active, from the repo root
cd react && npm install

Also compare api/.env.example with your api/.env. If the example gained a new key, add it to yours.

Running it on a server

On a server it runs as one process: Flask serves the built page and the API together, so there's no second server and no Node needed to run it.

The built page is committed in react/build/client, so a fresh clone already has it. You only rebuild when the front end changes (needs Node, see Step 1):

cd react
npm install
npm run build

Set up api/.env like Step 4, plus the server-only keys at the bottom of api/.env.example: NESTTRACK_PASSWORD for the shared login, and FRONTEND_ORIGIN and DROPBOX_REDIRECT_URI pointing at the server's own address. Then, from api/:

pip install -r requirements.txt
python serve.py

It listens on port 8000 (change it with PORT). Everyone signs in once with the shared password. Behind https through nginx or Apache, also set SECURE_COOKIES=1 and TRUST_PROXY=1 so logins and the Dropbox redirect use the real address.

Running the tests

The API tests are in tests/. They fake Dropbox, so they don't need a connection or a .env. With the venv active, from the repo root:

python -m pytest

You should see every test pass, like 60 passed.

To check the frontend's TypeScript:

cd react
npm run typecheck

Troubleshooting

What you see Why Fix
Node v22.x detected. react-router requires a Node version greater than 22.22.0 Node is too old nvm install 22, then nvm use 22, then reopen the terminal
Cannot GET / at localhost:5173 The dev server didn't finish starting, often right after switching Node versions Ctrl+C the React terminal and run npm run dev again
ModuleNotFoundError: No module named 'flask' (or dropbox, rasterio, pytest...) The venv isn't active, or packages are missing Activate the venv (Step 3b), then pip install -r api/requirements-dev.txt
KeyError: 'DROPBOX_APP_KEY' or KeyError: 'FLASK_SECRET_KEY' when starting the API api/.env is missing or that key is empty Do Step 4. Make sure the file is api/.env, not api/.env.txt
py / python is not recognized (Windows) Python isn't on PATH Reinstall Python with "Add python.exe to PATH" ticked, or use the full path, e.g. $env:LOCALAPPDATA\Programs\Python\Python312\python.exe
running scripts is disabled on this system when activating PowerShell's execution policy Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Sidebar says Connect Dropbox to load sequences This machine hasn't connected yet, or the connection was revoked Click Connect Dropbox (Step 7)
Clicking Connect Dropbox does nothing The browser blocked the popup Allow popups for localhost:5173 and click again
The popup says Dropbox authorization failed Usually a stale or reused login link Close the popup and click Connect Dropbox again
Dropbox shows an "invalid redirect_uri" error DROPBOX_REDIRECT_URI doesn't match what's registered in the Dropbox App Console Use http://localhost:5000/auth/dropbox/callback exactly. The app owner registers new URLs in the App Console under Settings, OAuth 2, Redirect URIs
Sidebar is empty and the browser console shows a CORS error The React app isn't on FRONTEND_ORIGIN Open the app at exactly http://localhost:5173, not 127.0.0.1:5173
Address already in use / port 5000 or 5173 busy An old server is still running Ctrl+C it in its terminal. On macOS, AirPlay Receiver uses port 5000: turn it off in System Settings, General, AirDrop & Handoff
Can't delete or recreate api/venv on Windows ("access denied") The API is still running and holding files open Stop it with Ctrl+C first
curl in PowerShell behaves strangely PowerShell's curl is an alias for Invoke-WebRequest Use curl.exe instead
A sequence opens with only the model's boxes, but you saved it before Your name is spelled differently than when you saved, or the save is from before saves had names Check the name under Annotating as. The card lists the names that have saves on that sequence. See "Names" under "Saved annotations"
Your unsaved changes didn't come back They're kept in one browser, under one name, at one address Use the same browser and computer, the same name, and the same address (localhost:5173, not 127.0.0.1:5173). A private window forgets them when it closes, and clearing the browser's site data deletes them

Sequence ids

A sequence is one spot watched across a season's flights. Its id is {site}_{year}_{sample_id}, like Joule_2026_7.

We didn't make this up. The lab already numbers these spots. Their old Shiny app (weecology/EvergladesTools, branch exp-nest-detect-imagery) has a sample CSV at App/Zooniverse/experiments/nest_detector_imagery_sample_locations.csv. For each site and year it mixes detected nests with birds that were only seen once, shuffles them, and numbers them sample_id 1 to N. Once a site-year is written it never gets renumbered, so the ids are stable.

  • site is the lab's spelling, letters and digits only: Joule, JetportSouth, 6thBridge. No underscores, since that's what we split on.
  • year is four digits.
  • sample_id is the lab's number for that spot within the site-year.
  • Henry's sample crops don't have a sample id yet, so the crop set's number stands in: the birds10 crops of 6thBridge become 6thBridge_2023_10. The file's source.crop_set says where it came from.

The id has to match ^[A-Za-z0-9]+_\d{4}_\d+$ (defined in api/naming.py). Each sequence is a folder of that name in the Dropbox Nest Track folder, and its data is <sequence_id>/sequence.json. The sequence_id inside the file has to match the folder name or the API gives a 404.

Each sequence file has a source block saying where it came from: the lab's sample row for a real spot, or the crop set and folder for Henry's crops. It leaves out known_nest and num_obs on purpose. Those say whether the spot is a nest or a control, which is the question we're asking the annotator, and the API sends the whole file to the browser. The answer key goes somewhere the API never serves.

Dropbox layout

Nest Track/                     # DROPBOX_SCOPED_FOLDER
├── 6thBridge_2023_10/          # one folder per sequence id
│   ├── sequence.json           # frames, flight dates, model boxes
│   ├── crops/                  # one JPEG per flight date
│   │   └── 6thBridge_02_17_2023__same_area.jpg
│   └── annotations/            # one file per save, made on the first save
│       └── 20261115T235124683000Z_brier-k.json   # when it was saved, and whose it is
├── 6thBridge_2023_30/
│   └── ...
└── _raw/                       # raw lab data; folders starting with _ are ignored by the API

The API never sends images through Flask. /crops/<sequence_id>/<file>.jpg redirects the browser to a temporary Dropbox download link (valid about 4 hours), and the browser downloads the image straight from Dropbox.

data/ in the repo holds older local copies of sequence files and an example save. The API reads sequences from Dropbox, not from data/.

Saved annotations

What the annotator saves is kept apart from what they start with. GET /api/sequences/<id> only ever sends the frames and the model's boxes. The annotator's work goes through three routes:

  • POST /api/sequences/<id>/annotations takes one save and writes it to Dropbox at <id>/annotations/<utc timestamp>_<name>.json. The name is the save's session.annotator, cleaned up (see "Names" below). Every post makes a new file, so two people doing the same spot never overwrite each other. A save that doesn't fit the shape below gets a 400 with an error saying what's wrong.
  • GET /api/sequences/<id>/annotations?annotator=<name> sends back that person's newest save, or a 204 with no body when they don't have one. Leave ?annotator= off and it sends the newest save from anyone.
  • GET /api/sequences/<id>/annotators lists the names that have saves on that sequence.

Saves go to Dropbox, next to the sequence's crops (see "Dropbox layout" above), so everyone sees the same saves no matter whose laptop runs the API. Nothing gets written locally. data/examples/6thBridge_2023_10.annotation.json is a complete example of a save.

In the app, Save sends the boxes on screen as a new save under your name and says whether it worked. Model boxes turns the model's boxes on and off (on by default). While they're off, the arrow keys, Enter, Delete, and Select can't reach them either. The save records pre_labels_shown as true if the boxes were on at any point since you opened the spot, so peeking and turning them back off before saving still counts. The switch stays how you left it until you close the tab, so a refresh in the middle of a blind check doesn't turn the boxes back on.

Opening a sequence loads your own newest save. Nobody else's save ever opens for you, so two people can do the same spot without seeing each other's work. If you don't have a save there, you start from the model's boxes, and the card under your name lists whose saves exist.

A save looks like this:

{
  "schema_version": "0.2.0",
  "sequence_id": "6thBridge_2023_10",
  "session": {
    "annotator": "brier-k",
    "opened_at": "2026-10-21T19:00:00Z",
    "submitted_at": "2026-10-21T19:04:30Z",
    "pre_labels_shown": true
  },
  "frames": [
    {
      "frame_index": 1,
      "annotations": [
        {
          "annotation_id": "ann-1-0",
          "track_id": "trk-1",
          "from_prediction": "pred-1-2",
          "action": "accepted",
          "label": "bird",
          "box_pct": {"x": 91.689, "y": 66.359, "width": 2.902, "height": 2.902},
          "note": "Great Egret"
        }
      ]
    }
  ]
}
  • sequence_id has to match the url.
  • session says who did it and when. opened_at and submitted_at are ISO 8601 in UTC, so we can compare against the lab's per-photo times. opened_at is when this piece of work was started. It survives a refresh, so the gap up to submitted_at can include breaks. pre_labels_shown is whether the model's boxes were on screen at any point in this work, not just at the moment of saving. Blind validation runs with them off the whole time. annotator is who made the save. The app always sends it. The API still takes a save without one, so a script doesn't need a name, and that save's file is just <utc timestamp>.json.
  • frames has one entry per flight date the annotator looked at, keyed by the sequence file's frame_index. In the app, a date counts as looked at once its photo loads on screen (a photo that fails to load doesn't count). Leave a date out if they never looked at it. An empty annotations list means they looked and there was nothing to mark. Looking at a date doesn't turn on the unsaved dot by itself, but it goes out with the next Save.
  • Each box is one annotation:
    • label is bird or nest. That's all the lab asked for on Sep 25.
    • species is optional: one of the lab's Label Studio species (SPECIES in react/app/config/settings.ts), or null. Eggs and anything else go in note.
    • action is accepted (a model box they said yes to), rejected (a model box they said no to), or added (a box they drew). Rejected boxes stay in the save so the lab can see what the model got wrong.
    • from_prediction is the prediction_id of the model box it came from, and has to exist on that frame. It's null when the action is added. A model box gets one verdict at most: a save that answers the same model box twice on a frame gets a 400.
    • box_pct is where the box ended up, in percents of the image like everywhere else. For an accepted box that may differ from the model's, if the annotator moved it.
    • track_id ties the same bird or nest together across dates. Boxes with the same track_id are the same thing. null means not linked.
    • note is free text and can be empty.

Check it, from the repo root with the API running and Dropbox connected (on Windows, use curl.exe):

curl -i -X POST -H "Content-Type: application/json" --data @data/examples/6thBridge_2023_10.annotation.json http://127.0.0.1:5000/api/sequences/6thBridge_2023_10/annotations
curl -i "http://127.0.0.1:5000/api/sequences/6thBridge_2023_10/annotations?annotator=example"

The first gives a 201 and the name of the new file, which ends in _example.json because that's the name in the example. The second gives that file back. To see it in the app, set your name to example and open 6thBridge_2023_10. The saved boxes show up on Feb 22 and Mar 1.

Names

There are no accounts, so a person is whatever name they typed. Names get cleaned to one spelling: lowercase letters, numbers, and hyphens. Brier K, brier k, and BRIER_K all become brier-k. Sara H becomes sara-h, which is not the same person as sarah. A name needs at least one letter or number and can be up to 40 characters. The cleaning is annotator_slug in api/naming.py, and the browser does the same thing in react/app/services/annotator.ts.

A person's saves are the files ending in _<name>.json. So for a script, someone's newest save on a sequence is the last of those files by name.

A typo makes a new person. If someone saved as briar-k and meant brier-k, those saves won't open under the right name. To fix it, rename the files in Dropbox so they end in _brier-k.json. The name inside the file stays what it was. The app goes by the file name.

Saves from before names were added end in just the timestamp. They stay in Dropbox, but the app doesn't open them for anyone. To claim one, add _<name> before .json the same way.

Unsaved changes

While you work, the app keeps your unsaved changes in the browser's local storage, under nesttrack.draft.<sequence_id>.<name>. It holds the same frames a save would, so opening the sequence again puts back exactly what Save would have saved. It's written after every change and removed once the boxes match your last save again, which is also what happens right after you Save.

These never leave the browser. The lab only gets the work when someone clicks Save. They're tied to one browser, one name, and one address, so they won't follow you to another computer. If you saved the same sequence somewhere else in the meantime, the app still opens your unsaved changes and tells you a newer save exists. Discard opens that save.

The browser's "Leave site?" box only shows when leaving would really cost something: the browser couldn't keep your changes (the text by Save turns red and says so), or a save is still sending or just failed.

Two tabs on the same sequence share one set of unsaved changes. If one tab changes or saves them, the other tab says its changes are no longer kept, so save from that one before closing it.

Discard doesn't erase the changes. It moves them to nesttrack.aside.<sequence_id>.<name>. To get them back, open the browser's dev tools, go to Application, then Local Storage, rename the key from nesttrack.aside. to nesttrack.draft., and reload. There's one spare per sequence and name, and each new one replaces the last.

Unsaved changes the app can't put back get set aside the same way, say because the sequence was re-imported with different dates. Renaming the key won't bring those back, since they still don't fit and the app sets them aside again. The JSON is still there to read by hand.

Adding lab data

You only need this to add new sequences. Everyday annotating doesn't.

The real images come from Henry's Dropbox folder Nest_track_CIS4301, one folder per site. Each site folder has birds10/geotiffs/ and birds30/geotiffs/ with one GeoTIFF per flight date, and next to each a birds10_predicts/ or birds30_predicts/ folder with one CSV of the model's boxes per date plus a summary.csv.

  1. Download a site and unzip it into lab_data/ at the repo root, so you have e.g. lab_data/6thbridge/birds10/geotiffs/.

  2. Make sure your API has connected to Dropbox at least once (Step 7). The import uses the same connection.

  3. With the venv active, from the repo root, run one crop set at a time:

    python scripts/import_crops.py lab_data/6thbridge birds10
    python scripts/import_crops.py lab_data/6thbridge birds30

Each run converts the GeoTIFFs to JPEGs, uploads them to <sequence_id>/crops/ in the Dropbox Nest Track folder, and uploads <sequence_id>/sequence.json. It checks the result against the lab's summary.csv first and refuses to upload a sequence the API or the app would trip over. Refresh the app and the new sequence appears in the sidebar.

lab_data/ is gitignored, so the lab's files never get committed.

Status

In use for the Weecology lab's Everglades bird surveys. You can step through a spot's flight dates, check and fix the model's boxes, add your own, and save and load your work from Dropbox, with each annotator's saves kept under their own name. It runs as one program the lab hosts on its own server.

About

Annotation workflow for reviewing time-series drone imagery and labeling possible bird nest locations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages