def testImportFMF(self): from fmfile import FMFLoader table = FMFLoader.loadFMFFromFile(self.filename) print "Testing imported SampleContainer for consistency..." for column in ['y0', 'y1', 'y2', 'y3', 'y4', 'y5', 'y6', 'y7', 'y8']: self.assertEqual(table[column].dimensions[0].id, table['x'].id)
def testListofStrings2(self): column = [['Hello', 'World'], 'World'] result = FMFLoader.column2FieldContainer('simple string', column) expectedResult = FieldContainer( numpy.array(['Hello, World', 'World']), longname='simple string' ) assertEqual(result, expectedResult)
def registerFMF(self, filename, temporary=False): """ Extracts a SampleContainer from a given FMF file and stores it permanently. The emd5 of the SampleContainer that has been generated is returned. filename -- path to the FMF file temporary -- see registerDataContainer """ sc = FMFLoader.loadFMFFromFile(filename) self.registerDataContainer(sc, temporary) return sc.id
def testVariableFirstNaN(self): column = [ ('T', 'NaN', Quantity('0.5 degC')), ('T', Quantity('11.2 degC'), None) ] result = FMFLoader.column2FieldContainer('temperature', column) expectedResult = FieldContainer( numpy.array([numpy.NaN, 11.2]), error=numpy.array([0.5, 0.0]), mask = numpy.array([True, False]), unit='1 degC', longname='temperature', shortname='T') assertEqual(result, expectedResult)
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. u""" """ import sys import unittest sys.path.append("..") import pkg_resources pkg_resources.require("Pyphant") from fmfile import FMFLoader import pyphant.visualizers.Chart as cv loader = FMFLoader.FMFLoader() loader.paramFilename.value = 'Sim_abs_210nm.fmf' data = loader.loadFMF() v = cv.LineChart(data['absorption']) v.figure.savefig('demoFMF.png')
def testValid(self): result = FMFLoader.checkAndCondense(self.valid) numpy.testing.assert_array_equal(self.x, result)
def setUp(self): self.loader = FMFLoader.FMFLoader() from fmfile import __path__ as path import os self.path = os.path.join(path[0], 'tests', 'resources', 'fmf')
def testReadSingleFile(self): """ Test the correct interpretation of physical constants as definied in FMF version 1.1. """ consts = FMFLoader.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 = FMFLoader.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") )
def testReadSingleFile(self): """ Test the correct interpretation of physical constants as definied in FMF version 1.0. """ consts = FMFLoader.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 = FMFLoader.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") )
def testJouleValue1_0(self): """Physical quantities with unit Joule are indicated by 'J'.""" result = FMFLoader.item2value( self.inputDict['Joule'], FMFversion='1.0' ) self.assertEqual(result, (Quantity(self.inputDict['Joule']), None))
def testComplexValue(self): """Imaginary numbers are indicated by 'j'.""" result = FMFLoader.item2value(self.inputDict['complexJ']) self.assertEqual(result, (complex(self.inputDict['complexJ']), None))