def _perform_operation(self, other, operation): """ """ # First, check the data compatibility dy, dy_other = self._validity_check(other) result = self.clone_without_data(len(self.x)) result.copy_from_datainfo(data1d=self) if self.dxw == None: result.dxw = None else: result.dxw = numpy.zeros(len(self.x)) if self.dxl == None: result.dxl = None else: result.dxl = numpy.zeros(len(self.x)) for i in range(numpy.size(self.x)): result.x[i] = self.x[i] if self.dx is not None and len(self.x) == len(self.dx): result.dx[i] = self.dx[i] if self.dxw is not None and len(self.x) == len(self.dxw): result.dxw[i] = self.dxw[i] if self.dxl is not None and len(self.x) == len(self.dxl): result.dxl[i] = self.dxl[i] a = Uncertainty(self.y[i], dy[i]**2) if isinstance(other, Data1D): b = Uncertainty(other.y[i], dy_other[i]**2) if other.dx is not None: result.dx[i] *= self.dx[i] result.dx[i] += (other.dx[i]**2) result.dx[i] /= 2 result.dx[i] = math.sqrt(result.dx[i]) if result.dxl is not None and other.dxl is not None: result.dxl[i] *= self.dxl[i] other.dxl[i] += (other.dxl[i]**2) result.dxl[i] /= 2 result.dxl[i] = math.sqrt(result.dxl[i]) if result.dxw is not None and self.dxw is not None: result.dxw[i] *= self.dxw[i] other.dxw[i] += (other.dxw[i]**2) result.dxw[i] /= 2 result.dxw[i] = math.sqrt(result.dxw[i]) else: b = other output = operation(a, b) result.y[i] = output.x result.dy[i] = math.sqrt(math.fabs(output.variance)) return result
def _perform_operation(self, other, operation): """ Perform 2D operations between data sets :param other: other data set :param operation: function defining the operation """ # First, check the data compatibility dy, dy_other = self._validity_check(other) result = self.clone_without_data(np.size(self.data)) if self.dqx_data is None or self.dqy_data is None: result.dqx_data = None result.dqy_data = None else: result.dqx_data = np.zeros(len(self.data)) result.dqy_data = np.zeros(len(self.data)) for i in range(np.size(self.data)): result.data[i] = self.data[i] if (self.err_data is not None and np.size(self.data) == np.size(self.err_data)): result.err_data[i] = self.err_data[i] if self.dqx_data is not None: result.dqx_data[i] = self.dqx_data[i] if self.dqy_data is not None: result.dqy_data[i] = self.dqy_data[i] result.qx_data[i] = self.qx_data[i] result.qy_data[i] = self.qy_data[i] result.q_data[i] = self.q_data[i] result.mask[i] = self.mask[i] a = Uncertainty(self.data[i], dy[i]**2) if isinstance(other, Data2D): b = Uncertainty(other.data[i], dy_other[i]**2) if other.dqx_data is not None and result.dqx_data is not None: result.dqx_data[i] *= self.dqx_data[i] result.dqx_data[i] += (other.dqx_data[i]**2) result.dqx_data[i] /= 2 result.dqx_data[i] = math.sqrt(result.dqx_data[i]) if other.dqy_data is not None and result.dqy_data is not None: result.dqy_data[i] *= self.dqy_data[i] result.dqy_data[i] += (other.dqy_data[i]**2) result.dqy_data[i] /= 2 result.dqy_data[i] = math.sqrt(result.dqy_data[i]) else: b = other output = operation(a, b) result.data[i] = output.x result.err_data[i] = math.sqrt(math.fabs(output.variance)) return result
def _perform_operation(self, other, operation): """ Perform 2D operations between data sets :param other: other data set :param operation: function defining the operation """ # First, check the data compatibility dy, dy_other = self._validity_check(other) result = Data2D(image=None, qx_data=None, qy_data=None, q_data=None, err_image=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None) result.clone_without_data(len(self.data)) result.copy_from_datainfo(data2d=self) result.xmin = self.xmin result.xmax = self.xmax result.ymin = self.ymin result.ymax = self.ymax if self.dqx_data == None or self.dqy_data == None: result.dqx_data = None result.dqy_data = None else: result.dqx_data = numpy.zeros(len(self.data)) result.dqy_data = numpy.zeros(len(self.data)) for i in range(numpy.size(self.data)): result.data[i] = self.data[i] if self.err_data is not None and \ numpy.size(self.data) == numpy.size(self.err_data): result.err_data[i] = self.err_data[i] if self.dqx_data is not None: result.dqx_data[i] = self.dqx_data[i] if self.dqy_data is not None: result.dqy_data[i] = self.dqy_data[i] result.qx_data[i] = self.qx_data[i] result.qy_data[i] = self.qy_data[i] result.q_data[i] = self.q_data[i] result.mask[i] = self.mask[i] a = Uncertainty(self.data[i], dy[i]**2) if isinstance(other, Data2D): b = Uncertainty(other.data[i], dy_other[i]**2) if other.dqx_data is not None and \ result.dqx_data is not None: result.dqx_data[i] *= self.dqx_data[i] result.dqx_data[i] += (other.dqx_data[i]**2) result.dqx_data[i] /= 2 result.dqx_data[i] = math.sqrt(result.dqx_data[i]) if other.dqy_data is not None and \ result.dqy_data is not None: result.dqy_data[i] *= self.dqy_data[i] result.dqy_data[i] += (other.dqy_data[i]**2) result.dqy_data[i] /= 2 result.dqy_data[i] = math.sqrt(result.dqy_data[i]) else: b = other output = operation(a, b) result.data[i] = output.x result.err_data[i] = math.sqrt(math.fabs(output.variance)) return result