Example #1
0
 def testFloatAccuracy(self):
     result = str2unit('16.8 mm', FMFversion='1.0')
     diff = result - Quantity('16.8 mm')
     self.assertEqual(abs(diff.value) < 2e-14,True)
     result = str2unit('16.8 mm', FMFversion='1.0')
     diff = Quantity('16.8 mm')
     self.assertEqual(result, diff)
Example #2
0
 def testFloatAccuracy(self):
     result = str2unit('16.8 mm', FMFversion='1.0')
     diff = result - Quantity('16.8 mm')
     self.assertEqual(abs(diff.value) < 2e-14,True)
     result = str2unit('16.8 mm', FMFversion='1.0')
     diff = Quantity('16.8 mm')
     self.assertEqual(result, diff)
Example #3
0
 def testHourPlanck(self):
     """
     In FMF 1.0 unit 'h' denotes hours,
     while in FMF 1.1 'h' denotes the Planck constant.
     """
     result = str2unit('1h')
     self.assertEqual(result, Quantity('6.62606896e-34 J*s'))
     result = str2unit('1h', FMFversion='1.0')
     self.assertEqual(result, Quantity('3600s'))
Example #4
0
 def testHourPlanck(self):
     """
     In FMF 1.0 unit 'h' denotes hours,
     while in FMF 1.1 'h' denotes the Planck constant.
     """
     result = str2unit('1h')
     self.assertEqual(result, Quantity('6.62606896e-34 J*s'))
     result = str2unit('1h', FMFversion='1.0')
     self.assertEqual(result, Quantity('3600s'))
Example #5
0
 def testComplexNumber(self):
     """
     Complex numbers have to be denoted by small 'j',
     in oder to discriminate them from Joule.
     """
     result = str2unit(self.inputDict['complexJ'])
     self.assertEqual(result, complex(self.inputDict['complexJ']))
Example #6
0
 def testComplexNumber(self):
     """
     Complex numbers have to be denoted by small 'j',
     in oder to discriminate them from Joule.
     """
     result = str2unit(self.inputDict['complexJ'])
     self.assertEqual(result, complex(self.inputDict['complexJ']))
Example #7
0
 def testSimpleQuantity(self):
     """
     The the conversion of a simple textual quantity specification
     to a quantity object.
     """
     expected = Quantity('1V')
     result = str2unit('1V')
     self.assertEqual(expected, result)
Example #8
0
 def testSimpleQuantity(self):
     """
     The the conversion of a simple textual quantity specification
     to a quantity object.
     """
     expected = Quantity('1V')
     result = str2unit('1V')
     self.assertEqual(expected, result)
Example #9
0
 def changeColumns(self, event=None):
     independentVariable = self.independentCombo.GetValue()
     dependentVariable = self.dependentCombo.GetValue()
     colorVariable = self.colorCombo.GetValue()
     if (u'' == independentVariable or u'' == dependentVariable
             or u'' == colorVariable):
         return
     self.plot_panel.x_key = independentVariable
     self.plot_panel.y_key = dependentVariable
     if self.plot_panel.c_key != colorVariable:
         self.plot_panel.c_key = colorVariable
         field = self.dataContainer[colorVariable]
         vmin = numpy.nanmin(field.data).round() * field.unit
         self.vmin_text.Value = str(vmin)
         vmax = numpy.nanmax(field.data).round() * field.unit
         self.vmax_text.Value = str(vmax)
     self.plot_panel.vmin = str2unit(self.vmin_text.Value)
     self.plot_panel.vmax = str2unit(self.vmax_text.Value)
     self.plot_panel.radius = str2unit(self.radius_text.Value)
     self.plot_panel.draw()
     self.GetSizer().Fit(self)
Example #10
0
 def changeColumns(self, event=None):
     independentVariable = self.independentCombo.GetValue()
     dependentVariable = self.dependentCombo.GetValue()
     colorVariable = self.colorCombo.GetValue()
     if (u''==independentVariable
         or u''==dependentVariable
         or u''==colorVariable):
         return
     self.plot_panel.x_key = independentVariable
     self.plot_panel.y_key = dependentVariable
     if self.plot_panel.c_key != colorVariable:
         self.plot_panel.c_key = colorVariable
         field = self.dataContainer[colorVariable]
         vmin = numpy.nanmin(field.data).round()*field.unit
         self.vmin_text.Value=str(vmin)
         vmax = numpy.nanmax(field.data).round()*field.unit
         self.vmax_text.Value=str(vmax)
     self.plot_panel.vmin = str2unit(self.vmin_text.Value)
     self.plot_panel.vmax = str2unit(self.vmax_text.Value)
     self.plot_panel.radius = str2unit(self.radius_text.Value)
     self.plot_panel.draw()
     self.GetSizer().Fit(self)
