Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111402874
merge_commune_all.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
Thu, May 1, 09:25
Size
1 KB
Mime Type
text/x-python
Expires
Sat, May 3, 09:25 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25893640
Attached To
R8800 solar_potential
merge_commune_all.py
View Options
import
numpy
as
np
import
pandas
as
pd
import
xarray
as
xr
import
os
import
time
import
sys
COMM_FP
=
'/work/hyenergy/output/solar_potential/Sonnendach_Gemeinden_Dachflaechen.csv'
OUTFILE
=
sys
.
argv
[
1
]
INFILES
=
lambda
i
:
(
os
.
path
.
splitext
(
OUTFILE
)[
0
]
+
'_
%d
.nc'
%
i
)
N_BATCHES
=
int
(
sys
.
argv
[
2
])
OUT_PV
=
os
.
path
.
splitext
(
OUTFILE
)[
0
]
+
'_pv.csv'
OUT_GT
=
os
.
path
.
splitext
(
OUTFILE
)[
0
]
+
'_gt.csv'
# Load data
comm_map
=
pd
.
read_csv
(
COMM_FP
,
encoding
=
'cp1250'
,
usecols
=
[
'DF_UID'
,
'BFS_NUMMER'
,
'NAME'
]
)
# For-loop
init
=
True
gt_weight
=
0
BFS_IDs
=
np
.
sort
(
comm_map
.
BFS_NUMMER
.
unique
())
for
BATCH
in
range
(
N_BATCHES
):
tt
=
time
.
time
()
try
:
new_data
=
xr
.
open_dataset
(
INFILES
(
BATCH
)
)
new_df
=
new_data
.
to_dataframe
()
.
dropna
()
.
reset_index
()
pv_new_df
=
new_df
.
pivot
(
values
=
'pv_potential'
,
index
=
'time'
,
columns
=
'BFS_NUMMER'
)
gt_new_df
=
new_df
.
pivot
(
values
=
'gt_weighted_by_APV'
,
index
=
'time'
,
columns
=
'BFS_NUMMER'
)
if
init
:
init
=
False
pv_df
=
pd
.
DataFrame
(
index
=
pv_new_df
.
index
,
columns
=
BFS_IDs
)
.
fillna
(
0
)
gt_df
=
pd
.
DataFrame
(
index
=
pv_new_df
.
index
,
columns
=
BFS_IDs
)
.
fillna
(
0
)
A_df
=
pd
.
Series
(
np
.
zeros
(
len
(
BFS_IDs
)),
index
=
BFS_IDs
)
pv_df
[
pv_new_df
.
columns
]
+=
pv_new_df
gt_df
[
gt_new_df
.
columns
]
+=
gt_new_df
A_df
[
new_data
.
BFS_NUMMER
.
values
]
+=
new_data
.
APV_weight_sum
.
to_pandas
()
except
:
print
(
'Error loading
%s
'
%
INFILES
(
BATCH
))
print
(
'Executed iteration
%i
in
%.2f
s'
%
(
BATCH
,
time
.
time
()
-
tt
))
gt_df
.
loc
[:,
A_df
>
0
]
/=
A_df
[
A_df
>
0
]
print
(
pv_df
.
head
())
print
(
gt_df
.
head
())
# Save output
tt
=
time
.
time
()
pv_df
.
to_csv
(
OUT_PV
)
gt_df
.
to_csv
(
OUT_GT
)
print
(
'
\n
Saved outputs
%s
and
%s
in
%.2f
s'
%
(
OUT_PV
,
OUT_GT
,
time
.
time
()
-
tt
))
Event Timeline
Log In to Comment