def f(s, shouldRaise=False): print try: v = PQU(s) except: if (not (shouldRaise)): print s print '========= FAILED =========' return if (shouldRaise): print s print '========= FAILED =========' print v print float(v), v.getUncertaintyValueAs()
def f(s, unc=None): print print s print unc a = PQU(s, uncertainty=unc) print a print a.info(significantDigits=15) a.truncate(True, True) print a print a.info(significantDigits=15)
def f(s): print print '-------------' a = parsers.parsePQUString(s) print s v = PQU(a[0], a[1], a[2]) print v print v.info(significantDigits=15) print p = 3.2 * v print p print p.info(significantDigits=15) print p = v * "3.2 MeV" print p print p.info(significantDigits=15) print p = v * "3.2%" print p print p.info(significantDigits=15)
def a(s): print print "<%s>" % s.strip() try: value, unit, uncertainty = PR.parsePQUString(s) # print '<%s> <%s> <%s>' % ( value.toString( ), uncertainty.toString( prefix = ' ' ), unit ) unitStr = str(unit) if (len(unitStr) > 0): unitStr = ' ' + unitStr # print '%s%s%s' % ( value.toString( ), uncertainty.toString( prefix = ' ' ), unitStr ) pqu = PQU(s) print '<%s>' % pqu except: print 'ERROR' raise
def convert_to_unit(self, column, unit): """ Converts a column from current unit to a new unit :param column: column name :param unit: new column unit :return: None """ # Which column are we modifying? oldUnit = self.get_unit(column) iCol = self.columns.get_loc(column).start # Convert the column convertUnits=numpy.frompyfunc(lambda x: float(PQU(x,oldUnit).inUnitsOf(unit)),1,1) # make a verctorized unit conversion widget self[column]=convertUnits(self[column]) # converts data in a column # Rebuild the column index newUnits=[] newCols=[] for i in range(self.columns.size): newCols.append(self.columns[i][0]) if i == iCol: newUnits.append(unit) else: newUnits.append(self.columns[i][1]) self.columns=pandas.MultiIndex.from_tuples( list(zip(newCols,newUnits)), names=['name','unit'] )
def ITYPE_4(MTDatas, info, verbose=0): """Convert ENDF ITYPE 4 data (decay data) into PoPs.""" errors = [] # Add ENDF documentation info.PoPs.documentation = '\n'.join(MTDatas[451][1][4:-info.NXC]) # The atom containing the parent nucleus parentAtom = toGNDMisc.getPoPsParticle(info, info.targetZA, name=None, levelIndex=info.levelIndex, level=info.level, levelUnit=energyUnit) decayParticle = parentAtom if (miscPoPsModule.hasNucleas(parentAtom)): decayParticle = parentAtom.nucleus if (457 in MTDatas): dataIndex = 0 MT457MF8Data = MTDatas[457][8] decayData = decayParticle.decayData # Read parent info block ZA, AWR, LIS, LISO, NST, NSP = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (LIS != 0): aliasID = "%s_m%s" % (isotopeModule.isotopeIDFromElementIDAndA( parentAtom.chemicalElement, parentAtom.A), LISO) info.PoPs.add( PoPsAliasModule.metaStable(aliasID, parentAtom.id, LISO)) HL, dHL, dummy, dummy, NC2, dummy = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[4]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) NC = NC2 // 2 # NC: number of decay energies if (NC not in [3, 17]): raise ValueError( "Number of decay energies must be 3 or 17, found %d" % NC) nlines = (NC2 + 5) // 6 aveDecayEnergies = [] for index in range(nlines): aveDecayEnergies.extend( endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex])) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (len([ aveDecayEnergy for aveDecayEnergy in aveDecayEnergies if (aveDecayEnergy != 0) ]) > 0): aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.lightParticles) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.electroMagneticRadiation) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.heavyParticles) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.betaMinus) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.betaPlus) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.AugerElectron) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.conversionElectron) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.gamma) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.xRay) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.internalBremsstrahlung) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.annihilation) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.alpha) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.recoil) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.spontaneousFission) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.fissionNeutrons) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.proton) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.neutrino) SPI, PAR, dum, dum, NDK6, NDK = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[1, 2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (-77.8 < SPI < -77.7): SPI = None # see page 180 of ENDF manual # FIXME: Need "UNKNOWN" markup halflifeValue = None if (NST == 1): halflifeValue = 'stable' if (PAR == 0): PAR = None # BRB, Happens for dec-013_Al_040.endf toGNDMisc.addParticleData(decayParticle, info, massValue=None, spinValue=SPI, parityValue=PAR, chargeValue=None, halflifeValue=halflifeValue) if (NST == 1): # Nucleus is stable, nothing to do pass elif (NST == 0): # Nucleus is unstable halflife = halflifeModule.double( info.PoPsLabel, HL, halflifeModule.baseUnit ) # FIXME: PQU(HL, 's', dHL), can't store uncertainty? decayParticle.halflife.add(halflife) # Iterate over decay chains decayModes = {} for i1 in range(NDK): # iterate over decay modes initialDecay, otherDecays, RTYP_key = getRTYP( MT457MF8Data[dataIndex]) RTYP, RFS, Q, dQ, BR, dBR = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (verbose > 3): print('RTYP = ', RTYP) RFS = int(RFS) # BRB, Isometic state of daughter allDecays = [initialDecay] + otherDecays decayMode = decayDataModule.decayMode( str(i1), ','.join([decayType[r_id] for r_id in allDecays])) decayModes[RTYP_key] = decayMode if (dBR): branching = PQU(BR, '', dBR) else: branching = PQU(BR, '') if (dQ): Qval = PQU(Q, energyUnit, dQ) else: Qval = PQU(Q, energyUnit) decayMode.Q.add( QModule.double('', Qval.getValue(), Qval.unit) ) # FIXME: PQU(Q, 'eV', dQ), can't store uncertainty decayMode.probability.add( probabilityModule.double("BR", branching.getValue(), '') ) # FIXME: PQU(BR, 's', dBR), can't store uncertainty # FIXME: what should we do for really small probabilities, so small ENDF gives 0, like spontaneous fission? n1 = len(otherDecays) - 1 residualZA = addDecayMode(info, decayMode, initialDecay, info.targetZA, RFS, -1 == n1) for i2, otherDecay in enumerate(otherDecays): residualZA = addDecayMode(info, decayMode, otherDecay, residualZA, RFS, i2 == n1) decayData.decayModes.add(decayMode) # LCON determines whether continuum spectra given: LCON 0: discrete only, 1: continuous only, 2: both for i1 in range(NSP): # Iterate over spectra initialDecay, otherDecays, STYP_key = getRTYP( MT457MF8Data[dataIndex], 11) dum, STYP, LCON, zero, six, NER = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) STYP = initialDecay specType = decayType[STYP] FD, dFD, ERave, dERave, FC, dFC = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex] ) # FD: discrete normalization, FC: continuum norm., ERave: average decay energy dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (LCON != 1): # Discrete spectra given. for i2 in range(NER): ER, dER, dum, dum, NT, dum = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) discreteSpectra = {'ER': ER, 'dER': dER} if (LCON != 1): if (NT not in (6, 8, 12)): raise ValueError( "Unexpected NT=%d encountered!" % NT) initialDecay, otherDecays, RTYP_key = getRTYP( MT457MF8Data[dataIndex]) discreteSpectra[ 'RTYP_plus'] = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (verbose > 3): print('STYP, RTYP = ', STYP, RTYP_key) if (NT > 6): RICC, dRICC, RICK, dRICK, RICL, dRICL = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) discreteSpectra['RICC'], discreteSpectra[ 'dRICC'] = RICC, dRICC if (NT > 8): discreteSpectra['RICK'], discreteSpectra[ 'dRICK'] = RICK, dRICK discreteSpectra['RICL'], discreteSpectra[ 'dRICL'] = RICL, dRICL addDiscreteSpectra(decayModes, RTYP_key, STYP, discreteSpectra) if (LCON != 0): # Continuum spectra given. initialDecay, otherDecays, RTYP_key = getRTYP( MT457MF8Data[dataIndex]) dataIndex, TAB1, regions = endfFileToGNDMisc.getTAB1Regions( dataIndex, MT457MF8Data) RTYP = TAB1['C1'] if (verbose > 3): print('STYP, RTYP = ', STYP, RTYP) LCOV = int(TAB1['L2']) if (len(regions) != 1): raise Exception('len( regions ) = %s' % len(regions)) covariance = None if (LCOV != 0): print(" LCOV != 0") dataIndex, covariance = getList( dataIndex, MT457MF8Data) addContinuumSpectrum(decayModes, RTYP_key, STYP, regions, covariance) else: raise ValueError( "In decay data (MT=457,MF=8), NST should be 0 or 1. Found %d" % NST) # Add documentation to PoPs return ({'PoPs': info.PoPs, 'errors': errors, 'info': info})
print '\na1 %s a2' % op try: b = eval('a1 %s a2' % op) print b print b.info(significantDigits=15) except ZeroDivisionError: print 'Divide by zero' except: raise print '\n' print a1 print a1.info(significantDigits=15) if (a1 is not a2): print a2 print a2.info(significantDigits=15) func2('+', a1, a2) func2('-', a1, a2) func2('*', a1, a2) func2('/', a1, a2) a1 = PQU(0, 'eV', .13) a2 = PQU(1.2, 'eV', .2) print 1 / a2 func(a1, a1) func(a2, a2) func(a1, a2) func(a2, a1)
print f, f.info(significantDigits=15) f = f + f3 print f, f.info(significantDigits=15) f = 1.2345e10 - f1 print f, f.info(significantDigits=15) print f1 == 1.234567e10 print f1 == 1.23456e10 print f1 != 1.23456e10 print f1 <= 1.23456e10 print f1 < 1.23456e10 print f1 >= 1.23456e10 print f1 > 1.23456e10 print p1 = PQU('0.0 +/- 0.05 Ang') p2 = PQU(' 0.135 +/- 1.2% eV/mm ') p3 = PQU(' 11.e4 ') p4 = PQU('13.5 +/- 3.2% eV/mm ') p5 = PQU('12.1 +/- 12.21% eV/mm ') p6 = PQU('12.1 +/- 1.2% eV/mm ') print p1 print p1.info(significantDigits=15) print p2 print p2.info(significantDigits=15) print p3 print p3.info(significantDigits=15) print p4 print p4.info(significantDigits=15) print p5
# information, apparatus, product, or process disclosed, or represents that its use # would not infringe privately-owned rights. # # 3. Also, reference herein to any specific commercial products, process, or services # by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU a = PQU('10.0(2) m') b = PQU('22.0(3) m') r = b / a print print a print a.info(significantDigits=15) print print b print b.info(significantDigits=15) print print r print r.info(significantDigits=15)
def changeUnc( s ) : print '============' b = PQU( s ) print b print b.info( significantDigits = 15 ) print b.changeUncertaintyPercent( not( b.uncertainty.isPercent( ) ) ) print b print b.info( significantDigits = 15 ) print b.changeUncertaintyPercent( not( b.uncertainty.isPercent( ) ) ) print b print b.info( significantDigits = 15 )
# product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert( 0, '../../' ) from pqu.PQU import pqu_float, pqu_uncertainty, PQU a = pqu_float( 1.234, 4 ) b = pqu_float( 1.234, 4, True ) print a print a.info( significantDigits = 15 ) print print b print b.info( significantDigits = 15 ) print u = pqu_uncertainty( pqu_uncertainty.pqu_uncertaintyStylePlusMinus, .12, isPercent = True ) print u print u.info( significantDigits = 15 ) c = PQU( "1e-12 +/- 1e-16" ) print print c print c.info( significantDigits = 15 ) c = PQU( "1.0000e-12(1)" ) print print c print c.info( significantDigits = 15 )
print b print b.info( significantDigits = 15 ) print b.changeUncertaintyStyle( pqu_uncertainty.pqu_uncertaintyStylePlusMinus ) print b print b.info( significantDigits = 15 ) changeUnc( "2.300098(4) MeV" ) changeUnc( "2.300000 +/- 4e-6 MeV" ) changeUnc( "2.300e12(4) MeV" ) changeUnc( "2.30e-12 +/- 4e-18 MeV" ) changeUnc( "2.300e-12(4)%" ) changeUnc( "(2.3e-12 +/- 4e-18)%" ) styles = [ pqu_uncertainty.pqu_uncertaintyStyleNone, pqu_uncertainty.pqu_uncertaintyStylePlusMinus, pqu_uncertainty.pqu_uncertaintyStyleParenthesis ] pqus = { pqu_uncertainty.pqu_uncertaintyStyleNone : PQU( "2.300098" ), pqu_uncertainty.pqu_uncertaintyStylePlusMinus : PQU( "2.300098 +/- 4e-6 MeV" ), pqu_uncertainty.pqu_uncertaintyStyleParenthesis : PQU( "2.300098(4) MeV" ) } for style in styles : pqu = pqus[style] for toStyle in styles : try : pqu.changeUncertaintyStyle( toStyle ) if( style != toStyle ) : if( ( style == pqu_uncertainty.pqu_uncertaintyStyleNone ) or ( toStyle == pqu_uncertainty.pqu_uncertaintyStyleNone ) ) : print '========= FAILED ========= 1) changeUncertaintyStyle: %s to %s' % ( style, toStyle ) except : if( style == toStyle ) : print '========= FAILED ========= 2) changeUncertaintyStyle: %s to %s' % ( style, toStyle )
# National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. # # 2. Neither the United States Government nor Lawrence Livermore National Security, # LLC nor any of their employees, makes any warranty, express or implied, or assumes # any liability or responsibility for the accuracy, completeness, or usefulness of any # information, apparatus, product, or process disclosed, or represents that its use # would not infringe privately-owned rights. # # 3. Also, reference herein to any specific commercial products, process, or services # by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU print PQU("1.23", "m", "12e-2") print PQU("1.23 m", uncertainty="12e-2") print print PQU("1.23", "m", "12%") print PQU("1.23 m", uncertainty="12%") print PQU("1.23 +/- 12%", "m") print PQU("1.23+/-12% m")
# LLC nor any of their employees, makes any warranty, express or implied, or assumes # any liability or responsibility for the accuracy, completeness, or usefulness of any # information, apparatus, product, or process disclosed, or represents that its use # would not infringe privately-owned rights. # # 3. Also, reference herein to any specific commercial products, process, or services # by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU c = PQU("0.0000 +/- 3e-4") print print c print c.info(significantDigits=15) c = PQU("0.0000(3)") print print c print c.info(significantDigits=15)
# 1. This notice is required to be provided under our contract with the U.S. # Department of Energy (DOE). This work was produced at Lawrence Livermore # National Laboratory under Contract No. DE-AC52-07NA27344 with the DOE. # # 2. Neither the United States Government nor Lawrence Livermore National Security, # LLC nor any of their employees, makes any warranty, express or implied, or assumes # any liability or responsibility for the accuracy, completeness, or usefulness of any # information, apparatus, product, or process disclosed, or represents that its use # would not infringe privately-owned rights. # # 3. Also, reference herein to any specific commercial products, process, or services # by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU t = PQU("314159.", 's') print t.info(significantDigits=15) s = t.inUnitsOf('d', 'h', 'min', 's') for i in s: print '\n', i, '\n', i.info(significantDigits=15)
# by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU print "2.32(12)" p1 = PQU("2.32(12)") print p1 print print "2.32(123)" try: p1 = PQU("2.32(123)") except: print p1 print p1.info(significantDigits=15) print '========= FAILED =========' print print "2.3237(1234)" try: p1 = PQU("2.3237(1234)") # print "2.3237(12)" and not "2.32(12)".
# by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU a = PQU("2.31(1) MeV / cm") print a print print a**6 # This prints "152.(3) MeV**6/cm**6" which is correct. print(a**6).info(significantDigits=15) print print a**7 # This prints "351.(1) MeV**7/cm**7" which should be "351.(9) MeV**7/cm**7" as the uncertainty is 8.88. print(a**7).info(significantDigits=15) print print a**12 print(a**12).info(significantDigits=15) a2 = PQU(2.3, "MeV") a = PQU("2.3000000000002(1) MeV") print a2.info(significantDigits=15)
# information, apparatus, product, or process disclosed, or represents that its use # would not infringe privately-owned rights. # # 3. Also, reference herein to any specific commercial products, process, or services # by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> from pqu.PQU import PQU v = PQU('1.234(56) eV') print v u = v.getValueAs('MeV') print type(u), u u = v.getValueAs('MeV', asPQU=True) print type(u), u u = v.getUncertaintyValueAs() print type(u), u u = v.getUncertaintyValueAs('MeV') print type(u), u u = v.getUncertaintyValueAs(asPQU=True)
# information, apparatus, product, or process disclosed, or represents that its use # would not infringe privately-owned rights. # # 3. Also, reference herein to any specific commercial products, process, or services # by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> from pqu.PQU import PQU pqu1 = PQU("1.23", "m", "12%") ref = pqu1 pqu1 += "3.21 m" print pqu1 print ref pqu1 -= "3.21 m" print pqu1 print ref pqu1 *= "2.2 kg" print pqu1 print ref pqu1 /= "2.2 kg" print pqu1
# by trade name, trademark, manufacturer or otherwise does not necessarily constitute # or imply its endorsement, recommendation, or favoring by the United States Government # or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed # herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import sys sys.path.insert(0, '../../') from pqu.PQU import PQU print a2 = PQU("2.300000000000(1) MeV") print a2 print a2.info(significantDigits=15) a2 = PQU("2.300000000001(1) MeV") print a2 print a2.info(significantDigits=15) print a2 = PQU("2.300000000003(1)", "MeV") print a2 print a2.info(significantDigits=15) print l = PQU(10., 'm') big_l = PQU(10., 'km') sum_l = big_l + l
def changeUnc( s ) : print '============' b = PQU( s ) print b print b.info( significantDigits = 15 ) print b.changeUncertaintyStyle( pqu_uncertainty.pqu_uncertaintyStyleParenthesis ) print b print b.info( significantDigits = 15 ) print b.changeUncertaintyStyle( pqu_uncertainty.pqu_uncertaintyStylePlusMinus ) print b print b.info( significantDigits = 15 )
print vv print print '---------' try: b(v, unitFrom, unitTo, False) except: if (doRaise): raise print "FAILED:", v, "'%s'" % unitFrom, "'%s'" % unitTo return b(v, unitFrom, unitTo, True) dl = _findUnit("") mm = _findUnit("mm") pqu_m = PQU("3.14 m") a(3.14, None, None) a(3.14, "", None) a(3.14, None, "") a(3.14, "", "") a(3.14, dl, None) a(3.14, None, dl) a(3.14, dl, dl) a(3.14, "m", None) a(3.14, "m", "cm") a(3.14, "cm", "m") doRaise = True