Example #11
0
 def testReadSingleFile(self):
     """
     Test the correct interpretation of physical constants
     as definied in FMF version 1.0.
     """
     consts = LoadFMF.readSingleFile(self.FMFinput, "testReadSingleFile")[0].attributes[
         "Mathematical and Physical Constants"
     ]
     self.assertEqual(consts[u"Speed of light"][1], str2unit("1 c", FMFversion="1.0"))
     self.assertEqual(consts[u"Speed of light"][1], str2unit("1 c"))
     self.assertEqual(consts[u"Permeability of vacuum"][1], str2unit("1 mu0", FMFversion="1.0"))
     self.assertEqual(consts[u"Permittivity of vacuum"][1], str2unit("1 eps0", FMFversion="1.0"))
     self.assertEqual(consts[u"Gravitational constant"][1], str2unit("1 Grav", FMFversion="1.0"))
     self.assertTrue(consts[u"Planck constant"][1], str2unit("1 hplanck", FMFversion="1.0"))
     self.almostEqual(consts[u"Planck constant / 2pi"][1], str2unit("1 hbar", FMFversion="1.0"))
     self.almostEqual(consts[u"Elementary charge"][1], str2unit("1 e", FMFversion="1.0"))
     self.assertNotEqual(
         consts[u"Elementary charge"][1],
         str2unit("1 e"),
         "Elementary charge has been adapted to new CODATA recommendations.",
     )
     self.assertEqual(consts[u"Electron mass"][1], str2unit("1 me", FMFversion="1.0"))
     self.assertNotEqual(
         consts[u"Electron mass"][1],
         str2unit("1 me"),
         "Electron mass has been adapted to new CODATA recommendations.",
     )
     self.assertEqual(consts[u"Proton mass"][1], str2unit("1 mp", FMFversion="1.0"))
     self.assertNotEqual(
         consts[u"Proton mass"][1], str2unit("1 mp"), "Proton mass has been adapted to new CODATA recommendations."
     )
     self.assertEqual(consts[u"Avogadro number"][1], str2unit("1 Nav", FMFversion="1.0"))
     self.assertEqual(consts[u"Boltzmann constant"][1], str2unit("1 k", FMFversion="1.0"))
     consts = LoadFMF.readSingleFile(self.FMFinput, "testReadSingleFile")[0].attributes[
         "Additional constants changed from FMF version 1.0 to 1.1"
     ]
     self.almostEqual(consts[u"Parsec"][1], str2unit("1 pc", FMFversion="1.0"))
     self.almostEqual(consts[u"US gallon"][1], str2unit("1 galUS", FMFversion="1.0"))
     self.assertEqual(consts[u"Atomic mass units"][1], str2unit("1 amu", FMFversion="1.0"))
