@@ -0,0 +1,2627 @@
+%22%22%22%0ACreate a list of samples in a specified folder as input for the demand sensitivity analysis.%0A%22%22%22%0Aimport os%0A%0Aimport numpy as np%0Aimport pandas as pd%0Afrom SALib.sample.saltelli import sample as sampler_sobol%0Afrom SALib.sample.morris import sample as sampler_morris%0Afrom cea.inputlocator import InputLocator%0A%0A%0Adef create_demand_samples(method='morris', num_samples=1000, variable_groups=%5B'THERMAL'%5D):%0A    %22%22%22%0A%0A    :param output_folder: Folder to place the output file 'samples.npy' (FIXME: should this be part of the%0A                          InputLocator?)%0A    :param method:%0A    :param num_samples:%0A    :param variable_groups: list of names of groups of variables to analyse. Possible values are:%0A        'THERMAL', 'ARCHITECTURE', 'INDOOR_COMFORT', 'INTERNAL_LOADS'. This list links to the probability density%0A        functions of the variables contained in locator.get_uncertainty_db().%0A    :return:%0A    %22%22%22%0A    locator = InputLocator(None)%0A%0A    pdf = pd.concat(%5Bpd.read_excel(locator.get_uncertainty_db(), group, axis=1) for group in variable_groups%5D)%0A    num_vars = pdf.name.count()  # integer with number of variables%0A    names = pdf.name.values  # %5B,,%5D with names of each variable%0A    bounds = %5B%5D  # a list of two-tuples containing the lower-bound and upper-bound of each variable%0A    for var in range(num_vars):%0A        limits = %5Bpdf.loc%5Bvar, 'min'%5D, pdf.loc%5Bvar, 'max'%5D%5D%0A        bounds.append(limits)%0A%0A    # define the problem%0A    problem = %7B'num_vars': num_vars, 'names': names, 'bounds': bounds, 'groups': None%7D%0A%0A    # create samples (combinations of variables)%0A    def sampler():%0A        if method is 'sobol':%0A            second_order = False%0A            return sampler_sobol(problem, N=num_samples, calc_second_order=second_order)%0A        else:%0A            grid = 2%0A            levels = 4%0A            return sampler_morris(problem, N=num_samples, grid_jump=grid, num_levels=levels)%0A%0A    return sampler(), problem%0A%0A%0Aif __name__ == '__main__':%0A    import argparse%0A%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('-m', '--method', help='Method to use %7Bmorris, sobol%7D', default='morris')%0A    parser.add_argument('-n', '--num-samples', help='number of samples (generally 1000 or until it converges',%0A                        default=1000)%0A    parser.add_argument('-o', '--output-folder', help='folder to place the output file (samples.npy) in',%0A                        default='.')%0A    args = parser.parse_args()%0A%0A    samples, problem = create_demand_samples(method=args.method, num_samples=args.num_samples)%0A%0A    # save out to disk%0A    np.save(os.path.join(args.output_folder, 'samples.npy'), samples)%0A

split off creation of samples to separate program