Beispiel #1
0
def __apply_func_with_worker_stream(args):
    """
    Call func, using ``queue`` to redirect stdout and stderr, with a tuple of args because multiprocessing.Pool.map
    only accepts one argument for the function.

    This function is called _inside_ a separate process.
    """

    # set up logging
    logger = multiprocessing.log_to_stderr()
    logger.setLevel(logging.WARNING)
    from cea import suppres_3rd_party_debug_loggers
    suppres_3rd_party_debug_loggers()

    # unpack the arguments
    func, queue, on_complete, i_queue, n, args = args[0], args[1], args[2], args[3], args[4], args[5:]

    # set up printing to stderr and stdout to go through the queue
    sys.stdout = QueueWorkerStream('stdout', queue)
    sys.stderr = QueueWorkerStream('stderr', queue)

    # CALL
    result = func(*args)

    if on_complete:
        on_complete(i_queue.get(), n, args, result)

    return result
Beispiel #2
0
def main(config=None):
    """

    :param cea.config.Configuration config: the configuration file to use (instead of creating a new one)
    :return:
    """
    t0 = datetime.datetime.now()

    if not config:
        config = cea.config.Configuration()

    from cea import suppres_3rd_party_debug_loggers
    suppres_3rd_party_debug_loggers()

    # handle arguments
    args = sys.argv[1:]  # drop the script name from the arguments
    if not len(args) or args[0].lower() == '--help':
        print_help(config, args[1:])
        sys.exit(1)
    if args[0].lower() == '--version':
        print('City Energy Analyst version %s' % cea.__version__)
        sys.exit(0)
    script_name = args.pop(0)
    cea_script = cea.scripts.by_name(script_name)
    config.restrict_to(cea_script.parameters)
    config.apply_command_line_args(args, cea_script.parameters)

    # save the updates to the configuration file (re-running the same tool will result in the
    # same parameters being set)
    config.save(cea.config.CEA_CONFIG)

    cea_script.print_script_configuration(config)
    if list(cea_script.missing_input_files(config)):
        cea_script.print_missing_input_files(config)
        return

    script_module = importlib.import_module(cea_script.module)
    try:
        script_module.main(config)
        print("Execution time: %.2fs" %
              (datetime.datetime.now() - t0).total_seconds())
    except cea.ConfigError as config_error:
        print('ERROR: %s' % config_error)
        sys.exit(config_error.rc)
    except cea.CustomDatabaseNotFound as error:
        print('ERROR: %s' % error)
        sys.exit(error.rc)
    except:
        raise
Beispiel #3
0
import Queue
import threading
import cea.config
import cea.scripts
from cea import suppres_3rd_party_debug_loggers

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

suppres_3rd_party_debug_loggers()


def consume_nowait(queue, msg):
    """
    Read from queue as much as possible and concatenate the results to ``msg``, returning that.
    If an ``EOFError`` is read from the queue, put it back and return the ``msg`` so far.
    """
    if not queue.empty():
        messages = [msg]
        try:
            msg = queue.get_nowait()
            while not msg is EOFError:
                messages.append(msg)
                msg = queue.get_nowait()
            # msg is now EOFError, put it back
"""
Geometry generator from
Shapefiles (buiding footprint)
and .tiff (terrain)

into 3D geometry with windows and roof equivalent to LOD3

"""
from __future__ import division
from __future__ import print_function

import cea
cea.suppres_3rd_party_debug_loggers()

import math
import os
import sys
import time

import gdal
import numpy as np
import py4design.py3dmodel.calculate as calculate
import py4design.py3dmodel.construct as construct
import py4design.py3dmodel.fetch as fetch
import py4design.py3dmodel.modify as modify
import py4design.py3dmodel.utility as utility
from OCC.IntCurvesFace import IntCurvesFace_ShapeIntersector
from OCC.gp import gp_Pnt, gp_Lin, gp_Ax1, gp_Dir
from geopandas import GeoDataFrame as gdf
from py4design import py3dmodel as py3dmodel
from py4design import urbangeom