Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F110249791
fill_shading_CH_v2.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
Fri, Apr 25, 08:58
Size
3 KB
Mime Type
text/x-python
Expires
Sun, Apr 27, 08:58 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25775410
Attached To
R8800 solar_potential
fill_shading_CH_v2.py
View Options
import
pandas
as
pd
import
numpy
as
np
import
xarray
as
xr
from
rooftop_handling
import
get_tilt_category
,
get_orientation_category
import
os
import
time
## == PATH DEFINITIONS == ##
path
=
'/work/hyenergy/output/solar_potential/geographic_potential/available_area/shading_stats'
data
=
'CH_LV03/CH_shading_all.csv'
cats
=
'CH_shading_categories.csv'
roofs
=
'/work/hyenergy/output/solar_potential/geographic_potential/available_area/ROOFS_CH_replaced.csv'
## == LOAD DATA == ##
tt
=
time
.
time
()
print
(
'
\n
Reading data ...'
)
shading_cats
=
pd
.
read_csv
(
os
.
path
.
join
(
path
,
cats
))
roof_cols
=
pd
.
read_csv
(
roofs
,
usecols
=
[
'DF_UID'
,
'NEIGUNG'
,
'AUSRICHTUNG'
]
)
shading
=
pd
.
read_csv
(
os
.
path
.
join
(
path
,
data
))
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
## == GET ALL ROOF UIDs == ##
tt
=
time
.
time
()
print
(
'Merging roofs and shading...'
)
all_roofs
=
roof_cols
.
merge
(
shading
,
on
=
'DF_UID'
,
how
=
'left'
)
all_roofs
.
drop_duplicates
(
inplace
=
True
)
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
## == GET MISSING ROOF ID'S & CORRESPONDING DATA == ##
tt
=
time
.
time
()
print
(
'Getting replacement values...'
)
shade_null_idx
=
all_roofs
[
'fully_shaded_ratio'
]
.
isnull
()
replacemnt_shade
=
all_roofs
.
loc
[
shade_null_idx
,
[
'DF_UID'
,
'NEIGUNG'
,
'AUSRICHTUNG'
]]
replacemnt_shade
[
'tilt_cat'
]
=
replacemnt_shade
.
apply
(
get_tilt_category
,
axis
=
1
)
replacemnt_shade
[
'orientation_cat'
]
=
replacemnt_shade
.
apply
(
get_orientation_category
,
axis
=
1
)
REPLACEMENT
=
replacemnt_shade
.
merge
(
shading_cats
,
how
=
'left'
,
on
=
[
'orientation_cat'
,
'tilt_cat'
])
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
## == REPLACE MISSING DATA == ##
tt
=
time
.
time
()
print
(
'Replacing missing data...'
)
replace
=
REPLACEMENT
[
all_roofs
.
columns
]
all_roofs
.
loc
[
shade_null_idx
]
=
replace
.
values
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
## == SELECT RELEVANT COLUMNS == ##
tt
=
time
.
time
()
print
(
'Saving fully shaded data to file...'
)
data
=
all_roofs
[
shading
.
columns
]
fully_shaded
=
data
[[
'DF_UID'
,
'non_null_cells'
,
'n_cells'
,
'fully_shaded_ratio'
]]
.
set_index
(
'DF_UID'
)
partly_shaded
=
data
.
drop
(
columns
=
[
'non_null_cells'
,
'n_cells'
,
'fully_shaded_ratio'
]
)
.
set_index
(
'DF_UID'
)
print
(
fully_shaded
.
head
())
print
(
fully_shaded
.
columns
)
# fully_shaded.to_csv("/work/hyenergy/output/solar_potential/geographic_potential/available_area/CH_fully_shaded_replaced.csv")
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
## == RENAME COLUMNS OF PARTLY SHADING == ##
tt
=
time
.
time
()
print
(
'Renaming partly shaded rows to timestamps...'
)
col_dict
=
{}
for
col_name
in
partly_shaded
.
columns
:
tmp
=
col_name
.
split
(
'_'
)
if
tmp
[
0
]
==
'mean'
:
month
=
tmp
[
1
]
hour
=
tmp
[
2
]
else
:
continue
col_dict
[
col_name
]
=
pd
.
to_datetime
(
'2001-
%s
-15
%s
'
%
(
month
,
hour
))
# partly_shaded.rename( { col_name : pd.to_datetime('2001-%s-15 %s' %(month, hour))}, axis = 1, inplace = True )
print
(
col_dict
)
partly_shaded
.
rename
(
col_dict
,
axis
=
1
,
inplace
=
True
)
print
(
partly_shaded
.
head
())
print
(
partly_shaded
.
columns
)
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
tt
=
time
.
time
()
print
(
'Saving replaced partly shading stats to file...'
)
partly_shaded
.
to_csv
(
"/scratch/walch/scratch/CH_partly_shaded_replaced.csv"
)
print
(
'Finished in
%.3f
seconds
\n
'
%
(
time
.
time
()
-
tt
))
Event Timeline
Log In to Comment