def save_redist_pattern_figure(level=0): name = "redist_figure" entropy_redist_potential = [( (70, -110), ippg.GradientParabolaMinusGauss_GaussDipFloor( #parab=[600, 900], amplitude=1, parab=[600 / 2., 900 / 2.], amplitude=1, gausscomp=[120, 180], gausscomp_height=0.2, level=level, # gauss=[60*.75*1.0, 60*.75*1.0], gauss_height=1, gauss=[60 * 1.0, 60 * 1.0], gauss_height=1, #gradient=[0.0000, 0.0002]# [++ -> upper right on atoms, ++ -> upper left] gradient=[0.0006, -0.0008 ] # [++ -> upper right on atoms, ++ -> upper left] ))] pattern_settings = { 'zero_pixel': (702, 816), 'sites': entropy_redist_potential, 'binarization_algorithm': 'error_diffusion' } potential = ippg.ProjectedPotential(**pattern_settings) binarized, real_valued = potential.binarized_potential, potential.real_valued_potential return binarized, real_valued
def get_boxes(cls): box_dict = { cls.center1():ippg.BoxFunction(radii = [cls.l_NE, cls.w_short], x_angle=cls.angle_long, amplitude=cls.amp1), cls.center2():ippg.BoxFunction(radii = [cls.w_long, cls.l_long], x_angle=cls.angle_long, amplitude=cls.amp2), cls.center3():ippg.BoxFunction(radii = [cls.l_NE, cls.w_short], x_angle=cls.angle_long, amplitude=cls.amp3), cls.center4():ippg.BoxFunction(radii = [cls.w_long, cls.l_long], x_angle=cls.angle_long, amplitude=cls.amp4), } return box_dict
def real_pattern_print(): #Prepare Pattern lc_dmd = lc.LC6500Device() settings = { 'compression':'rle', 'exposure_time':5000000 # in us } dmd_pattern = pc.DMDPattern(**settings) is_debug = False #TEST STUFF sites_dict = [((0, 0), ippg.GradientParabolaMinusGauss_GaussDip(parab=[600*1.5, 900*1.5], amplitude=1, gausscomp=[120, 180], gausscomp_height=0.2, gauss=[60, 90], gauss_height=1.0, #gradient=[0.0, 0.0] gradient=[-0.0003, 0.0002] # [++ -> upper right on atoms, ++ -> upper left] )) ] # settings = {'zero_pixel': (824, 429), settings = {'zero_pixel': (762, 586), 'sites': sites_dict, 'binarization_algorithm': 'threshold'}#''error_diffusion'} potential = ippg.ProjectedPotential(**settings) # uncomment this to get a saved copy of the potential # imsave('out.png', evaluated_matrix) # uncomment this to use the painted potential # potential.real_valued_potential = np.array(imread('out.png', mode='L')).astype('float') # potential.real_valued_potential /= float(np.max(potential.real_valued_potential)) binary_matrix =potential.binarized_potential if is_debug: plt.gray() plt.imshow(binary_matrix,interpolation='none') # plt.imshow(potential.real_valued_potential,interpolation='none') plt.figaspect(1) pkl.dump(binary_matrix, open('diffused.pkl', 'wb'), protocol=2) plt.show() dmd_pattern.pattern = binary_matrix dmd_patterns = {'patterns':[dmd_pattern]} lc_dmd.upload_image_sequence(dmd_patterns)
def real_pattern_series_test(): lc_dmd = lc.LC6500Device() print lc_dmd.dev #Prepare Pattern #settings = {'function':pc.stripes_2,#pc.circle_fun_2, settings = {'function':pc.circle_fun_2, 'compression':'rle', 'exposure_time':500000 # in us } dmd_pattern = pc.DMDPattern(**settings) dmd_pattern_2 = pc.DMDPattern(**settings) #dmd_pattern.compute_pattern() site_rad = 6 site_radii = [site_rad, site_rad] sites_dict = {(-25,-15):ippg.GaussFunction(radii = [1000,200])} settings = {'sites':sites_dict, 'binarization_algorithm':'randomize'} potential = ippg.ProjectedPotential(**settings) evaluated_matrix = potential.evaluate_potential() binary_matrix = potential.binarize() dmd_pattern.pattern = binary_matrix sites_dict = {(-25,-15):ippg.GaussFunction(radii = [200,1000])} settings = {'sites':sites_dict, 'binarization_algorithm':'threshold'} potential = ippg.ProjectedPotential(**settings) evaluated_matrix = potential.evaluate_potential() binary_matrix = potential.binarize() dmd_pattern_2.pattern = binary_matrix dmd_patterns = {'patterns':[dmd_pattern, dmd_pattern_2, dmd_pattern]} lc_dmd.upload_image_sequence(dmd_patterns) #lc_dmd.upload_image(dmd_pattern) #command_sequence = dmd_pattern.compress_pattern() #lc_dmd.upload_image(command_sequence) lc_dmd.release()
def save_redist_pattern(): name = "redist" entropy_redist_potential = [( (70, -110), ippg.GradientParabolaMinusGauss_GaussDipFloor( #parab=[600, 900], amplitude=1, parab=[600 / 2., 900 / 2.], amplitude=1, gausscomp=[120, 180], gausscomp_height=0.2, level=0.00, # gauss=[60*.75*1.0, 60*.75*1.0], gauss_height=1, gauss=[60 * 1.0, 60 * 1.0], gauss_height=1, #gradient=[0.0000, 0.0002]# [++ -> upper right on atoms, ++ -> upper left] gradient=[0.0006, -0.0008 ] # [++ -> upper right on atoms, ++ -> upper left] ))] # gradient=[0.0036, 0.0012]# [++ -> upper right on atoms, ++ -> upper left] # entropy_redist_potential = [((30, -60), ippg.GradientParabolaMinusGauss_GaussDipFloor( # #parab=[600, 900], amplitude=1, # parab=[600/2., 900/2.], amplitude=1, # gausscomp=[120, 180], # gausscomp_height=0.2, # level=0.0, #0.42, #0, # gauss=[60*.75*1.0, 60*.75*1.0], gauss_height=1, # #gradient=[0.0000, 0.0002]# [++ -> upper right on atoms, ++ -> upper left] # gradient=[0.0014, -0.0006]# [++ -> upper right on atoms, ++ -> upper left] # ))] pattern_settings = { 'zero_pixel': (702, 816), 'sites': entropy_redist_potential, 'binarization_algorithm': 'error_diffusion' } potential = ippg.ProjectedPotential(**pattern_settings) SavedPattern(potential.binarized_potential, potential.real_valued_potential, name, metadata=pattern_settings)
def save_focusing_pattern(): name = "focusing" entropy_redist_potential = [((30, -60), ippg.BoxFunction(radii=[20, 10])), ((80, 60), ippg.BoxFunction(radii=[20, 10])), ((30, 60), ippg.BoxFunction(radii=[20, 10])), ((80, -60), ippg.BoxFunction(radii=[20, 10]))] pattern_settings = { 'zero_pixel': (702, 816), 'sites': entropy_redist_potential, 'binarization_algorithm': 'threshold ' } potential = ippg.ProjectedPotential(**pattern_settings) SavedPattern(potential.binarized_potential, potential.real_valued_potential, name, metadata=pattern_settings)
def upload_video_pattern(dmd_idx): sites = [((0, 0), ippg.GaussFunction(radii=[100, 500], x_angle=1))] pattern_settings = [{ 'zero_pixel': (762, 429), 'sites': sites, 'binarization_algorithm': 'randomize' }] dmd_client = DmdClient(dmd_idx, pattern_settings) #dmd_client.ping_dmd_channel(1) dmd_client.upload_to_dmd_video_definition()
def real_pattern_test(): lc_dmd = lc.LC6500Device() #Prepare Pattern #settings = {'function':pc.stripes_2,#pc.circle_fun_2, settings = {'function':pc.circle_fun_2, 'compression':'rle', 'exposure_time':500000 } dmd_pattern = pc.DMDPattern(**settings) #dmd_pattern.compute_pattern() site_rad = 6 site_radii = [site_rad, site_rad] sites_dict = {#(0,0):ippg.CircFunction(radii = site_radii), #(1,0):ippg.CircFunction(radii = site_radii), #(3,1):ippg.CircFunction(radii = site_radii), #(0,0):ippg.GaussFunction(radii = [1000,1000]) (0,0):ippg.GaussFunction(radii = [500,500]) } #settings = {'sites':sites_dict, # 'binarization_algorithm':'error_diffusion'} # sites_dict = {(-100,-158):ippg.CircFunction(radii = [4,4], x_angle=1, amplitude=1)} #sites_dict = {(-188,-264):ippg.CircFunction(radii = [4,4], x_angle=1, amplitude=1)} settings = {'sites':sites_dict, 'binarization_algorithm':'threshold'} #'binarization_algorithm':'error_diffusion'} potential = ippg.ProjectedPotential(**settings) evaluated_matrix = potential.evaluate_potential() binary_matrix = potential.binarize() dmd_pattern.pattern = binary_matrix #dmd_pattern.show_pattern() lc_dmd.upload_image(dmd_pattern)
def save_manual_pattern(dmd_settings={}): """ Manually save a pickle and a png showing the pattern :param dmd_settings: optional dict of dmd settings. required if you want to use pattern on the fly mode :return: """ name = "TEST" sites = [((0, 0), ippg.BoxFunction(radii=[20, 10], x_angle=1)), ((0, 0), ippg.GaussFunction(radii=[100, 500], x_angle=1))] pattern_settings = { 'zero_pixel': (762, 429), 'sites': sites, 'binarization_algorithm': 'error_diffusion' } potential = ippg.ProjectedPotential(**pattern_settings) SavedPattern(potential.binarized_potential, potential.real_valued_potential, name, metadata=pattern_settings)
def upload_manual_pattern_on_the_fly(dmd_idx): dmd_settings = [{ 'compression': 'rle', 'exposure_time': 5000000 # in us }] sites_dict = {((0, 0), ippg.BoxFunction(radii=[100, 100], x_angle=1))} pattern_settings = [{ 'zero_pixel': (762, 429), 'sites': sites_dict, 'binarization_algorithm': 'error_diffusion' }] dmd_client = DmdClient(dmd_idx, pattern_settings, dmd_settings_list=dmd_settings) dmd_client.upload_to_dmd()
def upload_img_video_definition(self, potential_settings_list, **kwargs): """ Uploads the definition of the image (computed on dmd server) :param potential_settings_list: list of length 1, to be computed on the server :param kwargs: :return: 0 """ if not self.mode == 'normal_video': self._set_dmd_to_video_mode() if not len(potential_settings_list) == 1: raise Exception( "The video mode cannot play movies (ironic), since the device is not synced to the experiment" ) potential = ippg.ProjectedPotential(**potential_settings_list[0]) self.video_image = VideoImage(potential.binarized_potential, **kwargs) print "uploaded image with UUID %s" % self.video_image.img_uuid return 0
def send_pattern_to_dmd(self, dmd_settings_list, potential_settings_list): ''' :param dmd_settings: list of dict of settings for dmd :param potential_settings_list: list of dict of settings for various patterns :return: ''' self.dmd_settings_list = dmd_settings_list self.potential_settings_list = potential_settings_list dmd_patterns = [] for idx, pot_set in enumerate(potential_settings_list): dmd_pattern = pc.DMDPattern(**dmd_settings_list[idx]) potential = ippg.ProjectedPotential(**pot_set) #potential.evaluate_potential() #binary_matrix = potential.binarize() dmd_pattern.pattern = potential.binarized_potential dmd_patterns.append(dmd_pattern) dmd_patterns = {'patterns': dmd_patterns} self.lc_dmd = lc.LC6500Device() self.lc_dmd.upload_image_sequence(dmd_patterns) self.mode = 'pattern_on_the_fly'
def real_pattern_show(): lc_dmd = lc.LC6500Device() print lc_dmd.dev #Prepare Pattern settings = { 'compression':'rle', 'exposure_time':5000000 # in us } dmd_pattern = pc.DMDPattern(**settings) is_debug = False # sites_dict={} # sites_dict = {(-31,4):ippg.BoxFunction(radii = [30,10], x_angle=1), # (120, 72):ippg. # BoxFunction(radii=[30,3], x_angle=2.5), # (-31, 4):ippg.BoxFunction(radii=[30,10], x_angle=1) # } # sites_dict = {(0, 0):ippg.CircFunction(radii = [50,50], x_angle=1, amplitude=1)} # # sites_dict = BoxCancellation.get_boxes() # sites_dict = {(0,-0):ippg.GaussFunction(radii = [100,100])} # sites_dict = {(0, 0): ippg.Parabola_BoxDip(parab=[600, 900], amplitude=1, # box=[1, 1], box_height=0.0, # )} #sites_dict = {(0, 0): ippg.Parabola_EllipseDip(parab=[600, 900], amplitude=1, # ell=[40, 60], ell_height=0.0, # )} # sites_dict = {(0, 0): ippg.Parabola_GaussDip(parab=[600, 900], amplitude=1, # gauss=[60, 90], gauss_height=1., # )} #LAB STUFF ''' sites_dict = {(0, 0): ippg.GradientParabolaMinusGauss_GaussDip(parab=[600*1.5, 900*1.5], amplitude=1, gausscomp=[120, 180], gausscomp_height=0.2, gauss=[60, 90], gauss_height=1.0, #gradient=[0.0, 0.0] gradient=[-0.0003, 0.0002] # [++ -> upper right on atoms, ++ -> upper left] )} ''' #TEST STUFF sites_dict = {(0, 0): ippg.GradientParabolaMinusGauss_GaussDip(parab=[600*1.5, 900*1.5], amplitude=1, gausscomp=[120, 180], gausscomp_height=0.2, gauss=[60, 90], gauss_height=1.0, #gradient=[0.0, 0.0] gradient=[-0.0003, 0.0002] # [++ -> upper right on atoms, ++ -> upper left] )} # settings = {'zero_pixel': (824, 429), settings = {'zero_pixel': (762, 586), 'sites': sites_dict, 'binarization_algorithm': 'threshold'} potential = ippg.ProjectedPotential(**settings) evaluated_matrix = potential.evaluate_potential() # uncomment this to get a saved copy of the potential # imsave('out.png', evaluated_matrix) # uncomment this to use the painted potential # potential.real_valued_potential = np.array(imread('out.png', mode='L')).astype('float') # potential.real_valued_potential /= float(np.max(potential.real_valued_potential)) binary_matrix = potential.binarize() if is_debug: plt.gray() plt.imshow(binary_matrix,interpolation='none') # plt.imshow(potential.real_valued_potential,interpolation='none') plt.figaspect(1) plt.show() dmd_pattern.pattern = binary_matrix dmd_patterns = {'patterns':[dmd_pattern]} lc_dmd.upload_image_sequence(dmd_patterns)
def real_pattern_show(): lc_dmd = lc.LC6500Device() #Prepare Pattern settings = { 'function': pc.circle_fun_2, 'compression': 'rle', 'exposure_time': 100000000 # in us } dmd_pattern = pc.DMDPattern(**settings) is_debug = False sites_dict = {} circle_dict = { (0, 0): ippg.BoxFunction(radii=[200, 200], x_angle=0, amplitude=1), (0, 0): ippg.CircFunction(radii=[500, 500], x_angle=0, amplitude=1), } entire_beam_dict = { (0, 0): ippg.CircFunction(radii=[5000, 5000], x_angle=0, amplitude=1), } multipoint_dict = { (-100, -100): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), (100, -100): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), (-100, 100): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), (100, 100): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), (-150, -150): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), (150, -150): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), (50, -50): ippg.CircFunction(radii=[5, 5], x_angle=0, amplitude=1), } sites_dict = { (0, 0): ippg.Parabola_EllipseDip( parab=[400, 600], amplitude=1, ell=[80, 120], ell_height=0.0, ) } #93 # settings = {'zero_pixel': (824, 429), #'zero_pixel': (762, 429), settings = { 'zero_pixel': (762, 586), 'sites': sites_dict, 'binarization_algorithm': 'randomize' } potential = ippg.ProjectedPotential(**settings) evaluated_matrix = potential.evaluate_potential() binary_matrix = potential.binarize() if True: corrector = DMDBeamCorrector('points.pgm', 'profile.pgm', center=(772, 576)) arr = np.zeros((1080, 1920)) y, x = np.ogrid[0:1080, 0:1920] arr = corrector.homogenize(evaluated_matrix, w_center=(762, 586), w_size=(300, 300)) if is_debug: plt.gray() plt.imshow(arr, interpolation='none') plt.show() for y in range(arr.shape[1]): print y for x in range(arr.shape[0]): # custom floyd-steinberg op = arr[x][y] # arr[x][y] = 1 if random() < op else 0 if random() < 0: newp = 1 if random() < op else 0 else: newp = 1 if 0.5 < op else 0 arr[x][y] = newp err = op - newp if x < arr.shape[0] - 1: arr[x + 1][y] = arr[x + 1][y] + err * 7 / 16 if y < arr.shape[1] - 1: arr[x + 1][y + 1] = arr[x + 1][y + 1] + err * 1 / 16 if y < arr.shape[1] - 1: arr[x - 1][y + 1] = arr[x - 1][y + 1] + err * 3 / 16 arr[x][y + 1] = arr[x][y + 1] + err * 5 / 16 binary_matrix = arr if is_debug: plt.gray() plt.imshow(binary_matrix, interpolation='none') plt.show() dmd_pattern.pattern = binary_matrix dmd_patterns = {'patterns': [dmd_pattern]} lc_dmd.upload_image_sequence(dmd_patterns)