def test_get_building_schedules(self):
        """Make sure running get_building_schedules for same case returns the same value"""
        config = cea.config.Configuration()
        config.demand.use_stochastic_occupancy = False
        locator = ReferenceCaseOpenLocator()
        date_range = get_dates_from_year(2005)
        building_properties = BuildingProperties(locator,
                                                 override_variables=False)
        bpr = building_properties["B01"]

        # run get_building_schedules on clean folder - they're created from scratch
        if os.path.exists(locator.get_building_schedules("B01")):
            os.remove(locator.get_building_schedules("B01"))
        fresh_schedules = get_building_schedules(locator, bpr, date_range,
                                                 config)

        # run again to get the frozen version
        frozen_schedules = get_building_schedules(locator, bpr, date_range,
                                                  config)

        self.assertEqual(sorted(fresh_schedules.keys()),
                         sorted(frozen_schedules.keys()))
        for schedule in fresh_schedules:
            for i in range(len(fresh_schedules[schedule])):
                fresh = fresh_schedules[schedule][i]
                frozen = frozen_schedules[schedule][i]
                self.assertEqual(fresh, frozen)
            self.assertTrue(
                np.array_equal(fresh_schedules[schedule],
                               frozen_schedules[schedule]))
Beispiel #2
0
    def setUpClass(cls):
        import cea.examples
        cls.locator = cea.inputlocator.ReferenceCaseOpenLocator()
        cls.config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        cls.config.scenario = cls.locator.scenario
        weather_path = cls.locator.get_weather('Zug_inducity_2009')
        cls.weather_data = epwreader.epw_reader(weather_path)[[
            'year', 'drybulb_C', 'wetbulb_C', 'relhum_percent', 'windspd_ms',
            'skytemp_C'
        ]]
        year = cls.weather_data['year'][0]
        cls.date_range = get_date_range_hours_from_year(year)
        cls.test_config = configparser.ConfigParser()
        cls.test_config.read(
            os.path.join(os.path.dirname(__file__),
                         'test_calc_thermal_loads.config'))

        # run properties script
        import cea.datamanagement.archetypes_mapper
        cea.datamanagement.archetypes_mapper.archetypes_mapper(
            cls.locator, True, True, True, True, True, True,
            cls.locator.get_zone_building_names())

        cls.building_properties = BuildingProperties(
            cls.locator, epwreader.epw_reader(cls.locator.get_weather_file()))

        cls.use_dynamic_infiltration_calculation = cls.config.demand.use_dynamic_infiltration_calculation
        cls.resolution_output = cls.config.demand.resolution_output
        cls.loads_output = cls.config.demand.loads_output
        cls.massflows_output = cls.config.demand.massflows_output
        cls.temperatures_output = cls.config.demand.temperatures_output
        cls.debug = cls.config.debug
Beispiel #3
0
    def test_mixed_use_schedules(self):
        config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        stochastic_occupancy = config.demand.use_stochastic_occupancy
        gv = GlobalVariables()
        gv.config = config
        locator = ReferenceCaseOpenLocator()
        date = pd.date_range(gv.date_start, periods=8760, freq='H')

        building_properties = BuildingProperties(locator, gv, False, 'CH',
                                                 False)
        bpr = building_properties['B01']
        list_uses = ['OFFICE', 'INDUSTRIAL']
        bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5}

        # calculate schedules
        archetype_schedules, archetype_values = schedule_maker(
            'CH', date, locator, list_uses)
        calculated_schedules = calc_schedules(list_uses, archetype_schedules,
                                              bpr, archetype_values,
                                              stochastic_occupancy)

        config = ConfigParser.SafeConfigParser()
        config.read(get_test_config_path())
        reference_results = json.loads(
            config.get('test_mixed_use_schedules', 'reference_results'))

        for schedule in reference_results:
            self.assertAlmostEqual(
                calculated_schedules[schedule][REFERENCE_TIME],
                reference_results[schedule],
                places=4,
                msg="Schedule '%s' at time %s, %f != %f" %
                (schedule, str(REFERENCE_TIME),
                 calculated_schedules[schedule][REFERENCE_TIME],
                 reference_results[schedule]))
