def edf(self, x_start=0, x_end=0, x_step=1, y_start=0, y_end=0, y_step=1, z_start=0, z_end=0, z_step=1): """ Read 3-D tomographic projection data from an EDF (ESRF) file. Parameters file_name : str Input edf file. x_start, x_end, x_step : scalar, optional Values of the start, end and step of the slicing for the whole array. y_start, y_end, y_step : scalar, optional Values of the start, end and step of the slicing for the whole array. z_start, z_end, z_step : scalar, optional Values of the start, end and step of the slicing for the whole array. Returns out : array Returns the data as a matrix. """ # Read data from file. f = EdfFile(self.file_name, access='r') dic = f.GetStaticHeader(0) tmpdata = np.empty((f.NumImages, int(dic['Dim_2']), int(dic['Dim_1']))) for (i, ar) in enumerate(tmpdata): tmpdata[i::] = f.GetData(i) num_z, num_y, num_x = np.shape(tmpdata) if x_end is 0: x_end = num_x if y_end is 0: y_end = num_y if z_end is 0: z_end = num_z # Construct dataset from desired y. dataset = tmpdata[z_start:z_end:z_step, y_start:y_end:y_step, x_start:x_end:x_step] return dataset
def edf2(self, x_start=0, x_end=0, x_step=1, y_start=0, y_end=0, y_step=1): """ Read 2-D tomographic projection data from an EDF (ESRF) file. Parameters file_name : str Input edf file. x_start, x_end, x_step : scalar, optional Values of the start, end and step of the slicing for the whole array. y_start, y_end, y_step : scalar, optional Values of the start, end and step of the slicing for the whole array. Returns out : array Output 2-D matrix as numpy array. """ try: # Read data from file. f = EdfFile(self.file_name, access='r') dic = f.GetStaticHeader(0) tmpdata = np.empty((int(dic['Dim_2']), int(dic['Dim_1']))) tmpdata[::] = f.GetData(0) num_y, num_x = np.shape(tmpdata) if x_end is 0: x_end = num_x if y_end is 0: y_end = num_y array = tmpdata[y_start:y_end:y_step, x_start:x_end:x_step] except KeyError: self.logger.error( "FILE DOES NOT CONTAIN A VALID TOMOGRAPHY DATA SET") array = None return array
def edf2(self, x_start=0, x_end=0, x_step=1, y_start=0, y_end=0, y_step=1): """ Read 2-D tomographic projection data from an EDF (ESRF) file. Parameters file_name : str Input edf file. x_start, x_end, x_step : scalar, optional Values of the start, end and step of the slicing for the whole array. y_start, y_end, y_step : scalar, optional Values of the start, end and step of the slicing for the whole array. Returns out : array Output 2-D matrix as numpy array. """ # Read data from file. f = EdfFile(self.file_name, access='r') dic = f.GetStaticHeader(0) tmpdata = np.empty((int(dic['Dim_2']), int(dic['Dim_1']))) tmpdata[::] = f.GetData(0) num_y, num_x = np.shape(tmpdata) if x_end is 0: x_end = num_x if y_end is 0: y_end = num_y return tmpdata[y_start:y_end:y_step, x_start:x_end:x_step]