예제 #1
0
def simulate_demand_sample(locator, building_name, output_parameters):
    """
    This script runs the cea demand tool in series and returns a single value of cvrmse and rmse.

    :param locator: pointer to location of files in CEA
    :param building_name: name of building
    :param output_parameters: building load to consider in the anlysis
    :return:
    """

    # force simulation to be sequential and to only do one building
    gv = cea.globalvar.GlobalVariables()
    gv.multiprocessing = False
    gv.print_totals = False
    gv.simulate_building_list = [building_name]
    gv.testing = True

    #import weather and measured data
    weather_path = locator.get_default_weather()
    #weather_path = 'C:\CEAforArcGIS\cea\databases\weather\Zurich.epw'

    #calculate demand timeseries for buidling an calculate cvrms
    demand_main.demand_calculation(locator, gv)
    output_folder = locator.get_demand_results_folder()
    file_path = os.path.join(output_folder, "%(building_name)s.xls" % locals())
    #file_path=locator.get_demand_results_file(building_name)

    new_calcs = pd.read_excel(file_path)

    #cv_rmse, rmse = calc_cv_rmse(time_series_simulation[output_parameters].values, time_series_measured[output_parameters].values)

    return new_calcs  #cv_rmse, rmse
예제 #2
0
def simulate_demand_sample(locator, building_name, output_parameters, config):
    """
    This script runs the cea demand tool in series and returns a single value of cvrmse and rmse.

    :param locator: pointer to location of files in CEA
    :param building_name: name of building
    :param output_parameters: building load to consider in the anlysis
    :return:
    """

    # force simulation to be sequential and to only do one building
    config.multiprocessing = False
    config.demand.buildings = [building_name]
    config.demand.massflows_output = []
    config.demand.temperatures_output = []
    config.demand.format_output = "csv"
    config.demand.override_variables = True

    #import weather and measured data
    weather_path = locator.get_default_weather()
    #weather_path = 'C:\CEAforArcGIS\cea\databases\weather\Zurich.epw'

    #calculate demand timeseries for buidling an calculate cvrms
    demand_main.demand_calculation(locator, config)
    output_folder = locator.get_demand_results_folder()
    file_path = os.path.join(output_folder, "%(building_name)s.xls" % locals())
    #file_path=locator.get_demand_results_file(building_name)

    new_calcs = pd.read_excel(file_path)

    #cv_rmse, rmse = calc_cv_rmse(time_series_simulation[output_parameters].values, time_series_measured[output_parameters].values)

    return new_calcs  #cv_rmse, rmse
예제 #3
0
def sampling_scaler(locator, random_variables, target_parameters, boolean_vars,
                    list_building_names, number_samples_scaler, nn_delay, gv,
                    config, climatic_variables, year, use_daysim_radiation,
                    use_stochastic_occupancy, region):
    '''
    this function creates a number of random samples for the entire district (city)
    :param locator: points to the variables
    :param random_variables: a list containing the names of variables associated with uncertainty (can be accessed from 'nn_settings.py')
    :param target_parameters: a list containing the name of desirable outputs (can be accessed from 'nn_settings.py')
    :param list_building_names: a list containing the name of desired buildings
    :param weather_path: weather path
    :param gv: global variables
    :return: -
    '''

    #   get number of buildings
    size_city = np.shape(list_building_names)
    size_city = size_city[0]
    #   create random samples of the entire district
    for i in range(
            number_samples_scaler
    ):  # the parameter "number_samples" is accessible from 'nn_settings.py'
        bld_counter = 0
        # create list of samples with a LHC sampler and save to disk
        samples, samples_norm, pdf_list = latin_sampler(
            locator, size_city, random_variables, region)

        # create a file of overides with the samples
        dictionary = dict(zip(random_variables, samples.transpose()))
        overides_dataframe = pd.DataFrame(dictionary)
        overides_dataframe['Name'] = list_building_names

        # replace the 1, 0 with True and False
        for var in boolean_vars:
            somthing = overides_dataframe['ECONOMIZER']
            overides_dataframe[var].replace(1, 'True', inplace=True)
            overides_dataframe[var].replace(0, 'False', inplace=True)
            overides_dataframe[var].replace(0.0, 'False', inplace=True)

        # save file so the demand calculation can know about it.
        overides_dataframe.to_csv(locator.get_building_overrides())

        # run cea demand
        config.demand.override_variables = True
        demand_main.demand_calculation(locator, config)
        urban_input_matrix, urban_taget_matrix = input_prepare_main(
            list_building_names, locator, target_parameters, nn_delay,
            climatic_variables, config.region, year, use_daysim_radiation,
            use_stochastic_occupancy)

        scaler_inout_path = locator.get_minmaxscaler_folder()
        file_path_inputs = os.path.join(scaler_inout_path,
                                        "input%(i)s.csv" % locals())
        data_file_inputs = pd.DataFrame(urban_input_matrix)
        data_file_inputs.to_csv(file_path_inputs, header=False, index=False)

        file_path_targets = os.path.join(scaler_inout_path,
                                         "target%(i)s.csv" % locals())
        data_file_targets = pd.DataFrame(urban_taget_matrix)
        data_file_targets.to_csv(file_path_targets, header=False, index=False)
