示例#1
0
def test_asymptotic_relation():
    """Test for method to compute frequencies from the asymptotic relation"""

    # setup
    norders = cs.pars['norders']
    nsamples = cs.pars['nsamples']
    mod = asymp_spec_model(cs.st.f, norders)
    dnu, numax, eps, alpha = 3050.0, 135.0, 1.45, 10**-2.5  # roughly solar
    func = mod._asymptotic_relation
    inp = [dnu, numax, eps, alpha, norders]
    inp_arr = [
        np.float64(numax).repeat(nsamples),
        np.float64(dnu).repeat(nsamples),
        np.float64(eps).repeat(nsamples),
        np.float64(alpha).repeat(nsamples), norders
    ]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, (norders, ))
    pbt.right_shape(func, inp_arr, (norders, nsamples))

    # check that function returns the same as during testing given the above
    # inputs
    assert_allclose(func(*inp), [2896.028668, 3030.75434], atol=0.001)
示例#2
0
def test_get_nmax():
    """Test for method to get nmax"""

    # setup
    nsamples = cs.pars['nsamples']
    norders = cs.pars['norders']
    mod = asymp_spec_model(cs.st.f, norders)
    dnu, numax, eps = 10**cs.pars['asypars'][0], 10**cs.pars['asypars'][
        1], cs.pars['asypars'][2]
    func = mod._get_nmax
    inp = [dnu, numax, eps]
    inp_arr = [
        np.float64(dnu).repeat(nsamples),
        np.float64(numax).repeat(nsamples),
        np.float64(eps).repeat(nsamples)
    ]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, float)
    pbt.right_type(func, inp_arr, np.ndarray)

    pbt.right_shape(func, inp, ())
    pbt.right_shape(func, inp_arr, (nsamples, ))

    # check that function returns the same as during testing given the above
    # inputs
    assert (func(*inp) == 0.0)
示例#3
0
def test_outpath():
    """Tests for the function that sets the output filename
    
    Notes
    -----
    If adding more star inits, remember to os.rmdir(st.path) to clean up after
    the test. 
    
    """
    
    # setup
    pg = lk.periodogram.Periodogram(np.array([1,1])*units.microhertz, units.Quantity(np.array([1,1]), None))
    st = star('thisisatest', pg, (220.0, 3.0), (16.97, 0.05), (4750, 250), (1.34, 0.1))
    func = st._outpath
    inp = ['test.png']
    
    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, str)
    
    # Some input tests
    assert(os.path.isdir(os.path.dirname(func(*inp))))
    
    # cleanup
    os.rmdir(st.path)    
示例#4
0
def test_get_priorpath():
    """Tests the function for getting the default prior_data filepath"""

    # setup
    func = get_priorpath

    # simple tests
    pbt.does_it_run(func, None)
    pbt.does_it_return(func, None)
    pbt.right_type(func, None, str)

    # check some inputs
    assert ('prior_data.csv' in func())
    assert ('data' in func())
示例#5
0
def test_get_asy_start():
    """Test for getting starting location of asy fit"""

    # setup
    func = cs.st.asy_fit._get_asy_start

    # simple tests
    pbt.does_it_run(func, None)
    pbt.does_it_return(func, None)
    pbt.right_type(func, None, list)
    pbt.right_shape(func, None, (10, ))

    # check function returns expected values
    assert_allclose(func(), [10, 10, 1, 10, 10, 1, 1, 1, 10, 1])
示例#6
0
def test_get_freq_range():
    """Test for getting frequency range of modes"""

    # setup
    func = cs.st.asy_fit._get_freq_range

    # simple tests
    pbt.does_it_run(func, None)
    pbt.does_it_return(func, None)
    pbt.right_type(func, None, tuple)
    pbt.right_shape(func, None, (2, ))

    # check function returns expected values
    assert_allclose(func(), [-12.5, 22.5])
示例#7
0
def test_normal():
    """Test for the log of a normal distribution"""

    # setup
    func = normal
    inp = [0, 0, 1]
    inp_arr = [np.linspace(-10, 10, 100), 0, 1]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, float)
    pbt.right_shape(func, inp_arr, (len(inp_arr[0]), ))

    # check height at mean is correct
    assert (10**func(*inp) == 1)
示例#8
0
def test_select_prior_data():
    """Tests for kde.select_prior_data"""
    
    # Setup
    KDEsize = 87
    func = simp_kde.select_prior_data
    
    # Simplest run test. Given no numax it should return a sample that equals
    # the whole prior_data.csv
    pbt.does_it_run(func, None)
    assert(len(simp_kde.prior_data) == len(pdata))
    
    # With a given numax and KDEsize, should return KDEsize elements in the
    # prior_data attribute
    func(to_log10(30, 10), KDEsize)
    assert(len(simp_kde.prior_data) == KDEsize)
示例#9
0
def test_asymp_spec_model_call():
    """Test call method for asymptotic relation spectrum model class"""

    # setup
    norders = cs.pars['norders']
    mod = asymp_spec_model([0.5, 1], norders)
    func = mod.model
    inp = cs.pars['asypars']
    
    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, np.shape(cs.st.f))
    
    # check that the function doesn't change the output 
    assert_allclose(mod(inp), mod.model(*inp))
示例#10
0
def test_to_log10():
    """Test for the log of a normal distribution"""

    # setup
    func = to_log10
    inp = [10, 1]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, list)

    # check some inputs
    assert (func(*inp)[0] == 1)
    assert_almost_equal(func(*inp)[1], 0.043429, 5)

    inp = [1e5, 1e4]
    assert (func(*inp)[0] == 5)
