Inspecting a robot cell's cycle records often starts with a count and duration total by station. Station identifiers may come from several numbering schemes, so a file with a handful of observed stations can contain an ID much larger than the number of groups. Passing those IDs directly to NumPy's bincount creates an array indexed by the raw identifiers. A gap in the number scheme becomes a stretch of zero bins.
One way to keep the report compact is to collect the station labels seen in the input and use consecutive indices for those labels during aggregation. Keep the labels beside the results. This allows a reviewer to match each total to the original station and to distinguish a station that did not appear in the file from one that reported a zero-valued observation.
Run an example with three station IDs
The fixture uses five synthetic recorded durations in milliseconds. The station IDs appear in a mixed order and two of them repeat. A direct bincount is included only for this bounded example, where the size is known in advance. Its length is one more than the largest ID, yielding 9,002 bins for the three observed groups.
import numpy as np
station = np.array([9001, 12, 9001, 250, 12])
duration_ms = np.array([40, 26, 55, 33, 28])
raw_counts = np.bincount(station)
assert raw_counts.size == 9002
labels, step, counts = np.unique(
station, return_inverse=True, return_counts=True
)
assert np.array_equal(labels[step], station)
assert labels.tolist() == [12, 250, 9001]
assert counts.tolist() == [2, 1, 2]
duration_totals = np.bincount(step, weights=duration_ms,
minlength=labels.size)
assert duration_totals.tolist() == [54.0, 33.0, 95.0]
assert duration_totals.sum() == duration_ms.sum()
per_row_total = duration_totals[step]
assert per_row_total.tolist() == [95.0, 54.0, 95.0, 33.0, 54.0]
NumPy's unique call returns the sorted station labels, the indices that reconstruct the input from those labels and the occurrence counts. The index called step has one value per original record. The first record belongs to station 9001, which is the third entry in the sorted labels, so its index is two. Grouping durations by the compact indices produces three totals in that same order. The total for station 12 is 54 ms, the total for station 250 is 33 ms and the total for station 9001 is 95 ms.
If the goal is only to count observations, the counts from unique are enough. Weighted bincount is used here for the additional duration metric. It sums the supplied weights for each index and produces floating-point totals. The small integer durations in the fixture have exact totals. If a report requires exact arithmetic over very large integer counters or carries very different magnitudes, choose an accumulator with suitable numeric guarantees and test its range.
Preserve the label mapping across file boundaries
The consecutive indices belong to this input. Station 9001 could receive a different index in another file if lower-numbered stations appear or disappear. Store labels with each aggregate. When combining partial reports, match on the original station labels or use an explicit registry that assigns stable indices across files. Adding arrays by position works only when their label maps agree.
Validate station identity before grouping. If identifiers contain meaningful leading zeros or combine a cell namespace with a station number, preserve that representation in the source records. A missing identifier can have its own review status. Converting it to a numeric station ID just to make it fit in a count array can merge it with legitimate data. Also decide whether the report is to show observed stations only or list every station from a separate equipment roster. An observation-only report leaves unobserved labels out, while a roster-based report can mark their coverage explicitly.
Check reconstructed rows as well as totals
The fixture confirms that the compact indices reconstruct the original IDs, that the counts align with the sorted labels, and that group totals can be looked up in original record order. The last check matters when an operator opens a cycle record and wants to see the station aggregate in context. Test a file with a large gap in the ID range, a group with multiple records, and a file where one group is missing. If a merged report changes despite unchanged input rows, inspect the label mapping before comparing the numbers.
Sources
NumPy API reference, bincount
https://numpy.org/doc/stable/reference/generated/numpy.bincount.html
NumPy API reference, unique
https://numpy.org/doc/stable/reference/generated/numpy.unique.html