def properties_and_schedule(locator,
                            region,
                            year,
                            use_daysim_radiation,
                            override_variables=False):
    # this script is called from the Neural network please do not mess with it!

    date = pd.date_range(str(year) + '/01/01', periods=8760, freq='H')
    # building properties model

    building_properties = BuildingProperties(locator, use_daysim_radiation,
                                             region, override_variables)

    # schedules model
    list_uses = list(building_properties._prop_occupancy.columns)
    archetype_schedules, archetype_values = occupancy_model.schedule_maker(
        region, date, locator, list_uses)

    schedules_dict = {
        'list_uses': list_uses,
        'archetype_schedules': archetype_schedules,
        'occupancy_densities': archetype_values['people'],
        'archetype_values': archetype_values
    }
    return building_properties, schedules_dict, date
    def setUpClass(cls):
        import cea.examples
        cls.locator = cea.inputlocator.ReferenceCaseOpenLocator()
        cls.config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        weather_path = cls.locator.get_weather('Zug-inducity_1990_2010_TMY')
        cls.weather_data = epwreader.epw_reader(weather_path)[
            ['year', 'drybulb_C', 'wetbulb_C', 'relhum_percent', 'windspd_ms', 'skytemp_C']]
        year = cls.weather_data['year'][0]
        cls.date_range = get_dates_from_year(year)
        cls.test_config = ConfigParser.SafeConfigParser()
        cls.test_config.read(os.path.join(os.path.dirname(__file__), 'test_calc_thermal_loads.config'))

        # run properties script
        import cea.datamanagement.data_helper
        cea.datamanagement.data_helper.data_helper(cls.locator, 'CH', True, True, True, True, True, True, True)

        cls.building_properties = BuildingProperties(cls.locator, cls.config.demand.override_variables)

        cls.use_dynamic_infiltration_calculation = cls.config.demand.use_dynamic_infiltration_calculation
        cls.resolution_output = cls.config.demand.resolution_output
        cls.loads_output = cls.config.demand.loads_output
        cls.massflows_output = cls.config.demand.massflows_output
        cls.temperatures_output = cls.config.demand.temperatures_output
        cls.format_output = cls.config.demand.format_output
        cls.write_detailed_output = cls.config.demand.write_detailed_output
        cls.debug = cls.config.debug
Beispiel #6
0
    def test_mixed_use_schedules(self):
        locator = ReferenceCaseOpenLocator()
        config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        config.scenario = locator.scenario

        building_properties = BuildingProperties(locator, False)
        bpr = building_properties['B1011']
        bpr.occupancy = {'OFFICE': 0.5, 'SERVERROOM': 0.5}
        bpr.comfort['mainuse'] = 'OFFICE'

        # calculate schedules
        schedule_maker_main(locator, config)
        calculated_schedules = pd.read_csv(locator.get_schedule_model_file('B1011')).set_index('DATE')

        config = ConfigParser.SafeConfigParser()
        config.read(get_test_config_path())
        reference_results = json.loads(config.get('test_mixed_use_schedules', 'reference_results'))

        for schedule in reference_results:
            if (isinstance(calculated_schedules[schedule][REFERENCE_TIME], str)) and (isinstance(
                    reference_results[schedule], unicode)):
                self.assertEqual(calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule],
                                 msg="Schedule '{}' at time {}, {} != {}".format(schedule, str(REFERENCE_TIME),
                                                                                 calculated_schedules[schedule][
                                                                                     REFERENCE_TIME],
                                                                                 reference_results[schedule]))
            else:
                self.assertAlmostEqual(calculated_schedules[schedule][REFERENCE_TIME], reference_results[schedule],
                                       places=4,
                                       msg="Schedule '{}' at time {}, {} != {}".format(schedule, str(REFERENCE_TIME),
                                                                                       calculated_schedules[schedule][
                                                                                           REFERENCE_TIME],
                                                                                       reference_results[schedule]))
