'sgt1-150', 'training' + str(training_number), 'E_curvelhs'
        ]
        params_save_path = '/net/data1/ml2017/gpyparams/E_curve_gpy_log/' + str(
            kernel) + '_E_curve_training_' + str(
                training_number) + '_lhs_sgt1_150_multidim_log.pickle'

        #Set empty arrays with zeros for training and validation data
        train_obs = np.array([0])
        train_energy = np.array([0])

        LEC_LENGTH = 16

        train_lecs = np.array(np.zeros(LEC_LENGTH))

        #Read database data with the specified tags
        for row in dm.read(training_tags):
            train_obs = np.vstack((train_obs, row.observable))
            train_energy = np.vstack((train_energy, row.energy))
            train_lecs = np.vstack((train_lecs, row.LECs))

        # Clean up initialized zeros
        train_obs = np.delete(train_obs, 0, 0)
        train_energy = np.delete(train_energy, 0, 0)
        train_lecs = np.delete(train_lecs, 0, 0)

        train_lecs = np.hstack((train_lecs, train_energy))

        train_obs = np.log(train_obs)

        train_parameter_dim = 17
        lengthscale = 1.0
nsopt = NsoptCaller()
gauss = Gaussfit()
dm = Datamanager(echo=False)
gauss.save_fig = save_fig
gauss.save_path = save_path

if dm.num_matches(training_tags) <= 0 or dm.num_matches(validation_tags) <= 0:
    sys.exit('Check your tags. No matched found in database.')
else:
    #Set empty arrays with zeros for training and validation data
    train_obs = np.array([0])
    train_energy = np.array([0])
    train_lecs = np.array(np.zeros(LEC_LENGTH))

    #Read database data with the specified tags
    for row in dm.read(training_tags):
        train_obs = np.vstack((train_obs, row.observable))
        train_energy = np.vstack((train_energy, row.energy))
        train_lecs = np.vstack((train_lecs, row.LECs))

    # Clean up initialized zeros
    train_obs = np.delete(train_obs, 0, 0)
    train_energy = np.delete(train_energy, 0, 0)
    train_lecs = np.delete(train_lecs, 0, 0)

    # Set up Gaussfit stuff and plot our model error
    gauss.set_gp_kernel(kernel=kernel,
                        in_dim=LEC_LENGTH,
                        lengthscale=lengthscale,
                        multi_dim=multi_dim)
def main():
    """Controls the program flow determined by user input"""

    # Parses arguments supplied by the user.
    parser = argparse.ArgumentParser()
    parser.add_argument("-v",
                        "--verbosity",
                        action="store_true",
                        help="Show data output")

    # Add a group of arguments that can't coexist
    group = parser.add_mutually_exclusive_group()
    group.add_argument("-f",
                       "--function",
                       action="store",
                       help="Use specified function for GP")
    group.add_argument("-n",
                       "--nsopt",
                       action="store_true",
                       help="Use nsopt calculation for GP")

    #Add tag handling. Supports multiple arg seperated by space.
    group.add_argument("-l",
                       "--load",
                       nargs='+',
                       action='append',
                       help="Use stored data for GP")
    args = parser.parse_args()

    # Initialize project class objects
    nsopt = NsoptCaller()
    gauss = Gaussfit()
    dm = Datamanager()
    param = Parameters(
        0.1,
        100,
    )

    LECS = param.create_lhs_lecs()

    # Suggestion: X should have a more intuitive name (energy) //Martin
    # Read input arguments to get input vector
    X = nsopt.read_ini(args)

    # Load all data with the right tags and convert to array
    if args.load:
        print args.load
        data_list = dm.read(args.load[0])
        #TODO(Martin) Format data from data objects
        observables = []
        energies = []
        LECs = []
        for row in data_list:
            observables.append(row.observable)
            energies.append(row.energy)
            LECs.append(row.LECs)
        #data = np.asarray(data)
        return None  #Returning None for the moment, when LECs are in database this will work

    # Do we want to genereate new nsopt values or use specified function.
    if args.nsopt:
        Y = nsopt.get_nsopt_observable()
        Y = np.trim_zeros(Y)
        Y = Y.reshape(1, len(Y))
    else:
        Y = np.sin(X) + np.random.randn(20, 1) * 0.03

    # Set up GP-processes and plot output after optimization.
    gauss.set_gp_kernel()

    if args.load:
        #gauss.populate_gp_model(data) #TODO(rikard, Martin) Check data format.
        pass

    else:
        gauss.populate_gp_model(X, Y)
    gauss.optimize()
    gauss.plot()