def fract_exposed_from_mtx(person_sun_int_matrix, day_pattern):
    """Get a Data Collection of fraction exposed values from an intersection matrix.

    Args:
        person_sun_int_matrix: An intersection matrix of 0s and 1s for the points
            of a single person.
        day_pattern: A list of 8760 booleans indicating whether the sun is
            up (True) or down (Fasle).

    Returns:
         A data collection for the fraction of body exposed.
     """
    pt_count = len(person_sun_int_matrix)
    fract_per_sun = [
        sum(pt_int_ar) / pt_count for pt_int_ar in zip(*person_sun_int_matrix)
    ]
    fract_exp_vals = []
    per_sun_i = 0
    for is_sun in day_pattern:
        if is_sun:
            fract_exp_vals.append(fract_per_sun[per_sun_i])
            per_sun_i += 1
        else:
            fract_exp_vals.append(0)
    meta_dat = {'type': 'Fraction of Body Exposed to Direct Sun'}
    fract_exp_head = Header(Fraction(), 'fraction', AnalysisPeriod(), meta_dat)
    return HourlyContinuousCollection(fract_exp_head, fract_exp_vals)
Пример #2
0
def model_occ_schedules(model_json, threshold, period, output_file):
    """Translate a Model's occupancy schedules into a JSON of 0/1 values.

    \b
    Args:
        model_json: Full path to a Model JSON file.
    """
    try:
        # re-serialize the Model
        with open(model_json) as json_file:
            data = json.load(json_file)
        model = Model.from_dict(data)

        # loop through the rooms and collect all unique occupancy schedules
        scheds, room_occupancy = [], {}
        for room in model.rooms:
            people = room.properties.energy.people
            if people is not None:
                model.properties.energy._check_and_add_schedule(
                    people.occupancy_schedule, scheds)
                room_occupancy[room.identifier] = people.occupancy_schedule.identifier
            else:
                room_occupancy[room.identifier] = None

        # process the run period if it is supplied
        if period is not None and period != '' and period != 'None':
            a_per = AnalysisPeriod.from_string(period)
            start = Date(a_per.st_month, a_per.st_day)
            end = Date(a_per.end_month, a_per.end_day)
            a_period = AnalysisPeriod(start.month, start.day, 0, end.month, end.day, 23)
            timestep = a_per.timestep
        else:
            a_per = a_period = AnalysisPeriod()
            start, end, timestep = Date(1, 1), Date(12, 31), 1

        # convert occupancy schedules to lists of 0/1 values
        schedules = {}
        for sch in scheds:
            values = []
            for val in sch.values(timestep, start, end):
                is_occ = 0 if val < threshold else 1
                values.append(is_occ)
            header = Header(Fraction(), 'fraction', a_period)
            schedules[sch.identifier] = HourlyContinuousCollection(header, values)
        if a_per.st_hour != 0 or a_per.end_hour != 23:
            schedules = {key: data.filter_by_analysis_period(a_per)
                         for key, data in schedules.items()}
        schedules = {key: data.values for key, data in schedules.items()}

        # write out the JSON file
        occ_dict = {'schedules': schedules, 'room_occupancy': room_occupancy}
        output_file.write(json.dumps(occ_dict))
    except Exception as e:
        _logger.exception('Model translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
Пример #3
0
 def window_transmittance(self):
     """Data Collection of window transmittance."""
     return self._get_coll('_win_trans_coll', self._win_trans,
                           Fraction('Window Transmittance'), 'fraction')
Пример #4
0
 def sky_exposure(self):
     """Data Collection of sky view."""
     return self._get_coll('_sky_exp_coll', self._sky_exp,
                           Fraction('Sky Exposure'), 'fraction')
Пример #5
0
 def floor_reflectance(self):
     """Data Collection of floor reflectance."""
     return self._get_coll('_flr_ref_coll', self._flr_ref,
                           Fraction('Floor Reflectance'), 'fraction')
Пример #6
0
 def fraction_body_exposed(self):
     """Data Collection of body fraction exposed to direct sun."""
     return self._get_coll('_fract_exp_coll', self._fract_exp,
                           Fraction('Fraction Body Exposed'), 'fraction')
Пример #7
0
        # figure out the type of object to write into the metadata
        obj_name = os.path.basename(result_file).replace('.csv', '')
        if obj_name.startswith('Line.'):
            obj_name = obj_name.replace('Line.', '')
            obj_type = 'Electrical Connector Loading'
        elif obj_name.startswith('Transformer.'):
            obj_name = obj_name.replace('Transformer.', '')
            obj_type = 'Transformer Loading'
        else:
            obj_type = 'Building Voltage'
        metadata = {'type': obj_type, 'name': obj_name}

        # output the data collection of factors
        result_vals = [float(data[i][1]) for i in range(len(data))]
        header = Header(Fraction(), 'fraction', a_period, metadata)
        factors.append(HourlyContinuousCollection(header, result_vals))

        # output the data collection of conditions
        if len(data[0]) == 4:  # building voltage results
            cond_vals = []
            for row in data:
                cond = 0 if row[2] == 'False' else 1
                if cond != 1 and row[3] == 'True\n':
                    cond = -1
                cond_vals.append(cond)
            header = Header(volt_cond, volt_cond.units[0], a_period, metadata)
            condition.append(HourlyContinuousCollection(header, cond_vals))
        else:  # transformer or connector load
            cond_vals = []
            for row in data:
Пример #8
0
                pv = val[0]['size_kw']
            elif key == 'storage' and len(val) != 0:
                storage = [val[0]['size_kw'], val[0]['size_kwh']]
            elif key == 'generator' and len(val) != 0:
                generator = val[0]['size_kw']

    # parse the CSV results of the simulation if successful
    if os.path.isfile(re_csv):
        data = []  # final list of data to be collected
        # parse the data and figure out the timeseries properties
        csv_data = csv_to_matrix(re_csv)
        csv_header = csv_data.pop(0)
        a_period = extract_analysis_period(csv_data)
        for col, col_name in zip(zip(*csv_data), csv_header):
            if col_name.startswith('REopt:'):
                # figure out the type of object to write into the metadata
                base_name = col_name.replace('REopt:', '').split(':')
                end_name, units_init = base_name[-1].split('(')
                units_init = units_init.replace(')', '')
                if units_init == 'kw':
                    units, data_type = 'kW', Power()
                elif units_init == 'pct':
                    units, data_type = 'fraction', Fraction()
                else:
                    continue
                metadata = {'type': ':'.join(base_name[:-1] + [end_name])}
                # create the final data collections
                result_vals = [float(val) for val in col]
                header = Header(data_type, units, a_period, metadata)
                data.append(HourlyContinuousCollection(header, result_vals))