Example #1
0
def read_pixel_size(params):
    '''
    Read the pixel size and magnification from the HDF file.
    Use to compute the effective pixel size.
    '''
    log.info('  *** auto pixel size reading')
    if params.pixel_size_auto != True:
        log.info('  *** *** OFF')
        return params
    
    if check_item_exists_hdf(params.file_name,
                                '/measurement/instrument/detection_system/objective/resolution'):
        params.pixel_size = config.param_from_dxchange(params.file_name,
                                            '/measurement/instrument/detection_system/objective/resolution')
        log.info('  *** *** effective pixel size = {:6.4e} microns'.format(params.pixel_size))
        return(params)
    log.warning('  *** tomoScan resolution parameter not found.  Try old format')
    pixel_size = config.param_from_dxchange(params.file_name,
                                            '/measurement/instrument/detector/pixel_size_x')
    mag = config.param_from_dxchange(params.file_name,
                                    '/measurement/instrument/detection_system/objective/magnification')
    #Handle case where something wasn't read right
    if not (pixel_size and mag):
        log.warning('  *** *** problem reading pixel size from the HDF file')
        return params
    #What if pixel size isn't in microns, but in mm or m?
    for i in range(3):
        if pixel_size < 0.5:
            pixel_size *= 1e3
        else:
            break
    params.pixel_size = pixel_size / mag
    log.info('  *** *** effective pixel size = {:6.4e} microns'.format(params.pixel_size))
    return params
Example #2
0
def read_bright_ratio(params):
    '''Read the ratio between the bright exposure and other exposures.
    '''
    log.info('  *** *** %s' % params.flat_correction_method)
    if params.flat_correction_method != 'standard' or (
            not params.scintillator_auto):
        log.warning('  *** *** skip finding exposure ratio')
        params.bright_exp_ratio = 1
        return params
    log.info('  *** *** Find bright exposure ratio params from the HDF file')
    try:
        if check_item_exists_hdf(
                params.file_name,
                '/measurement/instrument/detector/different_flat_exposure'):
            diff_bright_exp = config.param_from_dxchange(
                params.file_name,
                '/measurement/instrument/detector/different_flat_exposure',
                attr=None,
                scalar=False,
                char_array=True)
            if diff_bright_exp.lower() == 'same':
                log.error('  *** *** used same flat and data exposures')
                params.bright_exp_ratio = 1
                return params
        if check_item_exists_hdf(
                params.file_name,
                '/measurement/instrument/detector/exposure_time_flat'):
            bright_exp = config.param_from_dxchange(
                params.file_name,
                '/measurement/instrument/detector/exposure_time_flat',
                attr=None,
                scalar=True,
                char_array=False)
        else:
            bright_exp = config.param_from_dxchange(
                params.file_name,
                '/measurement/instrument/detector/brightfield_exposure_time',
                attr=None,
                scalar=True,
                char_array=False)
        log.info('  *** *** %f' % bright_exp)
        norm_exp = config.param_from_dxchange(
            params.file_name,
            '/measurement/instrument/detector/exposure_time',
            attr=None,
            scalar=True,
            char_array=False)
        log.info('  *** *** %f' % norm_exp)
        params.bright_exp_ratio = bright_exp / norm_exp
        log.info('  *** *** found bright exposure ratio of {0:6.4f}'.format(
            params.bright_exp_ratio))
    except:
        log.warning('  *** *** problem getting bright exposure ratio.  Use 1.')
        params.bright_exp_ratio = 1
    return params
