I have a type of data that is output as ~28 million integers ranging from 0 to 4095 (It technically comes of the hardware out as a signed 16-bit integers ranging from 0 to (1/2) * 2^16, but this representation is needlessly precise). In principle therefore each datapoint's value can be represented by 12 bits - a byte and a nybble, if you will. I'm dealing with, in the long term, moderately large volumes of this data (Terabytes in the double digits) which I intend to store as binaries, so obviously losslessly compressing it to 75% of its size would be welcome.
Obviously I could just write a function that encodes my data into booleans and back and use Numpy's binary handling functions to parse. However I have to balance this against ease/speed of storage and retrieval. Therefore I wonder if there's any existing package, algorithm, etc which accomplishes this in a simple and efficient way. I can work with Fortran or C if I need to, so it's an option to make a module in those, but my colleagues would prefer if I didn't.