Пример #1
0
 def test_AcquisitionGeometry_allocate(self):
     ageometry = AcquisitionGeometry(dimension=2, angles=numpy.linspace(0, 180, num=10),
                                     geom_type='parallel', pixel_num_v=3,
                                     pixel_num_h=5, channels=2)
     sino = ageometry.allocate()
     shape = sino.shape
     print ("shape", shape)
     self.assertEqual(0,sino.as_array()[0][0][0][0])
     self.assertEqual(0,sino.as_array()[shape[0]-1][shape[1]-1][shape[2]-1][shape[3]-1])
     
     sino = ageometry.allocate(1)
     self.assertEqual(1,sino.as_array()[0][0][0][0])
     self.assertEqual(1,sino.as_array()[shape[0]-1][shape[1]-1][shape[2]-1][shape[3]-1])
     print (sino.dimension_labels, sino.shape, ageometry)
     
     default_order = ['channel' , ' angle' ,
                                       'vertical' , 'horizontal']
     self.assertEqual(default_order[0], sino.dimension_labels[0])
     self.assertEqual(default_order[1], sino.dimension_labels[1])
     self.assertEqual(default_order[2], sino.dimension_labels[2])
     self.assertEqual(default_order[3], sino.dimension_labels[3])
     order = ['vertical' , 'horizontal', 'channel' , 'angle' ]
     sino = ageometry.allocate(0,dimension_labels=order)
     print (sino.dimension_labels, sino.shape, ageometry)
     self.assertEqual(order[0], sino.dimension_labels[0])
     self.assertEqual(order[1], sino.dimension_labels[1])
     self.assertEqual(order[2], sino.dimension_labels[2])
     self.assertEqual(order[2], sino.dimension_labels[2])
Пример #2
0
    def testwriteAcquisitionData(self):
        im_size = 5
        ag2d = AcquisitionGeometry(geom_type = 'parallel', 
                                   dimension = '2D', 
                                   angles = numpy.array([0, 1]), 
                                   pixel_num_h = im_size, 
                                   pixel_size_h = 1, 
                                   pixel_num_v = im_size, 
                                   pixel_size_v = 1)
        ad2d = ag2d.allocate()
        writer = NEXUSDataWriter()
        writer.set_up(file_name = os.path.join(os.getcwd(), 'test_nexus_ad2d.nxs'),
                      data_container = ad2d)
        writer.write_file()
        
        ag3d = AcquisitionGeometry(geom_type = 'cone', 
                                   dimension = '3D', 
                                   angles = numpy.array([0, 1]), 
                                   pixel_num_h = im_size, 
                                   pixel_size_h = 1, 
                                   pixel_num_v = im_size, 
                                   pixel_size_v = 1,
                                   dist_source_center = 1,
                                   dist_center_detector = 1, 
                                   channels = im_size)
        ad3d = ag3d.allocate()
        writer = NEXUSDataWriter()
        writer.set_up(file_name = os.path.join(os.getcwd(), 'test_nexus_ad3d.nxs'),
                      data_container = ad3d)
        writer.write_file()

        self.stestreadAcquisitionData()
Пример #3
0
 def test_AcquisitionData(self):
     sgeometry = AcquisitionGeometry(dimension=2, angles=numpy.linspace(0, 180, num=10),
                                     geom_type='parallel', pixel_num_v=3,
                                     pixel_num_h=5, channels=2)
     #sino = AcquisitionData(geometry=sgeometry)
     sino = sgeometry.allocate()
     self.assertEqual(sino.shape, (2, 10, 3, 5))
     
     ag = AcquisitionGeometry (pixel_num_h=2,pixel_num_v=3,channels=4, dimension=2, angles=numpy.linspace(0, 180, num=10),
                                     geom_type='parallel', )
     print (ag.shape)
     print (ag.dimension_labels)
     
     data = ag.allocate()
     self.assertNumpyArrayEqual(numpy.asarray(data.shape), numpy.asarray(ag.shape))
     self.assertNumpyArrayEqual(numpy.asarray(data.shape), data.as_array().shape)
     
     print (data.shape, ag.shape, data.as_array().shape)
     
     ag2 = AcquisitionGeometry (pixel_num_h=2,pixel_num_v=3,channels=4, dimension=2, angles=numpy.linspace(0, 180, num=10),
                                             geom_type='parallel', 
                                             dimension_labels=[AcquisitionGeometry.VERTICAL ,
                      AcquisitionGeometry.ANGLE, AcquisitionGeometry.HORIZONTAL, AcquisitionGeometry.CHANNEL])
     
     data = ag2.allocate()
     print (data.shape, ag2.shape, data.as_array().shape)
     self.assertNumpyArrayEqual(numpy.asarray(data.shape), numpy.asarray(ag2.shape))
     self.assertNumpyArrayEqual(numpy.asarray(data.shape), data.as_array().shape)
