예제 #1
0
def defaultAxes(energyUnit, momentumDepositionUnit):

    axes = axesModule.axes(rank=2)
    axes[0] = axesModule.axis('averageProductMomentum', 0,
                              momentumDepositionUnit)
    axes[1] = axesModule.axis('energy_in', 1, energyUnit)
    return (axes)
예제 #2
0
파일: Q.py 프로젝트: alhajri/FUDGE
def defaultAxes( energyUnit ) :

    axes = axesModule.axes( )
# BRB6 make 'energy_in' a token
    axes[1] = axesModule.axis( 'energy_in', 0, energyUnit )
    axes[0] = axesModule.axis( component.moniker, 1, energyUnit )
    return( axes )
예제 #3
0
파일: plot2d.py 프로젝트: icmeyer/fudge
    def getW_XYs(self):

        from xData import axes as axesModule
        from xData import XYs as XYsModule
        from xData import multiD_XYs as multiD_XYsModule

        xUnit, yUnit, zUnit = '', '', ''
        if (self.xUnit is not None): xUnit = self.xUnit
        if (self.yUnit is not None): yUnit = self.yUnit
        if (self.zUnit is not None): zUnit = self.zUnit
        axes_3d = axesModule.axes(3)
        axes_3d[0] = axesModule.axis('z', 0, zUnit)
        axes_3d[1] = axesModule.axis('y', 0, yUnit)
        axes_3d[2] = axesModule.axis('x', 0, xUnit)
        w_xys = multiD_XYsModule.multiD_XYs(axes=axes_3d)

        axes_2d = axesModule.axes()
        axes_2d[0] = axes_3d[0]
        axes_2d[1] = axes_3d[1]

        for ix, x in enumerate(self.x):
            xys = [[y, self.z[iy][ix]] for iy, y in enumerate(self.y)]
            w_xys[ix] = XYsModule.XYs(xys,
                                      axes=axes_2d,
                                      accuracy=1e-3,
                                      value=x)
        return (w_xys)
예제 #4
0
def defaultAxes(energyUnit='eV', crossSectionUnit='b'):

    axes = axesModule.axes(rank=2)
    axes[0] = axesModule.axis(baseModule.crossSectionToken, 0,
                              crossSectionUnit)
    axes[1] = axesModule.axis('energy_in', 1, energyUnit)
    return (axes)
예제 #5
0
파일: angular.py 프로젝트: alhajri/FUDGE
def defaultAxes(energyUnit):

    axes = axesModule.axes(rank=3)
    axes[0] = axesModule.axis('P(mu|energy_in)', 0, '')
    axes[1] = axesModule.axis('mu', 1, '')
    axes[2] = axesModule.axis('energy_in', 2, energyUnit)
    return (axes)
예제 #6
0
    def defaultAxes():

        axes = axesModule.axes(rank=4)
        axes[0] = axesModule.axis('c_l', 0, '1/MeV')
        axes[1] = axesModule.axis('energy_out', 1, 'MeV')
        axes[2] = axesModule.axis('energy_in', 2, 'MeV')
        axes[3] = axesModule.axis('l', 3, '')
        return (axes)
예제 #7
0
파일: energy.py 프로젝트: icmeyer/fudge
    def defaultAxes(energyUnit='eV'):

        axes = axesModule.axes(rank=3)
        axes[0] = axesModule.axis('P(energy_out|energy_in)', 0,
                                  '1/' + energyUnit)
        axes[1] = axesModule.axis('energy_out', 1, energyUnit)
        axes[2] = axesModule.axis('energy_in', 2, energyUnit)
        return (axes)
예제 #8
0
파일: Legendre.py 프로젝트: alhajri/FUDGE
def defaultAxes(energyUnit):

    axes = axesModule.axes(rank=4)
    axes[3] = axesModule.axis('l', 3, '')
    axes[2] = axesModule.axis('energy_in', 2, energyUnit)
    axes[1] = axesModule.axis('energy_out', 1, energyUnit)
    axes[0] = axesModule.axis('c_l', 0, '1/' + energyUnit)
    return (axes)
예제 #9
0
def defaultAxes( energyUnit, probabilityLabel = 'P(mu,energy_out|energy_in)' ) :

    axes = axesModule.axes( rank = 4 )
    axes[3] = axesModule.axis( 'energy_in', 3, energyUnit )
    axes[2] = axesModule.axis( 'mu', 2, '' )
    axes[1] = axesModule.axis( 'energy_out', 1, energyUnit )
    axes[0] = axesModule.axis( probabilityLabel, 0, '1/' + energyUnit )
    return( axes )
