Exemplo n.º 1
0
def spect_gen(config):
    '''Fit a model

    Given a method (from config), generate spectrum for all input files.

    Args:
        config: The parsed ini file for this run

    Returns:
        Nothing or writes to MongoDB

    Raises:
        Nothing
    '''

    opensoundscape_dir = sys.path[0]
    sys.path.append(
        f"{opensoundscape_dir}/modules/spect_gen_algo/{config['spect_gen']['algo']}"
    )
    from spect_gen_algo import spect_gen_algo

    if config['general'].getboolean('db_rw'):
        write_ini_section(config, 'spect_gen')

    spect_gen_algo(config)
Exemplo n.º 2
0
def predict(config):
    '''Make a prediction

    Given a `predict_algo` method (from config), make a prediction based on
    that model.

    Args:
        config: The parsed ini file for this run

    Returns:
        A prediction

    Raises:
        Nothing

    To Do:
        -
    '''

    opensoundscape_dir = sys.path[0]
    sys.path.append(
        f"{opensoundscape_dir}/modules/predict_algo/{config['predict']['algo']}"
    )
    from predict_algo import predict_algo

    if config['general'].getboolean('db_rw'):
        write_ini_section(config, 'predict')

    predict_algo(config)
Exemplo n.º 3
0
def model_fit(config, rerun_statistics):
    '''Fit a model

    Given a directory and method (from config), fit a model against the
    training data. This is an abstraction layer from the actual fitting.
    Essentially, we are going to look in `modules/model_fit_algo` for
    a directory named config['model_fit_algo'] and try to import a function
    called `model_fit_algo` from `model_fit_algo.py`

    Args:
        config: The parsed ini file for this run
        rerun_statistics: Force recalculation of model_fit statistics

    Returns:
        Something or possibly writes to MongoDB?

    Raises:
        Nothing
    '''

    opensoundscape_dir = sys.path[0]
    sys.path.append(f"{opensoundscape_dir}/modules/model_fit_algo/{config['model_fit']['algo']}")
    from model_fit_algo import model_fit_algo

    if config['general'].getboolean('db_rw'):
        write_ini_section(config, 'model_fit')

    model_fit_algo(config, rerun_statistics)
Exemplo n.º 4
0
def test_write_ini_section_override_answer_yes(monkeypatch,
                                               coll_write_ini_section,
                                               ini_test_change):
    monkeypatch.setattr('builtins.input', lambda prompt: 'yes')
    write_ini_section(ini_test_change, 'general')
    item = coll_write_ini_section.find_one({'section': 'general'})
    assert item['db_sparse'] == 'False'
Exemplo n.º 5
0
def init(config):
    '''Initialize INI DB


    Args:
        config: The parsed ini file for this run

    Returns:
        Writes to DB

    Raises:
        Nothing
    '''

    if config['general'].getboolean('db_rw'):
        write_ini_section(config, 'general')
Exemplo n.º 6
0
def test_write_ini_section_override_answer_default(monkeypatch,
                                                   coll_write_ini_section,
                                                   ini_test_change):
    monkeypatch.setattr('builtins.input', lambda prompt: '')
    with pytest.raises(OpensoundscapeAttemptOverrideINISection):
        write_ini_section(ini_test_change, 'general')
Exemplo n.º 7
0
def test_write_ini_section_feed_same_ini_no_change(coll_write_ini_section,
                                                   ini_test):
    item = coll_write_ini_section.find_one({'section': 'general'})
    write_ini_section(ini_test, 'general')
    item2 = coll_write_ini_section.find_one({'section': 'general'})
    assert item == item2
Exemplo n.º 8
0
def coll_write_ini_section(coll, ini_test):
    write_ini_section(ini_test, 'general')
    return coll