Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F117680283
compute_PV_output_batch_SCENARIO.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
Sun, Jun 15, 01:02
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Jun 17, 01:02 (2 d)
Engine
blob
Format
Raw Data
Handle
26775913
Attached To
R8800 solar_potential
compute_PV_output_batch_SCENARIO.py
View Options
import
pandas
as
pd
import
xarray
as
xr
import
numpy
as
np
from
pvlib.tools
import
cosd
from
demand_mapping
import
get_yearly_sum
import
os
import
time
import
sys
TILTED_IRRAD_FP
=
sys
.
argv
[
1
]
# name of the tilted radiation file
ROOFS_FP
=
sys
.
argv
[
2
]
# roof scenario file (incl. 'DF_UID', 'available_area', 'NEIGUNG', 'panel_tilt')
OUTFILE_FP
=
sys
.
argv
[
3
]
# name of the output file
if
len
(
sys
.
argv
)
>
4
:
# indicate if data is a sample (i.e. few roofs)
if
sys
.
argv
[
4
]
==
'sample'
:
sample
=
True
else
:
sample
=
False
## ===== CONSTANTS ===== ##
CHUNKSIZE
=
1000
EFFICIENCY_FP
=
'/work/hyenergy/output/solar_potential/technical_potential/pv_efficiencies_proj_roofs.nc'
print
(
'
\n
Tilted irradiance file path:
%s
'
%
TILTED_IRRAD_FP
)
print
(
'Efficiency file path:
%s
'
%
EFFICIENCY_FP
)
print
(
'Output file path:
%s
\n\n
'
%
OUTFILE_FP
)
## =========================================================================================== ##
## ===== LOAD DATA ===== ##
tt
=
time
.
time
()
t0
=
time
.
time
()
irrad
=
xr
.
open_mfdataset
(
TILTED_IRRAD_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
},
combine
=
'by_coords'
,
lock
=
None
)
.
sortby
(
'DF_UID'
)
av_area
=
pd
.
read_csv
(
ROOFS_FP
,
usecols
=
[
'DF_UID'
,
'available_area'
,
'NEIGUNG'
,
'panel_tilt'
])
eff
=
xr
.
open_mfdataset
(
EFFICIENCY_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
},
combine
=
'by_coords'
,
lock
=
None
)
.
sel
(
DF_UID
=
irrad
.
DF_UID
.
values
)
if
sample
:
eff
=
eff
.
compute
()
print
(
eff
)
print
(
'Loaded all data in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
av_area
=
av_area
[
av_area
.
DF_UID
.
isin
(
irrad
.
DF_UID
.
values
)]
av_area
[
'panelled_area'
]
=
av_area
.
available_area
/
cosd
(
av_area
.
panel_tilt
-
av_area
.
NEIGUNG
)
print
(
'Merged roof info with available area'
)
## ===== PREPARE PV OUTPUT ===== ##
tt
=
time
.
time
()
print
(
'
\n
Computing PV potential ...'
)
# First get all required variables for computation of PV output
pv_output
=
irrad
.
tilted_irradiance
.
to_dataset
()
pv_output
[
'panelled_area'
]
=
av_area
.
set_index
(
'DF_UID'
)
.
to_xarray
()
.
panelled_area
pv_output
[
'available_area'
]
=
av_area
.
set_index
(
'DF_UID'
)
.
to_xarray
()
.
available_area
pv_output
[
'efficiency'
]
=
eff
[
'module_eff'
]
pv_output
[
'performance_factor'
]
=
eff
[
'PF_mean'
]
# Compute total PV output
pv_output
[
'pv_potential'
]
=
(
pv_output
.
tilted_irradiance
*
pv_output
.
panelled_area
*
pv_output
.
efficiency
*
pv_output
.
performance_factor
)
print
(
'Finished in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
tt
=
time
.
time
()
print
(
'
\n
Computing yearly sum ...'
)
# Compute yearly sums
if
'day'
in
pv_output
.
dims
:
pv_output
[
'yearly_PV_kWh'
]
=
pv_output
.
pv_potential
.
sum
(
dim
=
[
'timestamp'
,
'day'
])
/
1000
else
:
pv_output
[
'yearly_PV_kWh'
]
=
get_yearly_sum
(
pv_output
.
pv_potential
,
week_weighting
=
False
)
/
1000
print
(
pv_output
)
print
(
'Finished in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
tt
=
time
.
time
()
print
(
'
\n
Saving output ...'
)
pv_save
=
pv_output
[[
'pv_potential'
,
'yearly_PV_kWh'
]]
# reduce storage requirement
pv_save
[
'pv_potential'
]
=
pv_save
[
'pv_potential'
]
.
astype
(
'float32'
)
pv_save
[
'yearly_PV_kWh'
]
=
pv_save
[
'yearly_PV_kWh'
]
.
astype
(
'float32'
)
if
'time'
in
pv_save
.
variables
:
pv_save
[
'time'
]
=
irrad
.
time
print
(
pv_save
)
pv_save
.
to_netcdf
(
OUTFILE_FP
)
print
(
'Saved output in
%s
(
%.3f
s)'
%
(
OUTFILE_FP
,
time
.
time
()
-
tt
))
print
(
'
\n
DONE - total execution time:
%.3f
seconds'
%
(
time
.
time
()
-
t0
))
Event Timeline
Log In to Comment