Example #1
0
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
import os
import warnings

import numpy as np

import hftools.constants.si_units as si_units

from hftools.testing import TestCase, make_load_tests
from hftools.dataset import hfarray

warnings.resetwarnings()

warnings.simplefilter("error", DeprecationWarning)
load_tests = make_load_tests(si_units)
basepath = os.path.split(__file__)[0]

from hftools.constants import unit_to_multiplier


class Test_unit_to_multiplier(TestCase):
    unit = "Hz"

    def _helper(self, prefix, multiplier):
        res = si_units.unit_to_multiplier("%s%s" % (prefix, self.unit))
        self.assertEqual(res, (multiplier, self.unit))

    def test_a(self):
        self._helper("a", 1e-18)
Example #2
0
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
import os
import warnings

import numpy as np

import hftools.constants.si_units as si_units

from hftools.testing import TestCase, make_load_tests
from hftools.dataset import hfarray

warnings.resetwarnings()

warnings.simplefilter("error", DeprecationWarning)
load_tests = make_load_tests(si_units)
basepath = os.path.split(__file__)[0]

from hftools.constants import unit_to_multiplier


class Test_unit_to_multiplier(TestCase):
    unit = "Hz"

    def _helper(self, prefix, multiplier):
        res = si_units.unit_to_multiplier("%s%s" % (prefix, self.unit))
        self.assertEqual(res, (multiplier, self.unit))

    def test_a(self):
        self._helper("a", 1e-18)
Example #3
0
# Copyright (c) 2014, HFTools Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
import os

import numpy as np

import hftools.math as hfmath
from hftools.dataset import hfarray, DimSweep, DimMatrix_i, DimMatrix_j
from hftools.testing import TestCase, make_load_tests

basepath = os.path.split(__file__)[0]
load_tests = make_load_tests(hfmath)


class Test_angle(TestCase):
    def setUp(self):
        self.A = hfarray([1, 1j, -1, -1j])
        self.a = np.array([1, 1j, -1, -1j])

    def test_va_1(self):
        res = hfmath.angle(self.A, deg=False)
        self.assertAllclose(res, np.array([0, np.pi / 2, np.pi, -np.pi / 2]))

    def test_va_2(self):
        res = hfmath.angle(self.A, deg=True)
        self.assertAllclose(res, np.array([0, 90, 180, -90]))
Example #4
0
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

import datetime as datetimemodule
import os
import pdb
import shutil

import numpy as np

import hftools.utils as utils
from hftools.testing import TestCase, make_load_tests

load_tests = make_load_tests(utils)
basepath = os.path.split(__file__)[0]


