Exemple #1
0
def getMask(data, stat, pixelLists, DEBUG=const.DEBUG):
#============================
    """
    purpose: generate mask matrix to mark pixels above threshold
    input : real(= raw - overscan -bias) image matrix
            note:   real data = data[i] = read_fits (file_in[i])
            stat: stat[i] = [mean[i], sstd[i]]
                mean = mean[i]
                sstd = sstd[i], where i is the ith image
    output: mask matrix where > threshold pixels are marked
            pixelLists: pixel[i], list of candidate pixels of the ith image
    """

    mask = np.zeros((const.N_y, const.N_x),dtype=int )    # array to save the bitmap of each pixel
    for it in range(const.N_b):
        mean = stat[it][0]
        sstd = stat[it][1]
        for iy in range(const.N_y):
            for ix in range(const.N_x):
                # 3 sigma check
                pvalue = data[it, iy, ix]
                if ( pvalue - mean ) > const.th_pixel * sstd:
                      mask[iy,ix] = bits.setBit(mask[iy, ix], it)  # if > 3sigma, set the it-th bit to 1
                      pixelLists[it].append([iy, ix, pvalue])
        if DEBUG:
            print('image ', it, ' has ', len(pixelLists[it]), ' candidate pixels')
    return mask
Exemple #2
0
    def set_data_block_bitmap(self, block_num_array):
        # initialise the bitmap int value to 0
        bitmap = 0
        for i in block_num_array:
            bitmap = bits.setBit(bitmap, i)

        return bitmap
Exemple #3
0
def fromConf2Bits(conf):
    nr,nc = conf.shape
    x = 0
    idx = 0
    for i in range(nr):
       for j in range(nc):
          if conf[i,j] == 1: x = bits.setBit(x,idx)
          idx += 1
    return x
Exemple #4
0
    def initial_free_block_bitmap(self):
        # initialise the bitmap int value to 0
        bitmap = 0
        # counter for count the blocks
        count = 0
        for i in range(NUM_BLOCKS):
            # read each block in the disk
            block = disktools.read_block(i)

            # set the value to 0 for the non-free block in bit map
            if disktools.bytes_to_int(block) != 0:
                bitmap = bits.clearBit(bitmap, count)
                count += 1
            else:
                bitmap = bits.setBit(bitmap, count)
                count += 1

        # set the first block to 1 which means it is not free(will store bitmap into block 0).
        bitmap = bits.clearBit(bitmap, 0)
        # write the bitmap value at the first two bytes at block 0
        bitmap_disk = disktools.read_block(0)
        bitmap_disk[BITMAP_START:BITMAP_FINISH] = disktools.int_to_bytes(
            bitmap, 2)
        disktools.write_block(0, bitmap_disk)
Exemple #5
0
if DEBUG:
    print('mean, std: ', mean, sstd)

#mean = 0.03
#sstd = 10.28

count = 0

for it in range(const.N_b):
    pv = []
    for iy in range(const.N_y):
        for ix in range(const.N_x):
            # 3 sigma check
            pvalue = data[it, iy, ix]
            if (pvalue - mean) > const.th_pixel * sstd:
                mask[iy, ix] = bits.setBit(
                    mask[iy, ix], it)  # if > 3sigma, set the it-th bit to 1
                total_hits[it] = total_hits[it] + 1
                pv.append(
                    pvalue
                )  # above threshold pixel values used for histogram later
                # pixel values for all images
                pixel_value.append(pvalue)

                #if DEBUG:
                #print ('test bit = ', bits.testBit(mask[iy, ix], it))
                #print (data[it, iy, ix], mean, 3*sstd)
                #print (count, iy, ix, mask[iy,ix])
            # when all images are scanned, check how many times the same pixel is fired
            if it == (const.N_b - 1):
                # Count number of bits set
                count = bits.bitCount(mask[iy, ix])