Exemple #1
0
    def log(self):
        t_string = now_string(True)

        #seconds = float(datetime.datetime.strptime(t_string,'%Y%m%d%H%M%S.%f').strftime('%s.%f'))
        d = {}
        #d['time_seconds'] = np.array([seconds])
        d['x_slopes'] = self.x_slopes
        d['y_slopes'] = self.y_slopes
        d['x_centroids'] = self.x_centroids
        d['y_centroids'] = self.y_centroids
        d['search_box_x1'] = self.search_boxes.x1
        d['search_box_x2'] = self.search_boxes.x2
        d['search_box_y1'] = self.search_boxes.y1
        d['search_box_y2'] = self.search_boxes.y2
        d['ref_x'] = self.search_boxes.x
        d['ref_y'] = self.search_boxes.y
        d['error'] = np.array([np.squeeze(self.error)])
        #d['tip'] = self.tip
        #d['tilt'] = self.tilt
        d['wavefront'] = self.wavefront
        d['zernikes'] = np.squeeze(self.zernikes)
        d['spots_image'] = self.image.astype(np.uint16)

        for k in d.keys():
            outfn = os.path.join(ccfg.logging_directory,'sensor_%s_%s.txt'%(k,t_string))
            if k=='spots_image':
                np.savetxt(outfn,d[k],fmt='%d')
            else:
                np.savetxt(outfn,d[k])
 def make_coords(self):
     outfn = os.path.join(ccfg.reference_directory,
                          '%s_coords.txt' % now_string())
     print 'Reference coordinates saved in %s' % outfn
     print 'Please add the following line to config.py:'
     print "reference_coordinates_filename = '%s'" % outfn
     np.savetxt(outfn, self.xy)
Exemple #3
0
 def log(self):
     #outfn = os.path.join(ccfg.logging_directory,'mirror_%s.mat'%(now_string(True)))
     #d = {}
     #d['command'] = self.controller.command
     #sio.savemat(outfn,d)
     outfn = os.path.join(ccfg.logging_directory,'mirror_%s.txt'%(now_string(True)))
     np.savetxt(outfn,self.controller.command)
Exemple #4
0
    def run_poke(self):
        cmin = ccfg.poke_command_min
        cmax = ccfg.poke_command_max
        n_commands = ccfg.poke_n_command_steps
        commands = np.linspace(cmin, cmax, n_commands)

        self.pause()
        time.sleep(1)

        n_lenslets = self.sensor.n_lenslets
        n_actuators = self.mirror.n_actuators

        x_mat = np.zeros((n_lenslets, n_actuators, n_commands))
        y_mat = np.zeros((n_lenslets, n_actuators, n_commands))

        for k_actuator in range(n_actuators):
            self.mirror.flatten()
            for k_command in range(n_commands):
                cur = commands[k_command]
                print k_actuator, cur
                self.mirror.set_actuator(k_actuator, cur)
                QApplication.processEvents()
                time.sleep(.01)
                self.sensor.sense()
                sensor_mutex.lock()
                x_mat[:, k_actuator, k_command] = self.sensor.x_slopes
                y_mat[:, k_actuator, k_command] = self.sensor.y_slopes
                sensor_mutex.unlock()
                self.finished.emit()
        # print 'done'
        self.mirror.flatten()

        d_commands = np.mean(np.diff(commands))
        d_x_mat = np.diff(x_mat, axis=2)
        d_y_mat = np.diff(y_mat, axis=2)

        x_response = np.mean(d_x_mat / d_commands, axis=2)
        y_response = np.mean(d_y_mat / d_commands, axis=2)
        poke = np.vstack((x_response, y_response))
        ns = now_string()
        poke_fn = os.path.join(ccfg.poke_directory, '%s_poke.txt' % ns)
        command_fn = os.path.join(ccfg.poke_directory, '%s_currents.txt' % ns)
        chart_fn = os.path.join(ccfg.poke_directory, '%s_modes.pdf' % ns)
        np.savetxt(poke_fn, poke)
        np.savetxt(command_fn, commands)
        save_modes_chart(chart_fn, poke, commands, self.mirror.mask)

        self.poke = Poke(poke)

        time.sleep(1)
        self.unpause()
