Example #1
0
 def test_multiple_files(self):
     params = make_params()
     params.file_name = TEST_DIR
     find_rotation_axis(params)
     self.assertEqual(params.rotation_axis, 31.5)
     # Check YAML file
     with open(YAML_FILE, mode='r') as yfp:
         yaml_output = yaml.safe_load(yfp.read())
         self.assertEqual(yaml_output['test_tomogram.h5']['rotation-axis'],
                          31.5)
Example #2
0
def read_rot_center(params):
    """
    Read the rotation center from /process group in the DXchange file.
    Return: rotation center from this dataset or None if it doesn't exist.
    """
    log.info('  *** *** rotation axis')
    #First, try to read from the /process/tomopy-cli parameters
    with h5py.File(params.file_name, 'r') as file_name:
        try:
            dataset = '/process' + '/tomopy-cli-' + __version__ + '/' + 'find-rotation-axis' + '/' + 'rotation-axis'
            params.rotation_axis = float(file_name[dataset][0])
            log.info(
                '  *** *** Rotation center read from HDF5 file: {0:f}'.format(
                    params.rotation_axis))
            return params
        except (KeyError, ValueError):
            log.warning('  *** *** No rotation center stored in the HDF5 file')
    #If we get here, we need to either find it automatically or from config file.
    log.warning('  *** *** No rotation axis stored in DXchange file')
    if (params.rotation_axis_auto == True):
        log.warning('  *** *** Auto axis location requested')
        log.warning('  *** *** Computing rotation axis')
        params.rotation_axis = find_center.find_rotation_axis(params)
    log.info('  *** *** using config file value of {:f}'.format(
        params.rotation_axis))
    return params
Example #3
0
def read_rot_center(params):
    """
    Read the rotation center from /process group in the HDF file.
    Return: rotation center from this dataset or None if it doesn't exist.
    """
    log.info('  *** *** rotation axis')
    # Handle case of manual only: this is the easiest
    if params.rotation_axis_auto == 'manual':
        log.info('  *** *** Force use of config file value = {:f}'.format(
            params.rotation_axis))
    elif params.rotation_axis_auto == 'auto':
        log.info(
            '  *** *** Force auto calculation without reading config value')
        log.info('  *** *** Computing rotation axis')
        params = find_center.find_rotation_axis(params)
    else:
        # Try to read from HDF5 file
        log.info('  *** *** Try to read rotation center from file {}'.format(
            params.file_name))
        with h5py.File(params.file_name, 'r') as file_name:
            try:
                dataset = '/process/tomopy-cli-{}/find-rotation-axis/rotation-axis'.format(
                    __version__)
                params.rotation_axis = float(file_name[dataset][0])
                dataset = '/process/tomopy-cli-{}/find-rotation-axis/rotation-axis-flip'.format(
                    __version__)
                params.rotation_axis_flip = float(file_name[dataset][0])
                log.info(
                    '  *** *** Rotation center read from HDF5 file: {0:f}'.
                    format(params.rotation_axis))
                log.info(
                    '  *** *** Rotation center flip read from HDF5 file: {0:f}'
                    .format(params.rotation_axis_flip))
                return params
            except (KeyError, ValueError):
                log.warning(
                    '  *** *** No rotation center stored in the HDF5 file')
        # If we get here, we need to either find it automatically or from config file.
        log.warning('  *** *** No rotation axis stored in the HDF file')
        if (params.rotation_axis_auto == 'read_auto'):
            log.warning('  *** *** fall back to auto calculation')
            log.warning('  *** *** Computing rotation axis')
            params = find_center.find_rotation_axis(params)
        else:
            log.warning('  *** *** using config file value of {:f}'.format(
                params.rotation_axis))
    return params
Example #4
0
def run_find_center(args):
    if (str(args.file_format) in KNOWN_FORMATS):
        log.warning('find center start')
        args = find_center.find_rotation_axis(args)
        log.warning('find center end')
        # update tomopy.conf
        sections = config.RECON_PARAMS
        config.update_config(args, is_reconstruction=False)
    else:
        log.error("  *** %s is not a supported file format" % args.file_format)
        exit()
Example #5
0
 def test_single_file(self):
     params = make_params()
     find_rotation_axis(params)
     self.assertEqual(params.rotation_axis, 31.5)