Example #1
0
 def setUp(self):
     datastack.clear_stack()
     ui.clean()
     datastack.set_template_id("__ID")
     self._this_dir = os.path.dirname(sys.modules[self.__module__].__file__)
     self.loggingLevel = logger.getEffectiveLevel()
     logger.setLevel(logging.ERROR)
Example #2
0
 def setUp(self):
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
     self.ds = datastack.DataStack()
     self.loggingLevel = logger.getEffectiveLevel()
     logger.setLevel(logging.ERROR)
Example #3
0
 def setUp(self):
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
     self.ds = datastack.DataStack()
     self.loggingLevel = logger.getEffectiveLevel()
     logger.setLevel(logging.ERROR)
Example #4
0
 def setUp(self):
     datastack.clear_stack()
     ui.clean()
     datastack.set_template_id("__ID")
     self._this_dir = os.path.dirname(sys.modules[self.__module__].__file__)
     self.loggingLevel = logger.getEffectiveLevel()
     logger.setLevel(logging.ERROR)
def ds_setup_object():
    """Setup and teardown code for each test.

    Could try and be clever and re-use ds_setup here,
    but just repeat it to be simpler.
    """

    # Setup
    #
    ds = datastack.DataStack()
    datastack.clear_stack()
    ui.clean()
    loggingLevel = logger.getEffectiveLevel()
    logger.setLevel(logging.ERROR)
    datastack.set_stack_verbosity(logging.ERROR)
    datastack.set_template_id("__ID")

    # Run test, returning the stack object
    #
    yield ds

    # Cleanup
    #
    ds.clear_stack()
    datastack.clear_stack()
    ui.clean()
    datastack.set_template_id("__ID")
    logger.setLevel(loggingLevel)
Example #6
0
 def tearDown(self):
     datastack.clear_stack()
     ui.clean()
     datastack.set_template_id("__ID")
     os.remove(self.lisname)
     os.remove(self.name1)
     os.remove(self.name2)
     datastack.set_stack_verbose(False)
     logger.setLevel(self.loggingLevel)
Example #7
0
 def tearDown(self):
     datastack.clear_stack()
     ui.clean()
     datastack.set_template_id("__ID")
     os.remove(self.lisname)
     os.remove(self.name1)
     os.remove(self.name2)
     datastack.set_stack_verbose(False)
     logger.setLevel(self.loggingLevel)
def ds_setup():
    """Setup and teardown code for each test."""

    # Setup
    #
    datastack.clear_stack()
    ui.clean()
    loggingLevel = logger.getEffectiveLevel()
    logger.setLevel(logging.ERROR)
    datastack.set_stack_verbosity(logging.ERROR)
    datastack.set_template_id("__ID")

    # Run test
    #
    yield

    # Cleanup
    #
    datastack.clear_stack()
    ui.clean()
    datastack.set_template_id("__ID")
    logger.setLevel(loggingLevel)
