Exemplo n.º 1
0
Arquivo: hdf_data.py Projeto: FHe/tdl
 def read_point(self,num):
     """
     read data from the point to self
     
     return all data as a dictionary
     
     num should be the whole serial number string,
     eg '000328'
     
     """
     #self._check_file()
     self.point = num
     self.point_dict = {}
     for key in GEN_KEYS:
         key_loc = GEN_KEYS[key]
         self.point_dict[key] = self.file[num][key_loc[0]][key_loc[1]]
     for key in self.file[num]['position_labels']:
         key_loc = list(self.file[num]['position_labels']).index(key)
         self.point_dict[key] = self.file[num]['position_values'][key_loc]
     for key in self.file[num]['scaler_labels']:
         key_loc = list(self.file[num]['scaler_labels']).index(key)
         self.point_dict[key] = self.file[num]['scaler_values'][key_loc]
     for key in ATT_KEYS:
         if key.startswith('hist'):
             key = key + '.' + str(self.version)
             self.point_dict['hist'] = self.file[num].attrs[key]
         else:
             self.point_dict[key] = self.file[num].attrs[key]
     for key in MISC_KEYS:
         self.point_dict[key] = self.file[num][key]
     current_det_num = 0
     while True:
         try:
             det_str = 'det_%i' % current_det_num
             current_det = self.file[num][det_str]
             self.point_dict[det_str] = {}
             for key in DET_KEYS:
                 key_loc = DET_KEYS[key]
                 key_loc_path = key_loc[0] % (current_det_num, self.version)
                 self.point_dict[det_str][key] = \
                         self.file[num][key_loc_path][key_loc[1]]
             for key in DET_ATT_KEYS:
                 self.point_dict[det_str][key] = \
                         self.file[num][det_str].attrs[key]
             try:
                 point_image = \
                         numpy.array(self.file[num][det_str]['image_data'])
                 self.point_dict[det_str]['image_data'] = point_image
                 point_mask = str(self.point_dict[det_str]['bad_pixel_map'])
                 if not point_mask.startswith('(') and \
                    not point_mask.startswith('['):
                     point_mask = str(image_data.read_pixel_map(point_mask))
                     self.point_dict[det_str]['bad_pixel_map'] = point_mask
                 corrected_image = image_data.correct_image(point_image,
                                                            point_mask)
                 self.point_dict[det_str]['corrected_image'] = \
                                                             corrected_image
             except:
                 pass
             current_det_num += 1
         except:
             break
Exemplo n.º 2
0
 def read_point(self, num):
     """
     read data from the point to self
     
     return all data as a dictionary
     
     num should be the whole serial number string,
     eg '000328'
     
     """
     #self._check_file()
     self.point = num
     self.point_dict = {}
     for key in GEN_KEYS:
         key_loc = GEN_KEYS[key]
         self.point_dict[key] = self.file[num][key_loc[0]][key_loc[1]]
     for key in self.file[num]['position_labels']:
         key_loc = list(self.file[num]['position_labels']).index(key)
         self.point_dict[key] = self.file[num]['position_values'][key_loc]
     for key in self.file[num]['scaler_labels']:
         key_loc = list(self.file[num]['scaler_labels']).index(key)
         self.point_dict[key] = self.file[num]['scaler_values'][key_loc]
     for key in ATT_KEYS:
         if key.startswith('hist'):
             key = key + '.' + str(self.version)
             self.point_dict['hist'] = self.file[num].attrs[key]
         else:
             self.point_dict[key] = self.file[num].attrs[key]
     for key in MISC_KEYS:
         self.point_dict[key] = self.file[num][key]
     current_det_num = 0
     while True:
         try:
             det_str = 'det_%i' % current_det_num
             current_det = self.file[num][det_str]
             self.point_dict[det_str] = {}
             for key in DET_KEYS:
                 key_loc = DET_KEYS[key]
                 key_loc_path = key_loc[0] % (current_det_num, self.version)
                 self.point_dict[det_str][key] = \
                         self.file[num][key_loc_path][key_loc[1]]
             for key in DET_ATT_KEYS:
                 self.point_dict[det_str][key] = \
                         self.file[num][det_str].attrs[key]
             try:
                 point_image = \
                         numpy.array(self.file[num][det_str]['image_data'])
                 self.point_dict[det_str]['image_data'] = point_image
                 point_mask = str(self.point_dict[det_str]['bad_pixel_map'])
                 if not point_mask.startswith('(') and \
                    not point_mask.startswith('['):
                     point_mask = str(image_data.read_pixel_map(point_mask))
                     self.point_dict[det_str]['bad_pixel_map'] = point_mask
                 corrected_image = image_data.correct_image(
                     point_image, point_mask)
                 self.point_dict[det_str]['corrected_image'] = \
                                                             corrected_image
             except:
                 pass
             current_det_num += 1
         except:
             break
