Ejemplo n.º 1
0
def test_main_predict_tarball_cust_feats():
    """Test main predict function - tarball w/ custom feats"""

    generate_model_cust_feats()

    shutil.copy(pjoin(DATA_PATH, "215153_215176_218272_218934.tar.gz"),
                cfg.UPLOAD_FOLDER)
    shutil.copy(pjoin(DATA_PATH, "215153_215176_218272_218934_metadata.dat"),
                cfg.UPLOAD_FOLDER)
    shutil.copy(pjoin(DATA_PATH, "testfeature1.py"),
                pjoin(cfg.CUSTOM_FEATURE_SCRIPT_FOLDER,
                      "TESTRUN_CF.py"))

    pred_results_dict = pred.predict(
        pjoin(cfg.UPLOAD_FOLDER, "215153_215176_218272_218934.tar.gz"),
        "TEMP_TEST01", "RF", "TEMP_TEST01",
        metadata_file_path=pjoin(cfg.UPLOAD_FOLDER,
                                 "215153_215176_218272_218934_metadata.dat"),
        custom_features_script=pjoin(cfg.CUSTOM_FEATURE_SCRIPT_FOLDER,
                                     "TESTRUN_CF.py"))
    os.remove(pjoin(cfg.UPLOAD_FOLDER, "215153_215176_218272_218934.tar.gz"))
    os.remove(pjoin(cfg.UPLOAD_FOLDER,
                    "215153_215176_218272_218934_metadata.dat"))
    os.remove(pjoin(cfg.FEATURES_FOLDER, "TEMP_TEST01_features.csv"))
    os.remove(pjoin(cfg.FEATURES_FOLDER, "TEMP_TEST01_classes.npy"))
    os.remove(pjoin(cfg.MODELS_FOLDER, "TEMP_TEST01_RF.pkl"))
    os.remove(pjoin(cfg.CUSTOM_FEATURE_SCRIPT_FOLDER, "TESTRUN_CF.py"))
    npt.assert_equal(
        len(pred_results_dict["dotastro_215153"]["pred_results_list"]),
        3)
    npt.assert_equal(len(pred_results_dict), 4)
    for res_dict in pred_results_dict.values():
        assert(all(el[0] in ['Mira', 'Herbig_AEBE', 'Beta_Lyrae',
                                 'Classical_Cepheid', 'W_Ursae_Maj', 'Delta_Scuti']
                       for el in res_dict["pred_results_list"]))
Ejemplo n.º 2
0
def test_main_predict():
    """Test main predict function"""

    generate_model()

    shutil.copy(pjoin(DATA_PATH, "dotastro_215153.dat"),
                pjoin(cfg.UPLOAD_FOLDER, "TESTRUN_215153.dat"))
    shutil.copy(pjoin(DATA_PATH, "TESTRUN_215153_metadata.dat"),
                cfg.UPLOAD_FOLDER)

    pred_results_dict = pred.predict(
        pjoin(cfg.UPLOAD_FOLDER, "TESTRUN_215153.dat"),
        "TEMP_TEST01", "RF", "TEMP_TEST01",
        metadata_file_path=pjoin(cfg.UPLOAD_FOLDER,
                                 "TESTRUN_215153_metadata.dat"),
        custom_features_script=None)
    os.remove(pjoin(cfg.UPLOAD_FOLDER, "TESTRUN_215153.dat"))
    os.remove(pjoin(cfg.UPLOAD_FOLDER, "TESTRUN_215153_metadata.dat"))
    os.remove(pjoin(cfg.FEATURES_FOLDER, "TEMP_TEST01_features.csv"))
    os.remove(pjoin(cfg.FEATURES_FOLDER, "TEMP_TEST01_classes.npy"))
    os.remove(pjoin(cfg.MODELS_FOLDER, "TEMP_TEST01_RF.pkl"))
    npt.assert_equal(
        len(pred_results_dict["TESTRUN_215153"]["pred_results_list"]),
        3)
    assert(all(all(el[0] in ['Mira', 'Herbig_AEBE', 'Beta_Lyrae',
                             'Classical_Cepheid', 'W_Ursae_Maj', 'Delta_Scuti']
                   for el in pred_results_dict[fname]\
                   ["pred_results_list"]) for fname in pred_results_dict))
Ejemplo n.º 3
0
def test_predict():
    """Test class prediction."""
    results_dict = predict_class.predict(
        pjoin(DATA_PATH, "dotastro_215153.dat"),
        "TESTRUN",
        "RF",
        "TESTRUN",
        custom_features_script=pjoin(cfg.CUSTOM_FEATURE_SCRIPT_FOLDER, "testfeature1.py"),
        metadata_file_path=pjoin(DATA_PATH, "215153_metadata.dat"),
    )
    assert isinstance(results_dict, dict)
    assert "dotastro_215153.dat" in results_dict
    assert isinstance(results_dict["dotastro_215153.dat"]["features_dict"]["std_err"], float)