예제 #1
0
def modifier_from_rad(modifier_rad, output_file):
    """Translate a Modifier JSON file to a honeybee JSON as an array of modifiers.
    \n
    Args:
        modifier_rad: Full path to a Modifier .rad or .mat file. Only the modifiers
            and materials in this file will be extracted.
    """
    try:
        # re-serialize the Modifiers to Python
        mod_objs = []
        with open(modifier_rad) as f:
            rad_dicts = string_to_dicts(f.read())
            for mod_dict in rad_dicts:
                mod_objs.append(dict_to_modifier(mod_dict))

        # create the honeybee dictionaries
        json_dicts = [mod.to_dict() for mod in mod_objs]

        # write out the JSON file
        output_file.write(json.dumps(json_dicts))
    except Exception as e:
        _logger.exception('Modifier translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
def load_modifiers_from_folder(modifier_lib_folder):
    """Load all of the material layer objects from a modifier standards folder.

    Args:
        modifier_lib_folder: Path to a modifiers sub-folder within a
            honeybee standards folder.
    """
    user_modifiers = {}
    for f in os.listdir(modifier_lib_folder):
        f_path = os.path.join(modifier_lib_folder, f)
        if os.path.isfile(f_path):
            if f_path.endswith('.mat') or f_path.endswith('.rad'):
                with open(f_path) as f:
                    try:
                        rad_dicts = string_to_dicts(f.read())
                        for mod_dict in rad_dicts:
                            mod = dict_to_modifier(mod_dict)
                            mod.lock()
                            user_modifiers[mod.identifier] = mod
                    except ValueError:
                        pass  # empty rad file with no modifiers in them
            if f_path.endswith('.json'):
                with open(f_path) as json_file:
                    data = json.load(json_file)
                if 'type' in data:  # single object
                    load_modifier_object(data, user_modifiers)
                else:  # a collection of several objects
                    for mod_identifier in data:
                        load_modifier_object(data[mod_identifier],
                                             user_modifiers)
    return user_modifiers
예제 #3
0
def test_dict_to_primitive():
    f_path = './tests/assets/model/test_model.rad'
    with open(f_path) as f:
        rad_dicts = string_to_dicts(f.read())
        for rad_dict in rad_dicts:
            prim_obj = dict_to_primitive(rad_dict)
            assert isinstance(prim_obj, Primitive)
            assert prim_obj.__class__ != Primitive  # ensure it's inherited type
예제 #4
0
    def from_string(cls, primitive_string):
        """Create a Radiance primitive from a string.

        If the primitive modifier is not void or it has other dependencies,
        the modifier and/or dependencies must also be part of the input string.
        """
        pr_dict = string_to_dicts(primitive_string)
        assert len(pr_dict) == 1, \
            'Input string includes more than one Radiance objects.'
        return cls.from_primitive_dict(pr_dict[0])
예제 #5
0
        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


for f in os.listdir(folders.modifier_lib):
    f_path = os.path.join(folders.modifier_lib, f)
    if os.path.isfile(f_path):
        if f_path.endswith('.mat') or f_path.endswith('.rad'):
            with open(f_path) as f:
                try:
                    rad_dicts = string_to_dicts(f.read())
                    for mod_dict in rad_dicts:
                        mod = dict_to_modifier(mod_dict)
                        mod.lock()
                        _loaded_modifiers[mod.identifier] = mod
                except ValueError:
                    pass  # empty rad file with no modifiers in them
        if f_path.endswith('.json'):
            with open(f_path) as json_file:
                data = json.load(json_file)
            if 'type' in data:  # single object
                load_modifier_object(data)
            else:  # a collection of several objects
                for mod_identifier in data:
                    load_modifier_object(data[mod_identifier])