def fromXYs(cls, xys, value=None): if (xys.interpolation not in [ standardsModule.interpolation.linlinToken, standardsModule.interpolation.flatToken ]): xys = xys.toPointwise_withLinearXYs(accuracy=1e-3, lowerEps=0, upperEps=1e-8) try: norm = xys.normalize() except: norm = xys.copy() norm[0] = [norm[0][0], 1.0] norm = norm.normalize() print ' WARNGING: xs_pdf_cdf1d.fromXYs; distribution with 0 norm.' _cdf = norm.runningIntegral() _xs, _pdf = norm.copyDataToXsAndYs() _xs = xs(valuesModule.values(_xs)) _pdf = pdf(valuesModule.values(_pdf)) _cdf = cdf(valuesModule.values(_cdf)) return (cls(_xs, _pdf, _cdf, value=value, interpolation=xys.interpolation))
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 ) )
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 ) )
def convertUnits(self, unitMap): """ unitMap is a dictionary of the for { 'eV' : 'MeV', 'b' : 'mb' }. """ factors = self.axes.convertUnits(unitMap) yFactor = factors[0] self.__Ys = valuesModule.values( [yFactor * value for value in self.__Ys]) self.fixValuePerUnitChange(factors)
def processMultiGroup(self, style, tempInfo, indent): reactionSuite = tempInfo['reactionSuite'] axes = self.data.axes.copy() axes[1] = axesModule.grid( axes[1].label, 1, axes[1].unit, style=axesModule.parametersGridToken, values=valuesModule.values( [0], valueType=standardsModule.types.integer32Token)) axes[2] = style.transportables[ reactionSuite.projectile].group.boundaries.copy([]) data = self.data.processMultiGroup(style, tempInfo, indent) starts = valuesModule.values( [0], valueType=standardsModule.types.integer32Token) lengths = valuesModule.values( [len(data)], valueType=standardsModule.types.integer32Token) array = arrayModule.flattened(shape=(len(data), 1), data=data, starts=starts, lengths=lengths) data = gridded2d(axes=axes, array=array) return (data)
def add_values(v1, v2): v = set() v.update(v1.values) v.update(v2.values) return valuesModule.values(sorted(v))
fluxData.append(fluxModule.LegendreSeries([C0], value=newE, axes=axes)) flux = fluxModule.flux(args.fluxID, fluxData) if not (args.gid == None): for gidVal in args.gid: key, value = gidVal.split('=') if key not in gids: raise UserWarning( "particle grouping specified for unknown particle name : %s " % (key)) gids[key] = value transportables = [] for particle in gids: gbs = valuesModule.values([ PQUModule.PQU(boundary, 'MeV').getValueAs(args.energyUnit) for boundary in bdfls.group(gids[particle]).gb ]) grid = axesModule.grid('energy_in', 0, args.energyUnit, axesModule.boundariesGridToken, gbs) group = groupModule.group(gids[particle], grid) transportables.append( transportablesModule.transportable( particle, transportablesModule.conserve.number, group)) #### read in GND file reactionSuite = reactionSuiteModule.readXML(args.gnd) if (reactionSuite.projectile != IDsPoPsModule.neutron): tempsDefault = 0 if (args.temperatures == None): args.temperatures = [tempsDefault] ### fail on detection of existing processed data
def setUp(self): # ...................... example matrix 'a' ...................... axes = axesModule.axes( labelsUnits={ 0: ('matrix_elements', 'b**2'), 1: ('column_energy_bounds', 'MeV'), 2: ('row_energy_bounds', 'MeV') }) axes[2] = axesModule.grid(axes[2].label, axes[2].index, axes[2].unit, style=axesModule.boundariesGridToken, values=valuesModule.values([ 1.0000E-07, 1.1109E-01, 1.3534E+00, 1.9640E+01 ])) axes[1] = axesModule.grid(axes[1].label, axes[1].index, axes[1].unit, style=axesModule.linkGridToken, values=linkModule.link(link=axes[2].values, relative=True)) myMatrix = arrayModule.full((3, 3), [4.0, 1.0, 9.0, 0.0, 0.0, 25.0], symmetry=arrayModule.symmetryLowerToken) self.a = covariances.covarianceMatrix( 'eval', matrix=griddedModule.gridded2d(axes, myMatrix), type=covariances.tokens.relativeToken) # ...................... example matrix 'b' ...................... axes = axesModule.axes( labelsUnits={ 0: ('matrix_elements', 'b**2'), 1: ('column_energy_bounds', 'MeV'), 2: ('row_energy_bounds', 'MeV') }) axes[2] = axesModule.grid(axes[2].label, axes[2].index, axes[2].unit, style=axesModule.boundariesGridToken, values=valuesModule.values( [1.0e-5, 0.100, 1.0, 20.0])) axes[1] = axesModule.grid(axes[1].label, axes[1].index, axes[1].unit, style=axesModule.linkGridToken, values=linkModule.link(link=axes[2].values, relative=True)) myMatrix = arrayModule.full((3, 3), [4.0, 1.0, 9.0, 0.0, 0.0, 25.0], symmetry=arrayModule.symmetryLowerToken) self.b = covariances.covarianceMatrix( 'eval', matrix=griddedModule.gridded2d(axes, myMatrix), type=covariances.tokens.relativeToken) # ...................... example matrix 'c' ...................... axes = axesModule.axes( labelsUnits={ 0: ('matrix_elements', 'b**2'), 1: ('column_energy_bounds', 'MeV'), 2: ('row_energy_bounds', 'MeV') }) axes[2] = axesModule.grid(axes[2].label, axes[2].index, axes[2].unit, style=axesModule.boundariesGridToken, values=valuesModule.values([ 1.0000E-07, 6.7380E-02, 1.1109E-01, 1.3534E+00 ])) axes[1] = axesModule.grid(axes[1].label, axes[1].index, axes[1].unit, style=axesModule.linkGridToken, values=linkModule.link(link=axes[2].values, relative=True)) myMatrix = arrayModule.full((3, 3), [4.0, 1.0, 9.0, 0.0, 0.0, 25.0], symmetry=arrayModule.symmetryLowerToken) self.c = covariances.covarianceMatrix( 'eval', matrix=griddedModule.gridded2d(axes, myMatrix), type=covariances.tokens.relativeToken) # ...................... combine them for example matrix 'abc' ...................... abc = covariances.mixed.mixedForm(components=[self.a, self.b, self.c]) # FIXME: learn how to add abc to a section & to a covarianceSuite!, sumabc is built wrong! # ...................... 'sumabc' is just a way to exercise the summed class ...................... bds = abc.getRowBounds() self.sumabc = covariances.summed.summedCovariance( label='test', domainMin=float(bds[0]), domainMax=float(bds[1]), domainUnit=abc[0].matrix.axes[-1].unit, pointerList=[ linkModule.link(link=abc, path=abc.toXLink(), coefficient=1.0) ])