예제 #4
0
def sampling_single(locator, random_variables, target_parameters,
                    list_building_names, gv, config, nn_delay,
                    climatic_variables, region, year, use_daysim_radiation,
                    use_stochastic_occupancy):
    size_city = np.shape(list_building_names)
    size_city = size_city[0]

    bld_counter = 0
    # create list of samples with a LHC sampler and save to disk (*.csv)
    samples, samples_norm, pdf_list = latin_sampler(locator, size_city,
                                                    random_variables, region)
    for building_name in (list_building_names):
        np.save(locator.get_calibration_folder(), samples)
        building_load = config.single_calibration.load
        override_file = Gdf.from_file(
            locator.get_zone_geometry()).set_index('Name')
        override_file = pd.DataFrame(index=override_file.index)
        problem = {
            'variables': random_variables,
            'building_load': target_parameters,
            'probabiltiy_vars': pdf_list
        }
        pickle.dump(
            problem,
            file(locator.get_calibration_problem(building_name, building_load),
                 'w'))
        sample = np.asarray(zip(random_variables, samples[bld_counter, :]))
        apply_sample_parameters(locator, sample, override_file)
        bld_counter = bld_counter + 1
    # read the saved *.csv file and replace Boolean with logical (True/False)
    overwritten = pd.read_csv(locator.get_building_overrides())
    bld_counter = 0
    for building_name in (list_building_names):
        sample = np.asarray(zip(random_variables, samples[bld_counter, :]))
        for boolean_mask in (boolean_vars):
            indices = np.where(sample == boolean_mask)

            if sample[indices[0], 1] == '0.0':
                sample[indices[0], 1] = 'False'
            else:
                sample[indices[0], 1] = 'True'

        overwritten.loc[overwritten.Name == building_name,
                        random_variables] = sample[:, 1]
        bld_counter = bld_counter + 1

    # write to csv format
    overwritten.to_csv(locator.get_building_overrides())

    #   run cea demand
    demand_main.demand_calculation(locator, config)

    #   prepare the inputs for feeding into the neural network
    urban_input_matrix, urban_taget_matrix = input_prepare_main(
        list_building_names, locator, target_parameters, gv, nn_delay,
        climatic_variables, region, year, use_daysim_radiation,
        use_stochastic_occupancy)

    return urban_input_matrix, urban_taget_matrix
예제 #5
0
def screening_cea(counter, sample, var_names, output_parameters, locator,
                  weather_path, gv):
    """

    :param counter: counter keepin gth enumber of samples analyzed. it serves to sort the results from asynchronous
    multiprocessing in order
    :param sample: sample to simulate
    :param var_names: names of variables to analyze
    :param output_parameters: list of output parameters to analyse
    :param locator: path to locator class
    :param weather_path: path to weather file
    :param gv: global variables class
    :return: Dataframes with output of simulation of a building. It relates the results
    of every outputparameter.
    """

    # create a dict with the new input vatiables form the sample and pass in gv
    gv.samples = dict(zip(var_names, sample))
    result = None
    while result is None:  # trick to avoid that arcgis stops calculating the days and tries again.
        try:
            result = demand_main.demand_calculation(locator, weather_path,
                                                    gv)[output_parameters]
        except Exception, e:
            print e, result
            pass