class Test_to_numeric(TestCase):
    def test_float_1(self):
        self.assertEqual(utils.to_numeric("1.2"), 1.2)

    def test_int_1(self):
        self.assertEqual(utils.to_numeric("1"), 1)

    def test_cplx_1(self):
        self.assertEqual(utils.to_numeric("1+1j", False), "1+1j")

    def test_date_1(self):
        self.assertEqual(utils.to_numeric("2012-05-30 10:34:00"),
Example #5
0
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
import os
import warnings
import numpy as np

import hftools.dataset.dim as ddim

from hftools.dataset.dim import DimSweep, ComplexDiagAxis, ComplexIndepAxis,\
    ComplexDerivAxis, dims_has_complex, info_has_complex
from hftools.testing import TestCase, make_load_tests
from hftools.dataset import hfarray
from hftools.utils import reset_hftools_warnings, HFToolsDeprecationWarning

basepath = os.path.split(__file__)[0]
load_tests = make_load_tests(ddim)


class Test_Dim_init(TestCase):
    def setUp(self):
        self.dim = DimSweep("a", 10, unit="Hz")

    def test_1(self):
        a = DimSweep(self.dim)
        self.assertEqual(a, self.dim)
        self.assertEqual(a.name, "a")
        self.assertEqual(a.unit, "Hz")
        self.assertAllclose(a.data, range(10))

    def test_2(self):
        a = DimSweep(self.dim, data=range(5))
Example #6
0
import os
import warnings
import numpy as np

from numpy import newaxis

import hftools.dataset.arrayobj as aobj
import hftools.dataset.dim as dim
import hftools.dataset as ds

from hftools.testing import TestCase, make_load_tests
from hftools.testing import random_value_array
from hftools.utils import reset_hftools_warnings, HFToolsDeprecationWarning

basepath = os.path.split(__file__)[0]
load_tests = make_load_tests(aobj)


class TestDims(TestCase):
    def test_contains1(self):
        dims = (dim.DimSweep("a", 3), dim.DimSweep("b", 3),
                dim.DimSweep("c", 3))
        dims = aobj.Dims(dims)
        for d in dims:
            self.assertTrue(d in dims)
#        self.assertFalse("a" in dims)

    def test_get_matching_dim1(self):
        dims = aobj.Dims((dim.DimSweep("a", 3), dim.DimSweep("b", 3),
                          dim.DimSweep("c", 3)))
        self.assertEqual(dims.get_matching_dim(dim.DimSweep("a", 4)), dims[0])
Example #7
0
import numpy as np

import hftools.dataset.dim as ddim
import hftools.dataset.dataset as dset
import hftools.dataset as ds

from hftools.dataset import hfarray, DimSweep, DimRep, DimMatrix_i,\
    DimMatrix_j, DataBlockError, DataDict, DataBlock
from hftools.dataset.comments import Comments
from hftools.testing import random_value_array, random_complex_value_array,\
    random_value_array_from_dims, random_value_array, make_load_tests,\
    random_complex_value_array, random_value_array_from_dims, TestCase
from hftools.utils import reset_hftools_warnings, HFToolsWarning

basepath = os.path.split(__file__)[0]
load_tests = make_load_tests(dset)

VA = hfarray
import hftools.dataset


class Test_DataBlock(TestCase):
    def setUp(self):
        self.a = DataBlock()

    def test_report(self):
        self.a.report()

    def test_str(self):
        self.assertEqual(self.a.report(), str(self.a))
Example #8
0
import pdb

import numpy as np

import hftools.dataset.dim as ddim
import hftools.dataset.dataset as dset
import hftools.dataset as ds
from hftools.testing import random_value_array, random_complex_value_array,\
    random_value_array_from_dims
from hftools.dataset import hfarray, DimSweep, DimRep
from hftools.testing import TestCase, make_load_tests

from hftools.dataset import DataDict

basepath = os.path.split(__file__)[0]
load_tests = make_load_tests(dset)

VA = hfarray


class Test_DataDict(TestCase):
    def setUp(self):
        self.a = DataDict()
        self.b = DataDict(a=VA(1), c=VA(3), b=VA(2), d=VA(4))
        self.c = DataDict(e=VA(12), a=VA(4))

    def _outputformat(self, var, finaloutformat):
        v = getattr(self, var)
        v.outputformat = "%.0f"
        for x in v.values():
            self.assertEqual(x.outputformat, "%.0f")
Example #9
0
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
import os
import warnings
import numpy as np

import hftools.dataset.dim as ddim

from hftools.dataset.dim import DimSweep, ComplexDiagAxis, ComplexIndepAxis,\
    ComplexDerivAxis, dims_has_complex, info_has_complex
from hftools.testing import TestCase, make_load_tests
from hftools.dataset import hfarray
from hftools.utils import reset_hftools_warnings, HFToolsDeprecationWarning

basepath = os.path.split(__file__)[0]
load_tests = make_load_tests(ddim)


class Test_Dim_init(TestCase):
    def setUp(self):
        self.dim = DimSweep("a", 10, unit="Hz")

    def test_1(self):
        a = DimSweep(self.dim)
        self.assertEqual(a, self.dim)
        self.assertEqual(a.name, "a")
        self.assertEqual(a.unit, "Hz")
        self.assertAllclose(a.data, range(10))

    def test_2(self):
        a = DimSweep(self.dim, data=range(5))