예제 #10
0
    def defaultAxes(energyUnit='eV',
                    momentumDepositionName=averageProductMomentumToken,
                    momentumDepositionUnit='eV/c'):

        axes = axesModule.axes(rank=2)
        axes[0] = axesModule.axis(momentumDepositionName, 0,
                                  momentumDepositionUnit)
        axes[1] = axesModule.axis('energy_in', 1, energyUnit)
        return (axes)
예제 #11
0
    def defaultAxes( moniker ) :

        axes = axesModule.axes( rank = 3 )
        axes[2] = axesModule.axis( 'energy_in',  2, 'eV' )
        axes[1] = axesModule.axis( 'energy_out', 1, 'eV' )
        x0Unit = ''
        if( moniker == 'f' ) : x0Unit = '1/eV'
        axes[0] = axesModule.axis( moniker, 0, x0Unit )
        return( axes )
예제 #12
0
    def defaultAxes(energyUnit='eV',
                    energyDepositionName=averageProductEnergyToken,
                    energyDepositionUnit=None):

        if (energyDepositionUnit is None): energyDepositionUnit = energyUnit
        axes = axesModule.axes(rank=2)
        axes[0] = axesModule.axis(energyDepositionName, 0,
                                  energyDepositionUnit)
        axes[1] = axesModule.axis('energy_in', 1, energyUnit)
        return (axes)
예제 #13
0
def calculateDepositionEnergyFromEpP(E, EpP):
    "EpP is a list of [ E', P(E') ]"

    axes = axesModule.axes()
    axes[0] = axesModule.axis('a', 0, EpP.axes[0].unit)
    axes[1] = axesModule.axis('b', 1, EpP.axes[1].unit)
    Ep = XYsModule.XYs1d(data=[[EpP[0][0], EpP[0][0]],
                               [EpP[-1][0], EpP[-1][0]]],
                         axes=axes)
    return (float(EpP.integrateTwoFunctions(Ep)))
예제 #14
0
    def defaultAxes(moniker, energyUnit):

        axes = axesModule.axes(rank=3)
        axes[2] = axesModule.axis('energy_in', 2, energyUnit)
        axes[1] = axesModule.axis('energy_out', 1, energyUnit)
        if (moniker == 'f'):
            axes[0] = axesModule.axis(moniker, 0, '1/' + energyUnit)
        else:
            axes[0] = axesModule.axis(moniker, 0, '')
        return (axes)
예제 #15
0
    def defaultAxes(energyUnit='eV', probabilityUnit='', asLegendre=False):

        axes = axesModule.axes(rank=3)
        if (asLegendre):
            axes[0] = axesModule.axis('C_l(energy_in)', 0, '')
            axes[1] = axesModule.axis('l', 1, '')
        else:
            axes[0] = axesModule.axis('P(mu|energy_in)', 0, probabilityUnit)
            axes[1] = axesModule.axis('mu', 1, '')
        axes[2] = axesModule.axis('energy_in', 2, energyUnit)
        return (axes)
예제 #16
0
    def defaultAxes(energyUnit='eV',
                    energy_outUnit='eV',
                    probabilityUnit='1/eV'):

        axes = axesModule.axes(rank=4)
        axes[0] = axesModule.axis('P(mu,energy_out|energy_in)', 0,
                                  probabilityUnit)
        axes[1] = axesModule.axis('mu', 1, '')
        axes[2] = axesModule.axis('energy_out', 2, energy_outUnit)
        axes[3] = axesModule.axis('energy_in', 3, energyUnit)
        return (axes)
