コード例 #1
0
ファイル: test_io.py プロジェクト: mhquah/CCPi-Framework
class TestTXRMDataReader(unittest.TestCase):
    
    def setUp(self):
        print ("has_astra",has_astra)
        print ("has_wget",has_wget)
        print ("has_olefile",has_olefile)
        print ("has_dxchange",has_dxchange)
        print ("has_file",has_file)
        if has_file:
            self.reader = TXRMDataReader()
            angle_unit = AcquisitionGeometry.RADIAN
            
            self.reader.set_up(file_name=filename, 
                               angle_unit=angle_unit)
            data = self.reader.read()
            if data.geometry is None:
                raise AssertionError("WTF")
            # Choose the number of voxels to reconstruct onto as number of detector pixels
            N = data.geometry.pixel_num_h
            
            # Geometric magnification
            mag = (np.abs(data.geometry.dist_center_detector) + \
                np.abs(data.geometry.dist_source_center)) / \
                np.abs(data.geometry.dist_source_center)
                
            # Voxel size is detector pixel size divided by mag
            voxel_size_h = data.geometry.pixel_size_h / mag
            voxel_size_v = data.geometry.pixel_size_v / mag

            self.mag = mag
            self.N = N
            self.voxel_size_h = voxel_size_h
            self.voxel_size_v = voxel_size_v

            self.data = data


    def tearDown(self):
        pass

    def test_run_test(self):
        print("run test Zeiss Reader")
        self.assertTrue(True)
    
    @unittest.skipIf(True, 'skip test by default')
    def test_not_run_test(self):
        print("run test Zeiss Reader")
        self.assertTrue(True)

    @unittest.skipIf(not has_prerequisites, "Prerequisites not met")
    def test_read_and_reconstruct_2D(self):
        print (type(self.data))

        # get central slice
        data2d = self.data.subset(vertical='centre')
        # d512 = self.data.subset(vertical=512)
        # data2d.fill(d512.as_array())
        # neg log
        data2d.log(out=data2d)
        data2d *= -1

        ig2d = data2d.geometry.get_ImageGeometry()
        # Construct the appropriate ImageGeometry
        ig2d = ImageGeometry(voxel_num_x=self.N,
                            voxel_num_y=self.N,
                            voxel_size_x=self.voxel_size_h, 
                            voxel_size_y=self.voxel_size_h)
        if data2d.geometry is None:
            raise AssertionError('What? None?')
        fbpalg = FDK(ig2d,data2d.geometry)
        fbpalg.set_input(data2d)
        
        recfbp = fbpalg.get_output()
        
        wget.download('https://www.ccpi.ac.uk/sites/www.ccpi.ac.uk/files/walnut_slice512.nxs',
                      out=data_dir)
        fname = os.path.join(data_dir, 'walnut_slice512.nxs')
        reader = NEXUSDataReader()
        reader.set_up(file_name=fname)
        gt = reader.read()

        qm = mse(gt, recfbp)
        print ("MSE" , qm )

        np.testing.assert_almost_equal(qm, 0, decimal=3)
        fname = os.path.join(data_dir, 'walnut_slice512.nxs')
        os.remove(fname)
コード例 #2
0
from cil.plugins.astra.processors import FBP as aFBP
from cil.utilities.display import show2D
from cil.processors import CentreOfRotationCorrector
from cil.utilities.quality_measures import *

filename = os.path.abspath('/home/edo/scratch/Dataset/CCPi/valnut_tomo-A.txrm')
data_dir = os.getcwd()

# show2D(gt)
#%%
reader = TXRMDataReader()
angle_unit = AcquisitionGeometry.RADIAN

filename = os.path.abspath('/home/edo/scratch/Dataset/CCPi/valnut_tomo-A.txrm')

reader.set_up(file_name=filename, angle_unit=angle_unit)
data = reader.read()
if data.geometry is None:
    raise AssertionError("The reader should set the geometry!!")

# angles = data.geometry.angles * -1
# data.geometry.set_angles(angles)
#%%
show2D(data, slice_list=('vertical', 600))
#%%
# get central slice
data2d = [data.get_slice(vertical='centre')]
data2d.append(data2d[0].copy())

data2d[0].reorder(order='tigre')
data2d[1].reorder(order='astra')