Exemple #1
0
    def pointTransform(self,x,y, check=0):
        """
            illuminates a single point while performing a mapping transform
            function exists primarily for testing

        """
        MF = self.MF
        coord = self.ccd_to_dmd(x,y)
        # TODO:
        # multiplying by 4 because of confusing SUBPIXEL stuff fix in image 
        # generator
        # do all floats in FUTURE
        PI.py_illuminate_enable()
        PI.py_clear_framebuffer()
        PI.py_illuminate_point(coord[0],coord[1], MF.mask_number1)
        PI.py_illuminate_expose()                   # turn on the frame buffer
        if check == 1:
            img_array = PC.snapPtr(0.35,180,"spare")
            # just clobber the illumination point
            a = numpy.array([coord[0]])
            b = numpy.array([coord[1]])
            max_val = PI.py_illuminate_spot_find(img_array, a,b)
            if max_val < 100:
                print("point not found")
            # end if
            else:
                print("found(%d,%d)" % (a[0],b[0]))
            # end else
            PC.cameraClose() # also frees up image buffer memory
Exemple #2
0
    def grid(self,grid_spacing=10, square_size=1):
        """
        illuminates a single point while performing a mapping transform
        function exists primarily for testing

        """
        MF = self.MF


        pix = numpy.zeros((1000,1000), dtype=numpy.uint8)
        period = grid_spacing+square_size
        for i in range(1000/period):
            for j in range(1000/period):
                for p in range(square_size):
                    for q in range(square_size):
                        pix[period*i+p,period*j+q] = 1
                    # end for
                #end for
            # end for
        # end for

        itemind = numpy.where(pix==1)

        PI.py_clear_framebuffer()
        
        points_illum = self.n_ccd_to_dmd(itemind[1],itemind[0])

        PI.py_illuminate_enable()
        PI.py_illuminate_vector(points_illum[0],points_illum[1], \
                                MF.mask_number1, points_illum[0].size)
        PI.py_illuminate_expose()
Exemple #3
0
    def bitmap(self,transform=1):
        """
        illuminates a single point while performing a mapping transform
        function exists primarily for testing

        """
        MF = self.MF

        #im = Image.open("wyss_1000.bmp")
        #im = Image.open("wyss_1000_i2.bmp")
        #im = Image.open("alignment_DMD2.bmp")
        #im = Image.open("George_Church_04.bmp")
        #im = Image.open("George_Church_05.bmp")
        im = Image.open("../../data/TitlePres.bmp")
        #im = Image.open("all_white.bmp")

        pix = numpy.array(im.getdata(), dtype=numpy.uint8)

        pix = pix.reshape((1000,1000))
        #print("array created")
        itemind = numpy.where(pix==0)
        #print("points found")
        PI.py_clear_framebuffer()
        #print("framebuff cleared")
        points_illum = self.n_ccd_to_dmd(itemind[1],itemind[0])
        #print("transformed")

        PI.py_illuminate_enable()
        PI.py_illuminate_vector(points_illum[0],points_illum[1], \
                                MF.mask_number1, points_illum[0].size)
        PI.py_illuminate_expose()
Exemple #4
0
    def wyss(self,inverse=0,decimate=0):
        """
        illuminates a single point while performing a mapping transform
        function exists primarily for testing

        """
        MF = self.MF

        im = Image.open("../../data/wyss_1000_i2.bmp")

        pix = numpy.array(im.getdata(), dtype=numpy.uint8)

        # decimate it down
        if decimate > 0: 
            if inverse == 1:
                for i in range(pix.size/decimate):
                    for j in range(decimate-1):
                        pix[decimate*i+j+1] = 0
                    # end for
                # end for
            # end if
            else:
                for i in range(pix.size/decimate):
                    for j in range(decimate-1):
                        pix[decimate*i+j+1] = 1
                    # end for
                # end for
            # end else
        # end if
        pix = pix.reshape((1000,1000))

        itemind = numpy.where(pix==inverse)

        PI.py_clear_framebuffer()

        points_illum = self.n_ccd_to_dmd(itemind[1],itemind[0])

        PI.py_illuminate_enable()
        PI.py_illuminate_vector(points_illum[0],points_illum[1], \
                                MF.mask_number1, points_illum[0].size)
        PI.py_illuminate_expose()
Exemple #5
0
    def george(self,inverse=0,decimate=0):
        """
        illuminates a single point while performing a mapping transform
        function exists primarily for testing

        """
        MF = self.MF

        im = Image.open("../../data/George_Church_05.bmp")

        pix = numpy.array(im.getdata(), dtype=numpy.uint8)

        pix = pix.reshape((1000,1000))

        itemind = numpy.where(pix==inverse)

        PI.py_clear_framebuffer()

        points_illum = self.n_ccd_to_dmd(itemind[1],itemind[0])

        PI.py_illuminate_enable()
        PI.py_illuminate_vector(points_illum[0],points_illum[1], \ 
                                MF.mask_number1, points_illum[0].size)
        PI.py_illuminate_expose()
Exemple #6
0
def off():
    PI.py_illuminate_disable()
Exemple #7
0
def clear():
    PI.py_clear_framebuffer()
Exemple #8
0
def floaty():
    PI.py_illuminate_float()
Exemple #9
0
def expose():
    PI.py_illuminate_enable()
    PI.py_illuminate_expose()
Exemple #10
0
def main(argv=None):
    
    """
        Process command line
    """
    IlluminateWidth = 1920
    IlluminateHeight = 1080
    CameraWidth = 1000
    CameraHeight = 1000
    
    if argv is None:
        argv = sys.argv
    # end if
    argc = len(argv)
    print "newline\n"
    print "There are %d arguments\n" % argc     
    # make sure we have the correct number of arguments */
    if  (argc < 3) or (argc > 5):
        show_usage()
        sys.exit(-1)
    #end if
    
    MF = MaestroFunctions()
    
    # process the numeric arguments 
    int_time = float(argv[1])
    em_gain  = int(argv[2])

    # process cube name 
    if argc < 4:
        mycube = DEFAULT_CUBE
    # end if
    else:
        mycube = str(argv[3])
        
    # end else

    # process TDI flag
    if argc < 5:
        TDI_flag = DEFAULT_TDI
    # end if
    else:
        TDI_flag = int(argv[4])
    # end else

    """
        Set up imaging
    """

    MF.darkfield_off() 
    print "the third argument is %s\n" % mycube 
    MF.filter_goto(mycube)



    """
        set up release hardware
    """

    # initialize the release system 
    print "Initializing release system\n"
    PI.py_clear_memory();
    if PI.py_illuminate_init(IlluminateWidth, IlluminateHeight, \
                            CameraWidth, CameraHeight) < 0:
        sys.exit(-1)
    #end if
 
    # load an identity map for alignment parameters 
    PI.py_illuminate_alignment_load_identity()
   
    # enable release hardware 
    PI.py_illuminate_enable()

    # generate an image
    """
    im = Image.open("test.png")
  
    if im.size[0] > im.size[1]:
        scaler = IlluminateWidth/(im.size[0])
        im = im.resize((IlluminateWidth, scaler*im.size[1]),Image.BICUBIC)
    #end if
    else:
        scaler = IlluminateHeight/(im.size[1])
        im = im.resize((scaler*im.size[0], IlluminateHeight),Image.BICUBIC)
    #end else
    im.convert('L')
    im.show() 
    im.save("testout.png")
    """
    #im = Image.open("wyss_HD_R3.bmp")
    #im = Image.open("alignment_DMD.bmp")
    im = Image.open("George_Church_03.bmp")
    #im = Image.open("all_white.bmp")
    #im = im.rotate(90)
    im = im.transpose(Image.FLIP_LEFT_RIGHT)
    im = im.transpose(Image.FLIP_TOP_BOTTOM)
    #im = im.offset(50, -300)
    pix = im.load()
    
    mask_number = 0
    y_step = 1
    x_step = 1 
    #PI.py_clear_mask(mask_number)
    PI.py_clear_framebuffer()
    #PI.py_clear_memory()    # must run this or you will get line artifacts!!!!
  
    PI.py_illum_mask_radius_dmd(0,mask_number)
        
    for y in range(0,IlluminateHeight,y_step):
        for x in range(0,IlluminateWidth,x_step):
            #if pix[y,x] != 0:
            if pix[y,x] == 0:
                PI.py_illuminate_point(x,y,mask_number)
            #end if
        # end for
    # end for
 

    # expose image, so that it stays displayed 
    #PI.py_illuminate_disable()
    PI.py_illuminate_expose()

    """
    start imaging
    """

    # open shutter
    MF.shutter_open()

    # start imaging
    myargc = 3;
    myargv = ['0' ,'0','c','d']    # create a list of length 4
    myargv[2] = argv[1]
    myargv[3] = argv[2]

    # start in a separate process to avoid crash if window is closed
    
    #pid = os.fork()        # this is a UNIX only syscall
    #if pid == 0:
        #child process
     #   PC.py_camera_live(myargc, myargv, TDI_flag)
      #  return 0;
    # end if

    # in parent process 
    # wait for child to terminate 
    #os.waitpid(pid,os.WNOHANG)     # this option WNOHANG is UNIX only
    #os.wait()
    
    # close shutter
    #MF.shutter_close()
    return 0
Exemple #11
0
    def illumInit(self):
        """
            initialize the illumination system for use in the mapping process   
        """
     
        MF = self.MF
        print "Initializing release system\n"
        PI.py_clear_memory();
        
        # initialize module values
        if PI.py_illuminate_init(int(MF.IlluminateWidth),\
                                int(MF.IlluminateHeight),\
                                int(MF.CameraWidth),\
                                int(MF.CameraHeight)) < 0:
            sys.exit(-1)
        #end if

        # load an identity map for alignment parameters
        # CRUCIAL as for now!!!!!!!!!!!!
        PI.py_illuminate_alignment_load_identity()

        # enable release hardware
        PI.py_illuminate_enable()
        
        # Create a group of masks
        PI.py_illum_mask_radius(MF.mask_radius0,MF.mask_number0)
        PI.py_illum_mask_radius(MF.mask_radius1,MF.mask_number1)
        PI.py_illum_mask_radius(MF.mask_radius2,MF.mask_number2)
        PI.py_illum_mask_radius(MF.mask_radius3,MF.mask_number3)
Exemple #12
0
    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")
Exemple #13
0
def on():
    PI.py_light_all()
Exemple #14
0
 def closeDMD(self):
     """
     Float the DMD and clear the frame buffer
     """
     PI.py_illuminate_float()
     PI.py_clear_framebuffer()
Exemple #15
0
 def vector(self,vx,vy, num_points,spot_size=0):
     MF = self.MF
     
     outpoints = self.n_ccd_to_dmd(vx,vy)
     a = outpoints[0]
     b = outpoints[1]
     PI.py_illuminate_enable()
     PI.py_clear_framebuffer()
     if spot_size == 1:
         PI.py_illuminate_vector(a,b, MF.mask_number2, num_points)
     elif spot_size == 2:
         PI.py_illuminate_vector(a,b, MF.mask_number3, num_points)
     else:
         PI.py_illuminate_vector(a,b, MF.mask_number1, num_points)
     
     PI.py_illuminate_expose() # turn on the frame buffer
Exemple #16
0
 def lightAll(self):
     PI.py_light_all()
Exemple #17
0
 def enableDMD(self):
     # enable release hardware
     PI.py_illuminate_enable()
Exemple #18
0
def thing(expos=0.008, gain=2, mycube='spare', TDI_flag = 0):
    """
    Process command line.  This is used
    """
    IlluminateWidth = 1920
    IlluminateHeight = 1080
    CameraWidth = 1000
    CameraHeight = 1000

    #MF = MaestroFunctions.Maestro_Functions()
    MF = MaestroFunctions()

    # process the numeric arguments
    int_time = float(expos)
    em_gain  = int(gain)


    """
    Set up imaging
    """

    MF.darkfield_off()
    print "the third argument is %s\n" % mycube
    MF.filter_goto(mycube)



    """
    set up release hardware
    """

    # initialize the release system
    print "Initializing release system\n"
    PI.py_clear_memory();
    if PI.py_illuminate_init(IlluminateWidth, IlluminateHeight, \
                                            CameraWidth, CameraHeight) < 0:
        sys.exit(-1)
    #end if

    # load an identity map for alignment parameters
    # CRUCIAL as for now!!!!!!!!!!!!
    PI.py_illuminate_alignment_load_identity()

    # enable release hardware
    PI.py_illuminate_enable()

    # generate an image
    """
    im = Image.open("test.png")

    if im.size[0] > im.size[1]:
        scaler = IlluminateWidth/(im.size[0])
        im = im.resize((IlluminateWidth, scaler*im.size[1]),Image.BICUBIC)
    #end if
    else:
        scaler = IlluminateHeight/(im.size[1])
        im = im.resize((scaler*im.size[0], IlluminateHeight),Image.BICUBIC)
    #end else
    im.convert('L')
    im.show()
    im.save("testout.png")
    """
    #im = Image.open("wyss_HD_R3.bmp")
    im = Image.open("../data/alignment_DMD5.bmp")
    #im = Image.open("George_Church_03.bmp")
    #im = Image.open("all_white.bmp")
    #im = im.rotate(90)
    im = im.transpose(Image.FLIP_LEFT_RIGHT)
    im = im.transpose(Image.FLIP_TOP_BOTTOM)
    #im = im.offset(50, -300)
    pix = im.load()

    mask_number = 0
    y_step = 1
    x_step = 1
    #PI.py_clear_mask(mask_number)
    PI.py_clear_framebuffer()
    #PI.py_clear_memory()    # must run this or you will get line artifacts!!!!

    PI.py_illum_mask_radius(0,mask_number)
    #done = 0
    for y in range(0,IlluminateHeight,y_step):
        for x in range(0,IlluminateWidth,x_step):
            #if pix[y,x] != 0:
            if pix[y,x] == 0:# and done == 0:
                #x = 1920/2
                #y = 1080/2
                PI.py_illuminate_point(x,y,mask_number)
                #print x, y
                #done = 1;
            #end if
        # end for
    # end for


    # expose image, so that it stays displayed
    #PI.py_illuminate_disable()
    PI.py_illuminate_expose()

    """
    start imaging
    """

    # open shutter
    MF.shutter_open()
    return 0
Exemple #19
0
def main(argv=None):
    
    """
        Process command line
    """
    IlluminateWidth = 1920
    IlluminateHeight = 1080
    CameraWidth = 1000
    CameraHeight = 1000
    
    if argv is None:
        argv = sys.argv
    # end if
    argc = len(argv)
    print "newline\n"
    print "There are %d arguments\n" % argc     
    # make sure we have the correct number of arguments */
    if  (argc < 3) or (argc > 5):
        #testDMD.show_usage()
        show_usage()
        sys.exit(-1)
    #end if
    
    MF = MaestroFunctions()
    
    # process the numeric arguments 
    int_time = float(argv[1])
    em_gain  = int(argv[2])

    # process cube name 
    if argc < 4:
        mycube = DEFAULT_CUBE
    # end if
    else:
        mycube = str(argv[3])
        
    # end else

    # process TDI flag
    if argc < 5:
        TDI_flag = DEFAULT_TDI
    # end if
    else:
        TDI_flag = int(argv[4])
    # end else

    """
        Set up imaging
    """

    MF.darkfield_off() 
    print "the third argument is %s\n" % mycube 
    MF.filter_goto(mycube)



    """
        set up release hardware
    """

    # initialize the release system 
    print "Initializing release system\n"
    if PI.py_illuminate_init(IlluminateWidth, IlluminateHeight, \
                            CameraWidth, CameraHeight) < 0:
        sys.exit(-1)
    #end if
 
    # load an identity map for alignment parameters 
    PI.py_illuminate_alignment_load_identity()

    # enable release hardware 
    PI.py_illuminate_enable()
    PI.py_clear_memory()    # must run this or you will get line artifacts!!!!
    # generate an image 
    PI.generate_image()
    
    
    # expose image, so that it stays displayed 
    PI.py_illuminate_expose()

    """
    start imaging
    """

    # open shutter
    MF.shutter_open()

    # start imaging
    myargc = 3;
    myargv = ['0' ,'0','c','d']    # create a list of length 4
    myargv[2] = argv[1]
    myargv[3] = argv[2]

    # start in a separate process to avoid crash if window is closed
    
    pid = os.fork()        # this is a UNIX only syscall
    if pid == 0:
        #child process
        PC.cameraLive(myargc, myargv, TDI_flag)
        return 0;
    # end if

    # in parent process 
    # wait for child to terminate 
    #os.waitpid(pid,os.WNOHANG)     # this option WNOHANG is UNIX only
    os.wait()
    
    # close shutter
    MF.shutter_close()

    return 0