def integrateThreeFunctions(self, f2, f3, domainMin=None, domainMax=None): """ :param f2: :param f3: :param domainMin: :param domainMax: :return: """ if (not isinstance(f2, XYs1d)): raise TypeError("f2 must be an instance of an XYs1d") if (not isinstance(f3, XYs1d)): raise TypeError("f3 must be an instance of an XYs1d") unit = self.axes[xAxisIndex].unit if (f2.axes[xAxisIndex].unit != unit): f2 = f2.copy() f2.convertAxisToUnit(xAxisIndex, unit) if (f3.axes[xAxisIndex].unit != unit): f3 = f3.copy() f3.convertAxisToUnit(xAxisIndex, unit) domainMin, domainMax = baseModule.getDomainLimits( self, domainMin, domainMax, unit) domainMin = max(domainMin, self.domainMin, f2.domainMin, f3.domainMin) domainMax = min(domainMax, self.domainMax, f2.domainMax, f3.domainMax) return (pointwiseXY.groupThreeFunctions(self, [domainMin, domainMax], f2, f3)[0])
def integrateTwoFunctions(self, f2, domainMin=None, domainMax=None): """ :param f2: :param domainMin: :param domainMax: :return: """ if (not isinstance(f2, XYs1d)): raise TypeError("f2 must be an instance of an XYs1d") unit = self.axes[xAxisIndex].unit if (f2.axes[xAxisIndex].unit != unit): f2 = f2.copy() f2.convertAxisToUnit(xAxisIndex, unit) domainMin, domainMax = baseModule.getDomainLimits( self, domainMin, domainMax, unit) domainMin = max(domainMin, self.domainMin, f2.domainMin) domainMax = min(domainMax, self.domainMax, f2.domainMax) return (PQU.PQU(pointwiseXY.groupTwoFunctions(self, [domainMin, domainMax], f2)[0], baseModule.processUnits( baseModule.processUnits(unit, self.axes[yAxisIndex].unit, '*'), f2.axes[yAxisIndex].unit, '*'), checkOrder=False))
def integrate( self, domainMin = None, domainMax = None ) : """ Definite integral of current ``XYs1d`` instance from ``domainMin`` to ``domainMax``: .. math:: \int_{domainMin}^{domainMax} dx \; XYs(x) If ``domainMin`` or ``domainMax`` is unspecified, it is taken from the domain of the self. """ unit = self.getAxisUnitSafely( xAxisIndex ) domainMin, domainMax = baseModule.getDomainLimits( self, domainMin, domainMax, unit ) domainMin = max( domainMin, self.domainMin ) domainMax = min( domainMax, self.domainMax ) return( PQU.PQU( pointwiseXY.integrate( self, domainMin = domainMin, domainMax = domainMax ), baseModule.processUnits( unit, self.getAxisUnitSafely( yAxisIndex ), '*' ), checkOrder = False ) )
def integrate(self, **limits): """ Integrate a XYsnd function. Supports limits for each axis. Example: >XYsnd.integrate( energy_in = ('1e-5 eV', '10 eV'), energy_out = ('1 keV', '10 keV') ) :param limits: dictionary containing limits for each independent axis (keyed by axis label or index). If an independent axis is missing from the dictionary, integrate over the entire domain of that axis. :return: float or PQU """ domainMin, domainMax = None, None if self.axes[-1].label in limits: domainMin, domainMax = limits.pop(self.axes[-1].label) elif self.axes[-1].index in limits: domainMin, domainMax = limits.pop(self.axes[-1].index) xys_ = [] for functional in self: if isinstance(functional, (XYsModule.XYs1d, series1dModule.series)): xys_.append([ functional.value, functional.integrate(domainMin=domainMin, domainMax=domainMax) ]) elif isinstance(functional, (XYsnd, regionsModule.regions)): xys_.append([functional.value, functional.integrate(**limits)]) else: raise TypeError("Unsupported class for integration: %s" % type(functional)) yUnit = xys_[0][1].getUnitSymbol() xys = [[x, float(y)] for x, y in xys_] unit = self.getAxisUnitSafely(self.dimension) domainMin, domainMax = baseModule.getDomainLimits( self, domainMin, domainMax, unit) value = float( XYsModule.XYs1d(xys, interpolation=self.interpolation).integrate( domainMin, domainMax)) return (PQU.PQU(value, baseModule.processUnits(unit, yUnit, '*')))