Пример #1
0
    def __repr__(self):
        """Returns a string of the za and mass as they would appear in a bdfls file."""

        if (self.format == 'old'):
            s = "    %6.4d" % self.za
            if (self.mass == 0):
                s = s + "    0."
            elif (self.mass < 1.):
                s = s + "%14.8f" % self.mass
            elif (self.mass > (1.e4 - 1e-6)):
                if (self.mass <= (1.e5 - 1e-6)):
                    s = s + "%12.5f" % self.mass
                elif (self.mass <= (1.e6 - 1e-5)):
                    s = s + "%12.4f" % self.mass
                elif (self.mass <= (1.e7 - 1e-4)):
                    s = s + "%12.3f" % self.mass
                elif (self.mass <= (1.e8 - 1e-3)):
                    s = s + "%12.2f" % self.mass
                elif (self.mass <= (1.e9 - 1e-2)):
                    s = s + "%12.1f" % self.mass
                elif (self.mass <= (1.e10 - 1e-1)):
                    s = s + "%12.0f" % self.mass
                else:
                    s = s + "%12.5e" % self.mass
            else:
                s = s + "%12.6f" % self.mass
                if (((self.za % 1000) == 0) or (self.za == 99120)
                        or (self.za == 99125)):
                    while (s[-1] == '0'):
                        if (s[-2] == "."): break
                        s = s[:-1]
        elif (self.format == 'Audi2003'):
            s = "    %6d" % self.za
            d = ' %17.12f' % self.mass
            try:
                while (d[-1] == '0'):
                    d = d[:-1]
            except:
                fudgemisc.printWarning(d)
                raise
            s += d
        else:
            raise Exception(
                '\nError in bdfls.bdfls_mass.__repr__: bad format = "%s"' %
                self.format)
        return s
Пример #2
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)
Пример #3
0
def check4dData(data,
                allowNegativeT=False,
                allowZeroT=True,
                allowNegativeX=False,
                allowZeroX=True,
                allowSameY=False,
                allowNegativeY=False,
                allowZeroY=True,
                positiveZ=False,
                printWarning=True,
                printErrors=True,
                xCloseEps=None,
                maxAbsFloatValue=None):
    """Checks that data is a valid structure for endl4dmath data. Triggers a raise if it is not.  Data may be
    an instance that is a subclass of endl4dmath or a python list as required by endl4dmath. If allowZeroT is False, 
    a zero first t value will generate a raise.If allowNegativeT is true than the t data can have negative values 
    (many ENDL 4d-data have projectile energy as the t-data which must always be positive). For meanings of 
    allowNegativeX, allowZeroX, allowSameY, allowNegativeY, allowZeroY, positiveZ and xCloseEps see endl3dmathmisc.check3dData.
    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 endl3dmathmisc.check3dData."""

    import endl3dmathmisc
    points = get4dmathData(data, "check4dData", "")
    messages = []
    tPrior = None
    if ((points[0][0] < 0.) and (not allowNegativeT)):
        s = 'check4dData: 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 allowNegativeT)):
        s = 'check4dData: negative t = %e' % points[0][0]
        messages.append(s)
        if (printErrors):
            fudgemisc.printWarning('\n'.join(
                fudgemisc.checkMessagesToString(s, indentation='    ')))
    i = 0
    for t, xyz in points:
        fudgemath.checkNumber( t, "check4dData: t[%d]" % i, messages = messages, indentation = '    ', printErrors = printErrors, \
            maxAbsFloatValue = maxAbsFloatValue )
        if (tPrior != None):
            if (t <= tPrior):
                s = 'check4dData: t value t[%d] >= t[%d] (%e >= %e)' % (
                    i - 1, i, tPrior, t)
                messages.append(s)
                if (printErrors):
                    fudgemisc.printWarning('\n'.join(
                        fudgemisc.checkMessagesToString(s,
                                                        indentation='    ')))
        tPrior = t
        messages3d = endl3dmathmisc.check3dData(
            xyz,
            allowNegativeX=allowNegativeX,
            allowZeroX=allowZeroX,
            allowSameY=allowSameY,
            allowNegativeY=allowNegativeY,
            allowZeroY=allowZeroY,
            positiveZ=positiveZ,
            printWarning=printWarning,
            printErrors=False,
            xCloseEps=xCloseEps,
            maxAbsFloatValue=maxAbsFloatValue)
        if (len(messages3d) > 0):
            s = 'check4dData: t value = %e' % t
            messages.append([s, messages3d])
            if (printErrors):
                fudgemisc.printWarning('\n'.join(
                    fudgemisc.checkMessagesToString([messages[-1]],
                                                    indentation='    ')))
        i += 1
    if (printErrors and len(messages) > 0):
        raise Exception('      bad 4d data')
    return (messages)
Пример #4
0
# product endorsement purposes.
#
# <<END-copyright>>

import copy

from xData import axes as axesModule

from fudge.core import fudgemisc

numpyImported = False
try:
    import numpy
    numpyImported = True
except:
    fudgemisc.printWarning(
        "Warning from fudge2dGrouping.py: numpy not imported")

