def main(config):
    cache_folder = tempfile.mkdtemp()
    plot_cache = cea.plots.cache.MemoryPlotCache(cache_folder)

    with config.ignore_restrictions():
        if config.plots_supply_system.system == "_sys_today_":
            # BUGFIX: _sys_today_ not supported
            config.plots_supply_system.system = ""

    try:
        for category in cea.plots.categories.list_categories(plugins=[]):
            # create the new dashboard
            print(
                "Plotting category {category}".format(category=category.label))

            for plot_class in category.plots:
                print("- Plotting {plot_class}".format(
                    plot_class=plot_class.__name__))
                parameters = {
                    k: config.get(v)
                    for k, v in plot_class.expected_parameters.items()
                }
                plot = plot_class(config.project, parameters, plot_cache)
                print("    - plotting to {output_path}".format(
                    output_path=plot.output_path))
                plot.plot()
                print("    - plotting div (len={len})".format(
                    len=len(plot.plot_div())))
    finally:
        shutil.rmtree(cache_folder, ignore_errors=True)
Ejemplo n.º 2
0
def set_parameter(config, parameter, value):
    """Set a parameter to a value (expand with environment vars) without tripping the restricted_to part of config"""
    with config.ignore_restrictions():
        print("Setting {parameter}={value}".format(parameter=parameter.fqname,
                                                   value=value))
        if not isinstance(value, basestring):
            value = str(value)
        expanded_value = os.path.expandvars(value)
        parameter.set(parameter.decode(expanded_value))
def thermal_network_optimization(config, locator):
    # initialize timer
    start = time.time()
    # synchronize representative week method in network simulation
    with config.ignore_restrictions():
        config.thermal_network.use_representative_week_per_month = (
            config.thermal_network_optimization.use_representative_week_per_month
        )
        # read network type and ensure consistency in network layout and network_info
        network_type = config.thermal_network.network_type
        config.network_layout.network_type = network_type
    if network_type == 'DH':
        raise ValueError('This optimization procedure is not ready for district heating yet!')
    # initialize object
    network_info = Network_info(locator, config, network_type)
    # write buildings names to object
    total_demand = pd.read_csv(locator.get_total_demand())
    network_info.building_names = total_demand.Name.values
    network_info.number_of_buildings_in_district = total_demand.Name.count()
    # write possible plant location sites to object
    if not config.thermal_network_optimization.possible_plant_sites:
        # if there is no input from the config file as to which sites are potential plant locations, set all as possible locations
        config.thermal_network_optimization.possible_plant_sites = network_info.building_names

    # create initial population
    print 'Creating initial population.'
    newMutadedGen = generateInitialPopulation(network_info)
    # iterate through number of generations
    for generation_number in range(config.thermal_network_optimization.number_of_generations):
        print 'Running optimization for generation number ', generation_number
        # calculate network cost for each individual and sort by increasing cost
        sortedPop = network_cost_calculation(newMutadedGen, network_info, config)
        print 'Lowest cost individual: ', sortedPop[0], '\n'
        # setup next generation
        if generation_number < config.thermal_network_optimization.number_of_generations - 1:
            # select individuals for next generation
            selectedPop = selectFromPrevPop(sortedPop, network_info)
            # breed next generation
            newGen = breedNewGeneration(selectedPop, network_info)
            # add mutations
            newMutadedGen = mutateGeneration(newGen, network_info)
            print 'Finished mutation.'
    # write values into all_individuals_list and output results
    output_results_of_all_individuals(config, locator, network_info)
    print('thermal_network_optimization_main() succeeded')
    print('total time: ', time.time() - start)
def do_script_step(config, i, step, trace_input):
    """Run a script based on the step's "script" and "parameters" (optional) keys."""
    script = cea.scripts.by_name(step["script"], plugins=config.plugins)
    print("")
    print("=" * 80)
    print("Workflow step {i}: script={script}".format(i=i, script=script.name))
    print("=" * 80)
    with config.ignore_restrictions():
        parameters = {
            p.name: p.get()
            for s, p in config.matching_parameters(script.parameters)
        }
    if "parameters" in step:
        parameters.update(step["parameters"])
    py_script = script.name.replace("-", "_")
    py_parameters = {k.replace("-", "_"): v for k, v in parameters.items()}

    if trace_input:
        run_with_trace(config, py_script, **py_parameters)
    else:
        run(config, py_script, **py_parameters)