Пример #4
0
 def stestreadAcquisitionData(self):
     im_size = 5
     ag2d_test = AcquisitionGeometry(geom_type = 'parallel', 
                                     dimension = '2D', 
                                     angles = numpy.array([0, 1]), 
                                     pixel_num_h = im_size, 
                                     pixel_size_h = 1, 
                                     pixel_num_v = im_size, 
                                     pixel_size_v = 1)
     ad2d_test = ag2d_test.allocate()
     
     reader2d = NEXUSDataReader()
     reader2d.set_up(nexus_file = os.path.join(os.getcwd(), 'test_nexus_ad2d.nxs'))
     ad2d = reader2d.load_data()
     ag2d = reader2d.get_geometry()
     numpy.testing.assert_array_equal(ad2d.as_array(), ad2d_test.as_array(), 'Loaded image is not correct')
     self.assertEqual(ag2d.geom_type, ag2d_test.geom_type, 'ImageGeometry.geom_type is not correct')
     numpy.testing.assert_array_equal(ag2d.angles, ag2d_test.angles, 'ImageGeometry.angles is not correct')
     self.assertEqual(ag2d.pixel_num_h, ag2d_test.pixel_num_h, 'ImageGeometry.pixel_num_h is not correct')
     self.assertEqual(ag2d.pixel_size_h, ag2d_test.pixel_size_h, 'ImageGeometry.pixel_size_h is not correct')
     self.assertEqual(ag2d.pixel_num_v, ag2d_test.pixel_num_v, 'ImageGeometry.pixel_num_v is not correct')
     self.assertEqual(ag2d.pixel_size_v, ag2d_test.pixel_size_v, 'ImageGeometry.pixel_size_v is not correct')
     
     ag3d_test = AcquisitionGeometry(geom_type = 'cone', 
                                     dimension = '3D', 
                                     angles = numpy.array([0, 1]), 
                                     pixel_num_h = im_size, 
                                     pixel_size_h = 1, 
                                     pixel_num_v = im_size, 
                                     pixel_size_v = 1,
                                     dist_source_center = 1,
                                     dist_center_detector = 1, 
                                     channels = im_size)
     ad3d_test = ag3d_test.allocate()
     
     reader3d = NEXUSDataReader()
     reader3d.set_up(nexus_file = os.path.join(os.getcwd(), 'test_nexus_ad3d.nxs'))
     ad3d = reader3d.load_data()
     ag3d = reader3d.get_geometry()
     
     numpy.testing.assert_array_equal(ad3d.as_array(), ad3d_test.as_array(), 'Loaded image is not correct')
     numpy.testing.assert_array_equal(ag3d.angles, ag3d_test.angles, 'AcquisitionGeometry.angles is not correct')
     self.assertEqual(ag3d.geom_type, ag3d_test.geom_type, 'AcquisitionGeometry.geom_type is not correct')
     self.assertEqual(ag3d.dimension, ag3d_test.dimension, 'AcquisitionGeometry.dimension is not correct')
     self.assertEqual(ag3d.pixel_num_h, ag3d_test.pixel_num_h, 'AcquisitionGeometry.pixel_num_h is not correct')
     self.assertEqual(ag3d.pixel_size_h, ag3d_test.pixel_size_h, 'AcquisitionGeometry.pixel_size_h is not correct')
     self.assertEqual(ag3d.pixel_num_v, ag3d_test.pixel_num_v, 'AcquisitionGeometry.pixel_num_v is not correct')
     self.assertEqual(ag3d.pixel_size_v, ag3d_test.pixel_size_v, 'AcquisitionGeometry.pixel_size_v is not correct')
     self.assertEqual(ag3d.dist_source_center, ag3d_test.dist_source_center, 'AcquisitionGeometry.dist_source_center is not correct')
     self.assertEqual(ag3d.dist_center_detector, ag3d_test.dist_center_detector, 'AcquisitionGeometry.dist_center_detector is not correct')
     self.assertEqual(ag3d.channels, ag3d_test.channels, 'AcquisitionGeometry.channels is not correct')
             
     def tearDown(self):
         os.remove(os.path.join(os.getcwd(), 'test_nexus_im.nxs'))
         os.remove(os.path.join(os.getcwd(), 'test_nexus_ad2d.nxs'))
         os.remove(os.path.join(os.getcwd(), 'test_nexus_ad3d.nxs'))
