def get_files_in_group(group,root='.',start_data_angle=0): """ Get files in each group. :param group: :param root: :param start_data_angle: :return: """ files=[] stop_data_angle=start_data_angle for type_key in ['dark','data','empty']: if type_key in group: if 'filesnames' in group[type_key]: if 'regexp' in group[type_key]['filesnames']: cur_root=root fname_pattern=group[type_key]['filesnames']['regexp'] if 'folder' in group: cur_root=os.path.join(cur_root,group['folder']) delta_angle=get_value(group,[type_key,],'angles_step') exp_time=get_value(group,[type_key,],'exposure_time') rotation_angle=get_value(group,[type_key,],'rotation_angle') image_format=try_get_value(group,[type_key,],'image_format','fits') frames_per_angle=try_get_value(group,[type_key,],'frames_per_angle',1) tmp_files_names_list=glob.glob(os.path.join(cur_root,fname_pattern)) tmp_files_names_list=natsorted(tmp_files_names_list) tmp_files_list=[] for ef,f in enumerate(tmp_files_names_list): if type_key=='data': angle=start_data_angle+delta_angle*((ef-ef%frames_per_angle)/frames_per_angle) stop_data_angle=start_data_angle+delta_angle*(((ef+1)-(ef+1)%frames_per_angle)/frames_per_angle) else: angle=0 td= {'name': f, 'angle': angle, 'exposure_time': exp_time, 'type': type_key, 'rotation_angle': rotation_angle, 'image_format': image_format} tmp_files_list.append(td) files.extend(tmp_files_list) return files, stop_data_angle
def get_groups(config): """ Return dictionary of files groups. :param config: :return: Dictionary of files groups. :raise: """ known_keys=('exposure_time','folder','angles_step','image_format','rotation_angle','frames_per_angle') if not 'groups' in config: logging.error('Section GROUPS not found in config file') raise AttributeError res={} for group_name in config['groups']: tmp_grp= dict(config['groups'][group_name]) try: for key in config: if not key in tmp_grp: if key in known_keys: tmp_grp[key]=get_value(config,['groups',group_name],key) except KeyError: pass res[group_name]=tmp_grp return res