Exemplo n.º 3
0
Arquivo: hdf_data.py Projeto: FHe/tdl
    def get_all(self, key, points=None):
        """
        Gets the value of key for every point in points.
        If points is None, gets the value for every point
        in the file. To tunnel, pass a tuple to key,
        eg HdfObject.get_all(('det_0', 'image_data'))
        
        To ensure the returned values are up to date, replaces
        the point's value (if appropriate) with the value in
        the current dictionary.
        
        """
        
        all_results = {}

        #if self.point != 0 and self.point_dict != {}:
        #    self.write_point(self.point_dict, self.point)

        if points == None:
            points = []
            for item in self.all_items:
                points.append(item[0])
        #for point in points:
        if isinstance(key, basestring):
            if key in GEN_KEYS:
                key_loc = GEN_KEYS[key]
                for point in points:
                    all_results[point] = \
                            self.file[point][key_loc[0]][key_loc[1]]
                if self.point in points:
                    all_results[self.point] = self.point_dict[key]
            elif key in ATT_KEYS:
                if key.startswith('hist'):
                    key = key + '.' + str(self.version)
                for point in points:
                    all_results[point] = self.file[point].attrs[key]
                if self.point in points:
                    if key.startswith('hist'):
                        all_results[self.point] = self.point_dict['hist']
                    else:
                        all_results[self.point] = self.point_dict[key]
            elif key in MISC_KEYS:
                for point in points:
                    all_results[point] = self.file[point][key]
                if self.point in points:
                    all_results[self.point] = self.point_dict[key]
            else:
                for point in points:
                    if key in self.file[point]['position_labels']:
                        key_loc = \
                          list(self.file[point]['position_labels']).index(key)
                        all_results[point] = \
                                self.file[point]['position_values'][key_loc]
                    elif key in self.file[point]['scaler_labels']:
                        key_loc = \
                          list(self.file[point]['scaler_labels']).index(key)
                        all_results[point] = \
                                self.file[point]['scaler_values'][key_loc]
                    else:
                        print 'Unrecognized Key Error: ' , key
                if self.point in points and key in self.point_dict.keys():
                    all_results[self.point] = self.point_dict[key]
        elif isinstance(key, tuple):
            det_name = key[0]
            key = key[1]
            if key in DET_KEYS:
                key_loc = DET_KEYS[key]
                key_loc_path = key_loc[0].split('/')[1] % self.version
                for point in points:
                    all_results[point] = \
                            self.file[point][det_name][key_loc_path][key_loc[1]]
                if self.point in points:
                    all_results[self.point] = self.point_dict[det_name][key]
            elif key in DET_ATT_KEYS:
                for point in points:
                    all_results[point] = self.file[point][det_name].attrs[key]
                if self.point in points:
                    all_results[self.point] = self.point_dict[det_name][key]
            elif key.startswith('image_data'):
                for point in points:
                    try:
                        all_results[point] = self.file[point][det_name][key]
                    except:
                        pass
            elif key.startswith('corrected_image'):
                for point in points:
                    try:
                        point_image = \
                          numpy.array(self.file[point][det_name]['image_data'])
                        bpm_loc = DET_KEYS['bad_pixel_map']
                        current_corr = bpm_loc[0].split('/')[1] % self.version
                        point_mask = str(self.file[point][det_name]\
                                                  [current_corr][bpm_loc[1]])
                        if not point_mask.startswith('(') and \
                           not point_mask.startswith('['):
                            point_mask = \
                                    str(image_data.read_pixel_map(point_mask))
                        all_results[point] = \
                                image_data.correct_image(point_image,
                                                         point_mask)
                    except:
                        pass
                if self.point in points:
                    all_results[self.point] = self.point_dict[det_name][key]
            else:
                print 'Error: unrecognized key'
        else:
            print 'Error: unknown key type'
        return all_results
