示例#1
0
def build_universal_config(config_dir):
    """
    Build uni_config.yaml in the config_dir

    :param config_dir: directory where  exp_description.yaml
    :raise:
    """
    config_yaml_filename = os.path.join(config_dir,'exp_description.yaml')
    res=yamlutils.read_yaml(config_yaml_filename)[0]
    #    pprint(res)

    if not 'frames' in res:
        logging.error(str.format('Section FRAMES not found in config file {0}',config_yaml_filename))
        raise AttributeError
    uc = UniversalConfigBuilder()
    #TODO: fix this hack
    uc.add_section({'preprocess_config': res['preprocess_config']})
    uc.add_section({'description': res['description']})
    groups = get_groups(res['frames'])
    start_data_angle=0
    for group_name in natsorted(groups.keys()):
        group = groups[group_name]
        files,start_data_angle = get_files_in_group(group, root=config_dir, start_data_angle=start_data_angle)
        for f in files:
            uc.add_frame(group_name=group_name, frame_type=f['type'], file_name=f['name'],
                image_format=f['image_format'], angle=f['angle'], exposure_time=f['exposure_time'],
                rotation_angle=f['rotation_angle'])
    uc.save2yaml(os.path.join(config_dir,'uni_config.yaml'))
示例#2
0
def build_universal_config(config_dir):
    """
    Build uni_config.yaml in the config_dir

    :param config_dir: directory where  exp_description.yaml
    :raise:
    """
    config_yaml_filename = os.path.join(config_dir,'exp_description.yaml')
    res=yamlutils.read_yaml(config_yaml_filename)[0]
    #    pprint(res)

    if not 'frames' in res:
        logging.error(str.format('Section FRAMES not found in config file {0}',config_yaml_filename))
        raise AttributeError
    uc = UniversalConfigBuilder()
    #TODO: fix this hack
    uc.add_section({'preprocess_config': res['preprocess_config']})
    uc.add_section({'description': res['description']})
    files=get_files(config_dir)
    for f in files:
        uc.add_frame(group_name='0', frame_type=f['type'], file_name=f['name'],
            image_format=f['image_format'], angle=f['angle'], exposure_time=f['exposure_time'],
            rotation_angle=0)
    #add dark type by value
    if 'dark_value' in res['frames']:
        uc.add_frame(group_name='0', frame_type='dark', file_name=res['frames']['dark_value'],
            image_format='number', angle=0, exposure_time=1, rotation_angle=0)
    uc.save2yaml(os.path.join(config_dir,'uni_config.yaml'))
示例#3
0
def build_universal_config(config_dir):
    """
    Build uni_config.yaml in the config_dir

    :param config_dir: directory where  exp_description.yaml
    :raise:
    """
    config_yaml_filename = os.path.join(config_dir,'exp_description.yaml')
    res=yamlutils.read_yaml(config_yaml_filename)[0]
    #    pprint(res)

    if not 'frames' in res:
        logging.error(str.format('Section FRAMES not found in config file {0}',config_yaml_filename))
        raise AttributeError
    uc = UniversalConfigBuilder()
    #TODO: fix this hack
    uc.add_section({'preprocess_config': res['preprocess_config']})
    uc.add_section({'description': res['description']})
    data_dir=os.path.join(config_dir,'Data')
    files=glob.glob(os.path.join(data_dir,'*.tif'))
    for f_path in sorted(files):
        fname=os.path.split(f_path)[-1]
        f_prefix=fname.split('.')[0]
        if f_prefix=='eb':
            uc.add_frame(group_name='0',frame_type='empty',file_name=f_path,image_format='tiff',angle=0)
        elif f_prefix=='dc':
            uc.add_frame(group_name='0',frame_type='dark',file_name=f_path,image_format='tiff',angle=0)
        else:
            angle=float(f_prefix.replace(',','.'))
            uc.add_frame(group_name='0',frame_type='data',file_name=f_path,image_format='tiff',angle=angle)
    uc.save2yaml(os.path.join(config_dir,'uni_config.yaml'))
示例#4
0
def get_profile_name(data_root):
    """
    Get profile name from **exp_description.yaml** file

    :param data_root:
    :return:
    """
    config_yaml_filename=os.path.join(data_root,'exp_description.yaml')
    config=read_yaml(config_yaml_filename)[0]
    tomo_profile=config['profile']
    return tomo_profile
示例#5
0
def preprocess_and_save_all_data(data_root, res_folder, tomo_profile=None):
    """
    Preprocess all data (build universal config, normalize, shift, rotate, save to hdf5)
    :param data_root:
    :param res_folder:
    :param tomo_profile:
    :return:
    :raise:
    """
    if tomo_profile is None:
        tomo_profile = get_profile_name(data_root)
    if  tomo_profile == 'amur':
        from tomofrontend.profiles.amur_config import build_universal_config
    elif tomo_profile == 'senin':
        from tomofrontend.profiles.senin_config import build_universal_config
    elif tomo_profile == 'mediana':
        from tomofrontend.profiles.mediana_config import build_universal_config
    else:
        raise NameError, str.format('Unknown profile type {0}', tomo_profile)

    build_universal_config(data_root)

    config = read_yaml(os.path.join(data_root, 'uni_config.yaml'))[0]

    image_process_config = config['preprocess_config']

    frames_groups = config['frames']

    normalized_data = get_normalized_frames(frames_groups, image_process_config)

    op_ind = get_index_opposite_files(normalized_data)
    data0 = normalized_data[op_ind[0]]['data']
    data1 = numpy.fliplr(normalized_data[op_ind[1]]['data'])
    data0 = my_filter(data0)
    data1 = my_filter(data1)

    sh_ang = find_shift_and_rotation(data0, data1, image_process_config, res_folder)
    shift_val = sh_ang['shift']
    angle_val = sh_ang['angle']

    pixel_size = image_process_config['pixel_size']

    fix_axis_position(angle_val, shift_val, normalized_data, pixel_size)

    h5_postprocess_file = os.path.join(res_folder, 'postproc_data.h5')

    save_frames_hdf5(normalized_data, h5_postprocess_file)

    return h5_postprocess_file
示例#6
0
def get_files(config_dir):
    tomo_log=yamlutils.read_yaml(os.path.join(config_dir,'log.txt'))[0]
    files=[]

    data_files=tomo_log['---Data']
    frames_folder='Data'
    for f in data_files:
        tmp_frame = get_frame(config_dir, f, frames_folder,'data')
        files.append(tmp_frame)

    empty_files=tomo_log['---Empty']
    frames_folder='Background'
    for f in empty_files:
        tmp_frame = get_frame(config_dir, f, frames_folder,'empty')
        files.append(tmp_frame)

    return files
示例#7
0
def test_yaml_reader():
    test_yaml_filename = '/media/WD_ext4/bones/ikran/2012_02_02/F1-M2/exp_description.yaml'
    res=yamlutils.read_yaml(test_yaml_filename)
    pprint(list(res))
示例#8
0
 def load_tomo_config(self):
     tomo_dir=self.get_full_path()
     tomo_config = os.path.join(tomo_dir, 'original', 'exp_description.yaml')
     self['config']=read_yaml(tomo_config)[0]