Beispiel #7
0
def create_data():
    """Create test data to compare against - run this the first time you make changes that affect the results. Note,
    this will overwrite the previous test data."""
    test_config = ConfigParser.SafeConfigParser()
    test_config.read(get_test_config_path())
    if not test_config.has_section('test_mixed_use_archetype_values'):
        test_config.add_section('test_mixed_use_archetype_values')
    locator = ReferenceCaseOpenLocator()
    expected_results = calculate_mixed_use_archetype_values_results(locator)
    test_config.set('test_mixed_use_archetype_values', 'expected_results', expected_results.to_json())

    config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
    locator = ReferenceCaseOpenLocator()

    # calculate schedules
    building_properties = BuildingProperties(locator, False)
    bpr = building_properties['B1011']
    list_uses = ['OFFICE', 'LAB', 'INDUSTRIAL', 'SERVERRROOM']
    bpr.occupancy = {'OFFICE': 0.5, 'SERVERROOM': 0.5}
    # get year from weather file
    weather_path = locator.get_weather_file()
    weather_data = epwreader.epw_reader(weather_path)[['year']]
    year = weather_data['year'][0]
    date = pd.date_range(str(year) + '/01/01', periods=HOURS_IN_YEAR, freq='H')

    calculated_schedules = schedule_maker_main(locator, config)
    if not test_config.has_section('test_mixed_use_schedules'):
        test_config.add_section('test_mixed_use_schedules')
    test_config.set('test_mixed_use_schedules', 'reference_results', json.dumps(
        {schedule: calculated_schedules[schedule][REFERENCE_TIME] for schedule in calculated_schedules.keys()}))

    with open(get_test_config_path(), 'w') as f:
        test_config.write(f)
Beispiel #8
0
def main(config):
    from cea.demand.building_properties import BuildingProperties

    gv = cea.globalvar.GlobalVariables()
    gv.config = config
    locator = cea.inputlocator.InputLocator(scenario=config.scenario)
    config.demand.buildings = locator.get_zone_building_names()[0]
    date = pd.date_range(gv.date_start, periods=8760, freq='H')
    building_properties = BuildingProperties(locator, gv, True, 'CH', False)
    bpr = building_properties[locator.get_zone_building_names()[0]]
    list_uses = ['OFFICE', 'INDUSTRIAL']
    bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5}
    use_stochastic_occupancy = config.demand.use_stochastic_occupancy

    # calculate schedules
    archetype_schedules, archetype_values = schedule_maker('CH', date, locator, list_uses)
    return calc_schedules(list_uses, archetype_schedules, bpr, archetype_values, use_stochastic_occupancy)
