def pack(pqdict): """Pack a pixel quality dictionary into a 16-bit pixel quality value. Arguments: pqdict: pixel quality dictionary Returns: Packed pixel quality value (usually a 16-bit integer.) """ return sum((v << bits.lowest_set(PQ_BITMASKS[k])) for k,v in pqdict.iteritems())
def unpack(pqvalue): """Unpack a 16-bit (integer) pixel quality value. Arguments: pqvalue: pixel quality value (usually a 16-bit integer) Returns: Dictionary containing unpacked values for each pixel quality metric. """ return {k : ((pqvalue & v) >> bits.lowest_set(v)) for k,v in PQ_BITMASKS.iteritems()}
def pack(pqdict): """Pack a pixel quality dictionary into a 16-bit pixel quality value. Arguments: pqdict: pixel quality dictionary Returns: Packed pixel quality value (usually a 16-bit integer.) """ return sum( (v << bits.lowest_set(PQ_BITMASKS[k])) for k, v in pqdict.iteritems())
def unpack(pqvalue): """Unpack a 16-bit (integer) pixel quality value. Arguments: pqvalue: pixel quality value (usually a 16-bit integer) Returns: Dictionary containing unpacked values for each pixel quality metric. """ return { k: ((pqvalue & v) >> bits.lowest_set(v)) for k, v in PQ_BITMASKS.iteritems() }
def test_bitmasks(self): m = sum([v for v in PQ_BITMASKS.itervalues()]) self.assertEqual(bits.lowest_set(m), 0) self.assertEqual(bits.length(m), 16) self.assertEqual(m, 0b1111111111111111) print ' Bitmasks total (all ones): ', bin(m), m
def test_bitmasks(self): m = sum([v for v in PQ_BITMASKS.itervalues()]) self.assertEqual(bits.lowest_set(m), 0) self.assertEqual(bits.length(m), 16) self.assertEqual(m, 0b1111111111111111)