Пример #5
0
    def test_AcquisitionDataSubset(self):
        sgeometry = AcquisitionGeometry(dimension=2, angles=numpy.linspace(0, 180, num=10),
                                        geom_type='parallel', pixel_num_v=3,
                                        pixel_num_h=5, channels=2)
        # expected dimension_labels
        
        self.assertListEqual([AcquisitionGeometry.CHANNEL ,
                 AcquisitionGeometry.ANGLE , AcquisitionGeometry.VERTICAL ,
                 AcquisitionGeometry.HORIZONTAL],
                              sgeometry.dimension_labels)
        sino = sgeometry.allocate()

        # test reshape
        new_order = [AcquisitionGeometry.HORIZONTAL ,
                 AcquisitionGeometry.CHANNEL , AcquisitionGeometry.VERTICAL ,
                 AcquisitionGeometry.ANGLE]
        ss = sino.subset(new_order)

        self.assertListEqual(new_order, ss.geometry.dimension_labels)

        ss1 = ss.subset(vertical = 0)
        self.assertListEqual([AcquisitionGeometry.HORIZONTAL ,
                 AcquisitionGeometry.CHANNEL  ,
                 AcquisitionGeometry.ANGLE], ss1.geometry.dimension_labels)
        ss2 = ss.subset(vertical = 0, channel=0)
        self.assertListEqual([AcquisitionGeometry.HORIZONTAL ,
                 AcquisitionGeometry.ANGLE], ss2.geometry.dimension_labels)
Пример #6
0
def setupCCPiGeometries(ig, ag, counter):
    Phantom_ccpi = ig.allocate(dimension_labels=[
        ImageGeometry.HORIZONTAL_X, ImageGeometry.HORIZONTAL_Y,
        ImageGeometry.VERTICAL
    ])

    voxel_per_pixel = 1
    angles = ag.angles
    geoms = pbalg.pb_setup_geometry_from_image(Phantom_ccpi.as_array(), angles,
                                               voxel_per_pixel)

    pg = AcquisitionGeometry(
        'parallel',
        '3D',
        angles,
        geoms['n_h'],
        1.0,
        geoms['n_v'],
        1.0  #2D in 3D is a slice 1 pixel thick
    )

    center_of_rotation = Phantom_ccpi.get_dimension_size('horizontal_x') / 2
    #ad = AcquisitionData(geometry=pg,dimension_labels=['angle','vertical','horizontal'])
    ad = pg.allocate(dimension_labels=[
        AcquisitionGeometry.ANGLE, AcquisitionGeometry.VERTICAL,
        AcquisitionGeometry.HORIZONTAL
    ])
    geoms_i = pbalg.pb_setup_geometry_from_acquisition(ad.as_array(), angles,
                                                       center_of_rotation,
                                                       voxel_per_pixel)

    counter += 1

    if counter < 4:
        print(geoms, geoms_i)
        if (not (geoms_i == geoms)):
            print("not equal and {} {} {}".format(counter,
                                                  geoms['output_volume_z'],
                                                  geoms_i['output_volume_z']))
            X = max(geoms['output_volume_x'], geoms_i['output_volume_x'])
            Y = max(geoms['output_volume_y'], geoms_i['output_volume_y'])
            Z = max(geoms['output_volume_z'], geoms_i['output_volume_z'])
            return setupCCPiGeometries(X, Y, Z, angles, counter)
        else:
            print("happy now {} {} {}".format(counter,
                                              geoms['output_volume_z'],
                                              geoms_i['output_volume_z']))

            return geoms
    else:
        return geoms_i