Beispiel #9
0
def create_test_data():
    """Create test data to compare against - run this the first time you make changes that affect the results. Note,
    this will overwrite the previous test data."""
    config = ConfigParser.SafeConfigParser()
    config.read(get_test_config_path())
    if not config.has_section('test_mixed_use_archetype_values'):
        config.add_section('test_mixed_use_archetype_values')
    locator = ReferenceCaseOpenLocator()
    expected_results = calculate_test_mixed_use_archetype_values_results(
        locator)
    config.set('test_mixed_use_archetype_values', 'expected_results',
               expected_results.to_json())

    config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
    gv = GlobalVariables()
    gv.config = config
    locator = ReferenceCaseOpenLocator()

    # calculate schedules
    building_properties = BuildingProperties(locator, gv, False, 'CH', False)
    bpr = building_properties['B01']
    list_uses = ['OFFICE', 'INDUSTRIAL']
    bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5}
    gv = GlobalVariables()
    date = pd.date_range(gv.date_start, periods=8760, freq='H')
    archetype_schedules, archetype_values = schedule_maker(
        'CH', date, locator, list_uses)
    stochastic_occupancy = config.demand.use_stochastic_occupancy
    calculated_schedules = calc_schedules(list_uses, archetype_schedules, bpr,
                                          archetype_values,
                                          stochastic_occupancy)
    if not config.has_section('test_mixed_use_schedules'):
        config.add_section('test_mixed_use_schedules')
    config.set(
        'test_mixed_use_schedules', 'reference_results',
        json.dumps({
            schedule: calculated_schedules[schedule][REFERENCE_TIME]
            for schedule in calculated_schedules.keys()
        }))

    with open(get_test_config_path(), 'w') as f:
        config.write(f)
    def test_mixed_use_schedules(self):
        locator = ReferenceCaseOpenLocator()
        config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)
        config.scenario = locator.scenario
        stochastic_occupancy = config.demand.use_stochastic_occupancy

        # get year from weather file
        weather_path = locator.get_weather_file()
        weather_data = epwreader.epw_reader(weather_path)[['year']]
        year = weather_data['year'][0]
        date = pd.date_range(str(year) + '/01/01',
                             periods=HOURS_IN_YEAR,
                             freq='H')

        building_properties = BuildingProperties(locator, False)
        bpr = building_properties['B01']
        list_uses = ['OFFICE', 'INDUSTRIAL']
        bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5}

        # calculate schedules
        archetype_schedules, archetype_values = schedule_maker(
            date, locator, list_uses)
        calculated_schedules = calc_schedules(list_uses, archetype_schedules,
                                              bpr, archetype_values,
                                              stochastic_occupancy)

        config = ConfigParser.SafeConfigParser()
        config.read(get_test_config_path())
        reference_results = json.loads(
            config.get('test_mixed_use_schedules', 'reference_results'))

        for schedule in reference_results:
            self.assertAlmostEqual(
                calculated_schedules[schedule][REFERENCE_TIME],
                reference_results[schedule],
                places=4,
                msg="Schedule '%s' at time %s, %f != %f" %
                (schedule, str(REFERENCE_TIME),
                 calculated_schedules[schedule][REFERENCE_TIME],
                 reference_results[schedule]))
def main(config):
    from cea.demand.building_properties import BuildingProperties
    locator = cea.inputlocator.InputLocator(config.scenario)
    weather_path = locator.get_weather_file()
    weather_data = epwreader.epw_reader(weather_path)[['year']]
    year = weather_data['year'][0]
    dates = pd.date_range(str(year) + '/01/01',
                          periods=HOURS_IN_YEAR,
                          freq='H')
    locator = cea.inputlocator.InputLocator(scenario=config.scenario)
    config.demand.buildings = [locator.get_zone_building_names()[0]]
    building_properties = BuildingProperties(locator=locator,
                                             override_variables=False)
    bpr = building_properties[locator.get_zone_building_names()[0]]
    list_uses = ['OFFICE', 'INDUSTRIAL']
    bpr.occupancy = {'OFFICE': 0.5, 'INDUSTRIAL': 0.5}
    use_stochastic_occupancy = config.demand.use_stochastic_occupancy

    # calculate schedules
    archetype_schedules, archetype_values = schedule_maker(
        dates, locator, list_uses)
    return calc_schedules(list_uses, archetype_schedules, bpr,
                          archetype_values, use_stochastic_occupancy)
