Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111154336
compute_PV_output_batch.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
Tue, Apr 29, 22:13
Size
3 KB
Mime Type
text/x-python
Expires
Thu, May 1, 22:13 (2 d)
Engine
blob
Format
Raw Data
Handle
25875220
Attached To
R8800 solar_potential
compute_PV_output_batch.py
View Options
import
pandas
as
pd
import
xarray
as
xr
import
numpy
as
np
from
pvlib.tools
import
cosd
import
os
import
time
import
sys
TILTED_IRRAD_FP
=
sys
.
argv
[
1
]
# name of the tilted radiation file
OUTFILE_FP
=
sys
.
argv
[
2
]
# name of the output file
## ===== CONSTANTS ===== ##
CHUNKSIZE
=
1000
AVAIL_AREA_FP
=
'/work/hyenergy/output/solar_potential/geographic_potential/available_area/PRED_available_area_unc_filled.csv'
ROOFS_FP
=
'/work/hyenergy/output/solar_potential/geographic_potential/CH_ROOFS_all_replaced.csv'
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
(
'Available area file path:
%s
'
%
AVAIL_AREA_FP
)
print
(
'Roof surfaces file path:
%s
'
%
ROOFS_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'
)
.
sortby
(
'DF_UID'
)
av_area
=
pd
.
read_csv
(
AVAIL_AREA_FP
,
usecols
=
[
'DF_UID'
,
'tilted_area'
,
'available_area'
])
roofs
=
pd
.
read_csv
(
ROOFS_FP
,
usecols
=
[
'DF_UID'
,
'NEIGUNG'
,
'panel_tilt'
])
eff
=
xr
.
open_mfdataset
(
EFFICIENCY_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
},
combine
=
'by_coords'
)
.
sel
(
DF_UID
=
irrad
.
DF_UID
.
values
)
print
(
'Loaded all data in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
av_area
=
av_area
[
av_area
.
DF_UID
.
isin
(
irrad
.
DF_UID
.
values
)]
.
merge
(
roofs
[
roofs
.
DF_UID
.
isin
(
irrad
.
DF_UID
.
values
)],
on
=
'DF_UID'
,
how
=
'left'
)
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
[
'tilted_area'
]
=
av_area
.
set_index
(
'DF_UID'
)
.
to_xarray
()
.
tilted_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
pv_output
[
'yearly_PV_kWh'
]
=
pv_output
.
pv_potential
.
sum
(
dim
=
[
'timestamp'
,
'day'
])
/
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'
)
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