Пример #7
0
 def get_acquisition_data(self, dimensions=None):
     '''
     This method load the acquisition data and given dimension and returns an AcquisitionData Object
     '''
     data = self.load_projection(dimensions)
     dims = self.get_projection_dimensions()
     geometry = AcquisitionGeometry(
         'parallel',
         '3D',
         self.get_projection_angles(),
         pixel_num_h=dims[2],
         pixel_size_h=1,
         pixel_num_v=dims[1],
         pixel_size_v=1,
         dist_source_center=None,
         dist_center_detector=None,
         channels=1,
         dimension_labels=['angle', 'vertical', 'horizontal'])
     out = geometry.allocate()
     out.fill(data)
     return out
Пример #8
0
class XTEKReader(object):
    '''
    Reader class for loading XTEK files
    '''
    def __init__(self, xtek_config_filename=None):
        '''
        This takes in the xtek config filename and loads the dataset and the
        required geometry parameters
        '''
        self.projections = None
        self.geometry = {}
        self.filename = xtek_config_filename
        self.load()

    def load(self):
        pixel_num_h = 0
        pixel_num_v = 0
        xpixel_size = 0
        ypixel_size = 0
        source_x = 0
        detector_x = 0
        with open(self.filename) as f:
            content = f.readlines()
        content = [x.strip() for x in content]
        for line in content:
            if line.startswith("SrcToObject"):
                source_x = float(line.split('=')[1])
            elif line.startswith("SrcToDetector"):
                detector_x = float(line.split('=')[1])
            elif line.startswith("DetectorPixelsY"):
                pixel_num_v = int(line.split('=')[1])
                #self.num_of_vertical_pixels = self.calc_v_alighment(self.num_of_vertical_pixels, self.pixels_per_voxel)
            elif line.startswith("DetectorPixelsX"):
                pixel_num_h = int(line.split('=')[1])
            elif line.startswith("DetectorPixelSizeX"):
                xpixel_size = float(line.split('=')[1])
            elif line.startswith("DetectorPixelSizeY"):
                ypixel_size = float(line.split('=')[1])
            elif line.startswith("Projections"):
                self.num_projections = int(line.split('=')[1])
            elif line.startswith("InitialAngle"):
                self.initial_angle = float(line.split('=')[1])
            elif line.startswith("Name"):
                self.experiment_name = line.split('=')[1]
            elif line.startswith("Scattering"):
                self.scattering = float(line.split('=')[1])
            elif line.startswith("WhiteLevel"):
                self.white_level = float(line.split('=')[1])
            elif line.startswith("MaskRadius"):
                self.mask_radius = float(line.split('=')[1])

        #Read Angles
        angles = self.read_angles()
        self.geometry = AcquisitionGeometry(
            'cone',
            '3D',
            angles,
            pixel_num_h,
            xpixel_size,
            pixel_num_v,
            ypixel_size,
            -1 * source_x,
            detector_x - source_x,
        )

    def read_angles(self):
        """
        Read the angles file .ang or _ctdata.txt file and returns the angles
        as an numpy array. 
        """
        input_path = os.path.dirname(self.filename)
        angles_ctdata_file = os.path.join(input_path, '_ctdata.txt')
        angles_named_file = os.path.join(input_path,
                                         self.experiment_name + '.ang')
        angles = np.zeros(self.num_projections, dtype='f')
        #look for _ctdata.txt
        if os.path.exists(angles_ctdata_file):
            #read txt file with angles
            with open(angles_ctdata_file) as f:
                content = f.readlines()
            #skip firt three lines
            #read the middle value of 3 values in each line as angles in degrees
            index = 0
            for line in content[3:]:
                self.angles[index] = float(line.split(' ')[1])
                index += 1
            angles = np.deg2rad(self.angles + self.initial_angle)
        elif os.path.exists(angles_named_file):
            #read the angles file which is text with first line as header
            with open(angles_named_file) as f:
                content = f.readlines()
            #skip first line
            index = 0
            for line in content[1:]:
                angles[index] = float(line.split(':')[1])
                index += 1
            angles = np.flipud(
                angles + self.initial_angle)  #angles are in the reverse order
        else:
            raise RuntimeError("Can't find angles file")
        return angles

    def load_projection(self, dimensions=None):
        '''
        This method reads the projection images from the directory and returns a numpy array
        '''
        if not pilAvailable:
            raise ImportError('Image library pillow is not installed')
        if dimensions != None:
            raise NotImplementedError(
                'Extracting subset of data is not implemented')
        input_path = os.path.dirname(self.filename)
        pixels = np.zeros((self.num_projections, self.geometry.pixel_num_h,
                           self.geometry.pixel_num_v),
                          dtype='float32')
        for i in range(1, self.num_projections + 1):
            im = Image.open(
                os.path.join(input_path,
                             self.experiment_name + "_%04d" % i + ".tif"))
            pixels[i - 1, :, :] = np.fliplr(np.transpose(np.array(
                im)))  ##Not sure this is the correct way to populate the image

        #normalising the data
        #TODO: Move this to a processor
        pixels = pixels - (self.white_level * self.scattering) / 100.0
        pixels[
            pixels <
            0.0] = 0.000001  # all negative values to approximately 0 as the std log of zero and non negative number is not defined
        return pixels

    def get_acquisition_data(self, dimensions=None):
        '''
        This method load the acquisition data and given dimension and returns an AcquisitionData Object
        '''
        data = self.load_projection(dimensions)
        out = self.geometry.allocate()
        out.fill(data)
        return out