Example #12
0
 def testReadSingleFile(self):
     """
     Test the correct interpretation of physical constants
     as definied in FMF version 1.1.
     """
     consts = LoadFMF.readSingleFile(
         self.FMFinput, "testReadSingleFile"
     )[0].attributes['Mathematical and Physical Constants']
     self.assertEqual(consts[u'Speed of light'][1],
                      str2unit("1 c", FMFversion="1.1"))
     self.assertEqual(
         consts[u'Permeability of vacuum'][1],
         str2unit("1 mu0", FMFversion="1.1"),
         'The values differ by %s.' % (
             consts[u'Permeability of vacuum'][1] -\
             str2unit("1 mu0", FMFversion="1.1"),
             )
         )
     self.assertEqual(consts[u'Permittivity of vacuum'][1],
                      str2unit("1 eps0", FMFversion="1.1"))
     self.assertEqual(consts[u'Gravitational constant'][1],
                      str2unit("1 G", FMFversion="1.1"))
     self.assertEqual(consts[u'Planck constant'][1],
                      str2unit("1 h", FMFversion="1.1"))
     self.assertEqual(consts[u'Planck constant / 2pi'][1],
                      str2unit("1 hbar", FMFversion="1.1"))
     self.assertEqual(
         consts[u'Elementary charge'][1], str2unit("1 e", FMFversion="1.1"),
         'The elements %s and %s do not match.' %
         (consts[u'Elementary charge'][1], str2unit("1 e",
                                                    FMFversion="1.1")))
     self.assertEqual(consts[u'Electron mass'][1],
                      str2unit("1 me", FMFversion="1.1"))
     self.assertEqual(consts[u'Proton mass'][1],
                      str2unit("1 mp", FMFversion="1.1"))
     self.assertEqual(consts[u'Avogadro number'][1],
                      str2unit("1 NA", FMFversion="1.1"))
     self.assertEqual(consts[u'Boltzmann constant'][1],
                      str2unit("1 k", FMFversion="1.1"))
     self.assertEqual(consts[u'Rydberg constant'][1],
                      str2unit("1 Ryd", FMFversion="1.1"))
     consts = LoadFMF.readSingleFile(
         self.FMFinput, "testReadSingleFile")[0].attributes[
             'Additional constants changed from FMF version 1.0 to 1.1']
     self.assertEqual(consts[u'Parsec'][1],
                      str2unit("1 pc", FMFversion="1.1"))
     self.assertEqual(consts[u'US gallon'][1],
                      str2unit("1 galUS", FMFversion="1.1"))
     self.assertEqual(consts[u'Atomic mass units'][1],
                      str2unit("1 u", FMFversion="1.1"))
Example #13
0
 def testJouleValue(self):
     """Physical quantities with unit Joule are indicated by 'J'."""
     result = str2unit(self.inputDict['Joule'])
     self.assertEqual(result, Quantity(self.inputDict['Joule']))
Example #14
0
 def testGravitationalConstant(self):
     result = str2unit("1 Grav", FMFversion="1.0")
     self.assertEqual(result, str2unit('6.67259e-11 m**3/kg/s**2'))
Example #15
0
 def testJouleValue(self):
     """Physical quantities with unit Joule are indicated by 'J'."""
     result = str2unit(self.inputDict['Joule'])
     self.assertEqual(result, Quantity(self.inputDict['Joule']))
Example #16
0
 def testReadSingleFile(self):
     """
     Test the correct interpretation of physical constants
     as definied in FMF version 1.0.
     """
     consts = LoadFMF.readSingleFile(
         self.FMFinput, "testReadSingleFile"
     )[0].attributes['Mathematical and Physical Constants']
     self.assertEqual(consts[u'Speed of light'][1],
                      str2unit("1 c", FMFversion="1.0"))
     self.assertEqual(consts[u'Speed of light'][1], str2unit("1 c"))
     self.assertEqual(consts[u'Permeability of vacuum'][1],
                      str2unit("1 mu0", FMFversion="1.0"))
     self.assertEqual(consts[u'Permittivity of vacuum'][1],
                      str2unit("1 eps0", FMFversion="1.0"))
     self.assertEqual(consts[u'Gravitational constant'][1],
                      str2unit("1 Grav", FMFversion="1.0"))
     self.assertTrue(consts[u'Planck constant'][1],
                     str2unit("1 hplanck", FMFversion="1.0"))
     self.almostEqual(consts[u'Planck constant / 2pi'][1],
                      str2unit("1 hbar", FMFversion="1.0"))
     self.almostEqual(consts[u'Elementary charge'][1],
                      str2unit("1 e", FMFversion="1.0"))
     self.assertNotEqual(
         consts[u'Elementary charge'][1], str2unit("1 e"),
         "Elementary charge has been adapted to new CODATA recommendations."
     )
     self.assertEqual(consts[u'Electron mass'][1],
                      str2unit("1 me", FMFversion="1.0"))
     self.assertNotEqual(
         consts[u'Electron mass'][1], str2unit("1 me"),
         "Electron mass has been adapted to new CODATA recommendations.")
     self.assertEqual(consts[u'Proton mass'][1],
                      str2unit("1 mp", FMFversion="1.0"))
     self.assertNotEqual(
         consts[u'Proton mass'][1], str2unit("1 mp"),
         "Proton mass has been adapted to new CODATA recommendations.")
     self.assertEqual(consts[u'Avogadro number'][1],
                      str2unit("1 Nav", FMFversion="1.0"))
     self.assertEqual(consts[u'Boltzmann constant'][1],
                      str2unit("1 k", FMFversion="1.0"))
     consts = LoadFMF.readSingleFile(
         self.FMFinput, "testReadSingleFile")[0].attributes[
             'Additional constants changed from FMF version 1.0 to 1.1']
     self.almostEqual(consts[u'Parsec'][1],
                      str2unit("1 pc", FMFversion="1.0"))
     self.almostEqual(consts[u'US gallon'][1],
                      str2unit("1 galUS", FMFversion="1.0"))
     self.assertEqual(consts[u'Atomic mass units'][1],
                      str2unit("1 amu", FMFversion="1.0"))
