def test_AcquisitionDataPadder(self):
        reader = NexusReader(self.filename)
        ad = reader.get_acquisition_data_whole()
        print(ad.geometry)
        cf = CenterOfRotationFinder()
        cf.set_input(ad)
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())

        adp = AcquisitionDataPadder(
            acquisition_geometry=cf.get_input().geometry,
            center_of_rotation=cf.get_output(),
            pad_value=0)
        adp.set_input(ad)
        padded_data = adp.get_output()
        print("Padded data shape", padded_data.shape)
        print("      ", padded_data.dimension_labels)
        idx = None
        for k, v in padded_data.dimension_labels.items():
            if v == AcquisitionGeometry.HORIZONTAL:
                idx = k

        padded_axis = padded_data.shape[idx]
        self.assertEqual(padded_axis, math.ceil(cf.get_output() * 2))
        numpy.save("pippo.npy", padded_data.as_array())
示例#2
0
 def testLoadProjectionCompareFull(self):
     nr = NexusReader(self.filename)
     projections_full = nr.load_projection()
     projections_part = nr.load_projection(
         (slice(None, None), slice(None, None), slice(None, None)))
     numpy.testing.assert_array_equal(projections_part,
                                      projections_full[:, :, :])
示例#3
0
    def test_get_acquisition_data_subset(self):
        nr = NexusReader(self.filename)
        key = nr.get_image_keys()
        sl = nr.get_acquisition_data_subset(0, 10)
        data = nr.get_acquisition_data().subset(['vertical', 'horizontal'])

        self.assertTrue(sl.shape, (10, data.shape[1]))
示例#4
0
 def testLoadProjectionCompareRandom(self):
     nr = NexusReader(self.filename)
     projections_full = nr.load_projection()
     projections_part = nr.load_projection(
         (slice(1, 8), slice(5, 10), slice(8, 20)))
     numpy.testing.assert_array_equal(projections_part,
                                      projections_full[1:8, 5:10, 8:20])
示例#5
0
 def testLoadProjectionCompareMulti(self):
     nr = NexusReader(self.filename)
     projections_full = nr.load_projection()
     projections_part = nr.load_projection(
         (slice(0, 3), slice(0, 135), slice(0, 160)))
     numpy.testing.assert_array_equal(projections_part,
                                      projections_full[0:3, :, :])
示例#6
0
    def test_CenterOfRotation(self):
        reader = NexusReader(self.filename)
        data = reader.get_acquisition_data_whole()

        ad = data.clone()
        print(ad)
        cf = CenterOfRotationFinder()
        cf.set_input(ad)
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())

        #def test_CenterOfRotation_transpose(self):
        #reader = NexusReader(self.filename)
        #data = reader.get_acquisition_data_whole()

        ad = data.clone()
        ad = ad.subset(['vertical', 'angle', 'horizontal'])
        print(ad)
        cf = CenterOfRotationFinder()
        cf.set_input(ad)
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())

        #def test_CenterOfRotation_singleslice(self):
        #reader = NexusReader(self.filename)
        #data = reader.get_acquisition_data_whole()

        ad = data.clone()
        ad = ad.subset(vertical=67)
        print(ad)
        cf = CenterOfRotationFinder()
        cf.set_input(ad)
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())

        #def test_CenterOfRotation_slice(self):
        #reader = NexusReader(self.filename)
        #data = reader.get_acquisition_data_whole()

        ad = data.clone()
        print(ad)
        cf = CenterOfRotationFinder()
        cf.set_input(ad)
        cf.set_slice(80)
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())
        cf.set_slice()
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())
        cf.set_slice('centre')
        print("Center of rotation", cf.get_output())
        self.assertAlmostEqual(86.25, cf.get_output())
 def testProjectionAngles(self):
     nr = NexusReader(self.filename)
     angles = nr.getProjectionAngles()
     self.assertEqual(angles.shape, (91,), "Loaded projection number of angles are not correct")        
 def testLoadDarkCompareFull(self):
     nr = NexusReader(self.filename)
     darks_full = nr.loadDark()
     darks_part = nr.loadDark((slice(None,None), slice(None,None), slice(None,None))) 
     numpy.testing.assert_array_equal(darks_part, darks_full[:,:,:])
 def testLoadFlatCompareFull(self):
     nr = NexusReader(self.filename)
     flats_full = nr.loadFlat()
     flats_part = nr.loadFlat((slice(None,None), slice(None,None), slice(None,None))) 
     numpy.testing.assert_array_equal(flats_part, flats_full[:,:,:])
示例#10
0
 def testLoadProjectionWithDimensions(self):
     nr = NexusReader(self.filename)
     projections = nr.loadProjection((slice(0,1), slice(0,135), slice(0,160)))        
     self.assertEqual(projections.shape, (1,135,160), "Loaded projection data dimensions are not correct")        
示例#11
0
 def testGetProjectionDimensions(self):
     nr = NexusReader(self.filename)
     self.assertEqual(nr.getProjectionDimensions(), (91,135,160), "Projection dimensions are not correct")        
示例#12
0
 def testGetDimensions(self):
     nr = NexusReader(self.filename)
     self.assertEqual(nr.getSinogramDimensions(), (135, 91, 160), "Sinogram dimensions are not correct")
