def test_altitude(): from aict_tools.configuration import AICTConfig zd_config = AICTConfig.from_yaml("examples/config_source.yaml") assert "source_position_zd" in zd_config.disp.columns_to_read_train alt_config = AICTConfig.from_yaml("examples/config_source_altitude.yaml") assert "source_position_alt" in alt_config.disp.columns_to_read_train
def test_disp(): from aict_tools.configuration import AICTConfig c = AICTConfig.from_yaml("examples/config_source.yaml") assert "cog_x" in c.disp.columns_to_read_apply
def test_disp(): from aict_tools.configuration import AICTConfig c = AICTConfig.from_yaml('examples/config_source.yaml') assert 'cog_x' in c.disp.columns_to_read_apply
def test_seperation_results(): from aict_tools.scripts.train_separation_model import main as train from aict_tools.io import read_telescope_data from aict_tools.apply import predict_separator import joblib from aict_tools.configuration import AICTConfig configuration_path = 'examples/full_config.yaml' expectation = pd.read_csv('tests/expected_results.csv') with tempfile.TemporaryDirectory(prefix='aict_tools_test_') as d: gamma_path = os.path.join(d, 'gamma.hdf5') proton_path = os.path.join(d, 'proton.hdf5') model_path = os.path.join(d, 'test.pkl') shutil.copy('examples/gamma.hdf5', gamma_path) shutil.copy('examples/proton.hdf5', proton_path) runner = CliRunner() result = runner.invoke(train, [ configuration_path, gamma_path, proton_path, os.path.join(d, 'test.hdf5'), model_path, ]) assert result.exit_code == 0 config = AICTConfig.from_yaml(configuration_path) model_config = config.energy model = joblib.load(model_path) df = read_telescope_data( proton_path, config, model_config.columns_to_read_apply, feature_generation_config=model_config.feature_generation) protons_prediction = predict_separator( df[model_config.features], model, ) df = read_telescope_data( gamma_path, config, model_config.columns_to_read_apply, feature_generation_config=model_config.feature_generation) gammas_prediction = predict_separator( df[model_config.features], model, ) np.testing.assert_array_almost_equal( protons_prediction, expectation['separator_prediction_on_protons']) np.testing.assert_array_almost_equal( gammas_prediction, expectation['separator_prediction_on_gammas'])
def test_cta(): from aict_tools.configuration import AICTConfig cta_config = AICTConfig.from_yaml("examples/cta_full_config.yaml") assert cta_config.data_format == "CTA" assert cta_config.pointing_alt_column == "altitude" assert cta_config.telescopes is not None
def test_separator(): from aict_tools.configuration import AICTConfig c = AICTConfig.from_yaml("examples/config_separator.yaml") assert c.energy is None assert c.disp is None assert c.separator is not None
def test_full(): from aict_tools.configuration import AICTConfig c = AICTConfig.from_yaml('examples/full_config.yaml') assert c.energy is not None assert c.disp is not None assert c.separator is not None
def test_energy(): from aict_tools.configuration import AICTConfig c = AICTConfig.from_yaml('examples/config_energy.yaml') assert c.energy is not None assert c.disp is None assert c.separator is None assert 'size' in c.energy.columns_to_read_apply assert 'corsika_event_header_total_energy' not in c.energy.columns_to_read_apply assert 'corsika_event_header_total_energy' in c.energy.columns_to_read_train
def test_energy(): from aict_tools.configuration import AICTConfig c = AICTConfig.from_yaml("examples/config_energy.yaml") assert c.energy is not None assert c.disp is None assert c.separator is None assert "size" in c.energy.columns_to_read_apply assert "corsika_event_header_total_energy" not in c.energy.columns_to_read_apply assert "corsika_event_header_total_energy" in c.energy.columns_to_read_train
def test_energy_regression_results(): from aict_tools.scripts.train_energy_regressor import main as train from aict_tools.io import read_telescope_data from aict_tools.apply import predict_energy import joblib from aict_tools.configuration import AICTConfig configuration_path = "examples/full_config.yaml" with tempfile.TemporaryDirectory(prefix="aict_tools_test_") as d: data_path = os.path.join(d, "gamma.hdf5") model_path = os.path.join(d, "test.pkl") shutil.copy("examples/gamma.hdf5", data_path) runner = CliRunner() result = runner.invoke( train, [ configuration_path, data_path, os.path.join(d, "test.hdf5"), model_path, ], ) assert result.exit_code == 0 config = AICTConfig.from_yaml(configuration_path) model_config = config.energy model = joblib.load(model_path) df = read_telescope_data( data_path, config, model_config.columns_to_read_apply, feature_generation_config=model_config.feature_generation, ) energy_prediction = predict_energy( df[model_config.features], model, log_target=model_config.log_target, ) expectation = pd.read_csv("tests/expected_results.csv") np.testing.assert_array_almost_equal(energy_prediction, expectation["energy_prediction"])
def hdf5_file(tmpdir_factory, request): fn = tmpdir_factory.mktemp("aict_test_data").join("test_file.hdf5") shutil.copy("examples/gamma.hdf5", fn) return fn, "events", AICTConfig.from_yaml("examples/config_energy.yaml")
def test_source(): from aict_tools.configuration import AICTConfig with raises(ValueError): AICTConfig.from_yaml("tests/config_source.yaml")
def test_source(): from aict_tools.configuration import AICTConfig with raises(ValueError): AICTConfig.from_yaml('tests/config_source.yaml')
from aict_tools.cta_helpers import camera_to_horizontal_cta_simtel, horizontal_to_camera_cta_simtel from aict_tools.apply import predict_disp from aict_tools.configuration import AICTConfig from aict_tools.preprocessing import convert_to_float32, check_valid_rows, calc_true_disp if __name__ == '__main__': parser = argparse.ArgumentParser(description='PATH AND STUFF') parser.add_argument('data_path', type=str) parser.add_argument('disp_model_path', type=str) parser.add_argument('sign_model_path', type=str) parser.add_argument('configuration_path', type=str) parser.add_argument('output', type=str) args = parser.parse_args() config = AICTConfig.from_yaml(args.configuration_path) model_config = config.disp disp_model = load_model(args.disp_model_path) sign_model = load_model(args.sign_model_path) chunked_frames = [] chunksize = 2000 df_generator = read_telescope_data_chunked( args.data_path, config, chunksize, model_config.columns_to_read_apply + ['mc_energy'], feature_generation_config=model_config.feature_generation) for df_data, start, stop in tqdm(df_generator): df_data[model_config.delta_column] = np.deg2rad(
from sklearn.externals import joblib from aict_tools.plotting import ( plot_roc, plot_probabilities, plot_precision_recall, plot_feature_importances, ) import argparse import matplotlib.pyplot as plt if __name__ == '__main__': parser = argparse.ArgumentParser(description='PATH AND STUFF') parser.add_argument('model_path', type=str) parser.add_argument('model_name', type=str) parser.add_argument('config_path', type=str) parser.add_argument('output_path', type=str) args = parser.parse_args() config = AICTConfig.from_yaml(args.config_path) if args.model_name == 'disp': model_config = config.disp elif args.model_name == 'separator': model_config = config.separator features = model_config.features #features = [f.replace('_', r'\_') for f in features] model = joblib.load(args.model_path) #from IPython import embed; embed() fig, ax = plt.subplots(1, 1) plot_feature_importances(model, features, ax=ax) plt.savefig(args.output_path)
def fact_config(): from aict_tools.configuration import AICTConfig return AICTConfig.from_yaml('examples/config_energy.yaml')
def hdf5_file(tmpdir_factory, request): fn = tmpdir_factory.mktemp('aict_test_data').join('test_file.hdf5') shutil.copy('examples/gamma.hdf5', fn) return fn, 'events', AICTConfig.from_yaml('examples/config_energy.yaml')
def cta_config(): from aict_tools.configuration import AICTConfig return AICTConfig.from_yaml('examples/cta_config.yaml')