diff options
-rwxr-xr-x | Wrappers/Python/ccpi/framework/framework.py | 7 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/io/NEXUSDataReader.py | 25 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/io/NEXUSDataWriter.py | 31 |
3 files changed, 47 insertions, 16 deletions
diff --git a/Wrappers/Python/ccpi/framework/framework.py b/Wrappers/Python/ccpi/framework/framework.py index e0e1770..8ee2c75 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..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): @@ -94,10 +92,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 +148,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) ''' 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 |