def data_to_load_intensity(data_colls,
                           floor_area,
                           data_type,
                           cop=1,
                           mults=None):
    """Convert data collections output by EnergyPlus to a single load intensity collection.

    Args:
        data_colls: A list of monthly data collections for an energy term.
        floor_area: The total floor area of the rooms, used to compute EUI.
        data_type: Text for the data type of the collections (eg. "Cooling").
        cop: Optional number for the COP, which the results will be divided by.
    """
    if len(data_colls) != 0:
        if mults is not None:
            if 'Zone' in data_colls[0].header.metadata:
                rel_mults = [
                    mults[data.header.metadata['Zone']] for data in data_colls
                ]
                data_colls = [
                    dat * mul for dat, mul in zip(data_colls, rel_mults)
                ]
        total_vals = [
            sum(month_vals) / floor_area for month_vals in zip(*data_colls)
        ]
        if cop != 1:
            total_vals = [val / cop for val in total_vals]
    else:  # just make a "filler" collection of 0 values
        total_vals = [0] * 12
    meta_dat = {'type': data_type}
    total_head = Header(EnergyIntensity(), 'kWh/m2', AnalysisPeriod(),
                        meta_dat)
    return MonthlyCollection(total_head, total_vals, range(12))
Пример #2
0
    def _normalize_collection(collection, area, is_ip):
        """Normalize a given data collection by floor area.

        Args:
            collection: A data collection to be normalized.
            area: The floor area the the collection is normalize by.
            is_ip: Boolean to note whether the area is in square meters or square feet.
        """
        new_vals = [val / area for val in collection.values]
        head = collection.header
        new_unit = '{}/m2'.format(head.unit) if not is_ip else '{}/ft2'.format(
            head.unit)
        new_header = Header(EnergyIntensity(), new_unit, head.analysis_period,
                            head.metadata)
        if isinstance(collection, HourlyContinuousCollection):
            return HourlyContinuousCollection(new_header, new_vals)
        else:  # it's one of the data collections that needs datetimes
            return collection.__class__(new_header, new_vals,
                                        collection.datetimes)
Пример #3
0
    ]
    cmds.extend(sql_files)
    process = subprocess.Popen(cmds, stdout=subprocess.PIPE)
    stdout = process.communicate()
    results = json.loads(stdout[0], object_pairs_hook=OrderedDict)
    return results['eui'], results['total_floor_area'], results['end_uses']


if all_required_inputs(ghenv.Component):
    # ensure that _sql is a list rather than a single string
    if isinstance(_sql, basestring):
        _sql = [_sql]

# get the results
    get_results = get_results_windows if os.name == 'nt' else get_results_mac
    eui, gross_floor, end_use_pairs = get_results(_sql)

    # create separate lists for end use values and labels
    eui_end_use = end_use_pairs.values()
    end_uses = [use.replace('_', ' ').title() for use in end_use_pairs.keys()]

    # convert data to IP if requested
    if ip_:
        eui_typ, a_typ, e_typ = EnergyIntensity(), Area(), Energy()
        eui = round(eui_typ.to_ip([eui], 'kWh/m2')[0][0], 3)
        gross_floor = round(a_typ.to_ip([gross_floor], 'm2')[0][0], 3)
        eui_end_use = [
            round(eui_typ.to_ip([val], 'kWh/m2')[0][0], 3)
            for val in eui_end_use
        ]
