Skip to content
tishad.net
SearchCtrl K

Lessons / Part 7. Python, notebooks and the tools around them

37 Getting instrument files into a shape Python can load

An inventory of runs against measurements comes first, then a written tidy format, a converter that leaves raw files alone, a loader and a validator.

What people usually ask

Combine all my instrument exports into one dataset so I can start
modelling.

What comes back

A script that reads every file it finds, turns columns into numbers without saying so, and writes the result over the raw files.

Ask this instead

Stop before any combining. The exports come from three instruments;
one sample of each is attached. Step 1, an inventory: one line per
file with instrument, run id as it appears in the file name, row
count, column names and the units line if there is one; then a grid
of runs against measurements so I can see which runs lack which
measurement. Step 2, write out the tidy format we convert to: one
row per run per timestamp, column names and units fixed. Step 3, a
converter that never writes into raw/, only into processed/.
Step 4, a loader. Step 5, a validator that prints what is wrong:
missing runs, unit mismatch, duplicate timestamps. Today do step 1
only, on the three samples, and stop.

Attach: Three sample files, one from each instrument, and the raw/ and processed/ folder layout stated.

Why it works: The inventory shows what the files hold before any code decides what they mean, and raw files that are never written to can always be read again.

Drafted with Fable 5.1 from my notes; chosen and edited by me.