def test_loadData_1column(self):
     """check loading of one-column data.
     """
     d1c = numpy.arange(1, 6)
     d = loadData(loaddata01, usecols=[0], minrows=1)
     self.failUnless(numpy.array_equal(d1c, d))
     d = loadData(loaddata01, usecols=[0], minrows=2)
     self.failUnless(numpy.array_equal(d1c, d))
     d = loadData(loaddata01, usecols=[0], minrows=3)
     self.failIf(numpy.array_equal(d1c, d))
     return
Example #2
0
 def test_loadData_1column(self):
     """check loading of one-column data.
     """
     d1c = numpy.arange(1, 6)
     d = loadData(loaddata01, usecols=[0], minrows=1)
     self.failUnless(numpy.array_equal(d1c, d))
     d = loadData(loaddata01, usecols=[0], minrows=2)
     self.failUnless(numpy.array_equal(d1c, d))
     d = loadData(loaddata01, usecols=[0], minrows=3)
     self.failIf(numpy.array_equal(d1c, d))
     return
Example #3
0
 def test_loadData_default(self):
     """check loadData() with default options
     """
     d2c = numpy.array([[3, 31], [4, 32], [5, 33]])
     self.assertRaises(IOError, loadData, 'doesnotexist')
     # the default minrows=10 makes it read from the third line
     d = loadData(loaddata01)
     self.assertTrue(numpy.array_equal(d2c, d))
     # the usecols=(0, 1) would make it read from the third line
     d = loadData(loaddata01, minrows=1, usecols=(0, 1))
     self.assertTrue(numpy.array_equal(d2c, d))
     # check the effect of usecols effect
     d = loadData(loaddata01, usecols=(0,))
     self.assertTrue(numpy.array_equal(d2c[:,0], d))
     d = loadData(loaddata01, usecols=(1,))
     self.assertTrue(numpy.array_equal(d2c[:,1], d))
     return
Example #4
0
 def test_loadData_default(self):
     """check loadData() with default options
     """
     d2c = numpy.array([[3, 31], [4, 32], [5, 33]])
     self.assertRaises(IOError, loadData, 'doesnotexist')
     # the default minrows=10 makes it read from the third line
     d = loadData(loaddata01)
     self.assertTrue(numpy.array_equal(d2c, d))
     # the usecols=(0, 1) would make it read from the third line
     d = loadData(loaddata01, minrows=1, usecols=(0, 1))
     self.assertTrue(numpy.array_equal(d2c, d))
     # check the effect of usecols effect
     d = loadData(loaddata01, usecols=(0, ))
     self.assertTrue(numpy.array_equal(d2c[:, 0], d))
     d = loadData(loaddata01, usecols=(1, ))
     self.assertTrue(numpy.array_equal(d2c[:, 1], d))
     return
Example #5
0
 def setUp(self):
     self.factory = PDFRecipeFactory()
     # cubic
     self.cifbtoc = _datafile('BaTiO3-Pm3m.cif')
     # tetragonal
     self.cifbtot = _datafile('BaTiO3-P4mm.cif')
     data = loadData(_datafile('BaTiO3.gr'))
     self.r, self.g = data.T
     return
Example #6
0
def load_xy(files: List[str]) -> Tuple[List[array], List[array]]:
    """
    load x and y array from a list of data files and return a list iof x array and a list of y array.
    :param files: a list of data files.
    :return: x array list, y array list.
    """
    xs, ys = [], []
    for f in files:
        x, y = loadData(f).T
        xs.append(x)
        ys.append(y)
    return xs, ys
Example #7
0
def load_gr(files: List[str]) -> Tuple[List[array], List[array]]:
    """
    load r and g array from a list of data files and return a list of r array and a list of g array.
    :param files: path to data files.
    :return: r array list, g array list.
    """
    rs, gs = [], []
    for f in files:
        r, g = loadData(f).T
        rs.append(r)
        gs.append(g)
    return rs, gs
Example #8
0
def readPDF(fname):
    """Reads an .gr file, loads r and G(r) vectors.

    fname -- name of the file we want to read.

    Returns r and gr arrays.

    """
    from diffpy.utils.parsers import loadData

    rv = loadData(fname, unpack=True)
    if len(rv) >= 2:
        return rv[:2]
    return (None, None)
Example #9
0
def load_fgr(
    files: List[str]
) -> Tuple[List[array], List[array], List[array], List[array]]:
    """
    load r array, g calculation array, g data array and difference between data and calculation array from a lit of
    data files and return four list of arrays.
    :param files: a list of data files.
    :return: r array list, gcalc array list, g array list, gdiff array list.
    """
    rs, gcalcs, gs, gdiffs = [], [], [], []
    for f in files:
        r, gcalc, g, _ = loadData(f).T
        gdiff = g - gcalc
        rs.append(r)
        gcalcs.append(gcalc)
        gs.append(g)
        gdiffs.append(gdiff)
    return rs, gcalcs, gs, gdiffs