Exemplo n.º 1
0
def read_diamond_l12(fname, ind_tomo, proj=None):
    """
    Read Diamond Light Source L12 (JEEP) standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'im_001000.tif')
    flat_name = os.path.join(fname, 'flat_000000.tif')
    ind_flat = list(range(0, 1))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo)
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat)
    return tomo, flat
Exemplo n.º 2
0
def read_diamond_l12(fname, ind_tomo):
    """
    Read Diamond Light Source L12 (JEEP) standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'im_001000.tif')
    flat_name = os.path.join(fname, 'flat_000000.tif')
    ind_flat = list(range(0, 1))
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, digit=6)
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, digit=6)
    return tomo, flat
Exemplo n.º 3
0
def read_diamond_l12(fname, ind_tomo):
    """
    Read Diamond Light Source L12 (JEEP) standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'im_001000.tif')
    flat_name = os.path.join(fname, 'flat_000000.tif')
    ind_flat = list(range(0, 1))
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, digit=6)
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, digit=6)
    return tomo, flat
Exemplo n.º 4
0
def read_petraIII_p05(fname,
                      ind_tomo,
                      ind_flat,
                      ind_dark,
                      proj=None,
                      sino=None):
    """
    Read Petra-III P05 standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'scan_0002', 'ccd', 'pco01',
                             'ccd_0000.tif')
    flat_name = os.path.join(fname, 'scan_0001', 'ccd', 'pco01',
                             'ccd_0000.tif')
    dark_name = os.path.join(fname, 'scan_0000', 'ccd', 'pco01',
                             'ccd_0000.tif')
    tomo = dxreader.read_tiff_stack(tomo_name,
                                    ind=ind_tomo,
                                    digit=4,
                                    slc=(sino, proj))
    flat = dxreader.read_tiff_stack(flat_name,
                                    ind=ind_flat,
                                    digit=4,
                                    slc=(sino, None))
    dark = dxreader.read_tiff_stack(dark_name,
                                    ind=ind_dark,
                                    digit=4,
                                    slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 5
0
def read_diamond_l12(fname, ind_tomo, proj=None):
    """
    Read Diamond Light Source L12 (JEEP) standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'im_001000.tif')
    flat_name = os.path.join(fname, 'flat_000000.tif')
    ind_flat = list(range(0, 1))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo)
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat)
    return tomo, flat
Exemplo n.º 6
0
def read_elettra_syrmep(fname,
                        ind_tomo,
                        ind_flat,
                        ind_dark,
                        proj=None,
                        sino=None):
    """
    Read Elettra SYRMEP standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'tomo_0001.tif')
    flat_name = os.path.join(fname, 'flat_1.tif')
    dark_name = os.path.join(fname, 'dark_1.tif')
    tomo = dxreader.read_tiff_stack(tomo_name,
                                    ind=ind_tomo,
                                    digit=4,
                                    slc=(sino, proj))
    flat = dxreader.read_tiff_stack(flat_name,
                                    ind=ind_flat,
                                    digit=1,
                                    slc=(sino, None))
    dark = dxreader.read_tiff_stack(dark_name,
                                    ind=ind_dark,
                                    digit=1,
                                    slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 7
0
def read_anka_topotomo(fname,
                       ind_tomo,
                       ind_flat,
                       ind_dark,
                       proj=None,
                       sino=None):
    """
    Read ANKA TOMO-TOMO standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    ind_flat : list of int, optional
        Indices of the flat field files to read.

    ind_dark : list of int, optional
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'radios', 'image_00000.tif')
    flat_name = os.path.join(fname, 'flats', 'image_00000.tif')
    dark_name = os.path.join(fname, 'darks', 'image_00000.tif')
    tomo = dxreader.read_tiff_stack(tomo_name,
                                    ind=ind_tomo,
                                    digit=5,
                                    slc=(sino, proj))
    flat = dxreader.read_tiff_stack(flat_name,
                                    ind=ind_flat,
                                    digit=5,
                                    slc=(sino, None))
    dark = dxreader.read_tiff_stack(dark_name,
                                    ind=ind_dark,
                                    digit=5,
                                    slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 8
0
def read_petraIII_p05(
        fname, ind_tomo, ind_flat, ind_dark, proj=None, sino=None):
    """
    Read Petra-III P05 standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(
        fname, 'scan_0002', 'ccd', 'pco01', 'ccd_0000.tif')
    flat_name = os.path.join(
        fname, 'scan_0001', 'ccd', 'pco01', 'ccd_0000.tif')
    dark_name = os.path.join(
        fname, 'scan_0000', 'ccd', 'pco01', 'ccd_0000.tif')
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    tomo = dxreader.read_tiff_stack(
        tomo_name, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(
        flat_name, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(
        dark_name, ind=ind_dark, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 9
0
def read_aus_microct(fname,
                     ind_tomo,
                     ind_flat,
                     ind_dark,
                     proj=None,
                     sino=None):
    """
    Read Australian Synchrotron micro-CT standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'SAMPLE_T_0000.tif')
    flat_name = os.path.join(fname, 'BG__BEFORE_00.tif')
    dark_name = os.path.join(fname, 'DF__BEFORE_00.tif')

    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(dark_name, ind=ind_dark, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 10
0
def read_aus_microct(fname, ind_tomo, ind_flat, ind_dark, proj=None, sino=None):
    """
    Read Australian Synchrotron micro-CT standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'SAMPLE_T_0000.tif')
    flat_name = os.path.join(fname, 'BG__BEFORE_00.tif')
    dark_name = os.path.join(fname, 'DF__BEFORE_00.tif')

    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    tomo = dxreader.read_tiff_stack(
        tomo_name, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(
        flat_name, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(
        dark_name, ind=ind_dark, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 11
0
def read_anka_topotomo(
        fname, ind_tomo, ind_flat, ind_dark, proj=None, sino=None):
    """
    Read ANKA TOPO-TOMO standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder name without indices and extension.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int, optional
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'radios', 'image_00000.tif')
    flat_name = os.path.join(fname, 'flats', 'image_00000.tif')
    dark_name = os.path.join(fname, 'darks', 'image_00000.tif')
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    tomo = dxreader.read_tiff_stack(
        tomo_name, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(
        flat_name, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(
        dark_name, ind=ind_dark, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 12
0
def read_aps_5bm(fname, sino=None):
    """
    Read APS 5-BM standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'sdat0000.xmt')
    flat_name = os.path.join(fname, 'snor0000.xmt')
    dark_name = os.path.join(fname, 'sdarkfile.xmt')


    ntomo = len(fnmatch.filter(os.listdir(fname), 'sdat*'))
    ind_tomo = range(0, ntomo)
    nflat = len(fnmatch.filter(os.listdir(fname), 'snor*'))
    ind_flat = range(0, nflat)

    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff(dark_name, slc=(sino, None))

    # array bite swapping
    for index in ind_tomo:
        tomo[index] = tomo[index].byteswap()

    for index in ind_flat:
        flat[index] = flat[index].byteswap()

    dark = dark.byteswap()

    return tomo, flat, dark
Exemplo n.º 13
0
def read_aps_5bm(fname, sino=None):
    """
    Read APS 5-BM standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'sdat0000.xmt')
    flat_name = os.path.join(fname, 'snor0000.xmt')
    dark_name = os.path.join(fname, 'sdarkfile.xmt')


    ntomo = len(fnmatch.filter(os.listdir(fname), 'sdat*'))
    ind_tomo = range(0, ntomo)
    nflat = len(fnmatch.filter(os.listdir(fname), 'snor*'))
    ind_flat = range(0, nflat)

    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff(dark_name, slc=(sino, None))

    # array bite swapping
    for index in ind_tomo:
        tomo[index] = tomo[index].byteswap()

    for index in ind_flat:
         flat[index] = flat[index].byteswap()

    dark = dark.byteswap()

    return tomo, flat, dark
Exemplo n.º 14
0
def read_elettra_syrmep(
        fname, ind_tomo, ind_flat, ind_dark, proj=None, sino=None):
    """
    Read Elettra SYRMEP standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'tomo_0001.tif')
    flat_name = os.path.join(fname, 'flat_1.tif')
    dark_name = os.path.join(fname, 'dark_1.tif')
    tomo = dxreader.read_tiff_stack(
        tomo_name, ind=ind_tomo, digit=4, slc=(sino, proj))
    flat = dxreader.read_tiff_stack(
        flat_name, ind=ind_flat, digit=1, slc=(sino, None))
    dark = dxreader.read_tiff_stack(
        dark_name, ind=ind_dark, digit=1, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 15
0
def read_aus_microct(fname, ind_tomo, ind_flat, ind_dark):
    """
    Read Australian Synchrotron micro-CT standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'SAMPLE_T_0000.tif')
    flat_name = os.path.join(fname, 'BG__BEFORE_00.tif')
    dark_name = os.path.join(fname, 'DF__BEFORE_00.tif')
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, digit=4)
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, digit=2)
    dark = dxreader.read_tiff_stack(dark_name, ind=ind_dark, digit=2)
    return tomo, flat, dark
Exemplo n.º 16
0
def read_aus_microct(fname, ind_tomo, ind_flat, ind_dark):
    """
    Read Australian Synchrotron micro-CT standard data format.

    Parameters
    ----------
    fname : str
        Path to data folder.

    ind_tomo : list of int
        Indices of the projection files to read.

    ind_flat : list of int
        Indices of the flat field files to read.

    ind_dark : list of int
        Indices of the dark field files to read.

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    fname = os.path.abspath(fname)
    tomo_name = os.path.join(fname, 'SAMPLE_T_0000.tif')
    flat_name = os.path.join(fname, 'BG__BEFORE_00.tif')
    dark_name = os.path.join(fname, 'DF__BEFORE_00.tif')
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, digit=4)
    flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, digit=2)
    dark = dxreader.read_tiff_stack(dark_name, ind=ind_dark, digit=2)
    return tomo, flat, dark
Exemplo n.º 17
0
def find_roi(opt):
    """
    Use bright field to determine ROI (crop region)

    :param opt:
    output of tomo_par_init

    :return roi:
    roi = (x, y, w, h)
    """
    import dxchange.reader as dxread

    ind_to_read = [opt['ind_w1'][0][0]]
    roi = opt['roi']
    rot_angle = opt['rot_angle']
    medfilter_size = None
    fname = opt['input_template']

    imgw = dxread.read_tiff_stack(fname,
                                  ind=ind_to_read,
                                  digit=None,
                                  slc=None,
                                  angle=rot_angle,
                                  mblur=medfilter_size)
    imgn = cv2.normalize(imgw[0, :, :],
                         None,
                         alpha=0,
                         beta=255,
                         norm_type=cv2.NORM_MINMAX,
                         dtype=cv2.CV_8U)
    [ch, cw] = imgn.shape

    if roi[2] < cw or roi[3] < ch or roi[0] != 0 or roi[1] != 0:
        cv2.rectangle(imgn, (roi[0], roi[1]),
                      (roi[0] + roi[2], roi[1] + roi[3]), 255, 2, cv2.LINE_AA)
        cv2.putText(imgn, 'current ROI(x,y,w,h): ' + ','.join(map(str, roi)),
                    (roi[0], roi[1] - 5), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2,
                    cv2.LINE_AA)

    cv2.namedWindow('Select ROI', cv2.WINDOW_NORMAL)
    (x, y, w, h) = cv2.selectROI('Select ROI', imgn, True)
    if x + y + w + h == 0:
        print('ROI remains the same!!')
        return roi
    else:
        print('New ROI is ', x, y, w, h)
        return x, y, w, h
Exemplo n.º 18
0
Arquivo: inout.py Projeto: jhektor/qim
def merge_tiffs(fname,output,ind):
    print('Reading data')
    data = dxreader.read_tiff_stack(fname, ind)
    print('Saving merged data to {}'.format(output))
    dxwriter.write_tiff(data,fname=output)
Exemplo n.º 19
0
def read_als_832(fname, ind_tomo=None, normalized=False, proj=None, sino=None):
    """
    Read ALS 8.3.2 standard data format.

    Parameters
    ----------
    fname : str
        Path to file name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    normalized : boolean, optional
        If False, darks and flats will not be read. This should
        only be used for cases where tomo is already normalized.
        8.3.2 has a plugin that normalization is preferred to be
        done with prior to tomopy reconstruction.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """

    # File definitions.
    fname = os.path.abspath(fname)

    if not normalized:
        tomo_name = fname + '_0000_0000.tif'
        flat_name = fname + 'bak_0000.tif'
        dark_name = fname + 'drk_0000.tif'
        log_file = fname + '.sct'
    else:
        if "output" not in fname:
            raise Exception(
                'Please provide the normalized output directory as input')
        tomo_name = fname + '_0.tif'
        fname = fname.split('output')[0] + fname.split('/')[
            len(fname.split('/')) - 1]
        log_file = fname + '.sct'

    # Read metadata from ALS log file.
    contents = open(log_file, 'r')
    for line in contents:
        if '-nangles' in line:
            nproj = int(re.findall(r'\d+', line)[0])
        if '-num_bright_field' in line:
            nflat = int(re.findall(r'\d+', line)[0])
        if '-i0cycle' in line:
            inter_bright = int(re.findall(r'\d+', line)[1])
        if '-num_dark_fields' in line:
            ndark = int(re.findall(r'\d+', line)[0])
    contents.close()
    if ind_tomo is None:
        ind_tomo = list(range(0, nproj))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    if not normalized:
        ind_flat = list(range(0, nflat))
        if inter_bright > 0:
            ind_flat = list(range(0, nproj, inter_bright))
            flat_name = fname + 'bak_0000_0000.tif'
        ind_dark = list(range(0, ndark))

    # Read image data from tiff stack.
    tomo = dxreader.read_tiff_stack(tomo_name,
                                    ind=ind_tomo,
                                    digit=4,
                                    slc=(sino, None))

    if not normalized:

        # Adheres to 8.3.2 flat/dark naming conventions:
        # ----Flats----
        # root_namebak_xxxx_yyyy
        # For datasets that take flat at the start and end of its scan,
        # xxxx is in incrementals of one, and yyyy is either 0000 or the
        # last projection. For datasets that take flat while they scan
        # (when the beam fluctuates during scans),
        # xxxx is always 0000, and yyyy is in intervals given by log file.

        if inter_bright == 0:
            a = [0, nproj - 1]
            list_flat = dxreader._list_file_stack(flat_name, ind_flat, digit=4)
            for x in ind_flat:
                body = os.path.splitext(list_flat[x])[0] + "_"
                ext = os.path.splitext(list_flat[x])[1]
                for y, z in enumerate(a):
                    y = body + '{0:0={1}d}'.format(z, 4) + ext
                    if z == 0:
                        list_flat[x] = y
                    else:
                        list_flat.append(y)
            list_flat = sorted(list_flat)
            for m, image in enumerate(list_flat):
                _arr = dxreader.read_tiff(image)
                if m == 0:
                    dx = len(ind_flat * 2)
                    dy, dz = _arr.shape
                    flat = np.zeros((dx, dy, dz))
                flat[m] = _arr
            flat = dxreader._slice_array(flat, (None, sino))
        else:
            flat = dxreader.read_tiff_stack(flat_name,
                                            ind=ind_flat,
                                            digit=4,
                                            slc=(sino, None))

        # Adheres to 8.3.2 flat/dark naming conventions:
        # ----Darks----
        # root_namedrk_xxxx_yyyy
        # All datasets thus far that take darks at the start and end of
        # its scan, so xxxx is in incrementals of one, and yyyy is either
        # 0000 or the last projection.

        list_dark = dxreader._list_file_stack(dark_name, ind_dark, digit=4)
        for x in ind_dark:
            body = os.path.splitext(list_dark[x])[0] + '_'
            ext = os.path.splitext(list_dark[x])[1]
            body = body + '{0:0={1}d}'.format(nproj - 1, 4) + ext
            list_dark[x] = body
        list_dark = sorted(list_dark)
        for m, image in enumerate(list_dark):
            _arr = dxreader.read_tiff(image)
            if m == 0:
                dx = len(ind_dark)
                dy, dz = _arr.shape
                dark = np.zeros((dx, dy, dz))
            dark[m] = _arr
        dark = dxreader._slice_array(dark, (None, sino))
    else:
        flat = np.ones(1)
        dark = np.zeros(1)
    return tomo, flat, dark
Exemplo n.º 20
0
def read_aps_1id(fname, ind_tomo=None, proj=None, sino=None, layer=0):
    """
    Read APS 1-ID standard data format.

    Parameters
    ----------
    fname : str
        Path to file name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    layer: int, optional
        Specify the layer to reconstruct 

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    # File definitions.
    fname = os.path.abspath(fname)
    _fname = fname + '000001.tif'
    log_file = fname + 'TomoStillScan.dat'

    # parse the log/metadata file
    _metadf = dxreader.read_aps_1id_metafile(log_file)

    # meta data for layer to reconstruct
    try:
        _layerdf = _metadf[_metadf['layerID'] == layer]
    except:
        print("Valid layers for reconstruction are: {}".format(
            _metadf['layerID'].unique()))

    # -- queery image data meta for given layer
    # still/projection images
    prj_start = _layerdf.loc[_layerdf['type'] == 'still', 'nSeq'].values[0]
    nprj = _layerdf.loc[_layerdf['type'] == 'still', 'nSeq'].shape[0]
    # dark field images
    dark_start = _layerdf.loc[_layerdf['type'] == 'post_dark',
                              'nSeq'].values[0]
    ndark = _layerdf.loc[_layerdf['type'] == 'post_dark', 'nSeq'].shape[0]
    # white/flat field images (only use pre_white)
    # NOTE: The beam condition might change overtime, therefore flat field
    #       images are taken both before and after the experiment.
    #       The implementation here assumes the beam is stable throughout the
    #       experiment
    flat_start = _layerdf.loc[_layerdf['type'] == 'pre_white',
                              'nSeq'].values[0]
    nflat = _layerdf.loc[_layerdf['type'] == 'pre_white', 'nSeq'].shape[0]

    if ind_tomo is None:
        ind_tomo = list(range(prj_start, prj_start + nprj))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    ind_flat = list(range(flat_start, flat_start + nflat))
    ind_dark = list(range(dark_start, dark_start + ndark))
    tomo = dxreader.read_tiff_stack(_fname, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(_fname, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(_fname, ind=ind_dark, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 21
0
def read_sls_tomcat(fname, ind_tomo=None, proj=None, sino=None):
    """
    Read SLS TOMCAT standard data format.

    Parameters
    ----------
    fname : str
        Path to file name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    # File definitions.
    fname = os.path.abspath(fname)
    _fname = fname + '0001.tif'
    log_file = fname + '.log'

    # Read metadata from SLS log file.
    contents = open(log_file, 'r')
    for line in contents:
        ls = line.split()
        if len(ls) > 1:
            if ls[0] == 'Number' and ls[2] == 'projections':
                nproj = int(ls[4])
            elif ls[0] == 'Number' and ls[2] == 'flats':
                nflat = int(ls[4])
            elif ls[0] == 'Number' and ls[2] == 'darks':
                ndark = int(ls[4])
    contents.close()

    dark_start = 1
    dark_end = ndark + 1
    flat_start = dark_end
    flat_end = flat_start + nflat
    proj_start = flat_end
    proj_end = proj_start + nproj

    if ind_tomo is None:
        ind_tomo = list(range(proj_start, proj_end))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    ind_flat = list(range(flat_start, flat_end))
    ind_dark = list(range(dark_start, dark_end))
    tomo = dxreader.read_tiff_stack(_fname, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(_fname, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(_fname, ind=ind_dark, slc=(sino, None))

    return tomo, flat, dark
Exemplo n.º 22
0
def read_sls_tomcat(fname, ind_tomo=None, proj=None, sino=None):
    """
    Read SLS TOMCAT standard data format.

    Parameters
    ----------
    fname : str
        Path to file name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    # File definitions.
    fname = os.path.abspath(fname)
    _fname = fname + '0001.tif'
    log_file = fname + '.log'

    # Read metadata from SLS log file.
    contents = open(log_file, 'r')
    for line in contents:
        ls = line.split()
        if len(ls) > 1:
            if ls[0] == 'Number' and ls[2] == 'projections':
                nproj = int(ls[4])
            elif ls[0] == 'Number' and ls[2] == 'flats':
                nflat = int(ls[4])
            elif ls[0] == 'Number' and ls[2] == 'darks':
                ndark = int(ls[4])
    contents.close()

    dark_start = 1
    dark_end = ndark + 1
    flat_start = dark_end
    flat_end = flat_start + nflat
    proj_start = flat_end
    proj_end = proj_start + nproj

    if ind_tomo is None:
        ind_tomo = list(range(proj_start, proj_end))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    ind_flat = list(range(flat_start, flat_end))
    ind_dark = list(range(dark_start, dark_end))
    tomo = dxreader.read_tiff_stack(
        _fname, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(
        _fname, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(
        _fname, ind=ind_dark, slc=(sino, None))

    return tomo, flat, dark
Exemplo n.º 23
0
def read_als_832(fname, ind_tomo=None, normalized=False, proj=None, sino=None):
    """
    Read ALS 8.3.2 standard data format.

    Parameters
    ----------
    fname : str
        Path to file name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    normalized : boolean, optional
        If False, darks and flats will not be read. This should
        only be used for cases where tomo is already normalized.
        8.3.2 has a plugin that normalization is preferred to be
        done with prior to tomopy reconstruction.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """

    # File definitions.
    fname = os.path.abspath(fname)

    if not normalized:
        tomo_name = fname + '_0000_0000.tif'
        flat_name = fname + 'bak_0000.tif'
        dark_name = fname + 'drk_0000.tif'
        log_file = fname + '.sct'
    else:
        if "output" not in fname:
            raise Exception(
                'Please provide the normalized output directory as input')
        tomo_name = fname + '_0.tif'
        fname = fname.split(
            'output')[0] + fname.split('/')[len(fname.split('/')) - 1]
        log_file = fname + '.sct'

    # Read metadata from ALS log file.
    contents = open(log_file, 'r')
    for line in contents:
        if '-nangles' in line:
            nproj = int(re.findall(r'\d+', line)[0])
        if '-num_bright_field' in line:
            nflat = int(re.findall(r'\d+', line)[0])
        if '-i0cycle' in line:
            inter_bright = int(re.findall(r'\d+', line)[1])
        if '-num_dark_fields' in line:
            ndark = int(re.findall(r'\d+', line)[0])
    contents.close()
    if ind_tomo is None:
        ind_tomo = list(range(0, nproj))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    if not normalized:
        ind_flat = list(range(0, nflat))
        if inter_bright > 0:
            ind_flat = list(range(0, nproj, inter_bright))
            flat_name = fname + 'bak_0000_0000.tif'
        ind_dark = list(range(0, ndark))

    # Read image data from tiff stack.
    tomo = dxreader.read_tiff_stack(tomo_name, ind=ind_tomo, digit=4,
                                    slc=(sino, None))

    if not normalized:

        # Adheres to 8.3.2 flat/dark naming conventions:
        # ----Flats----
        # root_namebak_xxxx_yyyy
        # For datasets that take flat at the start and end of its scan,
        # xxxx is in incrementals of one, and yyyy is either 0000 or the
        # last projection. For datasets that take flat while they scan
        # (when the beam fluctuates during scans),
        # xxxx is always 0000, and yyyy is in intervals given by log file.

        if inter_bright == 0:
            a = [0, nproj - 1]
            list_flat = dxreader._list_file_stack(flat_name, ind_flat, digit=4)
            for x in ind_flat:
                body = os.path.splitext(list_flat[x])[0] + "_"
                ext = os.path.splitext(list_flat[x])[1]
                for y, z in enumerate(a):
                    y = body + '{0:0={1}d}'.format(z, 4) + ext
                    if z == 0:
                        list_flat[x] = y
                    else:
                        list_flat.append(y)
            list_flat = sorted(list_flat)
            for m, image in enumerate(list_flat):
                _arr = dxreader.read_tiff(image)
                if m == 0:
                    dx = len(ind_flat * 2)
                    dy, dz = _arr.shape
                    flat = np.zeros((dx, dy, dz))
                flat[m] = _arr
            flat = dxreader._slice_array(flat, (None, sino))
        else:
            flat = dxreader.read_tiff_stack(flat_name, ind=ind_flat, digit=4,
                                            slc=(sino, None))

        # Adheres to 8.3.2 flat/dark naming conventions:
        # ----Darks----
        # root_namedrk_xxxx_yyyy
        # All datasets thus far that take darks at the start and end of
        # its scan, so xxxx is in incrementals of one, and yyyy is either
        # 0000 or the last projection.

        list_dark = dxreader._list_file_stack(dark_name, ind_dark, digit=4)
        for x in ind_dark:
            body = os.path.splitext(list_dark[x])[0] + '_'
            ext = os.path.splitext(list_dark[x])[1]
            body = body + '{0:0={1}d}'.format(nproj - 1, 4) + ext
            list_dark[x] = body
        list_dark = sorted(list_dark)
        for m, image in enumerate(list_dark):
            _arr = dxreader.read_tiff(image)
            if m == 0:
                dx = len(ind_dark)
                dy, dz = _arr.shape
                dark = np.zeros((dx, dy, dz))
            dark[m] = _arr
        dark = dxreader._slice_array(dark, (None, sino))
    else:
        flat = np.ones(1)
        dark = np.zeros(1)
    return tomo, flat, dark
Exemplo n.º 24
0
def read_aps_1id(fname, ind_tomo=None, proj=None, sino=None):
    """
    Read APS 1-ID standard data format.

    Parameters
    ----------
    fname : str
        Path to file name without indices and extension.

    ind_tomo : list of int, optional
        Indices of the projection files to read.

    proj : {sequence, int}, optional
        Specify projections to read. (start, end, step)

    sino : {sequence, int}, optional
        Specify sinograms to read. (start, end, step)

    Returns
    -------
    ndarray
        3D tomographic data.

    ndarray
        3D flat field data.

    ndarray
        3D dark field data.
    """
    # File definitions.
    fname = os.path.abspath(fname)
    _fname = fname + '000001.tif'
    log_file = fname + 'TomoStillScan.dat'

    # Read APS 1-ID log file data
    contents = open(log_file, 'r')
    for line in contents:
        ls = line.split()
        if len(ls) > 1:
            if ls[0] == "Tomography" and ls[1] == "scan":
                prj_start = int(ls[6])
            elif ls[0] == "Number" and ls[2] == "scan":
                nprj = int(ls[4])
            elif ls[0] == "Dark" and ls[1] == "field":
                dark_start = int(ls[6])
            elif ls[0] == "Number" and ls[2] == "dark":
                ndark = int(ls[5])
            elif ls[0] == "White" and ls[1] == "field":
                flat_start = int(ls[6])
            elif ls[0] == "Number" and ls[2] == "white":
                nflat = int(ls[5])
    contents.close()

    if ind_tomo is None:
        ind_tomo = list(range(prj_start, prj_start + nprj))
    if proj is not None:
        ind_tomo = ind_tomo[slice(*proj)]
    ind_flat = list(range(flat_start, flat_start + nflat))
    ind_dark = list(range(dark_start, dark_start + ndark))
    tomo = dxreader.read_tiff_stack(
        _fname, ind=ind_tomo, slc=(sino, None))
    flat = dxreader.read_tiff_stack(
        _fname, ind=ind_flat, slc=(sino, None))
    dark = dxreader.read_tiff_stack(
        _fname, ind=ind_dark, slc=(sino, None))
    return tomo, flat, dark
Exemplo n.º 25
0
    if nstitch > 4:
        print('Do not support stitch > 4!!')
    elif nstitch == 3:
        # generate index of files
        ind_wf1 = opt['ind_w1'][2]
        ind_pj1 = opt['ind_pj'][0]
        ind_pj2 = opt['ind_pj'][1]
        ind_pj3 = opt['ind_pj'][2]
        ind_dk1 = opt['ind_dk'][0]

        tic = time.time()
        print("Start reading files....")
        wf1 = dxreader.read_tiff_stack(fname,
                                       ind=ind_wf1,
                                       digit=None,
                                       slc=(crop_y, crop_x),
                                       angle=rot_angle,
                                       mblur=medfilter_size)
        #wf2 = dxreader.read_tiff_stack(fname, ind=ind_wf2, digit=None, slc=(crop_y, crop_x), angle=rot_angle, mblur=medfilter_size)
        pj1 = dxreader.read_tiff_stack(fname,
                                       ind=ind_pj1,
                                       digit=None,
                                       slc=(crop_y, crop_x),
                                       angle=rot_angle,
                                       mblur=medfilter_size)
        pj2 = dxreader.read_tiff_stack(fname,
                                       ind=ind_pj2,
                                       digit=None,
                                       slc=(crop_y, crop_x),
                                       angle=rot_angle,
                                       mblur=medfilter_size)