Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# imports
# standard
import math
import random
from numbers import Real
from statistics import mean
import geopandas as gpd
# *****************************************************************************
# *****************************************************************************
# local, internal
from src.topupopt.data.gis.utils import read_gdf_file
from src.topupopt.data.buildings.dk import heat
from src.topupopt.data.buildings.dk import bbr
# *****************************************************************************
# *****************************************************************************
class TestDataBuildingsDK:
# *************************************************************************
# *************************************************************************
def test_demand_dict(self):
# heat_demand_dict_by_building_entrance
osm_data_filename = 'tests/data/gdf_osm.gpkg'
building_data_filename = 'tests/data/gdf_buildings.gpkg'
bdg_gdf_container_columns = ('ejerskaber','koordinater','bygningspunkt')
number_time_intervals = 12
min_to_max_ratio = 0.1
intraperiod_time_interval_duration = [
30*24*3600
for i in range(number_time_intervals)
]
annual_heat_demand_scenario = 1000
total_area = 1000
air_temperature_scenario = [10 for i in range(number_time_intervals)]
gdf_osm = gpd.read_file(osm_data_filename)
gdf_osm.set_index(['element_type', 'osmid'], drop=True, inplace=True)
gdf_buildings = read_gdf_file(
filename=building_data_filename,
packed_columns=bdg_gdf_container_columns,
index='index'
)
# order by state
heat_demand_dict = heat.heat_demand_dict_by_building_entrance(
gdf_osm=gdf_osm,
gdf_buildings=gdf_buildings,
number_intervals=number_time_intervals,
time_interval_durations=intraperiod_time_interval_duration,
bdg_min_to_max_ratio={
index: min_to_max_ratio for index in gdf_buildings.index
},
bdg_specific_demand={
index: annual_heat_demand_scenario/total_area
for index in gdf_buildings.index
},
bdg_demand_phase_shift=None,
avg_state=air_temperature_scenario,
state_correlates_with_output=False
)
assert type(heat_demand_dict) == dict
assert len(heat_demand_dict) == len(gdf_osm)
# no state preference, use phase shift
heat_demand_dict2 = heat.heat_demand_dict_by_building_entrance(
gdf_osm=gdf_osm,
gdf_buildings=gdf_buildings,
number_intervals=number_time_intervals,
time_interval_durations=intraperiod_time_interval_duration,
bdg_min_to_max_ratio={
index: min_to_max_ratio for index in gdf_buildings.index
},
bdg_specific_demand={
index: annual_heat_demand_scenario/total_area
for index in gdf_buildings.index
},
bdg_demand_phase_shift={
index: 2*math.pi*random.random() for index in gdf_buildings.index
},
avg_state=None,
state_correlates_with_output=False
)
assert type(heat_demand_dict2) == dict
assert len(heat_demand_dict2) == len(gdf_osm)
# total heating area
heating_area = heat.total_heating_area(gdf_osm, gdf_buildings)
assert isinstance(heating_area, Real)
assert math.isclose(heating_area, 100882, abs_tol=1e-3)
# *************************************************************************
# *************************************************************************
# def test_bbr(self):
# # test get_bbr_building_data_geodataframe
# osm_data_filename = 'tests/data/gdf_osm.gpkg'
# gdf_osm = gpd.read_file(osm_data_filename)
# gdf_osm.set_index(['element_type', 'osmid'], drop=True, inplace=True)
# error_raised = False
# try:
# gdf_buildings, drop_list = bbr.get_bbr_building_data_geodataframe(
# list(gdf_osm[heat.label_osm_entrance_id]),
# None,
# None,
# None)
# except UnboundLocalError:
# error_raised = True
# assert error_raised
# # drop the rows with no data
# gdf_osm = gdf_osm.drop(
# index=[
# (gdf_osm[
# gdf_osm[
# heat.label_osm_entrance_id
# ]==bdg_entrance_id].index)[0]
# for bdg_entrance_id in drop_list
# ]
# )
# *****************************************************************************
# *****************************************************************************