-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClass_Flags.py
More file actions
34 lines (28 loc) · 1.01 KB
/
Class_Flags.py
File metadata and controls
34 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
class Flags_General(object):
def __init__(self,flagMeanings,flagValues,dtype):
self.flagValues = flagValues
self.flagMeanings = flagMeanings
self.dtype = dtype if dtype is not None else 'int32'
def Code(self, flagList):
myCode = np.array(0).astype(self.dtype)
for flag in flagList:
myCode |= self.flagValues[self.flagMeanings.index(flag)]
return myCode
def Mask(self, flagValues, flagList):
myCode = self.Code(flagList)
flagValues = np.array(flagValues).astype(self.dtype)
#flags = np.uint64(flags)
# print(myCode,flags)
#print(myCode)
return np.bitwise_and(flagValues, myCode)
def Decode(self, val):
count = 0
res = []
mask = np.zeros(len(self.flagValues))
for value in self.flagValues:
if value & val:
res.append(self.flagMeanings[count])
mask[count] = 1
count += 1
return res, mask