예제 #6
0
def simulate_demand_sample(locator, building_name, building_load, config):
    """
    This script runs the cea demand tool in series and returns a single value of cvrmse and rmse.

    :param locator: pointer to location of files in CEA
    :param building_name: name of building
    :param output_parameters: building load to consider in the anlysis
    :return:
    """

    # force simulation to be sequential, for only one building and to override variables
    gv = cea.globalvar.GlobalVariables()
    config.demand.override_variables = True  # true so it reads the overrides file created
    config.multiprocessing = False
    config.demand.buildings = [building_name]
    config.demand.resolution_output = "hourly"
    config.demand.loads_output = [building_load]
    config.demand.massflows_output = [
        "mcphs_sys"
    ]  # give one entry so it doe snot plot all ( it saves memory)
    config.demand.temperatures_output = [
        "Tww_sys_sup"
    ]  # give one entry so it doe snot plot all ( it saves memory)
    config.demand.format_output = "csv"

    _, time_series = demand_main.demand_calculation(locator, config)
    return time_series[0][building_load + "_kWh"].values
예제 #7
0
def simulate_demand_sample(locator, config, output_parameters):
    """
    Run a demand simulation for a single sample. This function expects a locator that is already initialized to the
    simulation folder, that has already been prepared with `apply_sample_parameters`.

    :param locator: The InputLocator to use for the simulation
    :type locator: InputLocator

    :param weather: The path to the weather file (``*.epw``) to use for simulation. See the `weather_path` parameter in
                    `cea.demand.demand_main.demand_calculation` for more information.
    :type weather: str

    :param output_parameters: The list of output parameters to save to disk. This is a column-wise subset of the
                              output of `cea.demand.demand_main.demand_calculation`.
    :type output_parameters: list of str

    :return: Returns the columns of the results of `cea.demand.demand_main.demand_calculation` as defined in
            `output_parameters`.
    :rtype: pandas.DataFrame
    """

    # MODIFY CONFIG FILE TO RUN THE DEMAND FOR ONLY SPECIFIC QUANTITIES
    config.demand.resolution_output = "monthly"
    config.multiprocessing = False
    config.demand.massflows_output = []
    config.demand.temperatures_output = []
    config.demand.format_output = "csv"
    config.demand.override_variables = True

    # force simulation to be sequential
    totals, time_series = demand_main.demand_calculation(locator, config)
    return totals[output_parameters], time_series
예제 #8
0
def simulate_demand_sample(locator, weather_path, output_parameters):
    """
    Run a demand simulation for a single sample. This function expects a locator that is already initialized to the
    simulation folder, that has already been prepared with `apply_sample_parameters`.

    :param locator: The InputLocator to use for the simulation
    :type locator: InputLocator

    :param weather: The path to the weather file (``*.epw``) to use for simulation. See the `weather_path` parameter in
                    `cea.demand.demand_main.demand_calculation` for more information.
    :type weather: str

    :param output_parameters: The list of output parameters to save to disk. This is a column-wise subset of the
                              output of `cea.demand.demand_main.demand_calculation`.
    :type output_parameters: list of str

    :return: Returns the columns of the results of `cea.demand.demand_main.demand_calculation` as defined in
            `output_parameters`.
    :rtype: pandas.DataFrame
    """
    gv = cea.globalvar.GlobalVariables()
    gv.demand_writer = cea.demand.demand_writers.MonthlyDemandWriter(gv)
    # force simulation to be sequential
    gv.multiprocessing = False
    totals, time_series = demand_main.demand_calculation(
        locator, weather_path, gv)
    return totals[output_parameters], time_series