Пример #9
0
    def get_acquisition_data_batch(self, bmin=None, bmax=None):
        if not h5pyAvailable:
            raise Exception("Error: h5py is not installed")
        if self.filename is None:
            return
        try:

            with NexusFile(self.filename, 'r') as file:
                try:
                    dims = self.get_projection_dimensions()
                except KeyError:
                    dims = file[self.data_path].shape
                if bmin is None or bmax is None:
                    raise ValueError(
                        'get_acquisition_data_batch: please specify fastest index batch limits'
                    )

                if bmin >= 0 and bmin < bmax and bmax <= dims[0]:
                    data = np.array(file[self.data_path][bmin:bmax])
                else:
                    raise ValueError(
                        'get_acquisition_data_batch: bmin {0}>0 bmax {1}<{2}'.
                        format(bmin, bmax, dims[0]))

        except:
            print("Error reading nexus file")
            raise

        try:
            angles = self.get_projection_angles()[bmin:bmax]
        except KeyError as ke:
            n = data.shape[0]
            angles = np.linspace(0, n, n + 1, dtype=np.float32)[bmin:bmax]

        if bmax - bmin > 1:

            geometry = AcquisitionGeometry(
                'parallel',
                '3D',
                angles,
                pixel_num_h=dims[2],
                pixel_size_h=1,
                pixel_num_v=bmax - bmin,
                pixel_size_v=1,
                dist_source_center=None,
                dist_center_detector=None,
                channels=1,
                dimension_labels=['angle', 'vertical', 'horizontal'])
            out = geometry.allocate()
            out.fill(data)
            return out

        elif bmax - bmin == 1:
            geometry = AcquisitionGeometry(
                'parallel',
                '2D',
                angles,
                pixel_num_h=dims[2],
                pixel_size_h=1,
                dist_source_center=None,
                dist_center_detector=None,
                channels=1,
                dimension_labels=['angle', 'horizontal'])
            out = geometry.allocate()
            out.fill(data.squeeze())
            return out
