Nathan A. Baune·workshop

This page is also the handout. Press P for a full-screen view.

Why bother

Someone will need this data again, and it will probably be you.

  • Reproducibility: know what you (or they) did, when, and ideally why.
  • Whoever comes after you should be able to pick the work up without a week of archaeology.
  • You, years later, when you finally get around to publishing.
  • Catastrophes: a stolen laptop, a dead drive, a deleted folder, an overwritten script.

Comment your code and keep README files. Always.

I'm not projecting… you're projecting.

Part 1

Where your data lives

Storage decisions get made once, early, and lived with for years. This part covers where the copies go, where the computing happens, and how to organise files so someone else can read them.

Storage · 1

Keep three copies, on two kinds of storage, with one somewhere else.

  • 3 copies: the one you work on, plus two backups.
  • 2 kinds of storage: for example a laptop drive and a server, so one failure mode can't take both.
  • 1 off-site: a different building or a cloud service, so a fire, flood or theft can't take everything.
Working copy laptop Backup lab server Off-site cloud one building somewhere else 3 copies · 2 kinds of storage · 1 off-site
An illustration of the rule, not a recommendation of specific services.

Sync is not backup. A sync service copies your mistakes too: delete or corrupt a file on your laptop and it is deleted or corrupted everywhere seconds later, unless the service keeps a version history you can roll back.

Newer versions of the rule add an unchangeable (immutable) copy and a tested restore, against ransomware: "3-2-1-1-0". A backup you have never restored from is a hope, not a backup.

Storage · 2

Each place to keep data is good at something and bad at something else.

WhereGood forWatch out for
Your laptopActive work; fast; works offlineA single point of failure: theft, a dead drive, a spilled coffee
A lab or department serverShared lab data, one place everyone knowsAsk who backs it up, how often, and where the backup lives
Your institution's cloud drive (OneDrive, Google Drive, Box)Documents, sharing with collaborators, version historySync conflicts; whether it is approved for identifiable data
HPC cluster storageLarge datasets, right next to the computing"Scratch" space is usually not backed up and is cleared on a schedule
Cloud object storage (S3, Google Cloud Storage, Azure Blob)Very large or archived data; sharing at scaleMonthly cost to keep it, and charges to move it back out

Before identifiable participant data goes anywhere, check that your institution has approved that service for it, and that your IRB protocol says where the data will be kept.

Storage · 3

An HPC cluster is many computers behind one queue.

  • Login node: where you connect, edit and submit. Don't run heavy work here; everyone shares it.
  • Compute nodes: where jobs actually run, with many CPUs, lots of memory, sometimes GPUs.
  • Scheduler (often Slurm): you describe what a job needs and how long it takes, and it runs when the resources are free.
  • Storage tiers: home is small and backed up; project space is larger and shared by a group; scratch is fast and big, but not backed up, and old files are deleted.

A Slurm job: one task per participant

#!/bin/bash
#SBATCH --job-name=preproc
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
#SBATCH --time=04:00:00
#SBATCH --array=1-40   # one task per participant

# each task gets its own number
python preprocess.py --subject "$SLURM_ARRAY_TASK_ID"

Submit with sbatch job.sh; check on it with squeue -u $USER.

Every cluster names its storage differently and sets its own deletion policy. Read your cluster's documentation before trusting scratch with anything you can't regenerate.

Storage · 4

Cloud storage and compute: rent the computer, and pay for what moves.

Storage

  • Object storage keeps files as objects in "buckets", reached over the internet rather than mounted like a drive.
  • Cheap per gigabyte to keep; downloading data out again (egress) is usually charged separately.
  • Colder tiers cost less to store but more, and take longer, to read back.

Compute

  • Virtual machines and GPUs by the hour: big jobs without owning the hardware. Turn them off, or they keep billing.
  • Hosted notebooks (Google Colab, Posit Cloud) for smaller work, with nothing to install.
  • Good fit: bursty, occasional heavy jobs; collaborators at different institutions; no local cluster.

Two costs people forget: machines left running, and moving data out. Set a billing alert before your first job.

Storage · 5

Organise it so someone else can read it without you.

BIDS, the Brain Imaging Data Structure, is a shared standard for naming and arranging neuroimaging and physiology data: a folder per participant, file names that say what each file is, and metadata in plain JSON and TSV beside the data.

  • Tools can read any BIDS dataset without being told its layout.
  • Extensions cover EEG, MEG, iEEG and more.
  • The BIDS validator checks a dataset before you share it.