Example #9
0
    def test_case_5(self):
        x1 = np.arange(50) + 100
        y1 = 2 * (3 * x1**2 + x1)
        x2 = np.arange(50)
        y2 = 2 * (x2**2 + 3 * x2)
        x3 = np.arange(50) + 200
        y3 = 2 * (x3**2 + 3 * x3)

        ds = self.ds

        ds.load_arrays([[x1, y1], [x2, y2], [x3, y3]])

        ds.set_source('const1d.const * polynom1d.poly__ID')

        poly1 = ui._session._get_model_component('poly1')
        poly2 = ui._session._get_model_component('poly2')
        poly3 = ui._session._get_model_component('poly3')
        const = ui._session._get_model_component('const')

        ds.freeze('poly')
        ds.thaw('poly.c0')
        ds.thaw('poly.c1')
        ds.thaw('poly.c2')
        ds.thaw('const')

        assert poly1.c0.frozen is False
        assert poly1.c1.frozen is False
        assert poly1.c2.frozen is False
        assert poly1.c3.frozen is True

        assert poly2.c0.frozen is False
        assert poly2.c1.frozen is False
        assert poly2.c2.frozen is False
        assert poly2.c3.frozen is True

        assert poly3.c0.frozen is False
        assert poly3.c1.frozen is False
        assert poly3.c2.frozen is False
        assert poly3.c3.frozen is True

        ds.set_par('poly.c1', 0.45)

        assert poly1.c1.val == 0.45
        assert poly2.c1.val == 0.45
        assert poly3.c1.val == 0.45

        ds[1].set_par('poly.c1', 0.1)

        assert poly1.c1.val == 0.1
        assert poly2.c1.val == 0.45
        assert poly3.c1.val == 0.45

        ds.set_par('const.c0', 2)

        assert const.c0.val == 2

        ds.set_par('const.integrate', False)
        ds.freeze('const.c0')

        vals = ds.get_par('poly.c1.val')
        assert ([0.1, 0.45, 0.45] == vals).all()

        # QUS: pars is not checked, so is this just
        # checking that get_par doesn't fail?
        pars = ds.get_par('const.c0')

        ds.fit()

        assert round(poly1.c1.val) == 1
        assert round(poly1.c2.val) == 3
        assert round(poly2.c1.val) == 3
        assert round(poly2.c2.val) == 1
        assert round(poly3.c1.val) == 3
        assert round(poly3.c2.val) == 1

        ds.clear_stack()

        x1 = np.arange(50) + 100
        y1 = 7 * (3 * x1**2 + x1)
        x2 = np.arange(50)
        y2 = 2 * (x2**2 + 3 * x2)
        x3 = np.arange(50) + 200
        y3 = 2 * (x3**2 + 3 * x3)

        ds.load_arrays([[x1, y1], [x2, y2], [x3, y3]])

        datastack.set_template_id("foo")

        ds.set_source('const1d.constfoo * polynom1d.polyfoo')

        const1 = ui._session._get_model_component('const1')
        const2 = ui._session._get_model_component('const2')
        const3 = ui._session._get_model_component('const3')

        ds[2, 3].link('const.c0')

        ds[2].set_par('const.c0', 3)
        ds[1].set_par('const.c0', 7)

        ds[1].freeze('const.c0')

        assert const2.c0.frozen is False

        ds.fit()

        assert const2.c0.val == const3.c0.val
        assert const3.c0._link is const2.c0

        ds.unlink("const.c0")

        assert const3.c0._link is not const2.c0
Example #10
0
 def tearDown(self):
     self.ds.clear_stack()
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
     logger.setLevel(self.loggingLevel)
Example #11
0
 def tearDown(self):
     self.ds.clear_stack()
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
     logger.setLevel(self.loggingLevel)
Example #12
0
    def test_case_5(self):
        x1 = np.arange(50)+100
        y1 = 2*(3*x1**2 + x1)
        x2 = np.arange(50)
        y2 = 2*(x2**2 + 3*x2)
        x3 = np.arange(50)+200
        y3 = 2*(x3**2+3*x3)

        ds = self.ds

        ds.load_arrays([[x1, y1], [x2, y2], [x3, y3]])

        ds.set_source('const1d.const * polynom1d.poly__ID')

        poly1 = ui._session._get_model_component('poly1')
        poly2 = ui._session._get_model_component('poly2')
        poly3 = ui._session._get_model_component('poly3')
        const = ui._session._get_model_component('const')

        ds.freeze('poly')
        ds.thaw('poly.c0')
        ds.thaw('poly.c1')
        ds.thaw('poly.c2')
        ds.thaw('const')

        assert poly1.c0.frozen is False
        assert poly1.c1.frozen is False
        assert poly1.c2.frozen is False
        assert poly1.c3.frozen is True

        assert poly2.c0.frozen is False
        assert poly2.c1.frozen is False
        assert poly2.c2.frozen is False
        assert poly2.c3.frozen is True

        assert poly3.c0.frozen is False
        assert poly3.c1.frozen is False
        assert poly3.c2.frozen is False
        assert poly3.c3.frozen is True

        ds.set_par('poly.c1', 0.45)

        assert poly1.c1.val == 0.45
        assert poly2.c1.val == 0.45
        assert poly3.c1.val == 0.45

        ds[1].set_par('poly.c1', 0.1)

        assert poly1.c1.val == 0.1
        assert poly2.c1.val == 0.45
        assert poly3.c1.val == 0.45

        ds.set_par('const.c0', 2)

        assert const.c0.val == 2

        ds.set_par('const.integrate', False)
        ds.freeze('const.c0')

        vals = ds.get_par('poly.c1.val')
        assert ([0.1, 0.45, 0.45] == vals).all()

        pars = ds.get_par('const.c0')

        ds.fit()

        assert round(poly1.c1.val) == 1
        assert round(poly1.c2.val) == 3
        assert round(poly2.c1.val) == 3
        assert round(poly2.c2.val) == 1
        assert round(poly3.c1.val) == 3
        assert round(poly3.c2.val) == 1

        ds.clear_stack()

        x1 = np.arange(50)+100
        y1 = 7*(3*x1**2 + x1)
        x2 = np.arange(50)
        y2 = 2*(x2**2 + 3*x2)
        x3 = np.arange(50)+200
        y3 = 2*(x3**2+3*x3)

        ds.load_arrays([[x1, y1], [x2, y2], [x3, y3]])

        datastack.set_template_id("foo")

        ds.set_source('const1d.constfoo * polynom1d.polyfoo')

        const1 = ui._session._get_model_component('const1')
        const2 = ui._session._get_model_component('const2')
        const3 = ui._session._get_model_component('const3')

        ds[2,3].link('const.c0')

        ds[2].set_par('const.c0', 3)
        ds[1].set_par('const.c0', 7)

        ds[1].freeze('const.c0')

        assert const2.c0.frozen is False

        ds.fit()

        assert const2.c0.val == const3.c0.val
        assert const3.c0._link is const2.c0

        ds.unlink("const.c0")

        assert const3.c0._link is not const2.c0
