Exemple #1
0
def construction_to_idf(construction_json, output_file):
    """Translate a Construction JSON file to an IDF using direct-to-idf translators.

    \b
    Args:
        construction_json: Full path to a Construction JSON file. This file should
            either be an array of non-abridged Constructions or a dictionary where
            the values are non-abridged Constructions.
    """
    try:
        # re-serialize the Constructions to Python
        with open(construction_json) as json_file:
            data = json.load(json_file)
        constr_list = data.values() if isinstance(data, dict) else data
        constr_objs = [dict_to_construction(constr) for constr in constr_list]
        mat_objs = set()
        for constr in constr_objs:
            for mat in constr.materials:
                mat_objs.add(mat)

        # create the IDF strings
        idf_str_list = []
        idf_str_list.append('!-   ============== MATERIALS ==============\n')
        idf_str_list.extend([mat.to_idf() for mat in mat_objs])
        idf_str_list.append('!-   ============ CONSTRUCTIONS ============\n')
        idf_str_list.extend([constr.to_idf() for constr in constr_objs])
        idf_str = '\n\n'.join(idf_str_list)

        # write out the IDF file
        output_file.write(idf_str)
    except Exception as e:
        _logger.exception('Construction translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Exemple #2
0
def load_construction_object(con_dict):
    """Load a construction object from a dictionary and add it to the library dict."""
    try:
        constr = dict_abridged_to_construction(con_dict, _all_materials,
                                               _schedules, False)
        if constr is None:
            constr = dict_to_construction(con_dict, False)
        if constr is not None:
            lock_and_check_construction(constr)
            if isinstance(constr,
                          (OpaqueConstruction, AirBoundaryConstruction)):
                _opaque_constructions[con_dict['identifier']] = constr
            elif isinstance(constr,
                            (WindowConstruction, WindowConstructionShade)):
                _window_constructions[con_dict['identifier']] = constr
            else:  # it's a shade construction
                _shade_constructions[con_dict['identifier']] = constr
    except (TypeError, KeyError):
        pass  # not a Honeybee Construction JSON; possibly a comment
Exemple #3
0
def dict_to_object(honeybee_energy_dict, raise_exception=True):
    """Re-serialize a dictionary of almost any object within honeybee_energy.

    This includes any Material, Construction, ConstructionSet, Schedule, Load,
    ProgramType, or Simulation object.

    Args:
        honeybee_energy_dict: A dictionary of any Honeybee energy object. Note
            that this should be a non-abridged dictionary to be valid.
        raise_exception: Boolean to note whether an excpetion should be raised
            if the object is not identified as a part of honeybee_energy.
            Default: True.

    Returns:
        A Python object derived from the input honeybee_energy_dict.
    """
    try:  # get the type key from the dictionary
        obj_type = honeybee_energy_dict['type']
    except KeyError:
        raise ValueError(
            'Honeybee_energy dictionary lacks required "type" key.')

    if obj_type == 'ProgramType':
        return ProgramType.from_dict(honeybee_energy_dict)
    elif obj_type == 'ConstructionSet':
        return ConstructionSet.from_dict(honeybee_energy_dict)
    elif obj_type in SCHEDULE_TYPES:
        return dict_to_schedule(honeybee_energy_dict)
    elif obj_type in CONSTRUCTION_TYPES:
        return dict_to_construction(honeybee_energy_dict)
    elif obj_type in MATERIAL_TYPES:
        return dict_to_material(honeybee_energy_dict)
    elif obj_type in LOAD_TYPES:
        return dict_to_load(honeybee_energy_dict)
    elif obj_type in SIMULATION_TYPES:
        return dict_to_simulation(honeybee_energy_dict)
    elif raise_exception:
        raise ValueError(
            '{} is not a recognized honeybee energy object'.format(obj_type))