Exemplo n.º 1
0
def modifier_to_rad(modifier_json, minimal, output_file):
    """Translate a Modifier JSON file to an RAD using direct-to-rad translators.
    \n
    Args:
        modifier_json: Full path to a Modifier JSON file. This file should
            either be an array of non-abridged Modifiers or a dictionary where
            the values are non-abridged Modifiers.
    """
    try:
        # re-serialize the Modifiers to Python
        with open(modifier_json) as json_file:
            data = json.load(json_file)
        mod_list = data.values() if isinstance(data, dict) else data
        mod_objs = []
        for mod_dict in mod_list:
            m_class = modifier_class_from_type_string(mod_dict['type'].lower())
            mod_objs.append(m_class.from_dict(mod_dict))

        # create the RAD strings
        rad_str_list = []
        rad_str_list.extend([mod.to_radiance(minimal) for mod in mod_objs])
        rad_str = '\n\n'.join(rad_str_list)

        # write out the RAD file
        output_file.write(rad_str)
    except Exception as e:
        _logger.exception('Modifier translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Exemplo n.º 2
0
def load_modifier_object(mod_dict):
    """Load a modifier object from a dictionary and add it to the library dict."""
    try:
        m_class = modifier_class_from_type_string(mod_dict['type'].lower())
        mod = m_class.from_dict(mod_dict)
        mod.lock()
        assert mod_dict['identifier'] not in _default_mods, 'Cannot overwrite ' \
            'default modifier "{}".'.format(mod_dict['identifier'])
        _loaded_modifiers[mod_dict['identifier']] = mod
    except (TypeError, KeyError):
        pass  # not a Honeybee Modifier JSON; possibly a comment
Exemplo n.º 3
0
def primitive_class_from_type_string(type_string):
    """Get the class of any primitive using its 'type' string.

    Note that this function returns the class itself and not a class instance.

    Args:
        type_string: Text for the name of a primitive module/class. This should
            usually be lowercase and should be the same as the 'type' key used
            in the dictionary representation of the primitive.
    """
    if type_string in Primitive.GEOMETRYTYPES:
        target_module = geometry
    else:
        try:
            return modifier_class_from_type_string(type_string)
        except ValueError:
            raise NotImplementedError(
                'Honeybee currently does not support %s' % type_string)
    class_name = type_string.capitalize()
    return getattr(target_module, class_name)
Exemplo n.º 4
0
"""Load all modifiers from the IDF libraries."""
from honeybee_radiance.config import folders
from honeybee_radiance.reader import string_to_dicts
from honeybee_radiance.mutil import dict_to_modifier, modifier_class_from_type_string

import os
import json

# empty dictionary to hold loaded modifiers
_loaded_modifiers = {}

# first load the honeybee defaults
with open(folders.defaults_file) as json_file:
    default_data = json.load(json_file)['modifiers']
for mod_dict in default_data:
    m_class = modifier_class_from_type_string(mod_dict['type'].lower())
    mod = m_class.from_dict(mod_dict)
    mod.lock()
    _loaded_modifiers[mod_dict['identifier']] = mod
_default_mods = set(list(_loaded_modifiers.keys()))


# then load modifiers from the user-supplied files
def load_modifier_object(mod_dict):
    """Load a modifier object from a dictionary and add it to the library dict."""
    try:
        m_class = modifier_class_from_type_string(mod_dict['type'].lower())
        mod = m_class.from_dict(mod_dict)
        mod.lock()
        assert mod_dict['identifier'] not in _default_mods, 'Cannot overwrite ' \
            'default modifier "{}".'.format(mod_dict['identifier'])