Example #3
0
def read_scintillator(params):
    '''Read the scintillator type and thickness from the HDF file.
    '''
    if params.scintillator_auto:
        log.info('  *** auto reading scintillator params')
        dataset_name = '/measurement/instrument/detection_system/scintillator/scintillating_thickness'
        val = config.param_from_dxchange(params.file_name,
                                         dataset_name,
                                         attr=None,
                                         scalar=True,
                                         char_array=False)
        params.scintillator_thickness = float(val)
        log.info('  *** *** scintillator thickness = {:f}'.format(
            params.scintillator_thickness))
        tomoscan_path = '/measurement/instrument/detection_system/scintillator/name'
        scint_material_string = ''
        try:
            scint_material_string = config.param_from_dxchange(
                params.file_name, tomoscan_path, scalar=False, char_array=True)
        except KeyError:
            log.warning(
                '  *** *** scintillator material not in tomoscan form.  Try old format'
            )
        if not scint_material_string:
            old_path = '/measurement/instrument/detection_system/scintillator/description'
            try:
                scint_material_string = config.param_from_dxchange(
                    params.file_name, old_path, scalar=False, char_array=True)
            except KeyError:
                log.warning('  *** *** no scintillator material found')
                return (params)
        if scint_material_string.lower().startswith('luag'):
            params.scintillator_material = 'LuAG_Ce'
        elif scint_material_string.lower().startswith('lyso'):
            params.scintillator_material = 'LYSO_Ce'
        elif scint_material_string.lower().startswith('yag'):
            params.scintillator_material = 'YAG_Ce'
        else:
            log.warning('  *** *** scintillator {:s} not recognized!'.format(
                scint_material_string))
        log.info('  *** *** using scintillator {:s}'.format(
            params.scintillator_material))
    # Run the initialization for beam hardening.  Needed in case
    # rotation_axis must be computed later.
    # if params.beam_hardening_method.lower() == 'standard':
    #     beamhardening.initialize(params)
    return params
Example #4
0
def read_filter_materials_old(params):
    '''Read the beam filter configuration from the HDF file.
    
    If params.filter_1_material and/or params.filter_2_material are
    'auto', then try to read the filter configuration recorded during
    acquisition in the HDF5 file.
    
    Parameters
    ==========
    params
    
      The global parameter object, should have *filter_1_material*,
      *filter_1_thickness*, *filter_2_material*, and
      *filter_2_thickness* attributes.
    
    Returns
    =======
    params
      An equivalent object to the *params* input, optionally with
      *filter_1_material*, *filter_1_thickness*, *filter_2_material*,
      and *filter_2_thickness* attributes modified to reflect the HDF5
      file.
    
    '''
    log.info('  *** auto reading filter configuration')
    # Read the relevant data from disk
    filter_path = '/measurement/instrument/filters/Filter_{idx}_Material'
    param_path = 'filter_{idx}_{attr}'
    for idx_filter in (1, 2):
        filter_param = getattr(
            params, param_path.format(idx=idx_filter, attr='material'))
        if filter_param == 'auto':
            # Read recorded filter condition from the HDF5 file
            filter_str = config.param_from_dxchange(
                params.file_name,
                filter_path.format(idx=idx_filter),
                char_array=True,
                scalar=False)
            if filter_str is None:
                log.warning(
                    '  *** *** Could not load filter %d configuration from HDF5 file.'
                    % idx_filter)
                material, thickness = _filter_str_to_params('Open')
            else:
                material, thickness = _filter_str_to_params(filter_str)
            # Update the params with the loaded values
            setattr(params, param_path.format(idx=idx_filter, attr='material'),
                    material)
            setattr(params, param_path.format(idx=idx_filter,
                                              attr='thickness'), thickness)
            log.info('  *** *** Filter %d: (%s %f)' %
                     (idx_filter, material, thickness))
    return params
