def run_as_script():
    import cea.globalvar as gv
    import cea.inputlocator as inputlocator
    gv = gv.GlobalVariables()
    scenario_path = gv.scenario_reference
    locator = inputlocator.InputLocator(scenario_path=scenario_path)
    output_parameters = ['QHf_MWhyr', 'QCf_MWhyr', 'Ef_MWhyr', 'QEf_MWhyr']
    method = 'sobol' # method
    samples = 1000
    graph(locator, output_parameters, method, samples)
Exemple #2
0
def run_as_script():
    import cea.globalvar as gv
    import cea.inputlocator as inputlocator
    gv = gv.GlobalVariables()
    scenario_path = gv.scenario_reference
    locator = inputlocator.InputLocator(scenario_path=scenario_path)
    weather_path = locator.get_default_weather()
    output_parameters = ['QHf_MWhyr', 'QCf_MWhyr', 'Ef_MWhyr', 'QEf_MWhyr']
    method = 'morris'
    groups_var = ['THERMAL']
    num_samples = 1000  # generally 1000 or until it converges
    sensitivity_main(locator, weather_path, gv, output_parameters, groups_var,
                     num_samples, method)
Exemple #3
0
"""
===========================
Energyplus file reader
===========================
File history and credits:
C. Miller script development               10.08.14
J. A. Fonseca  adaptation for CEA tool      18.05.16
J. A. Fonseca  adding sky temperature Epuls model     20.10.16
"""
import pandas as pd

import cea.inputlocator
import cea.globalvar as globalvar
import numpy as np
gv = globalvar.GlobalVariables()

__author__ = "Clayton Miller"
__copyright__ = "Copyright 2014, Architecture and Building Systems - ETH Zurich"
__credits__ = ["Clayton Miller", "Jimeno A. Fonseca"]
__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "Daren Thomas"
__email__ = "*****@*****.**"
__status__ = "Production"