def screening_cea(counter, sample, var_names, output_parameters, locator, weather_path, gv):
    """

    :param counter: counter keepin gth enumber of samples analyzed. it serves to sort the results from asynchronous
    multiprocessing in order
    :param sample: sample to simulate
    :param var_names: names of variables to analyze
    :param output_parameters: list of output parameters to analyse
    :param locator: path to locator class
    :param weather_path: path to weather file
    :param gv: global variables class
    :return: Dataframes with output of simulation of a building. It relates the results
    of every outputparameter.
    """

    # create a dict with the new input vatiables form the sample and pass in gv
    gv.samples = dict(zip(var_names, sample))
    result = None
    while result is None:  # trick to avoid that arcgis stops calculating the days and tries again.
        try:
            result = demand_main.demand_calculation(locator, weather_path, gv)[output_parameters]
        except Exception, e:
            print e, result
            pass
예제 #10
0
def sampling_main(locator, random_variables, target_parameters,
                  list_building_names, weather_path, multiprocessing, config,
                  nn_delay, climatic_variables, year):
    '''
    this function creates a number of random samples for the entire district (city)
    :param locator: points to the variables
    :param random_variables: a list containing the names of variables associated with uncertainty (can be accessed from 'nn_settings.py')
    :param target_parameters: a list containing the name of desirable outputs (can be accessed from 'nn_settings.py')
    :param list_building_names: a list containing the name of desired buildings
    :param weather_path: weather path
    :return: -
    '''

    #   get number of buildings
    size_city = np.shape(list_building_names)
    size_city = size_city[0]
    #   create random samples of the entire district
    for i in range(
            number_samples
    ):  # the parameter "number_samples" is accessible from 'nn_settings.py'
        bld_counter = 0
        # create list of samples with a LHC sampler and save to disk
        samples, samples_norm, pdf_list = latin_sampler(
            locator, size_city, random_variables)
        #samples = samples[0]  # extract the non-normalized samples

        # create a file of overides with the samples
        dictionary = dict(zip(random_variables, samples.transpose()))
        overides_dataframe = pd.DataFrame(dictionary)
        overides_dataframe['Name'] = list_building_names

        # replace the 1, 0 with True and False
        for var in boolean_vars:
            overides_dataframe[var].replace(1, "True", inplace=True)
            overides_dataframe[var].replace(0, "False", inplace=True)
            overides_dataframe[var].replace(0.0, "False", inplace=True)

        # save file so the demand calculation can know about it.
        overides_dataframe.to_csv(locator.get_building_overrides())

        #   run cea demand
        config.demand.override_variables = True
        demand_main.demand_calculation(locator, config)
        #   prepare the inputs for feeding into the neural network
        urban_input_matrix, urban_taget_matrix = input_prepare_main(
            list_building_names, locator, target_parameters, nn_delay,
            climatic_variables, year)
        #   drop half the inputs and targets to avoid overfitting and save RAM / Disk space
        urban_input_matrix, urban_taget_matrix = input_dropout(
            urban_input_matrix, urban_taget_matrix)
        #   get the pathfor saving the files
        nn_inout_path = locator.get_nn_inout_folder()
        #   save inputs with sequential naming
        file_path_inputs = os.path.join(nn_inout_path,
                                        "input%(i)s.csv" % locals())
        data_file_inputs = pd.DataFrame(urban_input_matrix)
        data_file_inputs.to_csv(file_path_inputs, header=False, index=False)
        #   save inputs with sequential naming
        file_path_targets = os.path.join(nn_inout_path,
                                         "target%(i)s.csv" % locals())
        data_file_targets = pd.DataFrame(urban_taget_matrix)
        data_file_targets.to_csv(file_path_targets, header=False, index=False)
