Exemple #1
0
def check2dPoint(p):
    """check2dPoint( p )\n    Checks that p is the list [ number, number ]. A raise is generated if p is not."""

    if ((type(p) != type([])) or (len(p) != 2)
            or not (fudgemath.isNumber(p[0]))
            or not (fudgemath.isNumber(p[1]))):
        raise Exception(
            "\nError in check2dPoint: data point not list of [ number, number ]:",
            p)
Exemple #2
0
def check1dData(data):
    """Checks that data is a python list of numbers. Triggers a raise if it is not.  Data may be a
python list or an instance that is a subclass of endl1dmath."""

    data = get1dmathData(data, "check1dData", "")
    i = 0
    for p in data:
        if (not (fudgemath.isNumber(p))):
            raise Exception(
                "\nError in check1dData: data at index %d is not a number." %
                i)
        i += 1
Exemple #3
0
    def __div__(self, other):
        """Returns an endl3dmath instance that is the division of self by other. Currently, other must be a number."""

        if (fudgemath.isNumber(other)):
            d = self.copyData()
            for x, yzs in d.data:
                for yz in yzs:
                    yz[1] = yz[1] / other
        else:
            raise Exception(
                'divisor of an endl3dmath instance can only be a number, %s is not allowed'
                % brb.getType(other))
Exemple #4
0
    def __add__(self, other):
        """Returns an endl3dmath instance that is the addition of self and other. If other is a number, then other is added
        to all z-values. If other is an endl3dmath instance, then 
            1) a union of the x-values from self and other is formed,
            2) for each x-value, the yz-values from self and other are obtained and added as two endl2dmath objects
                which forms the addition at x.
        Note that a renormalization of the returned instance may be needed for normalized distributions."""

        if (fudgemath.isNumber(other)):
            other = float(other)
            d = self.copyData()
            for x, yzs in d.data:
                for yz in yzs:
                    yz[1] = yz[1] + other
        else:
            data = endl3dmathmisc.valid3dClassType(other, "endl3dmath.__add__",
                                                   "addition")
            if (len(self) < 1):
                d = data.copyData()
            elif (len(data) < 1):
                d = self.copyData()
            else:
                try:
                    unitBaseSelf = self.unitbase
                except:
                    unitBaseSelf = False
                try:
                    unitBaseOther = other.unitbase
                except:
                    unitBaseOther = False

                xs = [x for x, yz in self.data]
                for x, yz in other.data:
                    if (x not in xs): xs.append(x)
                xs.sort()
                d = []
                for x in xs:
                    yz = self.getAtX(
                        x, unitBase=unitBaseSelf,
                        endl2dmathObject=True) + other.getAtX(
                            x, unitBase=unitBaseOther, endl2dmathObject=True)
                    d.append([x, yz.data])
                d = endl3dmath(d,
                               interpolation=min(self.interpolation,
                                                 data.interpolation))
        return (d)
Exemple #5
0
def getTypeNameGamma(info, ZA, level=None, levelIndex=None):

    if (level is not None):
        if (fudgemath.isNumber(level)):
            if (level < 0):
                if ((level > -100) and (levelIndex == 0)):
                    level = 0
                else:
                    message = 'Negative excitation level = %s for ZA = %s and levelIndex = %s is not allowed' % (
                        level, ZA, levelIndex)
                    sys.stderr.write(message + '\n')
                    info.doRaise.append(message)
                    level = 0
        elif (type(level) != type('')):
            raise Exception(
                'for ZA %d, level (type ="%s") must be a number or a string' %
                (ZA, brb.getType(level)))
    if (ZA == 0): ZA = 7  # Special case for gammas which are yo = 7 for ENDL.
    p = getTypeName(info,
                    ZA,
                    level=level,
                    levelIndex=levelIndex,
                    levelUnit='eV')
    return (p)
Exemple #6
0
def check3dData(data,
                allowNegativeX=False,
                allowZeroX=True,
                allowNegativeY=False,
                allowSameY=False,
                allowZeroY=True,
                positiveZ=False,
                printWarning=True,
                printErrors=True,
                xCloseEps=None,
                maxAbsFloatValue=None):
    """Checks that data is a valid structure for endl3dmath data. Triggers a raise if it is not.  Data may be
    an instance that is a subclass of endl3dmath or a python list as required by endl3dmath. If allowZeroX is 
    False, a zero first x value will generate a raise. If allowNegativeX is true than the x data can have negative 
    values (ENDL 3d-data has projectile energy as the x-data which must always be > 0. ). See endl2dmathmisc.check2dData's 
    allowSameX, allowZeroX, positiveY and xCloseEps argument for meaning of allowSameY, allowZeroY, positiveZ and 
    xCloseEps respectively.  If printErrors is 'True' then errors are printed, and if at least one error exist, a 
    raise will be executed.  printWarning is just passed on to endl2dmathmisc.check2dData."""

    points = get3dmathData(data, "check3dData", "")
    messages = []
    xPrior = None
    if ((points[0][0] == 0.) and (not allowZeroX)):
        s = 'check3dData: zero x value at index = 0'
        messages.append(s)
        if (printErrors):
            fudgemisc.printWarning('\n'.join(
                fudgemisc.checkMessagesToString(s, indentation='      ')))
    elif ((points[0][0] < 0.) and (not allowNegativeX)):
        s = 'check3dData: negative x = %e' % points[0][0]
        messages.append(s)
        if (printErrors):
            fudgemisc.printWarning('\n'.join(
                fudgemisc.checkMessagesToString(s, indentation='      ')))
    i = 0
    for x, yz in points:
        if (fudgemath.isNumber(x)):
            fudgemath.checkNumber( x, "check3dData: x[%d]" % i, messages = messages, indentation = '      ', printErrors = printErrors, \
                maxAbsFloatValue = maxAbsFloatValue )
        else:
            s = 'check3dData: x = %s is not a number' % points[0][0]
            messages.append(s)
            if (printErrors):
                fudgemisc.printWarning('\n'.join(
                    fudgemisc.checkMessagesToString(s, indentation='      ')))
        if (xPrior is not None):
            if (x <= xPrior):
                s = 'check3dData: x value x[%d] >= x[%d] (%e >= %e)' % (
                    i - 1, i, xPrior, x)
                messages.append(s)
                if (printErrors):
                    fudgemisc.printWarning('\n'.join(
                        fudgemisc.checkMessagesToString(s,
                                                        indentation='      ')))
        ne, badXIndicies, messages2d = endl2dmathmisc.check2dData( yz, allowNegativeX = allowNegativeY, allowSameX = allowSameY, allowZeroX = allowZeroY, \
            positiveY = positiveZ, printWarning = printWarning, printErrors = False, xCloseEps = xCloseEps, maxAbsFloatValue = maxAbsFloatValue )
        if (len(messages2d) > 0):
            s = 'check3dData x value = %e' % x
            messages.append([s, messages2d])
            if (printErrors):
                fudgemisc.printWarning('\n'.join(
                    fudgemisc.checkMessagesToString(s, indentation='      ')))
        xPrior = x
        i += 1
    return (messages)