def epw_reader(weather_path):

    epw_labels = [
        'year', 'month', 'day', 'hour', 'minute', 'datasource', 'drybulb_C',
        'dewpoint_C', 'relhum_percent', 'atmos_Pa', 'exthorrad_Whm2',
Exemple #4
0
def run_as_script():
    import cea.globalvar as gv
    import cea.inputlocator as inputlocator
    gv = gv.GlobalVariables()
    scenario_path = gv.scenario_reference
    locator = inputlocator.InputLocator(scenario=scenario_path)

    #Options
    optimize = False
    raw_data_plot = True
    multicriteria = False
    plot_pareto = False
    clustering = True
    cluster_plot = True
    building_names = [
        'dorm', 'lab', 'office'
    ]  #['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B09']#['B01']#['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B09']
    building_load = 'Ef_kWh'
    type_data = 'measured'

    if optimize:
        for name in building_names:
            data = demand_CEA_reader(locator=locator,
                                     building_name=name,
                                     building_load=building_load,
                                     type=type_data)
            start_generation = None  # or the number of generation to start from
            number_individuals = 16
            number_generations = 50
            optimization_clustering_main(locator=locator,
                                         data=data,
                                         start_generation=start_generation,
                                         number_individuals=number_individuals,
                                         number_generations=number_generations,
                                         building_name=name,
                                         gv=gv)
    if multicriteria:
        for i, name in enumerate(building_names):
            generation = 50
            weight_fitness1 = 100  # accurracy
            weight_fitness2 = 100  # complexity
            weight_fitness3 = 70  # compression
            what_to_plot = "paretofrontier"
            output_path = locator.get_calibration_cluster_mcda(generation)

            # read_checkpoint
            input_path = locator.get_calibration_cluster_opt_checkpoint(
                generation, name)
            result = mcda_cluster_main(input_path=input_path,
                                       what_to_plot=what_to_plot,
                                       weight_fitness1=weight_fitness1,
                                       weight_fitness2=weight_fitness2,
                                       weight_fitness3=weight_fitness3)
            result["name"] = name
            if i == 0:
                result_final = pd.DataFrame(result).T
            else:
                result_final = result_final.append(pd.DataFrame(result).T,
                                                   ignore_index=True)
        result_final.to_csv(output_path)

    if plot_pareto:
        for name in building_names[:1]:
            data = demand_CEA_reader(locator=locator,
                                     building_name=name,
                                     building_load=building_load,
                                     type=type_data)
            days_of_analysis = len(data)
            generation_to_plot = 50
            annotate_benchmarks = True
            annotate_fitness = False
            show_in_screen = False
            save_to_disc = True
            what_to_plot = "paretofrontier"  #paretofrontier, halloffame, or population
            optimal_individual = pd.read_csv(
                locator.get_calibration_cluster_mcda(generation_to_plot))
            optimal_individual = optimal_individual.loc[
                optimal_individual["name"] == name]
            labelx = 'Accurracy (A) [-]'
            labely = 'Complexity (B) [-]'
            labelz = r'Compression ($\Gamma$) [-]'
            output = os.path.join(
                locator.get_calibration_clustering_plots_folder(),
                "plot_gen_" + str(generation_to_plot) + "_building_name_" +
                name + ".png")

            # read_checkpoint
            input_path = locator.get_calibration_cluster_opt_checkpoint(
                generation_to_plot, name)
            frontier_2D_3OB(
                input_path=input_path,
                what_to_plot=what_to_plot,
                output_path=output,
                labelx=labelx,
                labely=labely,
                labelz=labelz,
                days_of_analysis=days_of_analysis,
                show_benchmarks=annotate_benchmarks,
                show_fitness=annotate_fitness,
                show_in_screen=show_in_screen,
                save_to_disc=save_to_disc,
                optimal_individual=optimal_individual,
            )
    if clustering:
        name = 'lab'
        data = demand_CEA_reader(locator=locator,
                                 building_name=name,
                                 building_load=building_load,
                                 type=type_data)
        word_size = 4
        alphabet_size = 17

        clustering_sax(locator=locator,
                       data=data,
                       word_size=word_size,
                       alphabet_size=alphabet_size,
                       gv=gv)

        if cluster_plot:
            show_benchmark = True
            save_to_disc = True
            show_in_screen = False
            show_legend = False
            labelx = "Hour of the day"
            labely = "Electrical load [kW]"

            input_path = locator.get_calibration_cluster('clusters_mean')
            data = pd.read_csv(input_path)
            output_path = os.path.join(
                locator.get_calibration_clustering_plots_folder(),
                "w_a_" + str(word_size) + "_" + str(alphabet_size) +
                "_building_name_" + name + ".png")

            plot_day(
                data=data,
                output_path=output_path,
                labelx=labelx,
                labely=labely,
                save_to_disc=save_to_disc,
                show_in_screen=show_in_screen,
                show_legend=show_legend)  #, show_benchmark=show_benchmark)

    if raw_data_plot:
        name = 'lab'
        show_benchmark = True
        save_to_disc = True
        show_in_screen = False
        show_legend = True
        labelx = "Hour of the day"
        labely = "Electrical load [kW]"
        data = demand_CEA_reader(locator=locator,
                                 building_name=name,
                                 building_load=building_load,
                                 type=type_data)

        data = pd.DataFrame(
            dict((str(key), value) for (key, value) in enumerate(data)))

        # input_path = locator.get_calibration_cluster('clusters_mean')
        output_path = os.path.join(
            locator.get_calibration_clustering_plots_folder(),
            "raw_building_name_" + name + ".png")

        plot_day(data=data,
                 output_path=output_path,
                 labelx=labelx,
                 labely=labely,
                 save_to_disc=save_to_disc,
                 show_in_screen=show_in_screen,
                 show_legend=show_legend)  # , show_benchmark=show_benchmark)
Exemple #5
0
def sensAnalysis(locator, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, gen):
    """
    :param locator: path to input locator
    :param extraCosts: costs calculated before optimization of specific energy services
     (process heat and electricity)
    :param extraCO2: green house gas emissions calculated before optimization of specific energy services
     (process heat and electricity)
    :param extraPrim: primary energy calculated before optimization ofr specific energy services
     (process heat and electricity)
    :param solarFeat: solar features call to class
    :param ntwFeat: network features call to class
    :param gen: generation on which the sensitivity analysis is performed
    :type locator: string
    :type extraCosts: float
    :type extraCO2: float
    :type extraPrim: float
    :type solarFeat: class
    :type ntwFeat: class
    :type gen: int
    :return: returns the most sensitive parameter among the group provided
    :rtype: string
    """

    gV = glob.GlobalVariables()
    step = gV.sensibilityStep
    bandwidth = sensBandwidth()
    os.chdir(locator.get_optimization_master_results_folder())
    pop, eps, testedPop, ntwList, fitness = sFn.readCheckPoint(locator, gen, 0)
    toolbox = base.Toolbox()

    total_demand = pd.read_csv(locator.get_total_demand())
    buildList = total_demand.Name.values
    FactorResults = np.zeros((step + 1, bandwidth.nFactors * 2))

    def sensOneFactor(obj, factor_name, mini, maxi, colNumber):
        iniValue = getattr(obj, factor_name)
        index = 0
                
        for delta in np.arange(mini, maxi + 1E-5, (maxi-mini)/step):
            FactorResults[index][colNumber + 0] = delta
            if abs(delta) > 1E-10:
                setattr(obj, factor_name, iniValue * (1+delta))
    
                newpop = []
                for ind in pop:
                    newInd = toolbox.clone(ind)
                    newpop.append(newInd)
                    (costs, CO2, prim) = eI.evaluation_main(newInd, buildList, locator, solarFeat, ntwFeat, obj,,
                    newInd.fitness.values = (costs, CO2, prim)

            index += 1

        setattr(obj, factor_name, iniValue)

    sensOneFactor(gV, 'ELEC_PRICE', bandwidth.minElec, bandwidth.maxElec, 0)
    sensOneFactor(gV, 'NG_PRICE', bandwidth.minNG, bandwidth.maxNG, 2)
    sensOneFactor(gV, 'BG_PRICE', bandwidth.minBG, bandwidth.maxBG, 4)
    
    indexSensible = FactorResults.argmax()%(2*bandwidth.nFactors)
    if indexSensible == 1:
        mostSensitive = 'Electricity price'
    elif indexSensible == 3:
        mostSensitive = 'NG price'
    else:
        mostSensitive = 'BG price'

    print FactorResults
    print mostSensitive
    return mostSensitive

gen = 4

def run_as_script(scenario_path=None):

    import cea.globalvar
    import pandas as pd
    import cea.optimization.distribution.network_opt_main as network_opt
    from cea.optimization.preprocessing.preprocessing_main import preproccessing
    gv = cea.globalvar.GlobalVariables()

    if scenario_path is None:
        scenario_path = gv.scenario_reference

    locator = cea.inputlocator.InputLocator(scenario_path=scenario_path)
    total_demand = pd.read_csv(locator.get_total_demand())
    building_names = total_demand.Name.values
    gv.num_tot_buildings = total_demand.Name.count()
    weather_file = locator.get_default_weather()
    extraCosts, extraCO2, extraPrim, solarFeat = preproccessing(locator, total_demand, building_names,
                                                                   weather_file, gv)
    ntwFeat = network_opt.network_opt_main()
    sensAnalysis(locator, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat, gen)
    print 'sensitivity analysis succeeded'

if __name__ == '__main__':
    run_as_script(r'C:\reference-case-zug\baseline')
Exemple #6
0
def sensAnalysis(locator, extraCosts, extraCO2, extraPrim, solarFeat, ntwFeat,
                 gen):
    """
    :param locator: path to input locator
    :param extraCosts: costs calculated before optimization of specific energy services
     (process heat and electricity)
    :param extraCO2: green house gas emissions calculated before optimization of specific energy services
     (process heat and electricity)
    :param extraPrim: primary energy calculated before optimization ofr specific energy services
     (process heat and electricity)
    :param solarFeat: solar features call to class
    :param ntwFeat: network features call to class
    :param gen: generation on which the sensitivity analysis is performed
    :type locator: string
    :type extraCosts: float
    :type extraCO2: float
    :type extraPrim: float
    :type solarFeat: class
    :type ntwFeat: class
    :type gen: int
    :return: returns the most sensitive parameter among the group provided
    :rtype: string
    """

    gV = glob.GlobalVariables()
    step = gV.sensibilityStep
    bandwidth = sensBandwidth()
    os.chdir(locator.get_optimization_master_results_folder())
    pop, eps, testedPop, ntwList, fitness = sFn.readCheckPoint(locator, gen, 0)
    toolbox = base.Toolbox()

    total_demand = pd.read_csv(locator.get_total_demand())
    buildList = total_demand.Name.values
    FactorResults = np.zeros((step + 1, bandwidth.nFactors * 2))

    def sensOneFactor(obj, factor_name, mini, maxi, colNumber):
        iniValue = getattr(obj, factor_name)
        index = 0

        for delta in np.arange(mini, maxi + 1E-5, (maxi - mini) / step):
            FactorResults[index][colNumber + 0] = delta
            if abs(delta) > 1E-10:
                setattr(obj, factor_name, iniValue * (1 + delta))

                newpop = []
                for ind in pop:
                    newInd = toolbox.clone(ind)
                    newpop.append(newInd)
                    (costs, CO2, prim) = eI.evaluation_main(
                        newInd, buildList, locator, extraCosts, extraCO2,
                        extraPrim, solarFeat, ntwFeat, obj)
                    newInd.fitness.values = (costs, CO2, prim)

            index += 1

        setattr(obj, factor_name, iniValue)

    sensOneFactor(gV, 'ELEC_PRICE', bandwidth.minElec, bandwidth.maxElec, 0)
    sensOneFactor(gV, 'NG_PRICE', bandwidth.minNG, bandwidth.maxNG, 2)
    sensOneFactor(gV, 'BG_PRICE', bandwidth.minBG, bandwidth.maxBG, 4)

    indexSensible = FactorResults.argmax() % (2 * bandwidth.nFactors)
    if indexSensible == 1:
        mostSensitive = 'Electricity price'
    elif indexSensible == 3:
        mostSensitive = 'NG price'
    else:
        mostSensitive = 'BG price'

    print FactorResults
    print mostSensitive
    return mostSensitive