Commit 50d960f7 authored by Feng Lu's avatar Feng Lu
Browse files

Executable with provided __main__

parents
def flag(original_flag, isQualified=None, \
isBadPixel=None, \
isHotPixel=None, \
isSaturationContaminated=None, \
isCosmicRayContaminated=None,\
isSpacecraftContaminated=None,\
isGhostContaminated=None,\
isScatterLightContaminated=None):
# 合格像元/坏像元 0 可以用于有效科学研究的像元
# 热像元 1 因为宇宙线或其它外部原因造成的不可用于有效科学研究的像元
# 流量饱和溢出像元 2 饱和像元及流量溢出污染的像元
# 宇宙线像元 3 宇宙线污染的像元
# 卫星拖尾像元 4 卫星或者人造移动天体轨迹污染的像元
# 鬼像像元 5 鬼像污染的像元
# 散射光像元 6 散射光污染的像元(包括dragon breath)
# if a pixel is qualified, then, all other flags will be ignored
bad_pixel_bit_pos = 0
hot_pixel_bit_pos = 1
sat_pixel_bit_pos = 2
csr_pixel_bit_pos = 3
spc_pixel_bit_pos = 4
gst_pixel_bit_pos = 5
sct_pixel_bit_pos = 6
new_flag = original_flag
# # COMMENTED: Is "isQualified" flag exclusive with all other flags?
#
if isQualified==True:
new_flag = 0
return new_flag
bad_pixel_flag = False
if isHotPixel!=None:
new_flag = setBitValue(new_flag, hot_pixel_bit_pos, isHotPixel)
bad_pixel_flag = True
if isSaturationContaminated!=None:
new_flag = setBitValue(new_flag, sat_pixel_bit_pos, isSaturationContaminated)
bad_pixel_flag = True
if isCosmicRayContaminated!=None:
new_flag = setBitValue(new_flag, csr_pixel_bit_pos, isCosmicRayContaminated)
bad_pixel_flag = True
if isSpacecraftContaminated!=None:
new_flag = setBitValue(new_flag, spc_pixel_bit_pos, isSpacecraftContaminated)
bad_pixel_flag = True
if isGhostContaminated!=None:
new_flag = setBitValue(new_flag, gst_pixel_bit_pos, isGhostContaminated)
bad_pixel_flag = True
if isScatterLightContaminated!=None:
new_flag = setBitValue(new_flag, sct_pixel_bit_pos, isScatterLightContaminated)
bad_pixel_flag = True
if isBadPixel==True or bad_pixel_flag==True:
# if the pixel is defined as bad, or is defined as other non-ideal cases, the pixel will be marked as bad as well
new_flag = setBitValue(new_flag, bad_pixel_bit_pos, True)
return new_flag
def setBitValue(dataIn, bitPosition, bitValue):
# set a bit at bitPosition to be bitValue in dataIn and return the new value
if bitPosition<0:
raise Exception('bit position should always be a non negative integer')
if (bitValue!=True)&(bitValue!=False):
raise Exception('bit value should always be either 0 or 1, or, True or False')
dataOut = dataIn
if bitValue == True:
dataOut = dataOut | (bitValue<<bitPosition)
else:
dataOut = dataIn>>(bitPosition+1)<<(bitPosition+1)
dataOut = dataOut + (dataIn&((1<<bitPosition)-1))
return dataOut
def getBitValue(dataIn, bitPosition):
# get the bit value at bitPosition in dataIn and return the bit value
if bitPosition<0:
raise Exception('bit position should always be a non negative integer')
return (dataIn >> bitPosition) & 1
if __name__ == "__main__":
original_flag = 0
print(f'{bin(original_flag)}')
print(f'{bin(flag(original_flag, isHotPixel=True, isCosmicRayContaminated=True, isSpacecraftContaminated=True, isScatterLightContaminated=True))}')
print('should be 0b10110101')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment