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
import numpy as np import os from cil.io import TXRMDataReader, TIFFWriter from cil.processors import TransmissionAbsorptionConverter, Binner from cil.plugins.tigre import FBP from cil.utilities.display import show2D, show_geometry base_dir = os.path.abspath(r"C:\Users\ofn77899\Data\walnut") data_name = "valnut" filename = os.path.join(base_dir, data_name, "valnut_2014-03-21_643_28/tomo-A/valnut_tomo-A.txrm") is2D = False data = TXRMDataReader(file_name=filename).read() if is2D: data = data.get_slice(vertical='centre') else: binner = Binner(roi={ 'horizontal': (None, None, 4), 'vertical': (None, None, 4) }) data = binner(data) # show_geometry(data.geometry) data = TransmissionAbsorptionConverter()(data) data.reorder(order='tigre') ig = data.geometry.get_ImageGeometry()
#%% #%% path = os.path.abspath('/home/edo/scratch/Dataset/') filename = os.path.join(path, 'CCPi', 'valnut_tomo-A.txrm') # reader = TXRMDataReader() # reader.set_up(file_name=filename) # data = reader.read() # reader = TXRMDataReader(file_name=filename) # data = reader.read() data = TXRMDataReader(file_name=filename).read() print("read in data type", data.dtype) #%% show2D(data, slice_list=('angle', 800), cmap='inferno', origin='upper-right') #%% # get central slice # data2d = data.get_slice(vertical='centre') # data2d.reorder(order='tigre') #%% # Centre of rotation finder #%% # neg log
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)
import wget from cil.io import TXRMDataReader, NEXUSDataReader from cil.framework import AcquisitionGeometry, ImageGeometry from cil.plugins.tigre import FBP as tFBP 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