예제 #17
0
파일: group.py 프로젝트: alhajri/FUDGE
def toMultiGroup1d( cls, style, tempInfo, _axes, data, addLabel = True ) :
    """
    This function takes 1-d multi-group data as a list of floats and return to 1-d gridded instance
    containing the multi-group data. The list of data must contain n values where n is the
    number of groups.
    """

    reactionSuite = tempInfo['reactionSuite']

    axes = axesModule.axes( rank = 2 )
    axes[0] = axesModule.axis( _axes[0].label, 0, _axes[0].unit )
    energyInGrid = style.transportables[reactionSuite.projectile].group.boundaries.values.copy( )
    axes[1] = axesModule.grid( _axes[1].label, 1, _axes[1].unit, axesModule.boundariesGridToken, energyInGrid )
    shape = [ len( data ) ]
    data = valuesModule.values( data )
    for start, datum in enumerate( data ) :
        if( datum != 0 ) : break
    end = 0
    for i1, datum in enumerate( data ) :
        if( datum != 0 ) : end = i1
    if( start > end ) :                     # Only happens when all values are 0.
        start = 0
    else :
        end += 1
    data = data[start:end]
    starts = valuesModule.values( [ start ], valueType = standardsModule.types.integer32Token )
    lengths = valuesModule.values( [ len( data ) ], valueType = standardsModule.types.integer32Token )
    flattened = arrayModule.flattened( shape = shape, data = data, starts = starts, lengths = lengths )
    label = None
    if( addLabel ) : label = style.label
    return( cls( label = label, axes = axes, array = flattened ) )
예제 #18
0
def groupFunctionCrossSectionAndFlux(cls,
                                     style,
                                     tempInfo,
                                     f1,
                                     printMutualDomainWarning=False):

    crossSection = tempInfo['crossSection']
    norm = tempInfo['groupedFlux']
    grouped = groupTwoFunctionsAndFlux(
        style,
        tempInfo,
        f1,
        crossSection,
        norm=norm,
        printMutualDomainWarning=printMutualDomainWarning)

    unit = crossSection.axes[0].unit
    if (f1.axes[0].unit != ''): unit = '%s * %s' % (f1.axes[0].unit, unit)
    axis = axesModule.axis(label='%s * %s' %
                           (f1.axes[0].label, crossSection.axes[0].label),
                           unit=unit,
                           index=0)
    axes = f1.axes.copy()
    axes[0] = axis
    return (groupModule.toMultiGroup1d(cls, style, tempInfo, axes, grouped))
예제 #19
0
파일: group.py 프로젝트: alhajri/FUDGE
def TMs2Form( style, tempInfo, TM_1, TM_E ) :

    from fudge.processing import transportables as transportablesModule
    from fudge.gnd.productData.distributions import multiGroup as multiGroupModule

    reactionSuite = tempInfo['reactionSuite']
    productName = tempInfo['productName']
    transportable = style.transportables[productName]
    conserve = transportable.conserve
    energyUnit = tempInfo['incidentEnergyUnit']

# BRB hardwired.
    crossSectionUnit = 'b'                          # ?????? 'b' should not be hardwired.
    axes = axesModule.axes( rank = 4 )
    axes[0] = axesModule.axis( 'C_l(energy_in,energy_out)', 0, crossSectionUnit )
    lMaxPlus1 = len( TM_1[0][0] )
    lGrid = valuesModule.values( [ i1 for i1 in range( lMaxPlus1 ) ], valueType = standardsModule.types.integer32Token )
    axes[1] = axesModule.grid( 'l',                         1,         '', axesModule.parametersGridToken, lGrid )
    energyOutGrid = style.transportables[productName].group.boundaries.values.copy( )
    axes[2] = axesModule.grid( 'energy_out',                2, energyUnit, axesModule.boundariesGridToken, energyOutGrid )
    energyInGrid = style.transportables[reactionSuite.projectile].group.boundaries.values.copy( )
    axes[3] = axesModule.grid( 'energy_in',                 3, energyUnit, axesModule.boundariesGridToken, energyInGrid )
    if( conserve == transportablesModule.conserve.number ) :
        TM = TM_1
    else :
        raise NotImplementedError( 'Need to implement' )

    n1 = len( TM )
    n2 = len( TM[0] )
    n3 = len( TM[0][0] )
    data, starts, lengths = [], [], []
    for i1 in sorted( TM.keys( ) ) :
        TM_i1 = TM[i1]
        start, length = None, 0
        for i2 in sorted( TM_i1.keys( ) ) :
            TM_i1_i2 = TM_i1[i2]
            cellMin = min( TM_i1_i2 )
            cellMax = max( TM_i1_i2 )
            if( ( cellMin != 0 ) or ( cellMax != 0 ) ) :
                if( start is None ) : start = n3 * ( n2 * i1 + i2 )
                length += n3
                data += TM_i1_i2
            else :
                if( start is not None ) : 
                    starts.append( start )
                    lengths.append( length )
                    start, length = None, 0
        if( start is not None ) : 
            starts.append( start )
            lengths.append( length )
    shape = [ n1, n2, n3 ]
    data = valuesModule.values( data )
    starts = valuesModule.values( starts, valueType = standardsModule.types.integer32Token )
    lengths = valuesModule.values( lengths, valueType = standardsModule.types.integer32Token )
    flattened = arrayModule.flattened( shape = shape, data = data, starts = starts, lengths = lengths, 
            dataToString = multiGroupModule.gridded3d.dataToString )
    gridded3d = multiGroupModule.gridded3d( axes = axes, array = flattened )
    return( multiGroupModule.form( style.label, standardsModule.frames.labToken, gridded3d ) )
