Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F118369050
efficiency_mapping.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, Jun 19, 14:09
Size
3 KB
Mime Type
text/x-python
Expires
Sat, Jun 21, 14:09 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
26847159
Attached To
R8800 solar_potential
efficiency_mapping.py
View Options
import
numpy
as
np
import
xarray
as
xr
import
pandas
as
pd
from
pvlib
import
pvsystem
import
os
import
time
import
util
import
sys
## === SPECIFY FILE PATHS === ##
NAME
=
sys
.
argv
[
1
]
WORKDIR
=
'/scratch/walch/scenarios_GVA'
tilted_irrad_fp
=
os
.
path
.
join
(
WORKDIR
,
'tilted_irrad_GVA_flat_
%s
.nc'
%
NAME
)
# TILTED RADIATION FILE PATH
performance_fp
=
'/work/hyenergy/output/solar_potential/technical_potential/pv_efficiencies.nc'
# PANEL PERFORMANCE FILE PATH
T_max_mmd_fp
=
'/work/hyenergy/output/solar_potential/technical_potential/Tmax_surface_mmd.nc'
# MAX TEMPERATURE MMD FILE PATH
ROOFS_fp
=
os
.
path
.
join
(
WORKDIR
,
'flat_roofs_GVA_
%s
.csv'
%
NAME
)
# ROOFTOP CHARACTERISTICS FILE PATH
OUTFILE
=
os
.
path
.
join
(
WORKDIR
,
'efficiency_mapped_GVA_flat_
%s
.nc'
%
NAME
)
# FILE PATH FOR OUTPUT FILE
## === LOAD DATA === ##
tilted_irrad
=
xr
.
open_mfdataset
(
tilted_irrad_fp
,
chunks
=
{
'DF_UID'
:
100000
}
)
performance
=
xr
.
open_dataset
(
performance_fp
)
T_max_mmd
=
xr
.
open_dataset
(
T_max_mmd_fp
)
roofs
=
pd
.
read_csv
(
ROOFS_fp
,
usecols
=
[
'DF_UID'
,
'XCOORD'
,
'YCOORD'
])
OUTPATH
=
os
.
path
.
split
(
OUTFILE
)[
0
]
try
:
os
.
mkdir
(
os
.
path
.
join
(
OUTPATH
,
'tmp'
)
)
except
:
print
(
'tmp directory already exists'
)
# get pixel coordinates of roofs, by rounding to the coordinate of the closest pixel
roofs
[
'chx'
]
=
util
.
round_to_interval
(
roofs
[
'XCOORD'
]
-
500
,
1000
)
+
500
roofs
[
'chy'
]
=
util
.
round_to_interval
(
roofs
[
'YCOORD'
]
-
500
,
1000
)
+
500
## ==== MAP PANEL PERFORMANCE TO ROOFS ==== ##
month_old
=
0
# treat every timestamp independently
for
i
,
t
in
enumerate
(
tilted_irrad
.
timestamp
):
tt
=
time
.
time
()
# get month for maximum temperature
month
=
int
(
t
.
dt
.
month
)
# get tilted irradiance for given timestamp
Gt
=
tilted_irrad
.
sel
(
timestamp
=
t
)
.
tilted_irradiance
.
to_dataframe
()
.
reset_index
()
Gt
[
'G_t'
]
=
np
.
round
(
Gt
.
tilted_irradiance
)
if
month
!=
month_old
:
print
(
month
)
# get maximum temperature
Tmax
=
T_max_mmd
.
TmaxD
.
sel
(
month
=
month
)
.
to_dataframe
()
.
dropna
()
.
reset_index
()
.
drop
(
columns
=
[
'lon'
,
'lat'
,
'month'
])
Tmax
[
'T_amb'
]
=
np
.
round
(
Tmax
[
'TmaxD'
])
month_old
=
month
# get efficiency dataframe
eff
=
performance
.
to_dataframe
()
.
reset_index
()
.
drop
(
columns
=
[
'T_cell'
,
'losses'
,
'inverter_eff'
,
'PF'
])
# create dataset with all merged information
tmp
=
roofs
.
merge
(
Tmax
,
on
=
[
'chx'
,
'chy'
],
how
=
'left'
)
tmp
=
tmp
.
merge
(
Gt
,
on
=
'DF_UID'
,
how
=
'left'
)
roofs_w_eff
=
tmp
.
merge
(
eff
,
on
=
[
'T_amb'
,
'G_t'
],
how
=
'left'
)
# create xarray dataset from the relevant information and save intermediate file
eff_xr
=
roofs_w_eff
.
set_index
([
'DF_UID'
,
'timestamp'
])[[
'TmaxD'
,
'module_eff'
,
'PF_mean'
]]
.
to_xarray
()
eff_xr
.
to_netcdf
(
os
.
path
.
join
(
OUTPATH
,
'tmp'
,
'efficiency_mapped_
%d
.nc'
%
i
)
)
print
(
'Finished iteration
%d
in
%.3f
s'
%
(
i
,
time
.
time
()
-
tt
))
## ==== MERGE INTERMEDIATE FILES ==== ##
eff
=
[]
for
i
in
range
(
10
):
eff
.
append
(
xr
.
open_mfdataset
(
os
.
path
.
join
(
OUTPATH
,
'tmp'
,
'efficiency_mapped_
%d
*.nc'
%
i
),
chunks
=
{
'DF_UID'
:
100000
})
)
eff_xr
=
xr
.
concat
(
eff
,
dim
=
'timestamp'
)
.
sortby
(
'timestamp'
)
eff_xr
.
to_netcdf
(
OUTFILE
)
Event Timeline
Log In to Comment