Пример #10
0
    def get_acquisition_data_subset(self, ymin=None, ymax=None):
        '''
        This method load the acquisition data and given dimension and returns an AcquisitionData Object
        '''
        if not h5pyAvailable:
            raise Exception("Error: h5py is not installed")
        if self.filename is None:
            return
        try:

            with NexusFile(self.filename, 'r') as file:
                try:
                    dims = self.get_projection_dimensions()
                except KeyError:
                    pass
                dims = file[self.data_path].shape
                if ymin is None and ymax is None:

                    try:
                        image_keys = self.get_image_keys()
                        print("image_keys", image_keys)
                        projections = np.array(file[self.data_path])
                        data = projections[image_keys == 0]
                    except KeyError as ke:
                        print(ke)
                        data = np.array(file[self.data_path])

                else:
                    image_keys = self.get_image_keys()
                    print("image_keys", image_keys)
                    projections = np.array(
                        file[self.data_path])[image_keys == 0]
                    if ymin is None:
                        ymin = 0
                        if ymax > dims[1]:
                            raise ValueError('ymax out of range')
                        data = projections[:, :ymax, :]
                    elif ymax is None:
                        ymax = dims[1]
                        if ymin < 0:
                            raise ValueError('ymin out of range')
                        data = projections[:, ymin:, :]
                    else:
                        if ymax > dims[1]:
                            raise ValueError('ymax out of range')
                        if ymin < 0:
                            raise ValueError('ymin out of range')

                        data = projections[:, ymin:ymax, :]

        except:
            print("Error reading nexus file")
            raise

        try:
            angles = self.get_projection_angles()
        except KeyError as ke:
            n = data.shape[0]
            angles = np.linspace(0, n, n + 1, dtype=np.float32)

        if ymax - ymin > 1:

            geometry = AcquisitionGeometry(
                'parallel',
                '3D',
                angles,
                pixel_num_h=dims[2],
                pixel_size_h=1,
                pixel_num_v=ymax - ymin,
                pixel_size_v=1,
                dist_source_center=None,
                dist_center_detector=None,
                channels=1,
                dimension_labels=['angle', 'vertical', 'horizontal'])
            out = geometry.allocate()
            out.fill(data)
            return out
        elif ymax - ymin == 1:
            geometry = AcquisitionGeometry(
                'parallel',
                '2D',
                angles,
                pixel_num_h=dims[2],
                pixel_size_h=1,
                dist_source_center=None,
                dist_center_detector=None,
                channels=1,
                dimension_labels=['angle', 'horizontal'])
            out = geometry.allocate()
            out.fill(data.squeeze())
            return out
