Beispiel #1
0
def test_run_without_set_up():
    """
    Check that we raise a KeyError if we try to run a model without
    setting it up first.
    """
    test_m = model.Model()
    pytest.raises(KeyError, test_m.run)
Beispiel #2
0
def test_set_up_bad_source_or_term(test_layers):
    """
    Ensure that we raise an IndexError in the event we try to build a
    model with fewer than three layers.
    """
    test_m = model.Model()
    pytest.raises(TypeError, test_m.set_up, test_layers)
Beispiel #3
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')
Beispiel #4
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)
Beispiel #5
0
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)
Beispiel #6
0
def test_set_freq_range(f1, f2, nsample, expected):
    """Check that we can properly set the frequency sweep"""
    test_m = model.Model()
    if nsample == 0:
        pytest.raises(ValueError, test_m.set_freq_range, f1, f2, nsample)
        return
    test_m.set_freq_range(f1, f2, nsample)
    npt.assert_equal(test_m.freq_range, expected)
Beispiel #7
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))
Beispiel #8
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))
Beispiel #9
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.}
Beispiel #10
0
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
    assert test_m.pol == 's'
    assert test_m.incident_angle == 0.
Beispiel #11
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)
Beispiel #12
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
Beispiel #13
0
def test_check_freq_bounds(f1, f2, expected_low, expected_high):
    """Check that we can properly set the high and low frequency bounds"""
    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
Beispiel #14
0
def test_default_attr():
    """Check that we create `Model` class with expected attributes"""
    test_m = model.Model()
    model_attrs = [test_m.__dict__[key] for key in test_m.__dict__.keys()]
    expected = [None] * len(model_attrs)
    assert model_attrs == expected