コード例 #1
0
    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]))
コード例 #2
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]))
コード例 #3
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)
コード例 #4
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]))
コード例 #5
0
    def test_mixed_use_schedules(self):
        locator = ReferenceCaseOpenLocator()

        # calculate schedules
        list_uses = ['OFFICE', 'INDUSTRIAL']
        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(
            date, locator, list_uses)
        calculated_schedules = calc_schedules(list_uses, archetype_schedules,
                                              occupancy, archetype_values)

        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]))
コード例 #6
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())

    # calculate schedules
    list_uses = ['OFFICE', 'INDUSTRIAL']
    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(
        date, locator, list_uses)
    calculated_schedules = calc_schedules(list_uses, archetype_schedules,
                                          occupancy, archetype_values)
    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)
コード例 #7
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)
コード例 #8
0
    def test_mixed_use_archetype_values(self):
        # test if a sample mixed use building gets standard results
        locator = ReferenceCaseOpenLocator()
        config = ConfigParser.SafeConfigParser()
        config.read(get_test_config_path())

        calculated_results = calculate_test_mixed_use_archetype_values_results(
            locator).to_dict()

        # compare to reference values
        expected_results = pd.DataFrame(
            data=[['B1', 0.5, 0.5, 208.947368, 12.9],
                  ['B2', 0.25, 0.75, 236.382979, 11.4]],
            columns=['Name', 'OFFICE', 'GYM', 'X_ghp', 'El_Wm2'])

        expected_results = json.loads(
            config.get('test_mixed_use_archetype_values', 'expected_results'))
        for column, rows in expected_results.items():
            self.assertIn(column, calculated_results)
            for building, value in rows.items():
                self.assertIn(building, calculated_results[column])
                self.assertAlmostEqual(value,
                                       calculated_results[column][building], 4)

        architecture_DB = get_database(locator.get_archetypes_properties(),
                                       'ARCHITECTURE')
        architecture_DB['Code'] = architecture_DB.apply(
            lambda x: x['building_use'] + str(x['year_start']) + str(x[
                'year_end']) + x['standard'],
            axis=1)

        self.assertEqual(
            correct_archetype_areas(prop_architecture_df=pd.DataFrame(
                data=[['B1', 0.5, 0.5, 0.0, 2006, 2020, 'C'],
                      ['B2', 0.2, 0.8, 0.0, 1000, 1920, 'R']],
                columns=[
                    'Name', 'SERVERROOM', 'PARKING', 'Hs', 'year_start',
                    'year_end', 'standard'
                ]),
                                    architecture_DB=architecture_DB,
                                    list_uses=['SERVERROOM', 'PARKING']),
            [0.5, 0.2])
コード例 #9
0
    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]))
コード例 #10
0
    def test_mixed_use_archetype_values(self):
        # test if a sample mixed use building gets standard results
        locator = ReferenceCaseOpenLocator()
        config = ConfigParser.SafeConfigParser()
        config.read(get_test_config_path())

        calculated_results = calculate_mixed_use_archetype_values_results(locator).to_dict()
        print(calculated_results)
        # compare to reference values
        expected_results = json.loads(config.get('test_mixed_use_archetype_values', 'expected_results'))
        for column, rows in expected_results.items():
            self.assertIn(column, calculated_results)
            for building, value in rows.items():
                self.assertIn(building, calculated_results[column])
                self.assertAlmostEqual(value, calculated_results[column][building], 4)