Пример #11
0
class TestSubset(unittest.TestCase):
    def setUp(self):
        self.ig = ImageGeometry(1, 2, 3, channels=4)
        angles = numpy.asarray([90., 0., -90.], dtype=numpy.float32)

        self.ag = AcquisitionGeometry('cone',
                                      'edo',
                                      pixel_num_h=20,
                                      pixel_num_v=2,
                                      angles=angles,
                                      dist_source_center=312.2,
                                      dist_center_detector=123.,
                                      channels=4)

    def test_ImageDataAllocate1a(self):
        data = self.ig.allocate()
        default_dimension_labels = [
            ImageGeometry.CHANNEL, ImageGeometry.VERTICAL,
            ImageGeometry.HORIZONTAL_Y, ImageGeometry.HORIZONTAL_X
        ]
        self.assertTrue(
            default_dimension_labels == list(data.dimension_labels.values()))

    def test_ImageDataAllocate1b(self):
        data = self.ig.allocate()
        default_dimension_labels = [
            ImageGeometry.CHANNEL, ImageGeometry.VERTICAL,
            ImageGeometry.HORIZONTAL_Y, ImageGeometry.HORIZONTAL_X
        ]
        self.assertTrue(data.shape == (4, 3, 2, 1))

    def test_ImageDataAllocate2a(self):
        non_default_dimension_labels = [
            ImageGeometry.HORIZONTAL_X, ImageGeometry.VERTICAL,
            ImageGeometry.HORIZONTAL_Y, ImageGeometry.CHANNEL
        ]
        data = self.ig.allocate(dimension_labels=non_default_dimension_labels)
        self.assertTrue(non_default_dimension_labels == list(
            data.dimension_labels.values()))

    def test_ImageDataAllocate2b(self):
        non_default_dimension_labels = [
            ImageGeometry.HORIZONTAL_X, ImageGeometry.VERTICAL,
            ImageGeometry.HORIZONTAL_Y, ImageGeometry.CHANNEL
        ]
        data = self.ig.allocate(dimension_labels=non_default_dimension_labels)
        self.assertTrue(data.shape == (1, 3, 2, 4))

    def test_AcquisitionDataAllocate1a(self):
        data = self.ag.allocate()
        default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.ANGLE,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.HORIZONTAL
        ]
        self.assertTrue(
            default_dimension_labels == list(data.dimension_labels.values()))

    def test_AcquisitionDataAllocate1b(self):
        data = self.ag.allocate()
        default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.ANGLE,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.HORIZONTAL
        ]

        self.assertTrue(data.shape == (4, 3, 2, 20))

    def test_AcquisitionDataAllocate2a(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)

        self.assertTrue(non_default_dimension_labels == list(
            data.dimension_labels.values()))

    def test_AcquisitionDataAllocate2b(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)
        self.assertTrue(data.shape == (4, 20, 2, 3))

    def test_AcquisitionDataSubset1a(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)
        #self.assertTrue( data.shape == (4,20,2,3))
        sub = data.subset(vertical=0)
        self.assertTrue(sub.shape == (4, 20, 3))

    def test_AcquisitionDataSubset1b(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)
        #self.assertTrue( data.shape == (4,20,2,3))
        sub = data.subset(channel=0)
        self.assertTrue(sub.shape == (20, 2, 3))

    def test_AcquisitionDataSubset1c(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)
        #self.assertTrue( data.shape == (4,20,2,3))
        sub = data.subset(horizontal=0)
        self.assertTrue(sub.shape == (4, 2, 3))

    def test_AcquisitionDataSubset1d(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)
        #self.assertTrue( data.shape == (4,20,2,3))
        sliceme = 1
        sub = data.subset(angle=sliceme)
        #print (sub.shape  , sub.dimension_labels)
        self.assertTrue(sub.shape == (4, 20, 2))
        self.assertTrue(
            sub.geometry.angles[0] == data.geometry.angles[sliceme])

    def test_AcquisitionDataSubset1e(self):
        non_default_dimension_labels = [
            AcquisitionGeometry.CHANNEL, AcquisitionGeometry.HORIZONTAL,
            AcquisitionGeometry.VERTICAL, AcquisitionGeometry.ANGLE
        ]
        data = self.ag.allocate(dimension_labels=non_default_dimension_labels)
        #self.assertTrue( data.shape == (4,20,2,3))
        sliceme = 1
        sub = data.subset(angle=sliceme)
        self.assertTrue(
            sub.geometry.angles[0] == data.geometry.angles[sliceme])

    def test_AcquisitionDataSubset1f(self):

        data = self.ag.allocate()
        #self.assertTrue( data.shape == (4,20,2,3))
        sliceme = 1
        sub = data.subset(angle=sliceme)
        self.assertTrue(
            sub.geometry.angles[0] == data.geometry.angles[sliceme])
Пример #12
0
        return self.volume_geometry

    def range_geometry(self):
        return self.sinogram_geometry

    def norm(self):
        x0 = self.volume_geometry.allocate('random')
        self.s1, sall, svec = LinearOperator.PowerMethod(self, 50, x0)
        return self.s1


if __name__ == '__main__':

    N = 30
    angles = np.linspace(0, np.pi, 180)
    ig = ImageGeometry(N, N, N)
    ag = AcquisitionGeometry('parallel',
                             '3D',
                             angles,
                             pixel_num_h=N,
                             pixel_num_v=5)

    A = AstraProjector3DSimple(ig, ag)
    print(A.norm())

    x = ig.allocate('random_int')
    sin = A.direct(x)

    y = ag.allocate('random_int')
    im = A.adjoint(y)