예제 #20
0
    def __init__(self, angularEnergy_):

        self.productFrame = angularEnergy_.getProductFrame()
        axes_ = axes.defaultAxes(3)
        axes_[0] = angularEnergy_.axes[0]
        axes_[1] = angularEnergy_.axes[1]
        axes_[2] = axes.axis("P(mu|energy_in)", 2, "")
        W_XYs.W_XYs.__init__(self, axes_)

        for w_xys in angularEnergy_:
            P_mu = [[xys.value, xys.integrate()] for xys in w_xys]
            self.append(
                XYs.XYs(XYs.XYs.defaultAxes(), P_mu, 1e-3, value=w_xys.value))
예제 #21
0
파일: __init__.py 프로젝트: alhajri/FUDGE
def get_ENDF_flux(file, mat, mf, mt):
    import fudge.legacy.converting.ENDFToGND.endfFileToGNDMisc as endfFileToGNDMiscModule
    import xData.axes as axesModule
    import xData.XYs as XYsModule
    # Grab the data corresponding to the spectrum
    MF3Data = [
        line.strip('\r\n') for line in open(file).readlines()
        if int(line[67:70]) == int(mat) and int(line[70:72]) == int(mf)
        and int(line[72:75]) == int(mt)
    ]
    # Define the axes
    spectrumAxes = axesModule.axes(rank=2)
    spectrumAxes[0] = axesModule.axis('spectrum', 0, '1/eV')
    spectrumAxes[1] = axesModule.axis('energy_in', 1, 'eV')
    # Now make the spectrum as an XYs1d
    dataLine, TAB1, spectrumRegions = endfFileToGNDMiscModule.getTAB1Regions(
        1,
        MF3Data,
        allowInterpolation6=True,
        logFile=None,  #info.logs,
        axes=spectrumAxes,
        cls=XYsModule.XYs1d)
    if (len(spectrumRegions) == 1):  # Store as XYs1d.
        spectrumForm = XYsModule.XYs1d(
            data=spectrumRegions[0],
            label=None,
            axes=spectrumAxes,
            interpolation=spectrumRegions[0].interpolation)
    else:
        raise NotImplementedError(
            "Fluxes with multiple regions for %s/%s/%s/%s" %
            (file, mat, mf, mt))
        spectrumForm = crossSectionModule.regions1d(label=None,
                                                    axes=spectrumAxes)
        for region in spectrumRegions:
            if (len(region) > 1): spectrumForm.append(region)
    return (spectrumForm)
예제 #22
0
def multiGroupInverseSpeed(style, tempInfo):

    _groupBoundaries, flux = miscellaneousModule._groupFunctionsAndFluxInit(
        style, tempInfo, None)
    groupBoundaries = _groupBoundaries.values.values
    #                                         cm/sh
    const = 2. / (3. * math.sqrt(2) * 2.99792458e+02
                  )  # BRB - speed-of-light should not be hardwired.
    const *= math.sqrt(
        float(PQUModule.PQU(1, 'MeV').convertToUnit(_groupBoundaries.unit)))
    const *= math.sqrt(
        tempInfo['projectileMass'])  # Mass is in energy unit / c^2.

    numberOfGroups = len(groupBoundaries) - 1
    E1 = groupBoundaries[0]

    inverseSpeeds = []
    for i1 in range(numberOfGroups):
        E2 = groupBoundaries[i1 + 1]
        fluxSlice = flux.domainSlice(domainMin=E1, domainMax=E2, fill=True)
        fluxIntegral = 0
        inverseSpeedIntegral = 0
        _E1 = None
        for _E2, _flux2 in fluxSlice:
            if (_E1 is not None):
                fluxIntegral += (_E2 - _E1) * (_flux2 + _flux1)
                x1 = math.sqrt(_E1)
                x2 = math.sqrt(_E2)
                inverseSpeedIntegral += (x2 -
                                         x1) * (_flux1 + _flux2 +
                                                (_flux1 * x2 + _flux2 * x1) /
                                                (x1 + x2))
            _E1 = _E2
            _flux1 = _flux2
        inverseSpeed = 0
        if (fluxIntegral != 0):
            inverseSpeed = const * inverseSpeedIntegral / (fluxIntegral / 2)
        inverseSpeeds.append(inverseSpeed)
        E1 = E2

    axes = axesModule.axes(rank=2)
    axes[0] = axesModule.axis(label="inverse speed", unit="sh/cm", index=0)
    axes[1] = flux.axes[1]
    return (groupModule.toMultiGroup1d(gridded1d,
                                       style,
                                       tempInfo,
                                       axes,
                                       inverseSpeeds,
                                       addLabel=False))