示例#11
0
def test_model():
    """Test for method to compute the total asymptotic relation model"""

    # setup
    norders = cs.pars['norders']
    mod = asymp_spec_model([0.5, 1], norders)
    func = mod.model
    inp = cs.pars['asypars']

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, np.shape(cs.st.f))

    # check that function returns the same as during testing given the above
    # inputs
    assert_allclose(func(*inp), [7.93069307, 7.73076923], atol=0.001)
示例#12
0
def test_pair():
    """Test for method to compute the mode pairs"""

    # setup
    norders = cs.pars['norders']
    mod = asymp_spec_model([0.5, 1], norders)
    h, freq, w, d02 = 1, cs.st.f[0], 1, 0.5
    func = mod._pair
    inp = [h, freq, w, d02]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, np.shape(cs.st.f))

    # check that function returns the same as during testing given the above
    # inputs
    assert_array_equal(func(*inp), [1.2, 1.35])
示例#13
0
def test_lor():
    """Test for method to compute the lorentzian profiles"""

    # setup
    norders = cs.pars['norders']
    mod = asymp_spec_model(cs.st.f, norders)
    h, freq, w = 1, cs.st.f[0], 1
    func = mod._lor
    inp = [freq, h, w]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, np.shape(cs.st.f))

    # check that function returns the same as during testing given the above
    # inputs
    assert_array_equal(func(*inp), [1, 1])
示例#14
0
def test_P_envelope():
    """Test for method to get height of pmode envelope"""

    # setup
    norders = cs.pars['norders']
    mod = asymp_spec_model(cs.st.f, norders)
    nus = cs.pars['freqs']
    envheight, numax, envwidth = 10**1.5, nus[0], 10**2.2
    func = mod._P_envelope
    inp = [nus, envheight, numax, envwidth]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, np.shape(nus))

    # check that function returns the same as during testing given the above
    # inputs
    assert_allclose(func(*inp), [31.6227766, 31.5718312], atol=0.001)
示例#15
0
def test_get_percentiles():
    """Tests the function for getting the percentiless of a distribution"""

    # setup
    func = get_percentiles
    inp = [np.random.normal(0, 1, size=10), 3]

    #print(func(*inp)[])

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, (2 * inp[1] + 1, ))

    # check some different inputs
    inp = [np.random.normal(0, 1, size=30000), 5]
    pbt.right_shape(func, inp, (2 * inp[1] + 1, ))

    inp = [[0, 0, 0, 1, 1], 1]
    assert_array_equal(func(*inp), [0., 0., 1.])
示例#16
0
def test_run_kde():
    """Tests that a KDE can be created and sampled for given prior data

    Notes
    -----
    This test is incomplete

    """
    # setup
    pg = lk.periodogram.Periodogram(
        np.array([1, 1]) * units.microhertz,
        units.Quantity(np.array([1, 1]), None))
    st = star('thisisatest', pg, (220.0, 3.0), (16.97, 0.05), (4750, 250),
              (1.34, 0.1))
    func = st.run_kde

    # simple tests
    pbt.does_it_run(func, None)

    # cleanup
    os.rmdir(st.path)
示例#17
0
def test_get_enns():
    """Test for method to get the radial orders in the asymptotic relation"""

    # setup
    norders = cs.pars['norders']
    nmax = cs.pars['nmax']
    nsamples = cs.pars['nsamples']
    mod = asymp_spec_model(cs.st.f, norders)
    func = mod._get_enns
    inp = [nmax, norders]
    inp_arr = [np.array([nmax]).repeat(nsamples), norders]

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, (norders, ))
    pbt.right_shape(func, inp_arr, (nsamples, norders))

    # check that function returns the same as during testing given the above
    # inputs
    assert_array_equal(func(*inp), [0, 1])
示例#18
0
def test_asymp_spec_model_call():
    """Test call method for asymptotic relation spectrum model class"""

    # setup
    norders = cs.pars['norders']
    mod = asymp_spec_model([0.5, 1], norders)
    func = mod.model
    inp = cs.pars['asypars']

    # simple tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, np.ndarray)
    pbt.right_shape(func, inp, np.shape(cs.st.f))

    # check that the function doesn't change the output
    assert_allclose(mod(inp), mod.model(*inp))


# The test functions below require longer runs and are not suitable for GitHub
# workflows. the mark.slow decorator doesn't seem to work with GitHub workflows.

# #def test_asymptotic_fit_call():
示例#19
0
def test_kde_predict():
    """Tests for the kde.kde_predict method"""
    
    # Test raise statement
    with pytest.raises(ValueError):  
        kde().kde_predict(8)

    # Setup
    err = 0.01
    simp_kde.samples = np.vstack([np.random.normal(m, err*abs(m), 50) for m in solar_p]).T
    enns = range(15,25)
    func = simp_kde.kde_predict
    inp = [enns]
    
    # basic run/return/type/shape tests
    pbt.does_it_run(func, inp)
    pbt.does_it_return(func, inp)
    pbt.right_type(func, inp, tuple)
    pbt.right_shape(func, inp, (2, 10)) 
    
    # Test that errors propogate more or less correctly (probably not the most
    # robust test)
    out = simp_kde.kde_predict(enns)   
    assert_almost_equal(out[1]/out[0], np.ones_like(out[1])*err, decimal = 1)