File formats¶
ppk2 writes the two formats of the
Power Profiler app:
- the CSV the app exports;
- the
.ppk2session file it saves and loads.
A name ending in .ppk2 gives a session file, any other name a CSV.
CSV¶
ppk2 capture writes the same file as the app's export at the full
sample rate, to the character:
- the same 11 columns;
- the same way of writing timestamps;
- the same digital columns.
The header and three rows of a capture of the validation, where D0 rises:
Timestamp(ms),Current(uA),D0-D7,D0,D1,D2,D3,D4,D5,D6,D7
1057.78,64.940,00000000,0,0,0,0,0,0,0,0
1057.79,78.143,00000000,0,0,0,0,0,0,0,0
1057.8,81.985,10000000,1,0,0,0,0,0,0,0
| Column | Content |
|---|---|
Timestamp(ms) |
Milliseconds from the first sample. Trailing zeros are removed: 0, 0.01, 0.1, 1057.8, 1000 |
Current(uA) |
Microamperes, three decimals, after the spike filter |
D0-D7 |
The eight digital inputs as eight characters, D0 first: 10000000 is D0 high and the others low |
D0 to D7 |
The same inputs, one column each, 0 or 1 |
The timestamp is computed from the number of the sample, not from a clock: rows are exactly 0.01 ms apart.
D0 is the leftmost character
In the D0-D7 field the first character is D0. In the library,
Sample.logic is a number in which D0 is bit 0. The two look alike
and read in opposite directions.
What else to know:
- A lost sample is a row with a current of
0.200and all digital inputs at 0. Nordic's app records a lost sample this way, andppk2does the same so that the files can be compared. See lost samples below. - A value below 0.2 µA is written as
0.000, as in the app. - When the app exports at a lower sample rate, its digital columns can
also hold
-andX. At the full rate both tools write only0and1.ppk2 convertdoes not accept-andX: it reports the row as malformed. - A row is about 40 bytes. One minute is 240 MB and one hour 14 GB.
This format was chosen because it is the app's. A capture made here can be compared directly with one exported from the app, as the validation does. Any tool that reads the app's export reads this file too.
Reading a CSV¶
The current only, with numpy:
import numpy as np
ua = np.loadtxt("capture.csv", delimiter=",", skiprows=1, usecols=1)
print(f"{len(ua)} samples, mean {ua.mean():.2f} µA")
Everything, with pandas:
import pandas as pd
df = pd.read_csv("capture.csv", dtype={"D0-D7": str})
print((df["D0"] == 1).sum(), "samples with D0 high")
Pass dtype={"D0-D7": str}. Without it, pandas reads 00000001 as
the number 1 and the leading zeros are gone. A gzipped file reads the same
way: both libraries open capture.csv.gz directly.
Session file (.ppk2)¶
A .ppk2 file is what the app writes with Save / Export and loads
again. ppk2 capture --out x.ppk2 and ppk2 convert write this
format, so a capture made from a script can be opened in the app's
chart.
It is a zip of three files:
| File | Content |
|---|---|
session.raw |
The samples, 6 bytes each |
minimap.raw |
JSON: the lowest and highest value of the trace over at most 10,000 intervals. The app draws its overview from it |
metadata.json |
The sample rate and the version of the format, 2 |
One sample in session.raw:
---
config:
packet:
bitsPerRow: 48
bitWidth: 14
---
packet-beta
0-31: "current, float32 little-endian"
32-47: "digital channels, uint16 big-endian"
| Field | Bytes | Content |
|---|---|---|
| Current | 0 to 3 | Microamperes, a 32-bit float, little-endian. A lost sample is 0.2 |
| Digital channels | 4 and 5 | Two bits per channel, big-endian: 01 low, 10 high. D0 is in the lowest pair |
ppk2 writes a current below 0.2 µA as zero, which is how the app
reads it. For a capture at the full rate, metadata.json is:
The sample rate is a power of ten from 1 to 100,000. ppk2 convert
reads it from the timestamps of the CSV.
Verification status¶
The layout comes from the README of the app's repository and from its
source at v4.4.1. Unit tests check what ppk2 writes against that
layout:
- the three files;
- the bytes of a sample;
- the overview;
- the handling of lost samples.
A session file written by ppk2 convert was opened in the app:
30 s and 3,000,320 samples, with digital inputs. It loaded without an
error.
Over the last 10 s, the app showed the same figures as those computed from the CSV of the same capture:
- an average of 699.32 µA;
- a maximum of 171.80 mA;
- a charge of 6.99 mC.
D0 and D1 toggled as in the CSV. See the results for the table.
This is one file on one version of the app. A later version of the app may change the format.
Size and write procedure¶
A capture of 5 s on the bench of this repository took 0.7 MB as a session file and 20.1 MB as a CSV. The session file is compressed, so a noisier signal takes more space.
While a capture runs, the samples go to a file next to the output,
named after it with .frames added, 6 bytes per sample. At the end,
the session file is built from it and put in place in one step.
If that step fails:
- the
.framesfile stays; - an earlier session file of the same name is left untouched;
- a later run to the same name refuses to start while that
.framesfile is there, so that it is not lost.
A capture without a single sample writes no file.
Lost samples¶
When the computer does not keep up, the PPK2's samples are lost in
transit. Nordic's app records each lost sample as a reading of 0.2 µA
with its digital inputs low, to keep the time axis right. ppk2
writes the same in both formats, so a file made here and one saved by
the app treat a loss alike.
That value is a stand-in, not a reading. Each lost sample pulls a sum or a mean towards 0.2 µA: losing 1 % of the samples of a 1 mA trace lowers its mean by about 1 %.
Nothing in the file tells such a row from a real reading of 0.2 µA. The capture itself tells you: it warns once 500 samples are lost, and gives the total at the end. The mean it prints leaves the lost samples out.
In the library, a lost sample stays distinct: it arrives as a Sample
whose current is NaN. See the
architecture page for
the callback that receives it.