예제 #23
0
    def __init__( self, angularEnergy ) :

        self.__productFrame = angularEnergy.productFrame
        axes = axesModule.defaultAxes( 3 )
        axes2d[2] = angularEnergy.axes[2]
        axes2d[1] = angularEnergy.axes[1]
        axes2d[0] = axesModule.axis( "P(mu|energy_in)", 0, "" )
        axes1d = XYsModule.XYs1d.defaultAxes( )
        axes1d[0] = axes2d[0]
        axes1d[1] = axes2d[1]
        multiD_XYsModule.XYs2d.__init__( self, axes = axes2d )

        for P_EpGivenMu in angularEnergy :
            P_mu = [ [ xys.value, xys.integrate( ) ] for xys in P_EpGivenMu ]
            self.append( XYsModule.XYs1d( data = P_mu, axes = axes1d, accuracy = 1e-3, value = P_EpGivenMu.value ) )
예제 #24
0
    def calculate_a( self, energy_in, energy_out_cmMin, energy_out_cmMax, accuracy = 1e-6 ) :

        from fudge.core.math import fudgemath
        from fudge.particles import nuclear

        def getParticleData( particle ) :

            Z, A, suffix, ZA = particle.getZ_A_SuffixAndZA( )
            return( particle.name, Z, max( 0, A - Z ), A, particle.getMass( 'MeV/c**2' ) )

        energyFactor = PQU.PQU( 1, 'MeV' ).getValueAs( self.fSubform.data.axes[-1].unit )
        projectile = self.findAttributeInAncestry( 'projectile' )
        target = self.findAttributeInAncestry( 'target' )
        product = self.findClassInAncestry( fudge.gnd.product.product ).particle
        name_a, Z_a, N_a, A_a, AWRa = getParticleData( projectile )
        name_A, Z_A, N_A, A_A, AWRA = getParticleData( target )
        name_b, Z_b, N_b, A_b, AWRb = getParticleData( product )
        Z_C, N_C = Z_a + Z_A, N_a + N_A
        if( N_A == 0 ) : N_C = 0
        Z_B, N_B = Z_C - Z_b, max( 0, N_C - N_b )
        A_B = Z_B + N_B
        if( N_B == 0 ) : A_B = 0
        particles = self.findClassInAncestry( fudge.gnd.reactionSuite.reactionSuite ).particles
        residual = particles.getParticle( nuclear.nucleusNameFromZA( 1000 * Z_B + A_B ) )
        AWRB = residual.getMass( 'MeV/c**2' )
        Ma, Ia = self.KalbachMann_a_parameters[name_a]['M'], self.KalbachMann_a_parameters[name_a]['I']
        mb, Ib = self.KalbachMann_a_parameters[name_b]['m'], self.KalbachMann_a_parameters[name_b]['I']
        Sa, Sb = energyFactor * self.calculate_S_ab_MeV( Z_A, N_A, Z_C, N_C, Ia ), energyFactor * self.calculate_S_ab_MeV( Z_B, N_B, Z_C, N_C, Ib )

        C1, C2, C3 = 0.04 / energyFactor, 1.8e-6 / energyFactor**3, 6.7e-7 / energyFactor**4

        ea = energy_in * AWRA / ( AWRa + AWRA ) + Sa

        R1, R3 = 130 * energyFactor, 41 * energyFactor                        # MeV to self's energy units.
        if( ea < R1 ) : R1 = ea
        if( ea < R3 ) : R3 = ea

        def calculate_a2( energy_out_cm ) :

            eb = energy_out_cm * ( AWRb + AWRB ) / AWRB + Sb
            X1, X3 = R1 * eb / ea, R3 * eb / ea
            return( X1 * ( C1 + C2 * X1 * X1 ) + C3 * Ma * mb * X3**4 )

        class thicken_a :

            def __init__( self, calculate_a2, relativeTolerance, absoluteTolerance ) :

                self.calculate_a2 = calculate_a2
                self.relativeTolerance = relativeTolerance
                self.absoluteTolerance = absoluteTolerance

            def evaluateAtX( self, x ) :

                return( self.calculate_a2( x ) )

        a = [ [ energy_out_cmMin, calculate_a2( energy_out_cmMin ) ], [ energy_out_cmMax, calculate_a2( energy_out_cmMax ) ] ]
        a = fudgemath.thickenXYList( a, thicken_a( calculate_a2, accuracy, 1e-10 ) )

        axes = axesModule.axes( )
        axes[0] = axesModule.axis( 'a', 0, '' )
        axes[1] = self.fSubform.data.axes[1].copy( )
        return( XYsModule.XYs1d( data = a, axes = axes, accuracy = accuracy ) )
