Beispiel #1
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))
Beispiel #2
0
    def __rdiv__( self, other ) :

        unit2 = self.getAxisUnitSafely( yAxisIndex )
        other, unit1 = getOtherAndUnit( self, other )
        points = pointwiseXY.__rdiv__( self, other )
        unit = baseModule.processUnits( unit1, unit2, '/' )
        return( return_pointwiseXY_AsXYs( self, points, units = { yAxisIndex : unit } ) )
Beispiel #3
0
    def __idiv__( self, other ) :

        other, otherUnit1 = getOtherAndUnit( self, other )
        if( not( self.mutableYUnit ) ) :
            if( otherUnit1 != '' ) : raise Exception( "Self's y-unit is immutable and other has unit of '%s'" % otherUnit1 )
        pointwiseXY.__idiv__( self, other )
        if( otherUnit1 != '' ) : self.axes[yAxisIndex].unit = baseModule.processUnits( self.axes[yAxisIndex].unit, otherUnit1, '/' )
        return( self )
Beispiel #4
0
    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 ) )
Beispiel #5
0
    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, '*')))