Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111263554
prepare_area_query.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Apr 30, 11:14
Size
3 KB
Mime Type
text/x-python
Expires
Fri, May 2, 11:14 (2 d)
Engine
blob
Format
Raw Data
Handle
25900415
Attached To
R8800 solar_potential
prepare_area_query.py
View Options
import
pandas
as
pd
import
numpy
as
np
from
rooftop_handling
import
get_tilt_category
,
get_orientation_category
import
os
import
sys
import
time
###### GET DATA #########
ROOFS_info
=
sys
.
argv
[
1
]
ROOFS_corners
=
sys
.
argv
[
2
]
PANELS_ftr
=
sys
.
argv
[
3
]
SHADE_ftr
=
sys
.
argv
[
4
]
SHADE_cats
=
sys
.
argv
[
5
]
OUTFILE
=
sys
.
argv
[
6
]
############################
TILT_FIELD
=
'NEIGUNG'
ORIENTATION_FIELD
=
'AUSRICHTUN'
## == FUNCTION DEFINITIONS ==
def
print_input
():
print
(
""
)
print
(
'Rooftop info file:
%s
'
%
ROOFS_info
)
print
(
'Roof corner file:
%s
'
%
ROOFS_corners
)
print
(
'Panelling feature file:
%s
'
%
PANELS_ftr
)
print
(
'Shading feature file:
%s
'
%
SHADE_ftr
)
print
(
'Shading categories file:
%s
'
%
SHADE_cats
)
print
(
'Output file:
%s
'
%
OUTFILE
)
print
(
""
)
def
replace_shade_NaNs
(
roofs
,
shade_cats
):
# finds all rows in "roofs" with column "shaded_area_ratio_ftr" == NaN, and replaces these with the mean values
# in "shade_cats" based on the categorizations of "tilt_cat" and "orientation_cat" (specified in rooftop_handling.py)
# get columns with shaded area NaN and calculate tilt and orientation categories for these
shade_null_idx
=
roofs
.
shaded_area_ratio_ftr
.
isnull
()
replacemnt_shade
=
roofs
.
loc
[
shade_null_idx
,
[
'DF_UID'
,
TILT_FIELD
,
ORIENTATION_FIELD
]]
replacemnt_shade
.
rename
(
{
TILT_FIELD
:
'NEIGUNG'
,
ORIENTATION_FIELD
:
'AUSRICHTUNG'
},
axis
=
1
,
inplace
=
True
)
replacemnt_shade
[
'tilt_cat'
]
=
replacemnt_shade
.
apply
(
get_tilt_category
,
axis
=
1
)
replacemnt_shade
[
'orientation_cat'
]
=
replacemnt_shade
.
apply
(
get_orientation_category
,
axis
=
1
)
# find mean values for all rows with shaded area ratio NaN and replace
replaced_shade
=
replacemnt_shade
.
merge
(
shade_cats
.
loc
[:,[
'orientation_cat'
,
'tilt_cat'
,
'fully_shaded_ratio'
]],
how
=
'left'
,
on
=
[
'orientation_cat'
,
'tilt_cat'
])
roofs
.
loc
[
shade_null_idx
,
'shaded_area_ratio_ftr'
]
=
replaced_shade
.
fully_shaded_ratio
.
values
return
roofs
## == Load data ==
print_input
()
timer
=
time
.
time
()
roofs_info
=
pd
.
read_csv
(
ROOFS_info
)
roofs_corners
=
pd
.
read_csv
(
ROOFS_corners
)
panels_ftr
=
pd
.
read_csv
(
PANELS_ftr
)
shade_ftr
=
pd
.
read_csv
(
SHADE_ftr
,
usecols
=
[
'DF_UID'
,
'fully_shaded_ratio'
])
shade_cats
=
pd
.
read_csv
(
SHADE_cats
)
print
(
'Read all data in
%.3f
seconds'
%
(
time
.
time
()
-
timer
))
timer
=
time
.
time
()
## == Merge roofs with shading info and roofs with panelled area info
## Step 1: merge information of number of vertices (roofs_corners) to rooftop information
roofs
=
roofs_info
.
merge
(
roofs_corners
,
on
=
'DF_UID'
)
print
(
'Merged rooftop information in
%.3f
seconds'
%
(
time
.
time
()
-
timer
))
timer
=
time
.
time
()
## Step 2: add panel information (available for all rooftops, based on Sonnendach roof polygons)
## NOTE: all roofs with panelled area == 0 can be excluded from analysis - they are unsuitable for PV installation
roofs_with_available_area
=
panels_ftr
[
panels_ftr
.
panel_count
>
0
]
set_panels_ftr
=
roofs_with_available_area
.
loc
[:,[
'DF_UID'
,
'panel_tilt'
,
'best_align'
,
'panelled_area_ratio'
]]
# merge panelled area ratio for features
roofs_w_panels
=
roofs
.
merge
(
set_panels_ftr
,
how
=
'inner'
,
on
=
'DF_UID'
)
roofs_w_panels
.
rename
(
{
'panelled_area_ratio'
:
'panelled_area_ratio_ftr'
},
axis
=
1
,
inplace
=
True
)
print
(
'Added panel fitting information in
%.3f
seconds'
%
(
time
.
time
()
-
timer
))
timer
=
time
.
time
()
## Step 3: add shading information (shaded area only)
## Not available for all roofs (missing approx. 20%) - unavailable data is filled using shade_cats
roofs_w_shade
=
roofs_w_panels
.
merge
(
shade_ftr
,
how
=
'left'
,
on
=
'DF_UID'
)
roofs_w_shade
.
rename
({
'fully_shaded_ratio'
:
'shaded_area_ratio_ftr'
},
axis
=
1
,
inplace
=
True
)
print
(
'Added shading information in
%.3f
seconds'
%
(
time
.
time
()
-
timer
))
timer
=
time
.
time
()
roofs_final
=
replace_shade_NaNs
(
roofs_w_shade
,
shade_cats
)
print
(
'Replaced NaNs of shading in
%.3f
seconds'
%
(
time
.
time
()
-
timer
))
timer
=
time
.
time
()
## == Save results as csv
roofs_final
.
to_csv
(
OUTFILE
,
index
=
False
)
print
(
'DONE - saved output to
%s
'
%
OUTFILE
)
Event Timeline
Log In to Comment