コード例 #1
0
ファイル: mapping.py プロジェクト: REC17/Polonator
 def closeDMD(self):
     """
     Float the DMD and clear the frame buffer
     """
     PI.py_illuminate_float()
     PI.py_clear_framebuffer()
コード例 #2
0
ファイル: testDMD_lib.py プロジェクト: chaoli238/Polonator
def floaty():
    PI.py_illuminate_float()
コード例 #3
0
ファイル: mapping.py プロジェクト: REC17/Polonator
    def mapGen(self, test_me = False):
        """
        This function generates the mapping it:
        1)  loads the points to illuminate
        2)  generates a image for the DMD based on said coordinates
        3)  illuminates the image
        4) takes a picture
        5) copies the picture from the frame buffer
        6) finds the illuminated points in the camera coordinates
        7) generates a mapping to the DMD using a pseudoinverse
        8) writes the mapping to class memory
        9) writes the mapping to file
    
        Polonator_IlluminateFunctions is SWIGed as follows
        Illuminate and Hardware coordinates are mapped using the SWIG 
        This allows you to access an array of Coordinates in C and python
        as follows once the IlluminateCoords_type struct is also interfaced
        in SWIG :

        new_coordArray(int size) -- creates an array of size
        delete_coordArray(IlluminateCoords_type * arry) -- deletes and array
        coordArray_get_x(IlluminateCoords_type *c_xy, int i)  -- gets an value
        coordArray_set_x(IlluminateCoords_type *c_xy, int i, signed short
        int val) -- sets a value
        ptr_coordArray(IlluminateCoords_type *c_xy, int i)  returns a
        pointer to an index
        """
        """
        get points for bitmap and load them SWIG style
        mapping_basis is just a list of points to to illuminate to
        generate a good and sufficient mapping basis coordinates are given
        as a range from -1 to 1 with 0,0 being the image center
        """
        MF = self.MF
        print("STATUS:\tMappingFunctions: opening frame buffer\n")
        mapping_basis = open(MF.config_dir +'/mapping_basis.coordinates')
        print(  "STATUS:\tMappingFunctions: getting list of points \
                to illuminate from file\n")
        idx = -1
        num_points = 0
        for line in mapping_basis:
            if line[0] != '#':   
                # '#' is reserved for comments on a separate line
                basis_coordinate = line.split()  # tab delimited fields
                print(basis_coordinate)
                if basis_coordinate[0] == 'number':  
                    # this is the number of basis points we need to illuminate
                    num_points = int(basis_coordinate[1])
                    idx = num_points 
                    # this creates the array of coordinates to illuminate
                    points_to_illum_x = numpy.empty(idx, dtype=numpy.int32)
                    # this is the array containing the found points on the CCD
                    points_found_x = numpy.empty(idx, dtype=numpy.int32)
                    points_to_illum_y = numpy.empty(idx, dtype=numpy.int32)
                    points_found_y = numpy.empty(idx, dtype=numpy.int32)
                    # write coordinates in reverse
                    idx = idx - 1
                    print("number of Points to Illuminate: " + str(num_points))
                elif (basis_coordinate[0] == 'XY') and (idx > -1):
                # make sure its tagged as a coordinate and the index is positive
                    # scale to dimensions of the DMD
                    bc_x = int( float(MF.IlluminateWidth)/2 \
                                *float(basis_coordinate[1]) ) \
                                + (float(MF.IlluminateWidth)-1)/2
                    bc_y = int( float(MF.IlluminateHeight)/2 \
                                *float(basis_coordinate[2]) ) \
                                + (float(MF.IlluminateHeight)-1)/2
                    print("read(%d,%d)\n" % (bc_x, bc_y))
                    points_to_illum_x[idx] = bc_x
                    points_to_illum_y[idx] = bc_y  
                    idx = idx - 1
                #end if
            #end if
        #end for

        """
            Set up imaging
        """
        MaestroF = MF.MaestroF
        
        MaestroF.darkfield_off()
        MaestroF.filter_home()
        MaestroF.filter_goto("spare")
        time.sleep(1)
        #MaestroF.filter_unlock()
        """
            set up release hardware
        """

        #self.illumInit()
        num_sub = 0 # keeps track of not found points
        data_size = 1000000
        img_array = numpy.empty(data_size, dtype=numpy.uint16)
        #img_array_out = numpy.empty(data_size, dtype=numpy.uint16)
        img_array_float = numpy.zeros(data_size, dtype=numpy.float)
        
        for idx in range(num_points):
            # generate bitmap
            print("STATUS:\tMappingFunctions: clearing frame buffer\n")
            PI.py_clear_framebuffer()
            print("STATUS:\tMappingFunctions: creating mask\n")
            
            print("STATUS:\tMappingFunctions: generating one image of with ' + \
                    'one pixel\n")
            PI.py_illuminate_point( int(points_to_illum_x[idx]),\
                                    int(points_to_illum_y[idx]),\
                                    MF.mask_number0)
            # illuminate just ONE spot
            print("STATUS:\tMappingFunctions: illuminating one point\n")
            print("illuminating (%d,%d)\n" % \
                    (int(points_to_illum_x[idx]), int(points_to_illum_y[idx])))
            PI.py_illuminate_expose()    # turn on the frame buffer
            #time.sleep(1)

            # analyze image for centroid
            
            print("STATUS:\tMappingFunctions: taking picture \
                    of one illuminated point\n")

            # take a picture and get a pointer to the picture
            frames = 5
            for i in range(frames): 
                PC.py_snapPtr(img_array, MF.expose,MF.gain,"spare")
                # sum accumulator
                img_array_float += img_array.astype(numpy.float) 
            # end for
            # average over frames
            img_array_out = (img_array_float/frames).astype(numpy.uint16) 
            img_array_float *= 0 # reset accumulator
            
            self.convertPicPNG(img_array_out, \
                                points_to_illum_x[idx], points_to_illum_y[idx])
            # read in the config file.  must be formated correctly
            print("STATUS:\tMappingFunctions: find illuminated point\n")

            # SWIGged function for finding the centroid
            # doing array[x:x+1] returns a pointer to an index x in an array 
            # essentially in numpy
            a = points_found_x[idx:idx+1]
            b = points_found_y[idx:idx+1]
            max_val = PI.py_illuminate_spot_find(img_array_out,a,b)
            if max_val < 100:
                print("point not found")
                num_sub += 1
            # end if
            else:
                print("found(%d,%d)" % \ 
                        (points_found_x[idx],points_found_y[idx]) )
            # end else
            
            # free up memory
            #unload_camera_image(img_array)
            PI.py_clear_framebuffer()
            PI.py_illuminate_float()
            #PC.cameraClose() # also frees up image buffer memory
        #end for
        num_points -= num_sub
        # perform mapping operation
        print("STATUS:\tMappingFunctions: generating mapping\n")
        PC.cameraClose() # also frees up image buffer memory
        self.generateMapping(points_found_x, points_found_y, \
            points_to_illum_x, points_to_illum_y, num_points)
        self.writeMappingFile()
        for i in range(num_points):
            print("illuminated(%d,%d)" % \
                    (points_to_illum_x[i],points_to_illum_y[i]) )
            print("found(%d,%d)" % (points_found_x[i],points_found_y[i]) )
            print(" ")
        # end for
        print("Finished map generation\n")