Esempio n. 1
0
def reconstruct(sname, rot_center, ovlpfind, s_start, s_end):
    fname = dfolder + sname + '.h5'
    print(fname)
    start = s_start
    end = s_end
    chunks = 24
    num_sino = (end - start) // chunks
    for m in range(chunks):
        sino_start = start + num_sino * m
        sino_end = start + num_sino * (m + 1)
        start_read_time = time.time()
        proj, flat, dark, thetat = dxchange.read_aps_2bm(fname,
                                                         sino=(sino_start,
                                                               sino_end))
        print('   done read in %0.1f min' %
              ((time.time() - start_read_time) / 60))
        dark = proj[9001:9002]
        flat = proj[0:1]
        proj = proj[1:9000]
        theta = tomopy.angles(proj.shape[0], 0., 360.)
        proj = tomopy.sino_360_to_180(proj, overlap=ovlpfind, rotation='right')
        proj = tomopy.remove_outlier(proj, dif=0.4)
        proj = tomopy.normalize_bg(proj, air=10)
        proj = tomopy.minus_log(proj)
        center = rot_center
        start_ring_time = time.time()
        proj = tomopy.remove_stripe_fw(proj, wname='sym5', sigma=4, pad=False)
        proj = tomopy.remove_stripe_sf(proj, size=3)
        print('   done pre-process in %0.1f min' %
              ((time.time() - start_ring_time) / 60))
        start_phase_time = time.time()
        proj = tomopy.retrieve_phase(proj,
                                     pixel_size=detector_pixel_size_x,
                                     dist=sample_detector_distance,
                                     energy=energy,
                                     alpha=alpha,
                                     pad=True,
                                     ncore=None,
                                     nchunk=None)
        print('   done phase retrieval in %0.1f min' %
              ((time.time() - start_phase_time) / 60))
        start_recon_time = time.time()
        rec = tomopy.recon(proj,
                           theta,
                           center=center,
                           algorithm='gridrec',
                           filter_name='ramalk')
        tomopy.circ_mask(rec, axis=0, ratio=0.95)
        print("Reconstructed", rec.shape)
        dxchange.write_tiff_stack(rec,
                                  fname=dfolder + '/' + sname + '/' + sname,
                                  overwrite=True,
                                  start=sino_start)
        print('   Chunk reconstruction done in %0.1f min' %
              ((time.time() - start_recon_time) / 60))
    print("Done!")
Esempio n. 2
0
def read_aps_2bm_custom(fname, sino):

    # Read APS 2-BM raw data in temporary array to fix an acquisition error. 
    # All data (proj,dark and white) are stored in the proj array while flat/dark/theta arrays are invalid
    tproj, tflat, tdark, ttheta = dxchange.read_aps_2bm(fname, sino=sino)

    # Extracting from the tproj array proj, flat, dark and theta
    ndark = 10
    nflat = 10
    last_projection = tproj.shape[0] - nflat - ndark
    proj = tproj[0:last_projection, :, :]
    flat = tproj[last_projection:last_projection+nflat, :, :]
    dark = tproj[last_projection+nflat:last_projection+nflat+ndark, :, :]
    theta_size = proj.shape[0]
    theta = np.linspace(0. , np.pi, theta_size)
    
    return proj, flat, dark, theta
Esempio n. 3
0
def read_aps_2bm_custom(fname, sino):

    # Read APS 2-BM raw data in temporary array to fix an acquisition error. 
    # All data (proj,dark and white) are stored in the proj array while flat/dark/theta arrays are invalid
    tproj, tflat, tdark, ttheta = dxchange.read_aps_2bm(fname, sino=sino)

    # Extracting from the tproj array proj, flat, dark and theta
    ndark = 10
    nflat = 10
    last_projection = tproj.shape[0] - nflat - ndark
    proj = tproj[0:last_projection, :, :]
    flat = tproj[last_projection:last_projection+nflat, :, :]
    dark = tproj[last_projection+nflat:last_projection+nflat+ndark, :, :]
    theta_size = proj.shape[0]
    theta = np.linspace(0. , np.pi, theta_size)
    
    return proj, flat, dark, theta
Esempio n. 4
0
def reconstruct(sname, rot_center, ovlpfind, s_start, s_end):
    fname = dfolder + sname + '.h5'
    print (fname)
    start = s_start  
    end =   s_end
    chunks = 24 
    num_sino = (end - start) // chunks
    for m in range(chunks):
        sino_start = start + num_sino * m
        sino_end = start + num_sino * (m + 1)
        start_read_time = time.time()
        proj, flat, dark, thetat = dxchange.read_aps_2bm(fname, sino=(sino_start, sino_end))
        print('   done read in %0.1f min' % ((time.time() - start_read_time)/60))
        dark = proj[9001:9002]
        flat = proj[0:1]
        proj = proj[1:9000]
        theta = tomopy.angles(proj.shape[0], 0., 360.)
        proj = tomopy.sino_360_to_180(proj, overlap=ovlpfind, rotation='right')
        proj = tomopy.remove_outlier(proj, dif=0.4)
        proj = tomopy.normalize_bg(proj, air=10)
        proj = tomopy.minus_log(proj)
        center = rot_center
        start_ring_time = time.time()
        proj = tomopy.remove_stripe_fw(proj, wname='sym5', sigma=4, pad=False)
        proj = tomopy.remove_stripe_sf(proj, size=3)
        print('   done pre-process in %0.1f min' % ((time.time() - start_ring_time)/60))
        start_phase_time = time.time()
        proj = tomopy.retrieve_phase(proj, pixel_size=detector_pixel_size_x, dist=sample_detector_distance, energy=energy, alpha=alpha, pad=True, ncore=None, nchunk=None)
        print('   done phase retrieval in %0.1f min' % ((time.time() - start_phase_time)/60))
        start_recon_time = time.time()
        rec = tomopy.recon(proj, theta, center=center, algorithm='gridrec', filter_name='ramalk')
        tomopy.circ_mask(rec, axis=0, ratio=0.95)
        print ("Reconstructed", rec.shape)
        dxchange.write_tiff_stack(rec, fname = dfolder + '/' + sname + '/' + sname, overwrite=True, start=sino_start)
        print('   Chunk reconstruction done in %0.1f min' % ((time.time() - start_recon_time)/60))
    print ("Done!")
Esempio n. 5
0
            for iChunk in range(0,chunks):
                print('\n  -- chunk # %i' % (iChunk+1))
                sino_chunk_start = sino_start + nSino_per_chunk*iChunk 
                sino_chunk_end = sino_start + nSino_per_chunk*(iChunk+1)
                print('\n  --------> [%i, %i]' % (sino_chunk_start, sino_chunk_end))
                
                if sino_chunk_end > sino_end: 
                    break

                sino = (int(sino_chunk_start), int(sino_chunk_end))
                
                # Read APS 2-BM raw data.
                if (int(key) > 6):            
                    proj, flat, dark, theta = read_aps_2bm_custom(fname, sino=sino)
                else:
                    proj, flat, dark, theta = dxchange.read_aps_2bm(fname, sino=sino)

                # zinger_removal
                proj = tomopy.misc.corr.remove_outlier(proj, zinger_level, size=15, axis=0)
                flat = tomopy.misc.corr.remove_outlier(flat, zinger_level_w, size=15, axis=0)

                # Flat-field correction of raw data.
                data = tomopy.normalize(proj, flat, dark, cutoff=1.4)

                # remove stripes
                #proj = tomopy.remove_stripe_fw(proj,level=5,wname='sym16',sigma=1,pad=True)
                proj = tomopy.remove_stripe_ti(proj,2)
                proj = tomopy.remove_stripe_sf(proj,10)

                # phase retrieval
                ##data = tomopy.prep.phase.retrieve_phase(data,pixel_size=detector_pixel_size_x,dist=sample_detector_distance,energy=monochromator_energy,alpha=8e-3,pad=True)
Esempio n. 6
0
            fname = top + prefix + h5name + '/proj_' + h5name + '.hdf'
            rot_center = dict2[h5name]
            ##print(fname, rot_center)

            # Select sinogram range to reconstruct.
            sino = None
            
            start = 1000
            end = 1001
            sino = (start, end)

            # Read APS 2-BM raw data.
            if (int(key) > 6):            
                proj, flat, dark, theta = read_aps_2bm_custom(fname, sino=sino)
            else:
                proj, flat, dark, theta = dxchange.read_aps_2bm(fname, sino=sino)
            
            # zinger_removal
            proj = tomopy.misc.corr.remove_outlier(proj, zinger_level, size=15, axis=0)
            flat = tomopy.misc.corr.remove_outlier(flat, zinger_level_w, size=15, axis=0)

            # Flat-field correction of raw data.
            data = tomopy.normalize(proj, flat, dark, cutoff=1.4)

            # remove stripes
            #data = tomopy.remove_stripe_fw(data,level=5,wname='sym16',sigma=1,pad=True)
            ##data = tomopy.prep.stripe.remove_stripe_ti(data,alpha=7)
            ##data = tomopy.prep.stripe.remove_stripe_sf(data,size=51)

            # phase retrieval
            ##data = tomopy.prep.phase.retrieve_phase(data,pixel_size=detector_pixel_size_x,dist=sample_detector_distance,energy=monochromator_energy,alpha=alpha,pad=True)