Beispiel #12
0
def main(output_file):
    import cea.examples
    archive = zipfile.ZipFile(
        os.path.join(os.path.dirname(cea.examples.__file__),
                     'reference-case-open.zip'))
    archive.extractall(tempfile.gettempdir())
    reference_case = os.path.join(tempfile.gettempdir(), 'reference-case-open',
                                  'baseline')

    locator = InputLocator(reference_case)
    config = cea.config.Configuration(cea.config.DEFAULT_CONFIG)

    weather_path = locator.get_weather('Zug_inducity_2009')
    weather_data = epwreader.epw_reader(weather_path)[[
        'year', 'drybulb_C', 'wetbulb_C', 'relhum_percent', 'windspd_ms',
        'skytemp_C'
    ]]

    # run properties script
    import cea.datamanagement.archetypes_mapper
    cea.datamanagement.archetypes_mapper.archetypes_mapper(
        locator, True, True, True, True, True, True, [])

    year = weather_data['year'][0]
    date_range = get_date_range_hours_from_year(year)
    resolution_outputs = config.demand.resolution_output
    loads_output = config.demand.loads_output
    massflows_output = config.demand.massflows_output
    temperatures_output = config.demand.temperatures_output
    use_dynamic_infiltration_calculation = config.demand.use_dynamic_infiltration_calculation
    debug = config.debug
    building_properties = BuildingProperties(locator)

    print("data for test_calc_thermal_loads:")
    print(building_properties.list_building_names())

    schedule_maker_main(locator, config, building='B1011')

    bpr = building_properties['B1011']
    result = calc_thermal_loads('B1011', bpr, weather_data, date_range,
                                locator, use_dynamic_infiltration_calculation,
                                resolution_outputs, loads_output,
                                massflows_output, temperatures_output, config,
                                debug)

    # test the building csv file
    df = pd.read_csv(locator.get_demand_results_file('B1011'))

    expected_columns = list(df.columns)
    print("expected_columns = %s" % repr(expected_columns))

    test_config = configparser.ConfigParser()
    test_config.read(output_file)

    value_columns = [
        u"E_sys_kWh", u"Qcdata_sys_kWh", u"Qcre_sys_kWh", u"Qcs_sys_kWh",
        u"Qhs_sys_kWh", u"Qww_sys_kWh", u"Tcs_sys_re_C", u"Ths_sys_re_C",
        u"Tww_sys_re_C", u"Tcs_sys_sup_C", u"Ths_sys_sup_C", u"Tww_sys_sup_C"
    ]

    values = [float(df[column].sum()) for column in value_columns]
    print("values = %s " % repr(values))

    if not test_config.has_section("test_calc_thermal_loads"):
        test_config.add_section("test_calc_thermal_loads")
    test_config.set("test_calc_thermal_loads", "value_columns",
                    json.dumps(value_columns))
    print(values)
    test_config.set("test_calc_thermal_loads", "values", json.dumps(values))

    print("data for test_calc_thermal_loads_other_buildings:")
    buildings = [
        'B1013', 'B1012', 'B1010', 'B1000', 'B1009', 'B1011', 'B1006', 'B1003',
        'B1004', 'B1001', 'B1002', 'B1005', 'B1008', 'B1007', 'B1014'
    ]

    results = {}

    for building in buildings:
        bpr = building_properties[building]
        b, qhs_sys_kwh, qcs_sys_kwh, qww_sys_kwh = run_for_single_building(
            building, bpr, weather_data, date_range, locator,
            use_dynamic_infiltration_calculation, resolution_outputs,
            loads_output, massflows_output, temperatures_output, config, debug)
        print(
            "'%(b)s': (%(qhs_sys_kwh).5f, %(qcs_sys_kwh).5f, %(qww_sys_kwh).5f),"
            % locals())
        results[building] = (qhs_sys_kwh, qcs_sys_kwh, qww_sys_kwh)

    if not test_config.has_section("test_calc_thermal_loads_other_buildings"):
        test_config.add_section("test_calc_thermal_loads_other_buildings")
    test_config.set("test_calc_thermal_loads_other_buildings", "results",
                    json.dumps(results))
    with open(output_file, 'w') as f:
        test_config.write(f)
    print("Wrote output to %(output_file)s" % locals())