示例#13
0
    def testAll(self):
        if has_wget:
            # def testGetDimensions(self):
            nr = NexusReader(self.filename)
            self.assertEqual(nr.get_sinogram_dimensions(), (135, 91, 160),
                             "Sinogram dimensions are not correct")

            # def testGetProjectionDimensions(self):
            nr = NexusReader(self.filename)
            self.assertEqual(nr.get_projection_dimensions(), (91, 135, 160),
                             "Projection dimensions are not correct")

            # def testLoadProjectionWithoutDimensions(self):
            nr = NexusReader(self.filename)
            projections = nr.load_projection()
            self.assertEqual(
                projections.shape, (91, 135, 160),
                "Loaded projection data dimensions are not correct")

            # def testLoadProjectionWithDimensions(self):
            nr = NexusReader(self.filename)
            projections = nr.load_projection(
                (slice(0, 1), slice(0, 135), slice(0, 160)))
            self.assertEqual(
                projections.shape, (1, 135, 160),
                "Loaded projection data dimensions are not correct")

            # def testLoadProjectionCompareSingle(self):
            nr = NexusReader(self.filename)
            projections_full = nr.load_projection()
            projections_part = nr.load_projection(
                (slice(0, 1), slice(0, 135), slice(0, 160)))
            numpy.testing.assert_array_equal(projections_part,
                                             projections_full[0:1, :, :])

            # def testLoadProjectionCompareMulti(self):
            nr = NexusReader(self.filename)
            projections_full = nr.load_projection()
            projections_part = nr.load_projection(
                (slice(0, 3), slice(0, 135), slice(0, 160)))
            numpy.testing.assert_array_equal(projections_part,
                                             projections_full[0:3, :, :])

            # def testLoadProjectionCompareRandom(self):
            nr = NexusReader(self.filename)
            projections_full = nr.load_projection()
            projections_part = nr.load_projection(
                (slice(1, 8), slice(5, 10), slice(8, 20)))
            numpy.testing.assert_array_equal(projections_part,
                                             projections_full[1:8, 5:10, 8:20])

            # def testLoadProjectionCompareFull(self):
            nr = NexusReader(self.filename)
            projections_full = nr.load_projection()
            projections_part = nr.load_projection(
                (slice(None, None), slice(None, None), slice(None, None)))
            numpy.testing.assert_array_equal(projections_part,
                                             projections_full[:, :, :])

            # def testLoadFlatCompareFull(self):
            nr = NexusReader(self.filename)
            flats_full = nr.load_flat()
            flats_part = nr.load_flat(
                (slice(None, None), slice(None, None), slice(None, None)))
            numpy.testing.assert_array_equal(flats_part, flats_full[:, :, :])

            # def testLoadDarkCompareFull(self):
            nr = NexusReader(self.filename)
            darks_full = nr.load_dark()
            darks_part = nr.load_dark(
                (slice(None, None), slice(None, None), slice(None, None)))
            numpy.testing.assert_array_equal(darks_part, darks_full[:, :, :])

            # def testProjectionAngles(self):
            nr = NexusReader(self.filename)
            angles = nr.get_projection_angles()
            self.assertEqual(
                angles.shape, (91, ),
                "Loaded projection number of angles are not correct")

            # def test_get_acquisition_data_subset(self):
            nr = NexusReader(self.filename)
            key = nr.get_image_keys()
            sl = nr.get_acquisition_data_subset(0, 10)
            data = nr.get_acquisition_data()
            print(data.geometry)
            print(data.geometry.dimension_labels)
            print(data.dimension_labels)
            rdata = data.subset(channel=0)

            #

            self.assertTrue(sl.shape, (10, rdata.shape[1]))

            try:
                data.subset(['vertical', 'horizontal'])
                self.assertTrue(False)
            except ValueError as ve:
                print("Exception catched", ve)
                self.assertTrue(True)
        else:
            # skips all tests if module wget is not present
            self.assertFalse(has_wget)
示例#14
0
import os


# Define utility function to average over flat and dark images.
def avg_img(image):
    shape = list(numpy.shape(image))
    l = shape.pop(0)
    avg = numpy.zeros(shape)
    for i in range(l):
        avg += image[i] / l
    return avg


# Set up a reader object pointing to the Nexus data set. Revise path as needed.
reader = NexusReader(
    os.path.join("..", "..", "..", "..", "CCPi-ReconstructionFramework",
                 "data", "24737_fd.nxs"))

# Read and print the dimensions of the raw projections
dims = reader.get_projection_dimensions()
print(dims)

# Load and average all flat and dark images in preparation for normalising data.
flat = avg_img(reader.load_flat())
dark = avg_img(reader.load_dark())

# Set up normaliser object for normalising data by flat and dark images.
norm = Normalizer(flat_field=flat, dark_field=dark)

# Load the raw projections and pass as input to the normaliser.
norm.set_input(reader.get_acquisition_data())
示例#15
0
 def testLoadProjectionWithoutDimensions(self):
     nr = NexusReader(self.filename)
     projections = nr.load_projection()
     self.assertEqual(projections.shape, (91, 135, 160),
                      "Loaded projection data dimensions are not correct")
        i = 0
        while i < N:
            stats , i = DataStatMoments.add_sample(data, i, self.axis, stats, offset=self.offset)
        self.offset += N
        labels = ['StatisticalMoments']
        
        labels += [data.dimension_labels[i] \
                   for i in range(len(data.dimension_labels)) if i != ax]
        y = DataContainer( stats[:4] , False, 
                    dimension_labels=labels)
        return y

directory = r'E:\Documents\Dataset\CCPi\Nexus_test'
data_path="entry1/instrument/pco1_hw_hdf_nochunking/data"

reader = NexusReader(os.path.join( os.path.abspath(directory) , '74331.nxs'))

print ("read flat")
read_flat = NexusReader(os.path.join( os.path.abspath(directory) , '74240.nxs'))
read_flat.data_path = data_path
flatsslice = read_flat.get_acquisition_data_whole()
avg = DataStatMoments('angle')

avg.set_input(flatsslice)
flats = avg.get_output()

ave = averager()
ave.stats(flatsslice.array[:,0,0])

print ("avg" , ave.avg, flats.array[0][0][0])
print ("var" , ave.var, flats.array[1][0][0])