my_study/
  dataset_description.json
  participants.tsv
  sub-01/
    anat/
      sub-01_T1w.nii.gz
      sub-01_T1w.json
    eeg/
      sub-01_task-balance_eeg.edf
      sub-01_task-balance_eeg.json
      sub-01_task-balance_events.tsv

Even if your data isn't neuroimaging, the habits transfer: one folder per participant, names that say what a file is, and metadata in a machine-readable file next to it.

Storage · 6

Record what was done to the data, not just the result.

Provenance is the record of which raw files went in, which pipeline and version ran, with what settings, when, and what failed.

A worked example: BIDS-SQL keeps a BIDS dataset in a database (SQLite or PostgreSQL) with tables for processing runs and their stages, QC metrics, bad channels and rejected epochs. "Who still needs preprocessing?" becomes a query instead of a spreadsheet.

gitlab.com/neurotrophy-git/bids-sql

-- who has no EEG pipeline output yet?
SELECT s.subject_id
FROM subjects s
WHERE NOT EXISTS (
  SELECT 1
  FROM files f
  JOIN sessions se ON se.id = f.session_id
  WHERE se.subject_id = s.id
    AND f.is_derivative = 1
    AND f.pipeline_name = 'EEG.Flow'
);

Part 2

Version control

Version control records every change to your code, with who made it, when and why, and lets you go back. It replaces the folder of dated copies.

Version control · 1

No more final_draft_for_real_real_this_time_I_swear_version8_NB_AP_MB_TK__edits_SEP2023B.docx

  • Undo anything: every saved state is still there.
  • See what changed between the version that worked and the one that doesn't.
  • Work in parallel with other people without emailing files around.
  • A record for the methods section: exactly which code produced which figure.
  • No more asking "which computer did I run that analysis on?"

Version control · 2