Exemple #5
0
    def run_poke(self):
        cmin = kcfg.poke_command_min
        cmax = kcfg.poke_command_max
        n_commands = kcfg.poke_n_command_steps
        commands = np.linspace(cmin,cmax,n_commands)

        self.pause()
        time.sleep(1)
        
        n_lenslets = self.sensor.n_lenslets
        n_actuators = self.mirror.n_actuators
        
        x_mat = np.zeros((n_lenslets,n_actuators,n_commands))
        y_mat = np.zeros((n_lenslets,n_actuators,n_commands))
        
        for k_actuator in range(n_actuators):
            self.mirror.flatten()
            for k_command in range(n_commands):
                cur = commands[k_command]
                print k_actuator,cur
                self.mirror.set_actuator(k_actuator,cur)
                QApplication.processEvents()
                time.sleep(.01)
                self.sensor.sense()
                sensor_mutex.lock()
                x_mat[:,k_actuator,k_command] = self.sensor.x_slopes
                y_mat[:,k_actuator,k_command] = self.sensor.y_slopes
                sensor_mutex.unlock()
                self.finished.emit()
        # print 'done'
        self.mirror.flatten()
        
        d_commands = np.mean(np.diff(commands))
        d_x_mat = np.diff(x_mat,axis=2)
        d_y_mat = np.diff(y_mat,axis=2)

        x_response = np.mean(d_x_mat/d_commands,axis=2)
        y_response = np.mean(d_y_mat/d_commands,axis=2)
        poke = np.vstack((x_response,y_response))
        ns = now_string()
        poke_fn = os.path.join(kcfg.poke_directory,'%s_poke.txt'%ns)
        command_fn = os.path.join(kcfg.poke_directory,'%s_currents.txt'%ns)
        chart_fn = os.path.join(kcfg.poke_directory,'%s_modes.pdf'%ns)
        np.savetxt(poke_fn,poke)
        np.savetxt(command_fn,commands)
        save_modes_chart(chart_fn,poke,commands,self.mirror.mirror_mask)

        self.poke = Poke(poke)
        
        time.sleep(1)
        self.unpause()
Exemple #6
0
 def record_reference(self):
     print 'recording reference'
     self.pause()
     xcent = []
     ycent = []
     for k in range(kcfg.reference_n_measurements):
         print 'measurement %d of %d'%(k+1,kcfg.reference_n_measurements),
         self.sense()
         print '...done'
         xcent.append(self.x_centroids)
         ycent.append(self.y_centroids)
         
     x_ref = np.array(xcent).mean(0)
     y_ref = np.array(ycent).mean(0)
     self.search_boxes = SearchBoxes(x_ref,y_ref,self.search_boxes.half_width)
     outfn = os.path.join(kcfg.reference_directory,prepend('coords.txt',now_string()))
     refxy = np.array((x_ref,y_ref)).T
     np.savetxt(outfn,refxy,fmt='%0.2f')
     self.unpause()
     time.sleep(1)
Exemple #7
0
 def log(self):
     outfn = os.path.join(kcfg.logging_directory,'sensor_%s.mat'%(now_string(True)))
     d = {}
     d['x_slopes'] = self.x_slopes
     d['y_slopes'] = self.y_slopes
     d['x_centroids'] = self.x_centroids
     d['y_centroids'] = self.y_centroids
     d['search_box_x1'] = self.search_boxes.x1
     d['search_box_x2'] = self.search_boxes.x2
     d['search_box_y1'] = self.search_boxes.y1
     d['search_box_y2'] = self.search_boxes.y2
     d['ref_x'] = self.search_boxes.x
     d['ref_y'] = self.search_boxes.y
     d['error'] = self.error
     d['tip'] = self.tip
     d['tilt'] = self.tilt
     d['wavefront'] = self.wavefront
     d['zernikes'] = self.zernikes
     
     sio.savemat(outfn,d)
Exemple #8
0
    def log(self):
        outfn = os.path.join(ccfg.logging_directory,
                             'sensor_%s.mat' % (now_string(True)))
        d = {}
        d['x_slopes'] = self.x_slopes
        d['y_slopes'] = self.y_slopes
        d['x_centroids'] = self.x_centroids
        d['y_centroids'] = self.y_centroids
        d['search_box_x1'] = self.search_boxes.x1
        d['search_box_x2'] = self.search_boxes.x2
        d['search_box_y1'] = self.search_boxes.y1
        d['search_box_y2'] = self.search_boxes.y2
        d['ref_x'] = self.search_boxes.x
        d['ref_y'] = self.search_boxes.y
        d['error'] = self.error
        d['tip'] = self.tip
        d['tilt'] = self.tilt
        d['wavefront'] = self.wavefront
        d['zernikes'] = self.zernikes

        sio.savemat(outfn, d)
Exemple #9
0
    def record_reference(self):
        print 'recording reference'
        self.pause()
        xcent = []
        ycent = []
        for k in range(ccfg.reference_n_measurements):
            print 'measurement %d of %d' % (k + 1,
                                            ccfg.reference_n_measurements),
            self.sense()
            print '...done'
            xcent.append(self.x_centroids)
            ycent.append(self.y_centroids)

        xcent = np.array(xcent)
        ycent = np.array(ycent)

        x_ref = xcent.mean(0)
        y_ref = ycent.mean(0)

        x_var = xcent.var(0)
        y_var = ycent.var(0)
        err = np.sqrt(np.mean([x_var, y_var]))
        print 'reference coordinate error %0.3e px RMS' % err

        self.search_boxes = SearchBoxes(x_ref, y_ref,
                                        self.search_boxes.half_width)
        refxy = np.array((x_ref, y_ref)).T

        # Record the new reference set to two locations, the
        # filename specified by reference_coordinates_filename
        # in ciao config, and also an archival filename to keep
        # track of the history.
        archive_fn = os.path.join(ccfg.reference_directory,
                                  prepend('reference.txt', now_string()))

        np.savetxt(archive_fn, refxy, fmt='%0.3f')
        np.savetxt(ccfg.reference_coordinates_filename, refxy, fmt='%0.3f')

        self.unpause()
        time.sleep(1)
