-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class_Flags_OLCI.py
114 lines (93 loc) · 3 KB
/
Class_Flags_OLCI.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /usr/bin/env python
'''
$Id$
Introduction:
'''
import numpy as np
import numpy.ma as ma
class Class_Flags_OLCI(object):
def Code(self, maskList):
myCode = np.uint64(0)
for flag in maskList:
myCode |= self.maskValues[self.maskNames.index(flag)]
return myCode
def Mask(self, flags, maskList):
myCode = self.Code(maskList)
flags = np.uint64(flags)
# print(myCode,flags)
# print myCode
return np.bitwise_and(flags, myCode)
def Decode(self, val):
count = 0
res = []
mask = np.zeros(len(self.maskValues))
for value in self.maskValues:
if value & val:
res.append(self.maskNames[count])
mask[count] = 1
count += 1
return res, mask
def __init__(self, flagMasks, flagMeanings):
self.maskValues = flagMasks
self.maskNames = flagMeanings.split(' ')
# print(type(self.maskValues))
# print(type(self.maskNames))
class Class_Flags_Idepix(object):
def __init__(self, flagMasks, flagMeanings):
self.maskValues = flagMasks
flagMeanings = flagMeanings.replace(' ', ' ')
self.maskNames = flagMeanings.split(' ')
def Code(self, maskList):
myCode = np.int16(0)
for flag in maskList:
myCode |= self.maskValues[self.maskNames.index(flag)]
return myCode
def Mask(self, flags, maskList):
myCode = self.Code(maskList)
flags = np.int16(flags)
# print flags
# print myCode
return np.bitwise_and(flags, myCode)
def Decode(self, val):
count = 0
res = []
mask = np.zeros(len(self.maskValues))
for value in self.maskValues:
if value & val:
res.append(self.maskNames[count])
mask[count] = 1
count += 1
return (res, mask)
class Class_Flags_Polymer(object):
def __init__(self, flagMasks, flagMeanings):
self.maskValues = flagMasks
flagMeanings = flagMeanings.replace(' ', ' ')
self.maskNames = flagMeanings.split(' ')
def MaskGeneral(self, flags):
flags = np.int64(flags)
code = np.empty(flags.shape, dtype=np.int64)
code[:] = 1023
# print flags
# print myCode
return np.bitwise_and(flags, code)
def Code(self, maskList):
myCode = np.int64(0)
for flag in maskList:
myCode |= self.maskValues[self.maskNames.index(flag)]
return myCode
def Mask(self, flags, maskList):
myCode = self.Code(maskList)
flags = np.int64(flags)
# print flags
# print myCode
return np.bitwise_and(flags, myCode)
def Decode(self, val):
count = 0
res = []
mask = np.zeros(len(self.maskValues))
for value in self.maskValues:
if value & val:
res.append(self.maskNames[count])
mask[count] = 1
count += 1
return (res, mask)