Git keeps the history of a project, and copies of that history can live anywhere.

  • Repository: a project folder plus its full history.
  • Commit: a saved snapshot of the changes you chose, with a message. It is saved on your computer.
  • Push: send your commits to a shared copy (GitHub, GitLab, Bitbucket, or your institution's server).
  • Pull: bring in commits other people pushed.

Git stores a snapshot of the project at each commit and compresses what didn't change, so the history of text files stays small.

git init            # start tracking
git add analysis.R  # pick what to commit
git commit -m "Use median RT, not mean"
git push            # send commits
git pull            # get others' commits
git log --oneline   # see the history

You can commit many times during the day and push once, when you're sure things work. Each commit is still its own step you can return to.

Version control · 3

Branches let you try something without breaking what works.

  • Keep a main branch that stays working.
  • Start a branch for each new feature or experiment; several people can each have their own.
  • Merge it back when it works. Git combines the changes automatically.
  • A conflict happens only when the same lines changed on both branches. Git marks them, and you decide what to keep.
git switch -c try-ica  # new branch
# ...edit, commit...
git switch main
git merge try-ica      # bring it back
main try-ica merge
Commits are dots. The branch splits off, gets its own commits, and merges back.

Version control · 4

Small commits, with messages that say why.

Less usefulMore useful
updatesExclude trials with RT under 150 ms (anticipations)
fixed itFix off-by-one in epoch window; onsets were 1 sample late
new stuffAdd notch filter at 60 Hz before ICA
  • Commit often, one logical change at a time, so any one can be undone.
  • A .gitignore file lists what git should never track: data folders, outputs, local settings.
  • Tag the exact version behind a paper: git tag v1.0-paper.

Version control · 5

Keep data, secrets and anything identifiable out of git.

Don't commitWhyInstead
Participant data, even "de-identified"Repositories get shared, cloned and made public; history is permanentApproved storage from Part 1
Passwords, API keys, tokensAnyone with the repository has them, foreverEnvironment variables, or a config file listed in .gitignore
Large data and binaries (.mat, .nii, video)Every version is kept whole; the repository balloons; hosts limit file sizesTrack them with Git LFS, DataLad or DVC, or keep them in storage from Part 1
Word, Excel and PDF filesChanges can't be read line by line; each version is stored wholePlain text where you can: Markdown, CSV, scripts

Deleting a file in a later commit doesn't remove it from the history. If a password or key is ever committed, treat it as leaked and change it.

Git LFS replaces big files with small pointers and stores the content separately. DataLad (built on git and git-annex) and DVC version whole datasets and keep the data itself in storage of your choice.

Version control · 6

Use git from the tools you already work in.

  • Hosts: GitHub, GitLab and Bitbucket hold the shared copy, public or private, with issues and wikis alongside the code.
  • Desktop apps: GitHub Desktop and others put commit, push and pull behind buttons.
  • Built in: RStudio (the Git tab), VS Code (Source Control), MATLAB (source control panel), and JupyterLab with the jupyterlab-git extension.
  • AI coding assistants can write commit messages and keep logs for you. My workshop Spec it, log it, check it covers doing that without losing your own work.

Part 3

Sharing it

Sharing turns your files into something other people can find, cite and run, and more and more funders require it.

Sharing · 1

Share the code, the data, and the path between them.

  • Code: a repository with a README, a licence, and a tagged release.
  • Data: a data repository, with enough metadata to understand it.
  • The path: the scripts or notebooks that turn one into the figures.

The FAIR principles are a useful checklist: data should be Findable, Accessible, Interoperable and Reusable (Wilkinson et al., 2016).

Sharing · 2

A DOI makes your work citable, and keeps the link working.

  • Zenodo, run by CERN, is free and gives every upload a DOI.
  • Connect a GitHub repository and Zenodo archives each release with its own DOI, plus one "concept" DOI that always points to the newest version.
  • GitLab has no built-in connection: upload a release by hand, or with a CI job.
  • Example: MR.Flow, a neuroimaging pipeline, cited as doi:10.5281/zenodo.18186893.

Cite the version DOI in a paper (it always means those exact files) and the concept DOI when you mean the project in general.

Sharing · 3

Pick the repository that the people who'd reuse your data already search.

RepositoryBest forKnow before you upload
OpenNeuroNeuroimaging and electrophysiology in BIDSMust pass the BIDS validator; released under CC0; structural MRI must be defaced; can stay private for up to 36 months
OSFWhole projects: preregistrations, materials, data, codeFree; DOIs for public projects
FigshareFigures, datasets, any file typeGeneralist; DOIs
DryadThe data behind a published paperCurated; released under CC0
ZenodoCode releases and general dataDOIs and versions; GitHub releases archived automatically

Sharing · 4

Let people run it, not just read it.

Share results people can run

  • Binder (mybinder.org) turns a repository of notebooks into a live session in the browser, with nothing to install.
  • Shiny builds interactive web apps from R or Python, and can be embedded in a website.
  • Quarto documents mix code, results and prose, and publish as web pages or PDFs.

Work on code together, live

  • Google Colab: shared Python notebooks.
  • Posit Cloud (formerly RStudio Cloud): R and Python projects in the browser.
  • VS Code Live Share: edit the same code at the same time, each in your own editor.

Sharing · 5

If NIH funds it, sharing is required, and it's planned before the work starts.

  • The NIH Data Management and Sharing Policy took effect on January 25, 2023.
  • Researchers planning to generate scientific data must submit a Data Management and Sharing Plan with the application.
  • Data should be shared as soon as possible, and no later than the time of an associated publication, or the end of the performance period, whichever comes first.
  • NIH strongly encourages established repositories, like the ones on the last slides.
  • For applications due on or after May 25, 2026, the plan uses a simpler format, mostly yes-or-no questions. The policy itself has not changed.

Not everything must be shared, but every limit (consent, privacy, law) has to be explained in the plan. Write consent forms with sharing in mind.

Other funders, including NSF, have their own data management requirements. Check yours before you write the budget: repositories and curation can cost money, and those costs can be requested.

Sharing · 6

Three small files make work reusable: a licence, a README and a citation file.

  • LICENSE: without one, other people have no legal right to reuse your code, even if it is public. Common choices: MIT or Apache-2.0 for code, CC BY 4.0 or CC0 for data.
  • README: what it is, how to install and run it, how the data is laid out, and who to contact.
  • CITATION.cff: how to cite it. GitHub shows a "Cite this repository" button when the file is present.

A minimal CITATION.cff

cff-version: 1.2.0
message: "If you use this, please cite it as below."
title: "my-analysis"
authors:
  - family-names: Lastname
    given-names: Firstname
version: 1.0.0
doi: 10.5281/zenodo.0000000

Takeaways

Future you will thank you.

  • Storage: three copies, two kinds of storage, one off-site, and never only on your laptop. Know which places are approved for participant data.
  • Compute: use the cluster or the cloud for heavy jobs, and keep scratch for things you can regenerate.
  • Organise: a standard layout (BIDS if it fits), and a record of what was done to the data.
  • Version control: git, small commits, messages that say why, and no data or secrets in the repository.
  • Sharing: a repository people already search, a DOI, a licence, a README and a citation file. Plan it up front, because funders now ask.

Sources

Read more