From 1c1b7fc260743e56bf02fa1f26c3a04b713ebcda Mon Sep 17 00:00:00 2001 From: "Jakob Jorgensen, WS at HMXIF" Date: Wed, 12 Jun 2019 18:10:38 +0100 Subject: replace default for dot by numpy --- Wrappers/Python/ccpi/framework/framework.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/ccpi/framework/framework.py b/Wrappers/Python/ccpi/framework/framework.py index 7236e0e..e0e1770 100755 --- a/Wrappers/Python/ccpi/framework/framework.py +++ b/Wrappers/Python/ccpi/framework/framework.py @@ -764,14 +764,14 @@ class DataContainer(object): return numpy.sqrt(self.squared_norm()) def dot(self, other, *args, **kwargs): '''return the inner product of 2 DataContainers viewed as vectors''' - method = kwargs.get('method', 'reduce') + method = kwargs.get('method', 'numpy') if method not in ['numpy','reduce']: raise ValueError('dot: specified method not valid. Expecting numpy or reduce got {} '.format( method)) if self.shape == other.shape: # return (self*other).sum() if method == 'numpy': - return numpy.dot(self.as_array().ravel(), other.as_array()) + return numpy.dot(self.as_array().ravel(), other.as_array().ravel()) elif method == 'reduce': # see https://github.com/vais-ral/CCPi-Framework/pull/273 # notice that Python seems to be smart enough to use -- cgit v1.2.3 From 460e8a9022c5c2464133415c645ff54d176eb1ed Mon Sep 17 00:00:00 2001 From: Evelina Ametova Date: Thu, 13 Jun 2019 16:23:05 +0100 Subject: fix None values in Reader/ Wrirer --- Wrappers/Python/ccpi/framework/framework.py | 7 +++++-- Wrappers/Python/ccpi/io/NEXUSDataReader.py | 23 ++++++++++++++++++--- Wrappers/Python/ccpi/io/NEXUSDataWriter.py | 31 ++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 14 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/ccpi/framework/framework.py b/Wrappers/Python/ccpi/framework/framework.py index 7236e0e..94bc866 100755 --- a/Wrappers/Python/ccpi/framework/framework.py +++ b/Wrappers/Python/ccpi/framework/framework.py @@ -225,12 +225,15 @@ class AcquisitionGeometry(object): source_to_center_dist (if parallel: NaN) center_to_detector_dist (if parallel: NaN) standard or nonstandard (vec) geometry - angles + angles is expected numpy array, dtype - float32 angles_format radians or degrees """ self.geom_type = geom_type # 'parallel' or 'cone' self.dimension = dimension # 2D or 3D - self.angles = angles + if isinstance(angles, numpy.ndarray): + self.angles = angles + else: + raise ValueError('numpy array is expected') num_of_angles = len (angles) self.dist_source_center = dist_source_center diff --git a/Wrappers/Python/ccpi/io/NEXUSDataReader.py b/Wrappers/Python/ccpi/io/NEXUSDataReader.py index cf67e27..1a7be3b 100644 --- a/Wrappers/Python/ccpi/io/NEXUSDataReader.py +++ b/Wrappers/Python/ccpi/io/NEXUSDataReader.py @@ -94,10 +94,20 @@ class NEXUSDataReader(object): dimension_labels = dimension_labels) else: # AcquisitionData + if ds_data.attrs.__contains__('dist_source_center'): + dist_source_center = ds_data.attrs['dist_source_center'] + else: + dist_source_center = None + + if ds_data.attrs.__contains__('dist_center_detector'): + dist_center_detector = ds_data.attrs['dist_center_detector'] + else: + dist_center_detector = None + self._geometry = AcquisitionGeometry(geom_type = ds_data.attrs['geom_type'], dimension = ds_data.attrs['dimension'], - dist_source_center = ds_data.attrs['dist_source_center'], - dist_center_detector = ds_data.attrs['dist_center_detector'], + dist_source_center = dist_source_center, + dist_center_detector = dist_center_detector, pixel_num_h = ds_data.attrs['pixel_num_h'], pixel_size_h = ds_data.attrs['pixel_size_h'], pixel_num_v = ds_data.attrs['pixel_num_v'], @@ -140,4 +150,11 @@ image_data = reader.load_data() print(image_data) ig = reader.get_geometry() print(ig) -''' + +reader = NEXUSDataReader() +reader.set_up(nexus_file = '/home/evelina/test_nexus_ag.nxs') +ad = reader.load_data() +print(ad) +ad = reader.get_geometry() +print(ad) +''' \ No newline at end of file diff --git a/Wrappers/Python/ccpi/io/NEXUSDataWriter.py b/Wrappers/Python/ccpi/io/NEXUSDataWriter.py index f780f79..6f5c0b2 100644 --- a/Wrappers/Python/ccpi/io/NEXUSDataWriter.py +++ b/Wrappers/Python/ccpi/io/NEXUSDataWriter.py @@ -87,8 +87,10 @@ class NEXUSDataWriter(object): if (isinstance(self.data_container, AcquisitionData)): ds_data.attrs['geom_type'] = self.data_container.geometry.geom_type ds_data.attrs['dimension'] = self.data_container.geometry.dimension - ds_data.attrs['dist_source_center'] = self.data_container.geometry.dist_source_center - ds_data.attrs['dist_center_detector'] = self.data_container.geometry.dist_center_detector + if self.data_container.geometry.dist_source_center is not None: + ds_data.attrs['dist_source_center'] = self.data_container.geometry.dist_source_center + if self.data_container.geometry.dist_center_detector is not None: + ds_data.attrs['dist_center_detector'] = self.data_container.geometry.dist_center_detector ds_data.attrs['pixel_num_h'] = self.data_container.geometry.pixel_num_h ds_data.attrs['pixel_size_h'] = self.data_container.geometry.pixel_size_h ds_data.attrs['pixel_num_v'] = self.data_container.geometry.pixel_num_v @@ -138,14 +140,25 @@ writer.write_file() ig = ImageGeometry(voxel_num_x = 100, voxel_num_y = 100) - im = ImageData(array = numpy.zeros((100, 100), dtype = 'float'), geometry = ig) - im_writer = NEXUSDataWriter() -writer.set_up(file_name = '/home/evelina/test_nexus_im.nxs', - data_container = im) - -writer.write_file() -''' +im_writer.set_up(file_name = '/home/evelina/test_nexus_im.nxs', + data_container = im) +im_writer.write_file() + +ag = AcquisitionGeometry(geom_type = 'parallel', + dimension = '2D', + angles = numpy.array([0, 1]), + pixel_num_h = 200, + pixel_size_h = 1, + pixel_num_v = 100, + pixel_size_v = 1) + +ad = ag.allocate() +ag_writer = NEXUSDataWriter() +ag_writer.set_up(file_name = '/home/evelina/test_nexus_ag.nxs', + data_container = ad) +ag_writer.write_file() +''' \ No newline at end of file -- cgit v1.2.3 From 641b13bfc1e55335138b5ce14c309106f8699a8f Mon Sep 17 00:00:00 2001 From: evelinaametova <47400194+evelinaametova@users.noreply.github.com> Date: Thu, 13 Jun 2019 16:37:26 +0100 Subject: Update NEXUSDataReader.py --- Wrappers/Python/ccpi/io/NEXUSDataReader.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/ccpi/io/NEXUSDataReader.py b/Wrappers/Python/ccpi/io/NEXUSDataReader.py index 1a7be3b..e6d4d3b 100644 --- a/Wrappers/Python/ccpi/io/NEXUSDataReader.py +++ b/Wrappers/Python/ccpi/io/NEXUSDataReader.py @@ -35,9 +35,7 @@ class NEXUSDataReader(object): self.nexus_file = kwargs.get('nexus_file', None) if self.nexus_file is not None: - self.set_up(nexus_file = self.nexus_file, - roi = self.roi, - binning = self.binning) + self.set_up(nexus_file = self.nexus_file) def set_up(self, nexus_file = None): @@ -157,4 +155,4 @@ ad = reader.load_data() print(ad) ad = reader.get_geometry() print(ad) -''' \ No newline at end of file +''' -- cgit v1.2.3