Exemple #1
0
def test_set_up_lt3_layers():
    """
    Ensure that we raise an IndexError in the event we try to build a
    model with fewer than three layers.
    """
    layers = [layer.Source(), layer.Terminator()]
    test_m = model.Model()
    pytest.raises(IndexError, test_m.set_up, layers)
Exemple #2
0
def test_set_up_perpendicular_incidence():
    """
    Ensure that we raise an IndexError in the event we try to build a
    model with fewer than three layers.
    """
    layers = [layer.Source(), layer.Layer(), layer.Terminator()]
    test_m = model.Model()
    pytest.raises(ValueError, test_m.set_up, layers, 500e6, 500e9, np.pi/2, 's')
Exemple #3
0
def test_run_halpern():
    """
    Check that we can run the most basic model available, but with Halpern
    coefficients.
    """
    layers = [layer.Source(), layer.Layer(halperna=0., halpernb=0.), layer.Terminator()]
    test_m = model.Model()
    test_m.set_up(layers)
    results = test_m.run()
    npt.assert_allclose(results['transmittance'], np.ones(results['transmittance'].size))
    npt.assert_allclose(results['reflectance'], np.zeros(results['reflectance'].size))
Exemple #4
0
def test_run():
    """
    Check that we can run the most basic model available---i.e., all
    default values.
    """
    layers = [layer.Source(), layer.Layer(), layer.Terminator()]
    test_m = model.Model()
    test_m.set_up(layers)
    results = test_m.run()
    npt.assert_allclose(results['transmittance'], np.ones(results['transmittance'].size))
    npt.assert_allclose(results['reflectance'], np.zeros(results['reflectance'].size))
Exemple #5
0
def test_set_up_halpern_layer():
    """
    Check that we can set up a layer with Halpern coefficients, even if
    other layers aren't created with Halpern coefficients.
    """
    layers = [layer.Source(), layer.Layer(),
              layer.Layer(halperna=999., halpernb=111.),
              layer.Layer(), layer.Terminator()]
    test_m = model.Model()
    test_m.set_up(layers)
    assert list(test_m.halpern_layers.keys()) == [2]
    assert test_m.halpern_layers[2] == {'a' : 999., 'b' : 111., 'n' : 1.}
Exemple #6
0
def test_save():
    """
    Check that we can save the output of a model to a file
    """
    layers = [layer.Source(), layer.Layer(), layer.Terminator()]
    test_m = model.Model()
    test_m.set_up(layers)
    results = test_m.run()
    test_m.save(OUTPUT_LOC)
    dat = np.genfromtxt(OUTPUT_LOC, unpack=True)
    expected_fs = np.linspace(500e6, 500e9, num=1000)
    expected_ts = np.ones(1000)
    expected_rs = np.zeros(1000)
    assert dat.shape == (3, 1000)
    npt.assert_allclose(dat[0], expected_fs)
    npt.assert_allclose(dat[1], expected_ts)
    npt.assert_allclose(dat[2], expected_rs)
    os.remove(OUTPUT_LOC)
Exemple #7
0
def test_reset_model():
    """
    Check that we can create a basic model, then return all of the model's
    attributes to their defaults.
    """
    layers = [layer.Source(), layer.Layer(), layer.Terminator()]
    test_m = model.Model()
    expected_attrs = [None] * len(test_m.__dict__.keys())
    test_m.set_up(layers)
    assert test_m.rinds == [1., 1., 1]
    assert test_m.tands == [0., 0., 0.]
    assert test_m.thicks == [np.inf, 1., np.inf]
    assert test_m.low_freq == 500e6
    assert test_m.high_freq == 500e9
    assert test_m.pol == 's'
    assert test_m.incident_angle == 0.
    test_m.reset_model()
    reset_attrs = [test_m.__dict__[key] for key in test_m.__dict__.keys()]
    assert reset_attrs == expected_attrs
Exemple #8
0
    test_m = model.Model()
    test_m.set_freq_range(f1, f2)
    assert test_m.low_freq == expected_low
    assert test_m.high_freq == expected_high

def test_set_angle_range():
    """
    Check that we can properly set the angle sweep.

    This test should raise a NotImplementedError for now.
    """
    test_m = model.Model()
    pytest.raises(NotImplementedError, test_m.set_angle_range, 0, 0)

@pytest.mark.parametrize('test_layers, expected_rind', [
    ([layer.Source(), layer.Layer(rind=999), layer.Terminator(vac=True)], [1., 999., 1.]),
    ([layer.Source(), layer.Layer(rind=999), layer.Terminator(vac=False)], [1., 999., 999.]),
    ([layer.Source(), layer.Layer(rind=999), layer.Terminator(rind=333)], [1., 999., 333.]),
    ])
def test_set_up_basic(test_layers, expected_rind):
    """
    Check that we can run through `set_up` with the most basic default
    values.
    """
    test_m = model.Model()
    test_m.set_up(test_layers)
    assert test_m.rinds == expected_rind
    assert test_m.tands == [0., 0., 0.]
    assert test_m.thicks == [np.inf, 1., np.inf]
    assert test_m.low_freq == 500e6
    assert test_m.high_freq == 500e9
Exemple #9
0
"""
This set of tests evaluates the `BaseLayer` class and those classes that
inherit from it.
"""

import pytest
import numpy as np
from armmwave import layer


@pytest.mark.parametrize('test_l, expected', [
    (layer.BaseLayer(), ['Basic layer', 1., 0., 1.]),
    (layer.Layer(), ['Basic layer', None, None, 1., 0., 1.]),
    (layer.Source(), ['Source layer',
                      layer._Void(), 1., 0., np.inf]),
    (layer.Terminator(),
     ['Terminator layer',
      layer._Void(), 1., 0., np.inf, True]),
])
def test_default_class_attrs(test_l, expected):
    """
    Check that classes and subclasses are properly instantiated
    with sane default values.
    """
    test_attr = [
        test_l.__dict__[key] for key in sorted(test_l.__dict__.keys())
    ]
    assert test_attr == expected


def test_get_rind():