Exemple #10
0
    def record_reference(self):
        print 'recording reference'
        self.pause()
        xcent = []
        ycent = []
        for k in range(ccfg.reference_n_measurements):
            print 'measurement %d of %d' % (k + 1,
                                            ccfg.reference_n_measurements),
            self.sense()
            print '...done'
            xcent.append(self.x_centroids)
            ycent.append(self.y_centroids)

        x_ref = np.array(xcent).mean(0)
        y_ref = np.array(ycent).mean(0)
        self.search_boxes = SearchBoxes(x_ref, y_ref,
                                        self.search_boxes.half_width)
        outfn = os.path.join(ccfg.reference_directory,
                             prepend('coords.txt', now_string()))
        refxy = np.array((x_ref, y_ref)).T
        np.savetxt(outfn, refxy, fmt='%0.2f')
        self.unpause()
        time.sleep(1)
Exemple #11
0
    def log0(self):
        t_string = now_string(True)

        #seconds = float(datetime.datetime.strptime(t_string,'%Y%m%d%H%M%S.%f').strftime('%s.%f'))
        outfn = os.path.join(ccfg.logging_directory,'sensor_%s.mat'%(t_string))
        d = {}
        #d['time_seconds'] = seconds
        d['x_slopes'] = self.x_slopes
        d['y_slopes'] = self.y_slopes
        d['x_centroids'] = self.x_centroids
        d['y_centroids'] = self.y_centroids
        d['search_box_x1'] = self.search_boxes.x1
        d['search_box_x2'] = self.search_boxes.x2
        d['search_box_y1'] = self.search_boxes.y1
        d['search_box_y2'] = self.search_boxes.y2
        d['ref_x'] = self.search_boxes.x
        d['ref_y'] = self.search_boxes.y
        d['error'] = np.squeeze(self.error)
        d['tip'] = self.tip
        d['tilt'] = self.tilt
        d['wavefront'] = self.wavefront
        d['zernikes'] = np.squeeze(self.zernikes)
        #d['spots_image'] = self.image
        sio.savemat(outfn,d)
Exemple #12
0
 def log(self):
     outfn = os.path.join(ccfg.logging_directory,
                          'mirror_%s.mat' % (now_string(True)))
     d = {}
     d['command'] = self.controller.command
     sio.savemat(outfn, d)
Exemple #13
0
    def run_poke(self):
        cmin = ccfg.poke_command_min
        cmax = ccfg.poke_command_max
        n_commands = ccfg.poke_n_command_steps
        commands = np.linspace(cmin, cmax, n_commands)

        self.pause()
        time.sleep(1)

        n_lenslets = self.sensor.n_lenslets
        n_actuators = self.mirror.n_actuators

        x_mat = np.zeros((n_lenslets, n_actuators, n_commands))
        y_mat = np.zeros((n_lenslets, n_actuators, n_commands))

        for k_actuator in range(n_actuators):
            self.mirror.flatten()
            for k_command in range(n_commands):
                cur = commands[k_command]
                #print k_actuator,cur
                self.mirror.set_actuator(k_actuator, cur)
                QApplication.processEvents()
                time.sleep(.01)
                self.sensor.sense()
                self.sensor_mutex.lock()
                x_mat[:, k_actuator, k_command] = self.sensor.x_slopes
                y_mat[:, k_actuator, k_command] = self.sensor.y_slopes
        # print 'done'
        self.mirror.flatten()

        d_commands = np.mean(np.diff(commands))
        d_x_mat = np.diff(x_mat, axis=2)
        d_y_mat = np.diff(y_mat, axis=2)

        x_response = np.mean(d_x_mat / d_commands, axis=2)
        y_response = np.mean(d_y_mat / d_commands, axis=2)
        poke = np.vstack((x_response, y_response))
        ns = now_string()

        # After we make a new poke matrix, we will save it in
        # two files: an archive file that can be used to keep
        # track of old poke matrices, and the file specified
        # in the config file, e.g., 'poke.txt'.
        # The archive filename will use the time date string
        # generated above. This filename will also be used to
        # save the commands and the mirror mode chart PDF.

        poke_fn = ccfg.poke_filename
        archive_poke_fn = os.path.join(ccfg.poke_directory, '%s_poke.txt' % ns)
        archive_command_fn = os.path.join(ccfg.poke_directory,
                                          '%s_currents.txt' % ns)
        archive_chart_fn = os.path.join(ccfg.poke_directory,
                                        '%s_modes.pdf' % ns)

        np.savetxt(poke_fn, poke)
        np.savetxt(archive_poke_fn, poke)
        np.savetxt(archive_command_fn, commands)
        save_modes_chart(archive_chart_fn, poke, commands,
                         self.mirror.mirror_mask)
        self.poke = Poke(poke)

        time.sleep(1)
        self.unpause()
Exemple #14
0
 def log(self):
     outfn = os.path.join(kcfg.logging_directory,'mirror_%s.mat'%(now_string(True)))
     d = {}
     d['command'] = self.controller.command
     sio.savemat(outfn,d)