__metaclass__ = type


class groupedData:

    moniker = 'multiGroup'

    def __init__(self, data, axes_=None):

        if (axes_ is not None):
            self.axes = axes_
        elif (hasattr(data, 'axes')):
            self.axes = data.axes
        if (len(data) == 0):
Пример #5
0
def check2dData(data,
                allowNegativeX=True,
                allowSameX=False,
                allowZeroX=True,
                positiveY=True,
                printWarning=True,
                printErrors=True,
                xCloseEps=None,
                formatCode=12,
                maxAbsFloatValue=None):
    """Checks that data (or data.data if data is an endl2dmath instance) is a list containing
    valid endl2dmath points. If positiveY is true (default) then a negative y value
    generates a raise.  If positiveY is false then the number of negative y values
    is counted and the count is returned. The x values must be in increasing order
    else a raise is generated. If allowZeroX is False, a zero first x value will generate a 
    raise. Also all x values must be positive unless allowNegativeX
    is true. If printWarning is true than close x value warnings are printed. X values 
    x1 and x2 are considered close if x2 - x1 < xCloseEps * ( x1 + x2 ). If on input xCloseEps
    is None, the it is set to endlParameters.endlEpsx * pow( 0.1, formatCode - 14 ) / 3. 
    If on input formatCode is 12 then it is set to 14.
    This function returns an integer and an array. The integer is the number of negative
    y values and the array is a list of all indices with close x-values. If printWarning
    is 'True' than warnings are printed (warning will not execute a raise). If printErrors 
    is 'True' then errors are printed, and if at least one error exist, a raise will be 
    executed after all data has been checked."""

    points = get2dmathData(data, "check2dData", "")
    l = len(points)
    w = 0  # Number of close energy warnings.
    ne = 0  # Number of points with negative y values.
    badXIndicies = []
    messages = []
    if (xCloseEps == None):
        if (formatCode == 12): formatCode = 14
        xCloseEps = endlParameters.endlEpsx / 3. * pow(0.1, (formatCode - 14))
    if (l > 0):
        pl = None
        pn = points[0]
        i = 0
        if (pn[0] == 0.) and (not allowZeroX):
            s = 'check2dData: zero x value at index = 0'
            messages.append(s)
        elif ((pn[0] < 0.) and (not allowNegativeX)):
            s = 'check2dData: negative x value at index = %d, x = %e' % (i,
                                                                         pn[0])
            messages.append(s)
            if (printErrors):
                fudgemisc.printWarning('\n'.join(
                    fudgemisc.checkMessagesToString(s, indentation='      ')))
        while 1:
            check2dPoint(pn)
            fudgemath.checkNumber(pn[0],
                                  "check2dData: x[%d]" % i,
                                  messages=messages,
                                  indentation='      ',
                                  printErrors=printErrors,
                                  maxAbsFloatValue=maxAbsFloatValue)
            fudgemath.checkNumber(pn[1],
                                  "check2dData: y[%d]" % i,
                                  messages=messages,
                                  indentation='      ',
                                  printErrors=printErrors,
                                  maxAbsFloatValue=maxAbsFloatValue)
            if (pl != None):
                checkCloseness = True
                if (pl[0] >= pn[0]):
                    checkCloseness = False
                    if (not allowSameX):
                        s = 'check2dData: x value x[%d] >= x[%d] (%e >= %e)' % (
                            i - 1, i, pl[0], pn[0])
                        messages.append(s)
                        if (printErrors):
                            fudgemisc.printWarning('\n'.join(
                                fudgemisc.checkMessagesToString(
                                    s, indentation='      ')))
                if (checkCloseness and (pn[0] - pl[0]) <
                    ((pn[0] + pl[0]) * xCloseEps)):
                    sn = endl2d_repr_xFormat % pn[0]
                    sl = endl2d_repr_xFormat % pl[0]
                    if (sn[-4:] == 'e-00'): sn = sn[:-4] + 'e+00'
                    if (sl[-4:] == 'e-00'): sl = sl[:-4] + 'e+00'
                    if (sn == sl):
                        badXIndicies.append(i)
                        s = 'check2dData: x values %.16e and %.16e very close' % (
                            pl[0], pn[0])
                        messages.append(s)
                        if ((w < 2) and printWarning):
                            fudgemisc.printWarning('          Warning in %s' %
                                                   s)
                        w = w + 1
            if (pn[1] < 0):
                if (positiveY):
                    s = 'check2dData: negative y value at index = %d (x = %e y = %e)' % (
                        i, pn[0], pn[1])
                    messages.append(s)
                    if (printErrors):
                        fudgemisc.printWarning('\n'.join(
                            fudgemisc.checkMessagesToString(
                                s, indentation='      ')))
                ne = ne + 1
            i = i + 1
            if (i == l): break
            pl = pn
            pn = points[i]
        if (printWarning and (w > 1)):
            fudgemisc.printWarning(
                "          Warning in check2dData: %d x values very close" % w)
    if (printErrors and ((len(messages) - w) > 0)):
        raise Exception('          bad 2d data')
    return ne, badXIndicies, messages