예제 #25
0
    def defaultAxes( factorLabel, energyUnit ) :

        axes = axesModule.axes( rank = 2 )
        axes[0] = axesModule.axis( factorLabel, 0, "" )
        axes[1] = axesModule.axis( 'energy_in', 1, energyUnit )
        return( axes )
예제 #26
0
def defaultAxes(energyUnit):

    axes = axesModule.axes(rank=2)
    axes[0] = axesModule.axis('multiplicity', 0, '')
    axes[1] = axesModule.axis('energy_in', 1, energyUnit)
    return (axes)
예제 #27
0
def defaultAxes(energyUnit):

    axes = axesModule.axes(rank=2)
    axes[0] = axesModule.axis('energy_out', 0, energyUnit)
    axes[1] = axesModule.axis('energy_in', 1, energyUnit)
    return (axes)
예제 #28
0
파일: energy.py 프로젝트: icmeyer/fudge
    def defaultAxes():

        axes = axesModule.axes(rank=2)
        axes[0] = axesModule.axis('energy_loss(energy_in)', 0, 'eV')
        axes[1] = axesModule.axis('energy_in', 1, 'eV')
        return (axes)
예제 #29
0
파일: mixed.py 프로젝트: alhajri/FUDGE
    def toCovarianceMatrix(self, label="composed"):
        """
        Sum all parts together to build a single matrix.
        """
        if len(self.components) == 1:
            return self.components[0].toCovarianceMatrix()
        import fudge.gnd.covariances.base as base
        import numpy
        import xData.values as valuesModule
        import xData.array as arrayModule

        # Set up common data using first component
        firstCovMtx = self.components[0].toCovarianceMatrix()
        if not isinstance(firstCovMtx, base.covarianceMatrix):
            raise TypeError(
                "Shoudd have gotten base.covarianceMatrix, instead got %s" %
                str(firstCovMtx.__class__))
        commonRowAxis = firstCovMtx.matrix.axes[2].copy(
            [])  #FIXME: unresolvedLinks are still unresolved!
        if firstCovMtx.matrix.axes[1].style == 'link':
            commonColAxis = firstCovMtx.matrix.axes[2].copy(
                [])  #FIXME: unresolvedLinks are still unresolved!
        else:
            commonColAxis = firstCovMtx.matrix.axes[1].copy(
                [])  #FIXME: unresolvedLinks are still unresolved!
        commonMatrixAxis = firstCovMtx.matrix.axes[0].copy(
            [])  #FIXME: unresolvedLinks are still unresolved!
        commonType = firstCovMtx.type

        # We need all the covariances to be either absolute or relative
        def make_common_type(cm):
            if commonType == 'relative': return cm.toRelative()
            else: return cm.toAbsolute()

        # We're going to have to merge grids, so we'll need this function to do the dirty work
        def add_values(v1, v2):
            v = set()
            v.update(v1.values)
            v.update(v2.values)
            return valuesModule.values(sorted(v))

        # First pass through components is to collect bins to set up the common grid + do assorted checking
        for c in self.components[1:]:
            cc = make_common_type(c.toCovarianceMatrix(
            ))  # a little recursion to take care of nested covariances
            if cc.type != commonType:
                raise ValueError("Incompatible types in %s: %s vs. %s" %
                                 (self.__class__, commonType, cc.type))
            if cc.matrix.axes[0].unit != commonMatrixAxis.unit:
                raise ValueError(
                    "covariance matrix components with different units?!? %s vs. %s"
                    % (cc.matrix.axes[0].unit, commonMatrixAxis.unit))
            if cc.matrix.axes[1].style != 'link':
                cc.matrix.axes[1].convertToUnit(commonColAxis.unit)
            cc.matrix.axes[2].convertToUnit(commonRowAxis.unit)
            commonRowAxis.values.values = add_values(commonRowAxis.values,
                                                     cc.matrix.axes[2].values)
            if cc.matrix.axes[1].style == 'link':
                commonColAxis.values.values = add_values(
                    commonColAxis.values, cc.matrix.axes[2].values)
            else:
                commonColAxis.values.values = add_values(
                    commonColAxis.values, cc.matrix.axes[1].values)

        # Now sum up the components
        commonMatrix = numpy.mat(
            firstCovMtx.group(
                (commonRowAxis.values.values, commonColAxis.values.values),
                (commonRowAxis.unit,
                 commonColAxis.unit)).matrix.array.constructArray())
        for c in self.components[1:]:
            cc = make_common_type(c.toCovarianceMatrix(
            ))  # a little recursion to take care of nested covariances
            commonMatrix += numpy.mat(
                cc.group(
                    (commonRowAxis.values.values, commonColAxis.values.values),
                    (commonRowAxis.unit,
                     commonColAxis.unit)).matrix.array.constructArray())

        # Now create the instance of the resulting covarianceMatrix
        if all([
                component.toCovarianceMatrix().matrix.axes[1].style == 'link'
                for component in self.components
        ]):
            commonColAxis = self.components[0].toCovarianceMatrix(
            ).matrix.axes[1].copy(
                [])  #FIXME: unresolvedLinks are still unresolved!
        newAxes = axesModule.axes(
            labelsUnits={
                0: (commonMatrixAxis.label, commonMatrixAxis.unit),
                1: (commonColAxis.label, commonColAxis.unit),
                2: (commonRowAxis.label, commonRowAxis.unit)
            })
        newAxes[2] = axesModule.grid(commonRowAxis.label,
                                     commonRowAxis.index,
                                     commonRowAxis.unit,
                                     style=axesModule.boundariesGridToken,
                                     values=commonRowAxis.values)
        newAxes[1] = axesModule.grid(commonColAxis.label,
                                     commonColAxis.index,
                                     commonColAxis.unit,
                                     style=axesModule.linkGridToken,
                                     values=linkModule.link(
                                         link=commonRowAxis.values,
                                         relative=True))
        newAxes[0] = axesModule.axis(commonMatrixAxis.label,
                                     commonMatrixAxis.index,
                                     commonMatrixAxis.unit)
        trigdata = commonMatrix[numpy.tri(commonMatrix.shape[0]) ==
                                1.0].tolist()[0]
        gridded = griddedModule.gridded2d(
            axes=newAxes,
            array=arrayModule.full(shape=commonMatrix.shape,
                                   data=trigdata,
                                   symmetry=arrayModule.symmetryLowerToken))
        newCov = base.covarianceMatrix(label=label,
                                       type=commonType,
                                       matrix=gridded)
        newCov.setAncestor(self.ancestor)
        return newCov