Beispiel #13
0
def demand_calculation(locator, config):
    """
    Algorithm to calculate the hourly demand of energy services in buildings
    using the integrated model of [Fonseca2015]_.

    Produces a demand file per building and a total demand file for the whole zone of interest:
      - a csv file for every building with hourly demand data.
      - ``Total_demand.csv``, csv file of yearly demand data per building.


    :param locator: An InputLocator to locate input files
    :type locator: cea.inputlocator.InputLocator

    :param weather_path: A path to the EnergyPlus weather data file (.epw)
    :type weather_path: str

    :param use_dynamic_infiltration_calculation: Set this to ``True`` if the (slower) dynamic infiltration
        calculation method (:py:func:`cea.demand.ventilation_air_flows_detailed.calc_air_flows`) should be used instead
        of the standard.
    :type use_dynamic_infiltration_calculation: bool

    :param multiprocessing: Set this to ``True`` if the :py:mod:`multiprocessing` module should be used to speed up
        calculations by making use of multiple cores.
    :type multiprocessing: bool

    :returns: None
    :rtype: NoneType

    .. [Fonseca2015] Fonseca, Jimeno A., and Arno Schlueter. “Integrated Model for Characterization of
        Spatiotemporal Building Energy Consumption Patterns in Neighborhoods and City Districts.”
        Applied Energy 142 (2015): 247–265.
    """

    # INITIALIZE TIMER
    t0 = time.clock()

    # LOCAL VARIABLES
    building_names = config.demand.buildings
    use_dynamic_infiltration = config.demand.use_dynamic_infiltration_calculation
    resolution_output = config.demand.resolution_output
    loads_output = config.demand.loads_output
    massflows_output = config.demand.massflows_output
    temperatures_output = config.demand.temperatures_output
    debug = config.debug
    weather_path = locator.get_weather_file()
    weather_data = epwreader.epw_reader(weather_path)[['year', 'drybulb_C', 'wetbulb_C',
                                                       'relhum_percent', 'windspd_ms', 'skytemp_C']]
    year = weather_data['year'][0]
    # create date range for the calculation year
    date_range = get_date_range_hours_from_year(year)

    # SPECIFY NUMBER OF BUILDINGS TO SIMULATE
    print('Running demand calculation for the following buildings=%s' % building_names)

    # CALCULATE OBJECT WITH PROPERTIES OF ALL BUILDINGS
    building_properties = BuildingProperties(locator, building_names)

    # add a message i2065 of warning. This needs a more elegant solution
    def calc_buildings_less_100m2(building_properties):
        footprint = building_properties._prop_geometry.footprint
        floors = building_properties._prop_geometry.floors_ag
        names = building_properties._prop_geometry.index
        GFA_m2 = [x * y for x, y in zip(footprint, floors)]
        list_buildings_less_100m2 = []
        for name, gfa in zip(names, GFA_m2):
            if gfa < 100.0:
                list_buildings_less_100m2.append(name)
        return list_buildings_less_100m2

    list_buildings_less_100m2 = calc_buildings_less_100m2(building_properties)
    if list_buildings_less_100m2 != []:
        print('Warning! The following list of buildings have less than 100 m2 of gross floor area, CEA might fail: %s' % list_buildings_less_100m2)

    # DEMAND CALCULATION
    n = len(building_names)
    calc_thermal_loads = cea.utilities.parallel.vectorize(thermal_loads.calc_thermal_loads,
                                                          config.get_number_of_processes(), on_complete=print_progress)

    calc_thermal_loads(
        building_names,
        [building_properties[b] for b in building_names],
        repeat(weather_data, n),
        repeat(date_range, n),
        repeat(locator, n),
        repeat(use_dynamic_infiltration, n),
        repeat(resolution_output, n),
        repeat(loads_output, n),
        repeat(massflows_output, n),
        repeat(temperatures_output, n),
        repeat(config, n),
        repeat(debug, n))

    # WRITE TOTAL YEARLY VALUES
    writer_totals = demand_writers.YearlyDemandWriter(loads_output, massflows_output, temperatures_output)
    totals, time_series = writer_totals.write_to_csv(building_names, locator)
    time_elapsed = time.clock() - t0
    print('done - time elapsed: %d.2 seconds' % time_elapsed)

    return totals, time_series