Example #5
0
def read_scintillator(params):
    '''Read the scintillator type and thickness from DXchange.
    '''
    if params.scintillator_auto and params.beam_hardening_method.lower(
    ) == 'standard':
        log.info('  *** *** Find scintillator params from DXchange')
        params.scintillator_thickness = float(
            config.param_from_dxchange(
                params.file_name,
                '/measurement/instrument/detection_system/scintillator/scintillating_thickness',
                attr=None,
                scalar=True,
                char_array=False))
        log.info('  *** *** scintillator thickness = {:f}'.format(
            params.scintillator_thickness))
        scint_material_string = config.param_from_dxchange(
            params.file_name,
            '/measurement/instrument/detection_system/scintillator/description',
            scalar=False,
            char_array=True)
        if scint_material_string.lower().startswith('luag'):
            params.scintillator_material = 'LuAG_Ce'
        elif scint_material_string.lower().startswith('lyso'):
            params.scintillator_material = 'LYSO_Ce'
        elif scint_material_string.lower().startswith('yag'):
            params.scintillator_material = 'YAG_Ce'
        else:
            log.warning('  *** *** scintillator {:s} not recognized!'.format(
                scint_material_string))
        log.warning('  *** *** using scintillator {:s}'.format(
            params.scintillator_material))
    #Run the initialization for beam hardening.  Needed in case rotation_axis must
    #be computed later.
    if params.beam_hardening_method.lower() == 'standard':
        beamhardening.initialize(params)
    return params
Example #6
0
def read_filter_materials_tomoscan(params):
    '''Read the beam filter configuration from the HDF file.
    
    If params.filter_{n}_auto for n in [1,2,3] is True,
    then try to read the filter configuration recorded during
    acquisition in the HDF5 file.
    
    Parameters
    ==========
    params
    
      The global parameter object, should have *filter_n_material*,
      *filter_n_thickness*, and *filter_n_auto* for n in [1,2,3]
    
    Returns
    =======
    params
      An equivalent object to the *params* input, optionally with
      *filter_n_material* and *filter_n_thickness*
      attributes modified to reflect the HDF5 file.
    
    '''
    log.info('  *** auto reading filter configuration')
    # Read the relevant data from disk
    filter_path = '/measurement/instrument/attenuator_{idx}'
    param_path = 'filter_{idx}_{attr}'
    for idx_filter in range(1, 4, 1):
        if not check_item_exists_hdf(params.file_name,
                                     filter_path.format(idx=idx_filter)):
            log.warning(
                '  *** *** Filter {idx} not found in HDF file.  Set this filter to none'
                .format(idx=idx_filter))
            setattr(params, param_path.format(idx=idx_filter, attr='material'),
                    'Al')
            setattr(params, param_path.format(idx=idx_filter,
                                              attr='thickness'), 0.0)
            continue
        filter_auto = getattr(params,
                              param_path.format(idx=idx_filter, attr='auto'))
        if filter_auto != 'True' and filter_auto != True:
            log.warning(
                '  *** *** do not auto read filter {n}'.format(n=idx_filter))
            continue
        log.warning('  *** *** auto reading parameters for filter {0}'.format(
            idx_filter))
        # See if there are description and thickness fields
        if check_item_exists_hdf(
                params.file_name,
                filter_path.format(idx=idx_filter) + '/description'):
            filt_material = config.param_from_dxchange(
                params.file_name,
                filter_path.format(idx=idx_filter) + '/description',
                char_array=True,
                scalar=False)
            filt_thickness = int(
                config.param_from_dxchange(params.file_name,
                                           filter_path.format(idx=idx_filter) +
                                           '/thickness',
                                           char_array=False,
                                           scalar=True))
        else:
            #The filter info is just the raw string from the filter unit.
            log.warning(
                '  *** *** filter {idx} info must be read from the raw string'.
                format(idx=idx_filter))
            filter_str = config.param_from_dxchange(
                params.file_name,
                filter_path.format(idx=idx_filter) + '/setup/filter_unit_text',
                char_array=True,
                scalar=False)
            if filter_str is None:
                log.warning(
                    '  *** *** Could not load filter %d configuration from HDF5 file.'
                    % idx_filter)
                filt_material, filt_thickness = _filter_str_to_params('Open')
            else:
                filt_material, filt_thickness = _filter_str_to_params(
                    filter_str)

        # Update the params with the loaded values
        setattr(params, param_path.format(idx=idx_filter, attr='material'),
                filt_material)
        setattr(params, param_path.format(idx=idx_filter, attr='thickness'),
                filt_thickness)
        log.info('  *** *** Filter %d: (%s %f)' %
                 (idx_filter, filt_material, filt_thickness))
    return params