Example #13
0
 def tearDown(self):
     datastack.clear_stack()
     ui.clean()
     datastack.set_template_id("__ID")
     datastack.set_stack_verbose(False)
     logger.setLevel(self.loggingLevel)
Example #14
0
 def tearDown(self):
     self.ds.clear_stack()
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
Example #15
0
 def setUp(self):
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
     self.ds = datastack.DataStack()
Example #16
0
 def setUp(self):
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
     self.ds = datastack.DataStack()
Example #17
0
 def tearDown(self):
     self.ds.clear_stack()
     datastack.clear_stack()
     datastack.set_template_id("__ID")
     ui.clean()
def test_design_case_1(ds_setup, ds_datadir):

    datastack.set_template_id("ID")

    datadir = ds_datadir
    ls = '@' + '/'.join((datadir, '3c273.lis'))
    datastack.load_pha(ls, use_errors=True)

    assert 2 == len(datastack.DATASTACK.datasets)
    assert 2 == len(ui._session._data)

    datastack.load_pha("myid", '/'.join((datadir, "3c273.pi")))

    assert 2 == len(datastack.DATASTACK.datasets)
    assert 3 == len(ui._session._data)

    datastack.load_pha('/'.join((datadir, "3c273.pi")))

    assert 3 == len(datastack.DATASTACK.datasets)
    assert 4 == len(ui._session._data)

    datastack.load_pha([], '/'.join((datadir, "3c273.pi")))

    assert 4 == len(datastack.DATASTACK.datasets)
    assert 5 == len(ui._session._data)

    ds = datastack.DataStack()

    datastack.load_pha(ds, ls)

    assert 4 == len(datastack.DATASTACK.datasets)
    assert 7 == len(ui._session._data)
    assert 2 == len(ds.datasets)

    datastack.load_pha(ds, '/'.join((datadir, "3c273.pi")))

    assert 4 == len(datastack.DATASTACK.datasets)
    assert 8 == len(ui._session._data)
    assert 3 == len(ds.datasets)

    dids = datastack.DATASTACK.get_stack_ids()
    assert dids == [1, 2, 3, 4]

    sids = set(ui._session._data.keys())
    assert sids == {1, 2, 3, 4, 5, 6, 7, "myid"}

    datastack.set_source([1, 2], "powlaw1d.pID")
    datastack.set_source([3, 4], "brokenpowerlaw.bpID")

    dsids = ds.get_stack_ids()
    assert dsids == [5, 6, 7]

    p1 = ui._session._model_components['p1']
    p2 = ui._session._model_components['p2']
    bp3 = ui._session._model_components['bp3']
    bp4 = ui._session._model_components['bp4']

    assert p1 is not None
    assert p2 is not None
    assert bp3 is not None
    assert bp4 is not None

    datastack.set_source(1, "polynom1d.poly1")
    datastack.set_source([2, 3, 4], "atten.attID")

    poly1 = ui._session._model_components['poly1']
    a2 = ui._session._model_components['att2']
    a3 = ui._session._model_components['att3']
    a4 = ui._session._model_components['att4']

    assert poly1 is not None
    assert a2 is not None
    assert a3 is not None
    assert a4 is not None

    datastack.clean()

    assert 0 == len(datastack.DATASTACK.datasets)
    assert 0 == len(ui._session._data)
    assert 3 == len(ds.datasets)