Exemplo n.º 4
0
    def get_all(self, key, points=None):
        """
        Gets the value of key for every point in points.
        If points is None, gets the value for every point
        in the file. To tunnel, pass a tuple to key,
        eg HdfObject.get_all(('det_0', 'image_data'))
        
        To ensure the returned values are up to date, replaces
        the point's value (if appropriate) with the value in
        the current dictionary.
        
        """

        all_results = {}

        #if self.point != 0 and self.point_dict != {}:
        #    self.write_point(self.point_dict, self.point)

        if points == None:
            points = []
            for item in self.all_items:
                points.append(item[0])
        #for point in points:
        if isinstance(key, basestring):
            if key in GEN_KEYS:
                key_loc = GEN_KEYS[key]
                for point in points:
                    all_results[point] = \
                            self.file[point][key_loc[0]][key_loc[1]]
                if self.point in points:
                    all_results[self.point] = self.point_dict[key]
            elif key in ATT_KEYS:
                if key.startswith('hist'):
                    key = key + '.' + str(self.version)
                for point in points:
                    all_results[point] = self.file[point].attrs[key]
                if self.point in points:
                    if key.startswith('hist'):
                        all_results[self.point] = self.point_dict['hist']
                    else:
                        all_results[self.point] = self.point_dict[key]
            elif key in MISC_KEYS:
                for point in points:
                    all_results[point] = self.file[point][key]
                if self.point in points:
                    all_results[self.point] = self.point_dict[key]
            else:
                for point in points:
                    if key in self.file[point]['position_labels']:
                        key_loc = \
                          list(self.file[point]['position_labels']).index(key)
                        all_results[point] = \
                                self.file[point]['position_values'][key_loc]
                    elif key in self.file[point]['scaler_labels']:
                        key_loc = \
                          list(self.file[point]['scaler_labels']).index(key)
                        all_results[point] = \
                                self.file[point]['scaler_values'][key_loc]
                    else:
                        print 'Unrecognized Key Error: ', key
                if self.point in points and key in self.point_dict.keys():
                    all_results[self.point] = self.point_dict[key]
        elif isinstance(key, tuple):
            det_name = key[0]
            key = key[1]
            if key in DET_KEYS:
                key_loc = DET_KEYS[key]
                key_loc_path = key_loc[0].split('/')[1] % self.version
                for point in points:
                    all_results[point] = \
                            self.file[point][det_name][key_loc_path][key_loc[1]]
                if self.point in points:
                    all_results[self.point] = self.point_dict[det_name][key]
            elif key in DET_ATT_KEYS:
                for point in points:
                    all_results[point] = self.file[point][det_name].attrs[key]
                if self.point in points:
                    all_results[self.point] = self.point_dict[det_name][key]
            elif key.startswith('image_data'):
                for point in points:
                    try:
                        all_results[point] = self.file[point][det_name][key]
                    except:
                        pass
            elif key.startswith('corrected_image'):
                for point in points:
                    try:
                        point_image = \
                          numpy.array(self.file[point][det_name]['image_data'])
                        bpm_loc = DET_KEYS['bad_pixel_map']
                        current_corr = bpm_loc[0].split('/')[1] % self.version
                        point_mask = str(self.file[point][det_name]\
                                                  [current_corr][bpm_loc[1]])
                        if not point_mask.startswith('(') and \
                           not point_mask.startswith('['):
                            point_mask = \
                                    str(image_data.read_pixel_map(point_mask))
                        all_results[point] = \
                                image_data.correct_image(point_image,
                                                         point_mask)
                    except:
                        pass
                if self.point in points:
                    all_results[self.point] = self.point_dict[det_name][key]
            else:
                print 'Error: unrecognized key'
        else:
            print 'Error: unknown key type'
        return all_results