예제 #11
0
def calc_score(static_params, dynamic_params):
    """
    This tool reduces the error between observed (real life measured data) and predicted (output of the model data) values by changing some of CEA inputs.
    Annual data is compared in terms of MBE and monthly data in terms of NMBE and CvRMSE (follwing ASHRAE Guideline 14-2002).
    A new input folder with measurements has to be created, with a csv each for monthly and annual data provided as input for this tool.
    A new output csv is generated providing the calibration results (iteration number, parameters tested and results(score metric))
    """
    ## define set of CEA inputs to be calibrated and initial guess values
    SEED = dynamic_params['SEED']
    np.random.seed(
        SEED
    )  #initalize seed numpy randomly npy.random.seed (once call the function) - inside put the seed
    #import random (initialize) npy.random.randint(low=1, high=100, size= number of buildings)/1000 - for every parameter.
    Hs_ag = dynamic_params['Hs_ag']
    Tcs_set_C = dynamic_params['Tcs_set_C']
    Es = dynamic_params['Es']
    Ns = dynamic_params['Ns']
    Occ_m2pax = dynamic_params['Occ_m2pax']
    Vww_lpdpax = dynamic_params['Vww_lpdpax']
    Ea_Wm2 = dynamic_params['Ea_Wm2']
    El_Wm2 = dynamic_params['El_Wm2']

    ##define fixed constant parameters (to be redefined by CEA config file)
    #Hs_ag = 0.15
    #Tcs_set_C = 28
    Tcs_setb_C = 40
    void_deck = 1
    height_bg = 0
    floors_bg = 0

    scenario_list = static_params['scenario_list']
    config = static_params['config']

    locators_of_scenarios = []
    measured_building_names_of_scenarios = []
    for scenario in scenario_list:
        config.scenario = scenario
        locator = cea.inputlocator.InputLocator(config.scenario)
        measured_building_names = get_measured_building_names(locator)
        modify_monthly_multiplier(locator, config, measured_building_names)

        # store for later use
        locators_of_scenarios.append(locator)
        measured_building_names_of_scenarios.append(measured_building_names)

        ## overwrite inputs with corresponding initial values

        # Changes and saves variables related to the architecture
        df_arch = dbf_to_dataframe(locator.get_building_architecture())
        number_of_buildings = df_arch.shape[0]
        Rand_it = np.random.randint(low=-30, high=30,
                                    size=number_of_buildings) / 100
        df_arch.Es = Es * (1 + Rand_it)
        df_arch.Ns = Ns * (1 + Rand_it)
        df_arch.Hs_ag = Hs_ag * (1 + Rand_it)
        df_arch.void_deck = void_deck
        dataframe_to_dbf(df_arch, locator.get_building_architecture())

        # Changes and saves variables related to intetnal loads
        df_intload = dbf_to_dataframe(locator.get_building_internal())
        df_intload.Occ_m2pax = Occ_m2pax * (1 + Rand_it)
        df_intload.Vww_lpdpax = Vww_lpdpax * (1 + Rand_it)
        df_intload.Ea_Wm2 = Ea_Wm2 * (1 + Rand_it)
        df_intload.El_Wm2 = El_Wm2 * (1 + Rand_it)
        dataframe_to_dbf(df_intload, locator.get_building_internal())

        #Changes and saves variables related to comfort
        df_comfort = dbf_to_dataframe(locator.get_building_comfort())
        df_comfort.Tcs_set_C = Tcs_set_C * (1 + Rand_it)
        df_comfort.Tcs_setb_C = Tcs_setb_C
        dataframe_to_dbf(df_comfort, locator.get_building_comfort())

        # Changes and saves variables related to zone
        df_zone = dbf_to_dataframe(locator.get_zone_geometry().split('.')[0] +
                                   '.dbf')
        df_zone.height_bg = height_bg
        df_zone.floors_bg = floors_bg
        dataframe_to_dbf(df_zone,
                         locator.get_zone_geometry().split('.')[0] + '.dbf')

        ## run building schedules and energy demand
        config.schedule_maker.buildings = measured_building_names
        schedule_maker.schedule_maker_main(locator, config)
        config.demand.buildings = measured_building_names
        demand_main.demand_calculation(locator, config)

    # calculate the score
    score = validation.validation(scenario_list=scenario_list,
                                  locators_of_scenarios=locators_of_scenarios,
                                  measured_building_names_of_scenarios=
                                  measured_building_names_of_scenarios)

    return score