예제 #30
0
def toENDF6(self, MT, endfMFList, flags, targetInfo):
    """
    In ENDF MF=6, some distributions should really be treated as uncorrelated: NBodyPhaseSpace, and also 
    Legendre expansions when only L=0 is listed.
    For GND we split these into uncorrelated angular (isotropic) and energy distributions.
    Must put back in original format when writing back to ENDF.
    """

    frame = self.productFrame
    energySubform = self.energySubform.data
    angularSubform = self.angularSubform.data
    if (isinstance(energySubform, energyModule.NBodyPhaseSpace)):
        energySubform.toENDF6(MT, endfMFList, flags, targetInfo)
    elif (targetInfo['doMF4AsMF6']):
        if (isinstance(
                energySubform,
            (energyModule.discreteGamma, energyModule.primaryGamma))):
            # BRB - this needs to be checked.
            if (targetInfo['product'].id != IDsPoPsModule.photon):
                raise ValueError('This logic is only for discrete gammas')
            energyForm = energyModule.form(self.label, frame, energySubform)
            angularForm = angularModule.form(self.label, frame, angularSubform)
            energyForm.toENDF6(MT, endfMFList, flags, targetInfo)
            angularForm.toENDF6(MT, endfMFList, flags, targetInfo)
        elif (isinstance(angularSubform, angularModule.isotropic)
              ):  # Change to energyAngular with Legendre
            if (not (isinstance(energySubform, energyModule.XYs2d))):
                raise 'hell - fix me'
            axes = axesModule.axes(rank=4)
            axes[3] = axesModule.axis('energy_in', 3, 'eV')
            axes[2] = axesModule.axis('energy_out', 2, 'eV')
            axes[1] = axesModule.axis('l', 1, '')
            axes[0] = axesModule.axis('C_l(energy_out|energy_in)', 0, '1/eV')
            energyAngularSubform = energyAngularModule.XYs3d(
                axes=axes,
                interpolation=energySubform.interpolation,
                interpolationQualifier=energySubform.interpolationQualifier)
            EInFactor = PQUModule.PQU(
                1, energySubform.axes[2].unit).getValueAs('eV')

            for EIn in energySubform:
                if isinstance(EIn, regionsModule.regions1d):
                    # writing to MF6 LAW=1, LANG=1 doesn't support multiple regions, must recombine.
                    if (len(set([ein.interpolation for ein in EIn])) != 1):
                        raise NotImplemented, "ENDF MF6 LAW=1 LANG=1 doesn't support multiple E' interpolations!"
                    xyvals = EIn[0].copyDataToXYs()
                    for region in EIn[1:]:
                        xynew = region.copyDataToXYs()
                        xynew[0][0] *= 1.00000001
                        xyvals.extend(xynew)
                    EIn_copy = EIn[0].copy()
                    EIn_copy.value = EIn.value
                    EIn_copy.axes = EIn.axes.copy()
                    EIn_copy.setData(xyvals)
                    EIn = EIn_copy
                multiD_2d = energyAngularModule.XYs2d(
                    value=EIn.value * EInFactor,
                    interpolation=EIn.interpolation)
                EpCls = EIn.copyDataToXYs()
                for e_out, Cls in EpCls:
                    multiD_2d.append(
                        energyAngularModule.Legendre([Cls], value=e_out))
                energyAngularSubform.append(multiD_2d)
            form = energyAngularModule.form('', self.productFrame,
                                            energyAngularSubform)
            if (targetInfo.get("gammaToENDF6")): return (form)
            form.toENDF6(MT, endfMFList, flags, targetInfo)
        elif (isinstance(energySubform, energyModule.XYs2d)
              and isinstance(angularSubform, angularModule.XYs2d)):

            LANG, LEP = 12, 2
            if (energySubform.interpolation ==
                    standardsModule.interpolation.flatToken):
                LEP = 1  # interpolation for E_out
                LANG = 11
            elif (energySubform.interpolation
                  in (standardsModule.interpolation.loglinToken,
                      standardsModule.interpolation.loglogToken)):
                LANG = 14
            MF6 = [
                endfFormatsModule.endfContLine(0, 0, LANG, LEP, 1,
                                               len(energySubform))
            ]
            EInInterpolation = gndToENDF6Module.gndToENDFInterpolationFlag(
                energySubform.interpolation)
            MF6 += endfFormatsModule.endfInterpolationList(
                [len(energySubform), EInInterpolation])
            for indexE, EEpP in enumerate(energySubform):
                EMuP = angularSubform[indexE]
                if (EEpP.value != EMuP.value):
                    raise Exception("EEpP.value = %s != EMuP.value = %s" %
                                    (EEpP.value, EMuP.value))
                NA, NEP = 2 * len(EMuP), len(EEpP)
                MF6.append(
                    endfFormatsModule.endfContLine(0, EEpP.value, 0, NA,
                                                   NEP * (NA + 2), NEP))
                data = []
                for EpP in EEpP:
                    data = [EpP[0], EpP[1]]
                    for muP in EMuP:
                        data += muP
                    MF6 += endfFormatsModule.endfDataList(data)
            LAW = 1
            gndToENDF6Module.toENDF6_MF6(MT, endfMFList, flags, targetInfo,
                                         LAW, frame, MF6)
        else:
            raise Exception(
                'uncorrelated.toENDF6 not supported for energy subform = %s and angular subform = %s'
                % (energySubform.moniker, angularSubform.moniker))
    else:  # original data is in uncorrelated form
        if (MT not in [527, 528]):
            angularForm = angularModule.form("", frame,
                                             self.angularSubform.data)
            angularForm.toENDF6(MT, endfMFList, flags, targetInfo)
        energyForm = energyModule.form("", frame, self.energySubform.data)
        energyForm.toENDF6(MT, endfMFList, flags, targetInfo)
        if (MT == 527): endfMFList[26][MT][0]