Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Global Dynamic Exposure
gde-importer
Commits
2ba96d5b
Commit
2ba96d5b
authored
Nov 15, 2021
by
Cecilia Nievas
Browse files
Added feature to retrieve distribution of population at different times
parent
f98fb03c
Pipeline
#30455
passed with stage
in 2 minutes and 40 seconds
Changes
9
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
gdeimporter/aggregatedexposuremodel.py
View file @
2ba96d5b
...
...
@@ -246,6 +246,25 @@ class ExposureModelESRM20(AggregatedExposureModel):
self
.
file_structure
=
{
"metadata"
:
"sources/European_Exposure_Model_Data_Inputs_Sources.xlsx"
,
"CSVs"
:
"_exposure_models"
,
"population_time_distribution"
:
{
"filename"
:
"social_indicators/population_distribution_PAGER.xlsx"
,
"tab"
:
"data"
,
"residential"
:
{
"Day"
:
"RES_DAY"
,
"Night"
:
"RES_NIGHT"
,
"Transit"
:
"RES_TRANSIT"
,
},
"commercial"
:
{
"Day"
:
"NONRES_DAY"
,
"Night"
:
"NONRES_NIGHT"
,
"Transit"
:
"NONRES_TRANSIT"
,
},
"industrial"
:
{
"Day"
:
"NONRES_DAY"
,
"Night"
:
"NONRES_NIGHT"
,
"Transit"
:
"NONRES_TRANSIT"
,
},
},
}
self
.
csv_column_names
=
{
"Buildings"
:
"BUILDINGS"
,
...
...
@@ -310,12 +329,22 @@ class ExposureModelESRM20(AggregatedExposureModel):
"with retrieve_exposure_entities"
%
configuration
.
exposure_format
)
# Read metadata on the distribution of population during day, night and transit times
population_time
=
pandas
.
read_excel
(
os
.
path
.
join
(
configuration
.
data_pathname
,
self
.
file_structure
[
"population_time_distribution"
][
"filename"
],
),
sheet_name
=
self
.
file_structure
[
"population_time_distribution"
][
"tab"
],
index_col
=
0
,
# Use first column as index
)
# Needs to go by occupancy case because the names and properties of the exposure
# entities can only be read from the metadata file for a sheet that is associated
# with a particular occupancy case:
for
case
in
self
.
occupancy_cases
.
keys
():
# Read the file (errors will be handled by pandas)
# Read the
general metadata
file (errors will be handled by pandas)
metadata
=
pandas
.
read_excel
(
os
.
path
.
join
(
configuration
.
data_pathname
,
self
.
file_structure
[
"metadata"
]),
sheet_name
=
self
.
occupancy_cases
[
case
][
"sheet_name"
],
...
...
@@ -375,8 +404,19 @@ class ExposureModelESRM20(AggregatedExposureModel):
"data_units_type"
:
data_units_type
,
"data_units_level"
:
data_units_level
,
"data_units_definition"
:
data_units_definition
,
"population_time_distribution"
:
{},
}
for
time
in
self
.
file_structure
[
"population_time_distribution"
][
case
].
keys
():
output
[
"population_time_distribution"
][
time
]
=
round
(
population_time
.
loc
[
exposure_entity
,
self
.
file_structure
[
"population_time_distribution"
][
case
][
time
],
]
/
100.0
,
7
,
)
# Write the contents occupancy_cases to the ExposureEntity object
exposure_entities
[
exposure_entity
].
occupancy_cases
[
case
]
=
output
...
...
gdeimporter/exposureentity.py
View file @
2ba96d5b
...
...
@@ -76,6 +76,21 @@ class ExposureEntity:
| | represent the smallest geographical unit where an exposure model
| | is defined. See attributes in description of DataUnit. The keys
| | of the dictionary are the IDs of the corresponding data units.
| |_ population_time_distribution (dict):
| | Dictionary containing factors by which the census population per
| | building can be multiplied to obtain an estimate of the
| | in the buildings at a certain time of the day. It contains the
| | following keys:
| | Day (float):
| | Factor to obtain the population expected to be inside the
| | buildings during the day (approx. 10 am to 6 pm).
| | Night (float):
| | Factor to obtain the population expected to be inside the
| | buildings during the night (approx. 10 pm to 6 am).
| | Transit (float):
| | Factor to obtain the population expected to be inside the
| | buildings during transit times (approx. 6 am to 10 am and
| | 6 pm to 10 pm).
|_ occupancy_cases.keys()[1]
| |_ data_units_type: ...
|_ ...
...
...
tests/data/ExposureModelESRM20_non_trivial/_exposure_models/Exposure_Model_Entity_1_Com.csv
View file @
2ba96d5b
LON,LAT,TAXONOMY,SETTLEMENT_TYPE,OCCUPANCY_TYPE,BUILDINGS,ID_1,
DWELLINGS,
AREA_PER_
DWELL
ING_SQM,COST_PER_AREA_EUR,TOTAL_REPL_COST_EUR,COST_STRUCTURAL_EUR,COST_NONSTRUCTURAL_EUR,COST_CONTENTS_EUR,OCCUPANTS_PER_ASSET,OCCUPANTS_PER_ASSET_DAY,OCCUPANTS_PER_ASSET_NIGHT,OCCUPANTS_PER_ASSET_TRANSIT,OCCUPANTS_PER_ASSET_AVERAGE
20.1,47.3,A,BIG_CITY,ALL,35.2,Unit_X,
35.2,
90,1400,316800000,126720000,63360000,126720000,1056,844.8,105.6,211.2,387.2
20.1,47.3,B,RURAL,ALL,12.7,Unit_X,
12.7,
120,1050,114300000,45720000,22860000,45720000,381,304.8,38.1,76.2,139.7
20.1,47.3,C,BIG_CITY,ALL,8.9,Unit_X,
8.9,
85,1300,80100000,32040000,16020000,32040000,267,213.6,26.7,53.4,97.9
20.1,47.3,C,BIG_CITY,ALL,5.7,Unit_X,
5.7,
85,1300,51300000,20520000,10260000,20520000,171,136.8,17.1,34.2,62.7
19.8,47.4,A,RURAL,ALL,25.6,Unit_Y,
25.6,
110,980,230400000,92160000,46080000,92160000,768,614.4,76.8,153.6,281.6
19.8,47.4,A,URBAN,ALL,7.9,Unit_Y,
7.9,
95,1280,71100000,28440000,14220000,28440000,237,189.6,23.7,47.4,86.9
19.8,47.4,B,RURAL,ALL,23.5,Unit_Y,
23.5,
120,1050,211500000,84600000,42300000,84600000,705,564,70.5,141,258.5
20.4,46.9,A,BIG_CITY,ALL,40.2,Unit_Z,
40.2,
90,1400,361800000,144720000,72360000,144720000,1206,964.8,120.6,241.2,442.2
20.4,46.9,B,BIG_CITY,ALL,16.3,Unit_Z,
16.3,
110,1100,146700000,58680000,29340000,58680000,489,391.2,48.9,97.8,179.3
20.4,46.9,C,RURAL,ALL,33.4,Unit_Z,
33.4,
115,1200,300600000,120240000,60120000,120240000,1002,801.6,100.2,200.4,367.4
LON,LAT,TAXONOMY,SETTLEMENT_TYPE,OCCUPANCY_TYPE,BUILDINGS,ID_1,AREA_PER_
BUILD
ING_SQM,COST_PER_AREA_EUR,TOTAL_REPL_COST_EUR,COST_STRUCTURAL_EUR,COST_NONSTRUCTURAL_EUR,COST_CONTENTS_EUR,OCCUPANTS_PER_ASSET,OCCUPANTS_PER_ASSET_DAY,OCCUPANTS_PER_ASSET_NIGHT,OCCUPANTS_PER_ASSET_TRANSIT,OCCUPANTS_PER_ASSET_AVERAGE
20.1,47.3,A,BIG_CITY,ALL,35.2,Unit_X,90,1400,316800000,126720000,63360000,126720000,1056,844.8,105.6,211.2,387.2
20.1,47.3,B,RURAL,ALL,12.7,Unit_X,120,1050,114300000,45720000,22860000,45720000,381,304.8,38.1,76.2,139.7
20.1,47.3,C,BIG_CITY,ALL,8.9,Unit_X,85,1300,80100000,32040000,16020000,32040000,267,213.6,26.7,53.4,97.9
20.1,47.3,C,BIG_CITY,ALL,5.7,Unit_X,85,1300,51300000,20520000,10260000,20520000,171,136.8,17.1,34.2,62.7
19.8,47.4,A,RURAL,ALL,25.6,Unit_Y,110,980,230400000,92160000,46080000,92160000,768,614.4,76.8,153.6,281.6
19.8,47.4,A,URBAN,ALL,7.9,Unit_Y,95,1280,71100000,28440000,14220000,28440000,237,189.6,23.7,47.4,86.9
19.8,47.4,B,RURAL,ALL,23.5,Unit_Y,120,1050,211500000,84600000,42300000,84600000,705,564,70.5,141,258.5
20.4,46.9,A,BIG_CITY,ALL,40.2,Unit_Z,90,1400,361800000,144720000,72360000,144720000,1206,964.8,120.6,241.2,442.2
20.4,46.9,B,BIG_CITY,ALL,16.3,Unit_Z,110,1100,146700000,58680000,29340000,58680000,489,391.2,48.9,97.8,179.3
20.4,46.9,C,RURAL,ALL,33.4,Unit_Z,115,1200,300600000,120240000,60120000,120240000,1002,801.6,100.2,200.4,367.4
tests/data/ExposureModelESRM20_non_trivial/_exposure_models/Exposure_Model_Entity_2_Com.csv
View file @
2ba96d5b
LON,LAT,TAXONOMY,BUILDINGS,OCCUPANCY_TYPE,ID_2,
DWELLINGS,
AREA_PER_
DWELL
ING_SQM,COST_PER_AREA_EUR,TOTAL_REPL_COST_EUR,COST_STRUCTURAL_EUR,COST_NONSTRUCTURAL_EUR,COST_CONTENTS_EUR,OCCUPANTS_PER_ASSET,OCCUPANTS_PER_ASSET_DAY,OCCUPANTS_PER_ASSET_NIGHT,OCCUPANTS_PER_ASSET_TRANSIT,OCCUPANTS_PER_ASSET_AVERAGE
20.6,46.8,A,38.72,Offices,Unit_A,
38.72,
150,1400,348480000,139392000,69696000,139392000,1161.6,929.28,116.16,232.32,425.92
20.6,46.8,B,13.97,Offices,Unit_A,
13.97,
200,1300,125730000,50292000,25146000,50292000,419.1,335.28,41.91,83.82,153.67
20.6,46.8,B,9.79,Hotels,Unit_A,
9.79,
500,1200,88110000,35244000,17622000,35244000,293.7,234.96,29.37,58.74,107.69
20.6,46.8,C,6.27,Trade,Unit_A,
6.27,
300,1100,56430000,22572000,11286000,22572000,188.1,150.48,18.81,37.62,68.97
20.3,46.9,A,28.16,Offices,Unit_B,
28.16,
150,1400,253440000,101376000,50688000,101376000,844.8,675.84,84.48,168.96,309.76
20.3,46.9,C,8.69,Trade,Unit_B,
8.69,
400,1500,78210000,31284000,15642000,31284000,260.7,208.56,26.07,52.14,95.59
20.3,46.9,C,25.85,Offices,Unit_B,
25.85,
250,1350,232650000,93060000,46530000,93060000,775.5,620.4,77.55,155.1,284.35
20.9,46.4,A,44.22,Offices,Unit_C,
44.22,
150,1400,397980000,159192000,79596000,159192000,1326.6,1061.28,132.66,265.32,486.42
20.9,46.4,B,17.93,Hotels,Unit_C,
17.93,
500,1200,161370000,64548000,32274000,64548000,537.9,430.32,53.79,107.58,197.23
20.9,46.4,C,36.74,Trade,Unit_C,
36.74,
300,1100,330660000,132264000,66132000,132264000,1102.2,881.76,110.22,220.44,404.14
LON,LAT,TAXONOMY,BUILDINGS,OCCUPANCY_TYPE,ID_2,AREA_PER_
BUILD
ING_SQM,COST_PER_AREA_EUR,TOTAL_REPL_COST_EUR,COST_STRUCTURAL_EUR,COST_NONSTRUCTURAL_EUR,COST_CONTENTS_EUR,OCCUPANTS_PER_ASSET,OCCUPANTS_PER_ASSET_DAY,OCCUPANTS_PER_ASSET_NIGHT,OCCUPANTS_PER_ASSET_TRANSIT,OCCUPANTS_PER_ASSET_AVERAGE
20.6,46.8,A,38.72,Offices,Unit_A,150,1400,348480000,139392000,69696000,139392000,1161.6,929.28,116.16,232.32,425.92
20.6,46.8,B,13.97,Offices,Unit_A,200,1300,125730000,50292000,25146000,50292000,419.1,335.28,41.91,83.82,153.67
20.6,46.8,B,9.79,Hotels,Unit_A,500,1200,88110000,35244000,17622000,35244000,293.7,234.96,29.37,58.74,107.69
20.6,46.8,C,6.27,Trade,Unit_A,300,1100,56430000,22572000,11286000,22572000,188.1,150.48,18.81,37.62,68.97
20.3,46.9,A,28.16,Offices,Unit_B,150,1400,253440000,101376000,50688000,101376000,844.8,675.84,84.48,168.96,309.76
20.3,46.9,C,8.69,Trade,Unit_B,400,1500,78210000,31284000,15642000,31284000,260.7,208.56,26.07,52.14,95.59
20.3,46.9,C,25.85,Offices,Unit_B,250,1350,232650000,93060000,46530000,93060000,775.5,620.4,77.55,155.1,284.35
20.9,46.4,A,44.22,Offices,Unit_C,150,1400,397980000,159192000,79596000,159192000,1326.6,1061.28,132.66,265.32,486.42
20.9,46.4,B,17.93,Hotels,Unit_C,500,1200,161370000,64548000,32274000,64548000,537.9,430.32,53.79,107.58,197.23
20.9,46.4,C,36.74,Trade,Unit_C,300,1100,330660000,132264000,66132000,132264000,1102.2,881.76,110.22,220.44,404.14
tests/data/ExposureModelESRM20_non_trivial/social_indicators/population_distribution_PAGER.xlsx
0 → 100644
View file @
2ba96d5b
File added
tests/data/ExposureModelESRM20_repeated_col/social_indicators/population_distribution_PAGER.xlsx
0 → 100644
View file @
2ba96d5b
File added
tests/data/ExposureModelESRM20_repeated_field/social_indicators/population_distribution_PAGER.xlsx
0 → 100644
View file @
2ba96d5b
File added
tests/data/expected_results_population_time_distribution.csv
0 → 100644
View file @
2ba96d5b
Exposure_Entity,residential_Day,residential_Night,residential_Transit,commercial_Day,commercial_Night,commercial_Transit,industrial_Day,industrial_Night,industrial_Transit
Entity_1,0.3152198,0.9806095,0.6666045,0.3437615,0.0167615,0.0361393,0.3437615,0.0167615,0.0361393
Entity_2,0.2218848,0.9466345,0.5020595,0.530598,0.0480615,0.1025873,0.530598,0.0480615,0.1025873
Entity_3,0.2459968,0.9655865,0.5782345,0.420349,0.0306245,0.0656878,0.420349,0.0306245,0.0656878
Entity_4,0.2036243,0.9384255,0.4664715,0.5684185,0.0557305,0.1159908,0.5684185,0.0557305,0.1159908
Entity_5,0.1873898,0.9363455,0.448765,0.5857665,0.0575465,0.1227253,0.5857665,0.0575465,0.1227253
Entity_6,0.2954163,0.9745045,0.6377095,0.3656715,0.0225345,0.0445928,0.3656715,0.0225345,0.0445928
Entity_7,0.2124588,0.949209,0.505847,0.5103985,0.0457365,0.0968598,0.5103985,0.0457365,0.0968598
Entity_8,0.0809063,0.896849,0.265278,0.7723475,0.0943445,0.1900738,0.7723475,0.0943445,0.1900738
tests/test_aggregatedexposuremodel.py
View file @
2ba96d5b
...
...
@@ -149,6 +149,16 @@ def test_ExposureModelESRM20():
expected_contents
[
"Entity_7"
][
"industrial"
][
"data_units_definition"
]
=
"NUTS"
expected_contents
[
"Entity_8"
][
"industrial"
][
"data_units_definition"
]
=
"WGS84"
expected_population_time_distribution
=
pandas
.
read_csv
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"data"
,
"expected_results_population_time_distribution.csv"
,
),
sep
=
","
,
index_col
=
0
,
# Use first column as index
)
# Compare
for
i
,
exposure_entity
in
enumerate
(
returned_aem
.
exposure_entities
.
keys
()):
assert
returned_aem
.
exposure_entities
[
exposure_entity
].
name
==
expected_names
[
i
]
...
...
@@ -165,6 +175,17 @@ def test_ExposureModelESRM20():
==
expected_contents
[
"Entity_%s"
%
(
i
+
1
)][
case
][
parameter
]
)
for
time
in
[
"Day"
,
"Night"
,
"Transit"
]:
column
=
"%s_%s"
%
(
case
,
time
)
assert
round
(
returned_aem
.
exposure_entities
[
exposure_entity
].
occupancy_cases
[
case
][
"population_time_distribution"
][
time
],
7
,
)
==
round
(
expected_population_time_distribution
.
loc
[
exposure_entity
,
column
],
7
)
# Go on to test the retrieval of the data units
exposure_entities_to_run
=
[
"Entity_1"
,
"Entity_2"
]
occupancies_to_run
=
[
"residential"
,
"commercial"
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment