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()
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()
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
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)
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
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()
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()
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
def expose(): PI.py_illuminate_enable() PI.py_illuminate_expose()
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
def enableDMD(self): # enable release hardware PI.py_illuminate_enable()
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