Example #17
0
 colspec_re = re.compile(ur"(?P<shortname>[^\s([]*)\s*(?P<deps>\([^)]*\))?\s*(?:(?:\\pm|\+-|\+/-)\s*(?P<error>[^\s[]*))?\s*(?P<unit>\[[^]]*])?")
 fields = []
 fields_by_name = {}
 dimensions_for_fields = {}
 errors_for_fields = {}
 for i, (fieldLongname, spec) in enumerate(config.items()):
     if type(spec) == type([]):
         spec = ','.join(spec)
     try:
         match = re.search(colspec_re, spec)
     except TypeError, e:
         _logger.error("""Cannot interpret definition of data column "%s", \
                         which is given as "%s"!""" % (fieldLongname, spec))
     unit = match.group('unit')
     if unit != None:
         unit = str2unit(unit[1: -1], FMFversion)
     else:
         unit = 1.0
     fieldShortname = match.group('shortname')
     dimensions = match.group('deps')
     if dimensions != None:
         dimensions_for_fields[fieldShortname] = dimensions[1: -1].split(',')
     else:
         dimensions_for_fields[fieldShortname] = None
     errors_for_fields[fieldShortname] = match.group('error')
     field = DataContainer.FieldContainer(datTable[i],
                                          longname=fieldLongname,
                                          shortname=fieldShortname,
                                          unit=unit)
     fields.append(field)
     fields_by_name[fieldShortname] = field
Example #18
0
 def testReadSingleFile(self):
     """
     Test the correct interpretation of physical constants
     as definied in FMF version 1.1.
     """
     consts = LoadFMF.readSingleFile(self.FMFinput, "testReadSingleFile")[0].attributes[
         "Mathematical and Physical Constants"
     ]
     self.assertEqual(consts[u"Speed of light"][1], str2unit("1 c", FMFversion="1.1"))
     self.assertEqual(
         consts[u"Permeability of vacuum"][1],
         str2unit("1 mu0", FMFversion="1.1"),
         "The values differ by %s." % (consts[u"Permeability of vacuum"][1] - str2unit("1 mu0", FMFversion="1.1"),),
     )
     self.assertEqual(consts[u"Permittivity of vacuum"][1], str2unit("1 eps0", FMFversion="1.1"))
     self.assertEqual(consts[u"Gravitational constant"][1], str2unit("1 G", FMFversion="1.1"))
     self.assertEqual(consts[u"Planck constant"][1], str2unit("1 h", FMFversion="1.1"))
     self.assertEqual(consts[u"Planck constant / 2pi"][1], str2unit("1 hbar", FMFversion="1.1"))
     self.assertEqual(
         consts[u"Elementary charge"][1],
         str2unit("1 e", FMFversion="1.1"),
         "The elements %s and %s do not match."
         % (consts[u"Elementary charge"][1], str2unit("1 e", FMFversion="1.1")),
     )
     self.assertEqual(consts[u"Electron mass"][1], str2unit("1 me", FMFversion="1.1"))
     self.assertEqual(consts[u"Proton mass"][1], str2unit("1 mp", FMFversion="1.1"))
     self.assertEqual(consts[u"Avogadro number"][1], str2unit("1 NA", FMFversion="1.1"))
     self.assertEqual(consts[u"Boltzmann constant"][1], str2unit("1 k", FMFversion="1.1"))
     self.assertEqual(consts[u"Rydberg constant"][1], str2unit("1 Ryd", FMFversion="1.1"))
     consts = LoadFMF.readSingleFile(self.FMFinput, "testReadSingleFile")[0].attributes[
         "Additional constants changed from FMF version 1.0 to 1.1"
     ]
     self.assertEqual(consts[u"Parsec"][1], str2unit("1 pc", FMFversion="1.1"))
     self.assertEqual(consts[u"US gallon"][1], str2unit("1 galUS", FMFversion="1.1"))
     self.assertEqual(consts[u"Atomic mass units"][1], str2unit("1 u", FMFversion="1.1"))
