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
def epw_reader(weather_path): epw_data = epw_to_dataframe(weather_path) year = epw_data["year"][0] # Create date range from epw data date_range = pd.DatetimeIndex( pd.to_datetime(dict(year=epw_data.year, month=epw_data.month, day=epw_data.day, hour=epw_data.hour - 1)) ) epw_data['date'] = date_range epw_data['dayofyear'] = date_range.dayofyear if isleap(year): epw_data = epw_data[~((date_range.month == 2) & (date_range.day == 29))].reset_index() # Make sure data has the correct number of rows if len(epw_data) != HOURS_IN_YEAR: # Check for missing dates from expected date range expected_date_index = get_date_range_hours_from_year(year) difference = expected_date_index.difference(epw_data.index) if len(difference): print(f"Dates missing: {difference}") raise Exception('Incorrect number of rows. Expected {}, got {}'.format(HOURS_IN_YEAR, len(epw_data))) epw_data['ratio_diffhout'] = epw_data['difhorrad_Whm2'] / epw_data['glohorrad_Whm2'] epw_data['ratio_diffhout'] = epw_data['ratio_diffhout'].replace(np.inf, np.nan) epw_data['wetbulb_C'] = np.vectorize(calc_wetbulb)(epw_data['drybulb_C'], epw_data['relhum_percent']) epw_data['skytemp_C'] = np.vectorize(calc_skytemp)(epw_data['drybulb_C'], epw_data['dewpoint_C'], epw_data['opaqskycvr_tenths']) return epw_data
def schedule_maker_main(locator, config, building=None): # local variables buildings = config.schedule_maker.buildings schedule_model = config.schedule_maker.schedule_model if schedule_model == 'deterministic': stochastic_schedule = False elif schedule_model == 'stochastic': stochastic_schedule = True else: raise ValueError("Invalid schedule model: {schedule_model}".format(**locals())) if building != None: buildings = [building] # this is to run the tests # CHECK DATABASE if is_3_22(config.scenario): raise ValueError("""The data format of indoor comfort has been changed after v3.22. Please run Data migrator in Utilities.""") # get variables of indoor comfort and internal loads internal_loads = dbf_to_dataframe(locator.get_building_internal()).set_index('Name') indoor_comfort = dbf_to_dataframe(locator.get_building_comfort()).set_index('Name') architecture = dbf_to_dataframe(locator.get_building_architecture()).set_index('Name') # get building properties prop_geometry = Gdf.from_file(locator.get_zone_geometry()) prop_geometry['footprint'] = prop_geometry.area prop_geometry['GFA_m2'] = prop_geometry['footprint'] * (prop_geometry['floors_ag'] + prop_geometry['floors_bg']) prop_geometry['GFA_ag_m2'] = prop_geometry['footprint'] * prop_geometry['floors_ag'] prop_geometry['GFA_bg_m2'] = prop_geometry['footprint'] * prop_geometry['floors_bg'] prop_geometry = prop_geometry.merge(architecture, on='Name').set_index('Name') prop_geometry = calc_useful_areas(prop_geometry) # get calculation year from weather file 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) # SCHEDULE MAKER n = len(buildings) calc_schedules_multiprocessing = cea.utilities.parallel.vectorize(calc_schedules, config.get_number_of_processes(), on_complete=print_progress) calc_schedules_multiprocessing(repeat(locator, n), buildings, repeat(date_range, n), [internal_loads.loc[b] for b in buildings], [indoor_comfort.loc[b] for b in buildings], [prop_geometry.loc[b] for b in buildings], repeat(stochastic_schedule, n)) return None
def calc_datetime_local_from_weather_file(weather_data, latitude, longitude): # read date from the weather file year = weather_data['year'][0] datetime = get_date_range_hours_from_year(year) # get local time zone etc_timezone = get_local_etc_timezone(latitude, longitude) # convert to local time zone datetime_local = datetime.tz_localize(tz=etc_timezone) return datetime_local
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())
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