summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python
diff options
context:
space:
mode:
authorEvelina Ametova <evelinaametova@gmail.com>2019-06-13 16:23:05 +0100
committerEvelina Ametova <evelinaametova@gmail.com>2019-06-13 16:23:05 +0100
commit460e8a9022c5c2464133415c645ff54d176eb1ed (patch)
tree38084f657e5f6371862295f20459b40bdd821d61 /Wrappers/Python
parentd7fa15c50ee9155ac24ecfa88ca74b111690532e (diff)
downloadframework-460e8a9022c5c2464133415c645ff54d176eb1ed.tar.gz
framework-460e8a9022c5c2464133415c645ff54d176eb1ed.tar.bz2
framework-460e8a9022c5c2464133415c645ff54d176eb1ed.tar.xz
framework-460e8a9022c5c2464133415c645ff54d176eb1ed.zip
fix None values in Reader/ Wrirer
Diffstat (limited to 'Wrappers/Python')
-rwxr-xr-xWrappers/Python/ccpi/framework/framework.py7
-rw-r--r--Wrappers/Python/ccpi/io/NEXUSDataReader.py23
-rw-r--r--Wrappers/Python/ccpi/io/NEXUSDataWriter.py31
3 files changed, 47 insertions, 14 deletions
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