bim2sim.kernel package

Kernel module of bim2sim

Holds central target simulation independent logic.

exception bim2sim.kernel.IFCDomainError

Bases: Exception

Exception raised if IFCDomain of file and element do not fit.

Subpackages

Submodules

bim2sim.kernel.decorators module

bim2sim.kernel.decorators.log(name)

Decorator for logging of entering and leaving method

bim2sim.kernel.ifc_file module

class bim2sim.kernel.ifc_file.IfcFileClass(ifc_path: Path, reset_guids: bool = False, ifc_domain: IFCDomain = None)

Bases: object

Combine IfcOpenShell file instance, finder and units together.

Especially if we handle multiple IFC files this dataclass helps us to keep track which finder and units belong to which ifc file.

Args:

ifc_path: Pathlib object that points to ifc file reset_guids: Boolean that determine if GUIDs should be reset ifc_domain: Domain of the given ifc file if this is known

get_ifc_units() dict

Returns dict to translate IFC units to pint units

To use units from IFC we get all unit definitions from the ifc and their corresponding measurement elements and map them to pint units.

Returns:

dict where key is the IfcMeasurement and value the pint unit definition. e.g. ‘IfcLengthMeasure’: meter

initialize_finder(finder_path)
static load_ifcopenshell_file(ifc_path) file

Loads the IfcOpenShell file instance

bim2sim.kernel.log module

class bim2sim.kernel.log.AudienceFilter(audience, name='')

Bases: Filter

filter(record: LogRecord) bool

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

class bim2sim.kernel.log.BufferedHandler(level=0)

Bases: Handler

Handler to buffer messages and don’t loose them.

emit(record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

flush_buffer(file_handler)
class bim2sim.kernel.log.CustomFormatter(fmt)

Bases: Formatter

Custom logging design based on https://stackoverflow.com/questions/384076/how-can-i-color-python -logging-output

format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class bim2sim.kernel.log.ThreadLogFilter(thread_name, *args, **kwargs)

Bases: Filter

This filter only show log entries for specified thread name.

filter(record)

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

bim2sim.kernel.log.get_user_logger(name)
bim2sim.kernel.log.initial_logging_setup(level=10)

Initial setup before project folder exists.

This is the first of the two-step logging setup. It makes sure that logging messages before project folder creation are still prompted to stream handler and saved to BufferHandler to get complete log files later.

bim2sim.kernel.log.project_logging_setup(prj=None) Tuple[List[Handler], List[ThreadLogFilter]]

Setup project logging

This is the second step of the two-step logging setup. After project folder creation this step adds completes the setup and adds the filder handlers that store the logs.

This creates the following: * the file output file bim2sim.log where the logs are stored * the logger quality_logger which stores all information about the quality of existing information of the BIM model. This logger is only on file to keep the logs cleaner

bim2sim.kernel.log.teardown_loggers()

Closes and removes all handlers from loggers in the ‘bim2sim’ hierarchy.

Iterates through all existing loggers and cleans up those that start with ‘bim2sim’. For each matching logger, all handlers are properly closed and removed. Errors during file handler closure (e.g., due to already deleted l og files) are silently ignored.