Example #19
0
 def tearDown(self):
     datastack.clear_stack()
     ui.clean()
     datastack.set_template_id("__ID")
     datastack.set_stack_verbose(False)
     logger.setLevel(self.loggingLevel)
Example #20
0
    def test_case_2(self):
        x1 = np.arange(50)+100
        y1 = 2*(3*x1**2 + x1)
        x2 = np.arange(50)
        y2 = 2*(x2**2 + 3*x2)
        x3 = np.arange(50)+200
        y3 = 2*(x3**2+3*x3)

        datastack.load_arrays([[x1, y1], [x2, y2], [x3, y3]])

        datastack.set_source([], 'const1d.const * polynom1d.poly__ID')

        poly1 = ui._session._get_model_component('poly1')
        poly2 = ui._session._get_model_component('poly2')
        poly3 = ui._session._get_model_component('poly3')
        const = ui._session._get_model_component('const')

        datastack.freeze([], 'poly')
        datastack.thaw([], 'poly.c0')
        datastack.thaw([], 'poly.c1')
        datastack.thaw([], 'poly.c2')
        datastack.thaw([], 'const')

        assert poly1.c0.frozen is False
        assert poly1.c1.frozen is False
        assert poly1.c2.frozen is False
        assert poly1.c3.frozen is True

        assert poly2.c0.frozen is False
        assert poly2.c1.frozen is False
        assert poly2.c2.frozen is False
        assert poly2.c3.frozen is True

        assert poly3.c0.frozen is False
        assert poly3.c1.frozen is False
        assert poly3.c2.frozen is False
        assert poly3.c3.frozen is True

        datastack.set_par([], 'poly.c1', 0.45)

        assert poly1.c1.val == 0.45
        assert poly2.c1.val == 0.45
        assert poly3.c1.val == 0.45

        datastack.set_par([1], 'poly.c1', 0.1)

        assert poly1.c1.val == 0.1
        assert poly2.c1.val == 0.45
        assert poly3.c1.val == 0.45

        datastack.set_par([], 'const.c0', 2)

        assert const.c0.val == 2

        datastack.set_par([], 'const.integrate', False)
        datastack.freeze([], 'const.c0')

        vals = datastack.get_par([], 'poly.c1.val')
        assert ([0.1, 0.45, 0.45] == vals).all()

        # QUS: pars is not checked, so is this just
        # checking that get_par doesn't fail?
        pars = datastack.get_par([], 'const.c0')

        datastack.fit([])

        assert round(poly1.c1.val) == 1
        assert round(poly1.c2.val) == 3
        assert round(poly2.c1.val) == 3
        assert round(poly2.c2.val) == 1
        assert round(poly3.c1.val) == 3
        assert round(poly3.c2.val) == 1

        datastack.clear_stack()

        x1 = np.arange(50)+100
        y1 = 7*(3*x1**2 + x1)
        x2 = np.arange(50)
        y2 = 2*(x2**2 + 3*x2)
        x3 = np.arange(50)+200
        y3 = 2*(x3**2+3*x3)

        datastack.load_arrays([[x1, y1], [x2, y2], [x3, y3]])

        datastack.set_template_id("foo")

        datastack.set_source([], 'const1d.constfoo * polynom1d.polyfoo')

        const1 = ui._session._get_model_component('const1')
        const2 = ui._session._get_model_component('const2')
        const3 = ui._session._get_model_component('const3')

        datastack.link([2,3], 'const.c0')

        datastack.set_par([2], 'const.c0', 3)
        datastack.set_par([1], 'const.c0', 7)

        datastack.freeze([1], 'const.c0')

        assert const2.c0.frozen is False

        datastack.fit([])

        assert const2.c0.val == const3.c0.val
        assert const3.c0._link is const2.c0

        datastack.unlink([], "const.c0")

        assert const3.c0._link is not const2.c0