Source code for fudge.gnds.productData.distributions.base

# <<BEGIN-copyright>>
# <<END-copyright>>

"""Base classes for distributions."""

from fudge.core.utilities import brb

import xData.ancestry as ancestryModule
import xData.standards as standardsModule

from fudge.gnds import abstractClasses as abstractClassesModule

__metaclass__ = type

#
# Standard genre can only be composited from one of the following standard forms.
#

angularTwoBodyGenre = 'angularTwoBody'
unknownGenre = 'unknown'
referenceGenre = 'reference'
NBodyGenre = 'NBody'

noneFormToken = 'none'
semiPiecewiseFormToken = 'semiPiecewise'
equalProbableBinsFormToken = 'equalProbableBins'
groupedFormToken = 'grouped'
LegendrePointwiseFormToken = 'LegendrePointwise'
LegendrePiecewiseFormToken = 'LegendrePiecewise'

[docs]class form( abstractClassesModule.form ) : def __init__( self, label, productFrame, subForms ) : abstractClassesModule.form.__init__( self ) self.label = label if( productFrame is not None ) : if( productFrame not in standardsModule.frames.allowedFrames ) : raise TypeError( 'Invalid productFrame = "%s"' % brb.limitObjectToString( productFrame ) ) self.__productFrame = productFrame for i1, subform_ in enumerate( subForms ) : setattr( self, self.subformAttributes[i1], subform_ ) if( subform_ is not None ) : subform_.setAncestor( self ) self.subforms = [ subform_ for subform_ in subForms ] @property def label( self ) : return( self.__label ) @label.setter def label( self, value ) : if( value is not None ) : if( not( isinstance( value, str ) ) ) : raise TypeError( 'value must be a string' ) self.__label = value @property def productFrame( self ) : return( self.__productFrame )
[docs] def convertUnits( self, unitMap ) : """See documentation for reactionSuite.convertUnits.""" if( hasattr( self, 'subforms' ) ) : for subform_ in self.subforms : if( subform_ is None ) : continue # FIXME, needed for photo-atomic coherentScattering data with no anomalousScattering subforms. subform_.convertUnits( unitMap )
[docs] def findEntity( self, entityName, attribute = None, value = None ): """ Find specific subform within the form. Overrides ancestry.findEntity. """ for subform_ in self.subforms : if( subform_.moniker == entityName ) : return( subform_ ) return( ancestryModule.ancestry.findEntity( self, entityName, attribute, value ) )
[docs] def isTwoBody( self ) : return( False )
[docs] def isSpecified( self ) : return( True )
[docs] def toPointwise_withLinearXYs( self, **kwargs ) : return( self.subforms[0].toPointwise_withLinearXYs( **kwargs ) )
[docs] def toXMLList( self, indent = '', **kwargs ) : indent2 = indent + kwargs.get( 'incrementalIndent', ' ' ) attributeStr = '' if( self.label is not None ) : attributeStr += ' label="%s"' % self.label if( self.productFrame is not None ) : attributeStr += ' productFrame="%s"' % self.productFrame xmlString = [ '%s<%s%s>' % ( indent, self.moniker, attributeStr ) ] for subform_ in self.subforms : xmlString += subform_.toXMLList( indent2, **kwargs ) xmlString[-1] += '</%s>' % self.moniker return( xmlString )
[docs]class subform( ancestryModule.ancestry ) : def __init__( self ) : ancestryModule.ancestry.__init__( self ) self.label = None
[docs] def XMLStartTagString( self, indent = '', extraAttributesAsStrings = '', emptyTag = False ) : emptyTagStr = '' if( emptyTag ) : emptyTagStr = '/' attributeStr = '' if( self.label is not None ) : attributeStr += ' label="%s"' % self.label return( '%s<%s%s%s%s>' % ( indent, self.moniker, attributeStr, extraAttributesAsStrings, emptyTagStr ) )