cea.utilities package

class cea.utilities.devnull[source]

Bases: object

Suppress sys.stdout so that it goes to devnull for duration of the with block

__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[source]
__init__()[source]
write(_)[source]
cea.utilities.identifier(s, sep='-')[source]

First, all characters are lowercased, then, any character that is not in ascii_lowercase is replaced with sep.

Parameters:
  • s (str) – the string to create an identifier of

  • use_underscores (str) – if set to true, underscores (“_”) will be used instead of dashes (“-“)

Return type:

str

class cea.utilities.pushd(path)[source]

Bases: object

Manage an os.chdir so that at the end of a with block, the path is set back to what it was

__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[source]
__init__(path)[source]
cea.utilities.remap(x, in_min, in_max, out_min, out_max)[source]

Scale x from range [in_min, in_max] to [out_min, out_max] Based on this StackOverflow answer: https://stackoverflow.com/a/43567380/2260

cea.utilities.simple_memoize(obj)[source]
cea.utilities.unique(sequence)[source]

Return only the unique elements in sequence, preserving order.

Parameters:

sequence (Sequence[T]) – the sequence to unique-ify

Return type:

List[T]

Submodules

cea.utilities.color_fader module

cea.utilities.compile_pyd_files module

Compile the .pyd files using Numba pycc to speed up the calculation of certain modules. Currently used for:

  • calc_tm.pyd (used in demand/sensible_loads.py)

  • calc_radiator.pyd (used in technologies/radiators.py)

In order to run this script, you will need to install Numba. Try: conda install numba

cea.utilities.compile_pyd_files.compile_radiators()[source]
cea.utilities.compile_pyd_files.compile_rc_model_sia()[source]
cea.utilities.compile_pyd_files.compile_storagetank()[source]
cea.utilities.compile_pyd_files.copy_pyd(source, destination)[source]
cea.utilities.compile_pyd_files.delete_pyd(*pathspec)[source]

Delete the file with the pathspec. pathspec is an array of path segments.

cea.utilities.compile_pyd_files.main()[source]

cea.utilities.create_mixed_use_type module

cea.utilities.create_polygon module

cea.utilities.date module

cea.utilities.dbf module

cea.utilities.doc_glossary module

cea.utilities.doc_graphviz module

cea.utilities.doc_html module

cea.utilities.doc_schemas module

cea.utilities.epwreader module

cea.utilities.latin_hypercube module

cea.utilities.parallel module

Standardizes multiprocessing use. In the CEA, some functions are run using the standard multiprocessing library. They are run by map``ing the function to a list of arguments (see ``multiprocessing.Pool.map_async) and waiting for the processes to finish, while at the same time piping STDOUT, STDERR through cea.utilities.workerstream.QueueWorkerStream - this ensures that the dashboard interface can read the output from the sub-processes.

The way this was done in CEA < v2.23 included boiler plate code that needed to be repeated every time multiprocessing was used. Issue [#2344](https://github.com/architecture-building-systems/CityEnergyAnalyst/issues/2344) was a result of not applying this technique to the demand script.

This module exports the function map which is intended to replace both map_async and the builtin map function (which was used when config.multiprocessing == False). This simplifies multiprocessing.

cea.utilities.parallel.__apply_func_with_worker_stream(args)[source]

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.

cea.utilities.parallel.__multiprocess_wrapper(func, processes, on_complete)[source]

Create a worker pool to map the function, taking care to set up STDOUT and STDERR

cea.utilities.parallel.single_process_wrapper(func, on_complete)[source]

The simplest form of vectorization: Just loop

cea.utilities.parallel.test(a, b)[source]
cea.utilities.parallel.vectorize(func, processes=1, on_complete=None)[source]

Similar to numpy.vectorize, this function wraps func so that it operates on sequences (of same length) of inputs and outputs a sequence of results, similar to map(func, *args).

The main point of using vectorize is to unify single-processing with multi-processing - if processes > 1, then multiprocessing is used and the function will be run on a pool of processes. STDOUT and STDERR of these processes are fed through a cea.workerstream.QueueWorkerStream so it can be shown in the dashboard job output.

The parameter on_complete is an optional callable that is called for each completed call of func. It takes 4 arguments:

  • i: the 0-based order in which this call was completed

  • n: the total number of function calls to be made

  • args: the arguments passed to this call to func

  • result: the return value of this call to func

Parameters:
  • func – The function to vectorize

  • processes (int) – The number of processes to use (use config.get_number_of_processes())

  • on_complete – An optional function to call for each completed call to func.

cea.utilities.physics module

Physical functions

cea.utilities.physics.calc_rho_air(temp_air)[source]

Calculation of density of air according to 6.4.2.1 in [1]

temp_air : air temperature in (°C)

rho_air : air density in (kg/m3)

cea.utilities.physics.kelvin_to_fahrenheit(T_Kelvin)[source]

cea.utilities.rename_building module

cea.utilities.reporting module

cea.utilities.schedule_reader module

cea.utilities.solar_equations module

cea.utilities.standardize_coordinates module

cea.utilities.workerstream module

This file implements WorkerStream for capturing stdout and stderr.

class cea.utilities.workerstream.HttpWorkerStream(name, jobid, url)[source]

Bases: object

__init__(name, jobid, url)[source]
class cea.utilities.workerstream.QueueWorkerStream(name, q)[source]

Bases: object

File-like object for wrapping the output of the scripts with queues - to be created in child process

__init__(name, q)[source]
__repr__()[source]

Return repr(self).

close()[source]
flush()[source]
isatty()[source]
write(str)[source]
class cea.utilities.workerstream.WorkerStream(name, connection)[source]

Bases: object

File-like object for wrapping the output of the scripts into connection messages

__init__(name, connection)[source]
__repr__()[source]

Return repr(self).

close()[source]
flush()[source]
isatty()[source]
write(str)[source]
cea.utilities.workerstream.stream_from_queue(q)[source]

Stream the contents from the queue to STDOUT / STDERR - to be called from parent process