Example #19
0
 def testReadSingleFile(self):
     """
     Test the correct interpretation of physical constants
     as definied in FMF version 1.1.
     """
     consts = LoadFMF.readSingleFile(
         self.FMFinput, "testReadSingleFile")[0].attributes[
         'Mathematical and Physical Constants'
         ]
     self.assertEqual(
         consts[u'Speed of light'][1], str2unit("1 c", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Permeability of vacuum'][1],
         str2unit("1 mu0", FMFversion="1.1"),
         'The values differ by %s.' % (
             consts[u'Permeability of vacuum'][1] -\
             str2unit("1 mu0", FMFversion="1.1"),
             )
         )
     self.assertEqual(
         consts[u'Permittivity of vacuum'][1],
         str2unit("1 eps0", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Gravitational constant'][1],
         str2unit("1 G", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Planck constant'][1],
         str2unit("1 h", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Planck constant / 2pi'][1],
         str2unit("1 hbar", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Elementary charge'][1], str2unit("1 e",FMFversion="1.1"),
         'The elements %s and %s do not match.' % (
             consts[u'Elementary charge'][1],
             str2unit("1 e", FMFversion="1.1")
             )
         )
     self.assertEqual(
         consts[u'Electron mass'][1], str2unit("1 me", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Proton mass'][1], str2unit("1 mp", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Avogadro number'][1], str2unit("1 NA", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Boltzmann constant'][1], str2unit("1 k",FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Rydberg constant'][1], str2unit("1 Ryd", FMFversion="1.1")
         )
     consts = LoadFMF.readSingleFile(
         self.FMFinput, "testReadSingleFile")[0].attributes[
         'Additional constants changed from FMF version 1.0 to 1.1'
         ]
     self.assertEqual(
         consts[u'Parsec'][1], str2unit("1 pc", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'US gallon'][1], str2unit("1 galUS", FMFversion="1.1")
         )
     self.assertEqual(
         consts[u'Atomic mass units'][1], str2unit("1 u", FMFversion="1.1")
         )
Example #20
0
 def testGravitationalConstant(self):
     result = str2unit("1 Grav", FMFversion="1.0")
     self.assertEqual(result, str2unit('6.67259e-11 m**3/kg/s**2'))
Example #21
0
 )
 fields = []
 fields_by_name = {}
 dimensions_for_fields = {}
 errors_for_fields = {}
 for i, (fieldLongname, spec) in enumerate(config.items()):
     if type(spec) == type([]):
         spec = ','.join(spec)
     try:
         match = re.search(colspec_re, spec)
     except TypeError, e:
         _logger.error("""Cannot interpret definition of data column "%s", \
                         which is given as "%s"!""" % (fieldLongname, spec))
     unit = match.group('unit')
     if unit != None:
         unit = str2unit(unit[1:-1], FMFversion)
     else:
         unit = 1.0
     fieldShortname = match.group('shortname')
     dimensions = match.group('deps')
     if dimensions != None:
         dimensions_for_fields[fieldShortname] = dimensions[1:-1].split(',')
     else:
         dimensions_for_fields[fieldShortname] = None
     errors_for_fields[fieldShortname] = match.group('error')
     field = DataContainer.FieldContainer(datTable[i],
                                          longname=fieldLongname,
                                          shortname=fieldShortname,
                                          unit=unit)
     fields.append(field)
     fields_by_name[fieldShortname] = field
Example #22
0
 def testDegC(self):
     for version in ['1.0', '1.1']:
         result = str2unit("9.0 degC", FMFversion=version)
         self.assertEqual(result.value, 9, 'Error in FMF version '+version)