Пример #4
0
def energy_use_intensity(result_paths, si, output_file):
    """Get information about energy use intensity and an EUI breakdown by end use.

    \b
    Args:
        result_paths: Path to one or more SQLite files that were generated by
            EnergyPlus or folders containing such files. Folders can be from a
            single EnergyPlus simulation or may contain multiple SQLite files.
            EUI will be computed across all files provided.
    """
    try:
        # set initial values that will be computed based on results
        total_floor_area, conditioned_floor_area, total_energy = 0, 0, 0
        all_uses = \
            ('heating', 'cooling', 'interior_lighting', 'exterior_lighting',
             'interior_equipment', 'exterior_equipment', 'fans', 'pumps',
             'heat_rejection', 'humidification', 'heat_recovery', 'water_systems',
             'refrigeration', 'generators')
        end_uses = {}
        for use in all_uses:
            end_uses[use] = 0

        # create a list of sql file path that were either passed directly or are
        # contained within passed folders
        sql_paths = []
        for file_or_folder_path in result_paths:
            if os.path.isdir(file_or_folder_path):
                for file_path in os.listdir(file_or_folder_path):
                    if file_path.endswith('.sql'):
                        sql_paths.append(os.path.join(file_or_folder_path, file_path))
            elif file_or_folder_path.endswith('.sql'):
                sql_paths.append(file_or_folder_path)

        # loop through the sql files and add the energy use
        for sql_path in sql_paths:
            # parse the SQL file
            sql_obj = SQLiteResult(sql_path)
            # get the total floor area of the model
            area_dict = sql_obj.tabular_data_by_name('Building Area')
            areas = tuple(area_dict.values())
            total_floor_area += areas[0][0]
            conditioned_floor_area += areas[1][0]
            # get the energy use
            eui_dict = sql_obj.tabular_data_by_name('End Uses')
            euis = tuple(eui_dict.values())
            total_energy += sum([val for val in euis[-2][:12]])
            end_uses['heating'] += sum([val for val in euis[0][:12]])
            end_uses['cooling'] += sum([val for val in euis[1][:12]])
            end_uses['interior_lighting'] += sum([val for val in euis[2][:12]])
            end_uses['exterior_lighting'] += sum([val for val in euis[3][:12]])
            end_uses['interior_equipment'] += sum([val for val in euis[4][:12]])
            end_uses['exterior_equipment'] += sum([val for val in euis[5][:12]])
            end_uses['fans'] += sum([val for val in euis[6][:12]])
            end_uses['pumps'] += sum([val for val in euis[7][:12]])
            end_uses['heat_rejection'] += sum([val for val in euis[8][:12]])
            end_uses['humidification'] += sum([val for val in euis[9][:12]])
            end_uses['heat_recovery'] += sum([val for val in euis[10][:12]])
            end_uses['water_systems'] += sum([val for val in euis[11][:12]])
            end_uses['refrigeration'] += sum([val for val in euis[12][:12]])
            end_uses['generators'] += sum([val for val in euis[13][:12]])

        # assemble all of the results into a final dictionary
        result_dict = {
            'eui': round(total_energy / total_floor_area, 3),
            'total_floor_area': total_floor_area,
            'conditioned_floor_area': conditioned_floor_area,
            'total_energy': round(total_energy, 3)
        }
        result_dict['end_uses'] = {key: round(val / total_floor_area, 3)
                                   for key, val in end_uses.items() if val != 0}

        # convert data to IP if requested
        if not si:
            eui_typ, a_typ, e_typ = EnergyIntensity(), Area(), Energy()
            result_dict['eui'] = \
                round(eui_typ.to_ip([result_dict['eui']], 'kWh/m2')[0][0], 3)
            result_dict['total_floor_area'] = \
                round(a_typ.to_ip([result_dict['total_floor_area']], 'm2')[0][0], 3)
            result_dict['conditioned_floor_area'] = \
                round(a_typ.to_ip(
                    [result_dict['conditioned_floor_area']], 'm2')[0][0], 3)
            result_dict['total_energy'] = \
                round(e_typ.to_ip([result_dict['total_energy']], 'kWh')[0][0], 3)
            result_dict['end_uses'] = \
                {key: round(eui_typ.to_ip([val], 'kWh/m2')[0][0], 3)
                 for key, val in result_dict['end_uses'].items()}

        # write everthing into the output file
        output_file.write(json.dumps(result_dict, indent=4))
    except Exception as e:
        _logger.exception('Failed to compute EUI from sql files.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)