Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111310629
compute_tilted_irrad_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
Wed, Apr 30, 17:17
Size
3 KB
Mime Type
text/x-python
Expires
Fri, May 2, 17:17 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25884868
Attached To
R8800 solar_potential
compute_tilted_irrad_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
## ===== INPUTS ========== ##
POA_IRRAD_FP
=
sys
.
argv
[
1
]
# name of the tilted radiation file
OUTFILE_FP
=
sys
.
argv
[
2
]
# name of the output file
## ===== CONSTANTS ===== ##
CHUNKSIZE
=
10000
FLAT_TILT
=
30
FLAT_DIST
=
1
PARTLY_SHADING_FP
=
'/work/hyenergy/output/solar_potential/geographic_potential/available_area/shading_stats/CH_partly_shading_replaced_debiased.nc'
SVF_FP
=
'/work/hyenergy/output/solar_potential/geographic_potential/tilted_irradiance/SVF_CH_replaced.csv'
MUTUAL_SHADE_FP
=
'/work/hyenergy/output/solar_potential/technical_potential/flat_roofs/mutual_shading.nc'
ROOFS_FP
=
'/work/hyenergy/output/solar_potential/geographic_potential/CH_ROOFS_all_replaced.csv'
print
(
'
\n
Shading file path:
%s
'
%
PARTLY_SHADING_FP
)
print
(
'POA irradiance file path:
%s
'
%
POA_IRRAD_FP
)
print
(
'Skyview factor file path:
%s
'
%
SVF_FP
)
print
(
'Mutual shading file path:
%s
'
%
MUTUAL_SHADE_FP
)
print
(
'Roof surfaces file path:
%s
'
%
ROOFS_FP
)
print
(
'Output file path:
%s
'
%
OUTFILE_FP
)
## =========================================================================================== ##
## ===== LOAD DATA ===== ##
tt
=
time
.
time
()
t0
=
time
.
time
()
irrad
=
xr
.
open_mfdataset
(
POA_IRRAD_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
},
combine
=
'by_coords'
)
.
sortby
(
'DF_UID'
)
shading
=
xr
.
open_mfdataset
(
PARTLY_SHADING_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
},
combine
=
'by_coords'
)
.
sel
(
DF_UID
=
irrad
.
DF_UID
.
values
)
svf
=
pd
.
read_csv
(
SVF_FP
)
mutual_shade
=
xr
.
open_dataset
(
MUTUAL_SHADE_FP
)
roofs
=
pd
.
read_csv
(
ROOFS_FP
,
usecols
=
[
'DF_UID'
,
'NEIGUNG'
,
'panel_tilt'
]
)
print
(
'Loaded all data in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
flat_roofs
=
roofs
[(
roofs
.
DF_UID
.
isin
(
irrad
.
DF_UID
.
values
))
&
(
roofs
.
NEIGUNG
==
0
)]
## ===== COMPUTE MEAN IRRADIANCE ON ROOFTOPS ===== ##
print
(
shading
)
print
(
irrad
)
print
(
mutual_shade
)
print
(
'
\n
Computing mean irradiance on rooftops ...'
)
tt
=
time
.
time
()
tilted_irrad
=
xr
.
merge
(
[
shading
,
irrad
.
drop
(
'time'
)
]
)
.
fillna
(
0
)
mutual_shade_flat
=
mutual_shade
.
sel
(
tilt
=
FLAT_TILT
,
distance
=
FLAT_DIST
,
timestamp
=
irrad
.
timestamp
[
irrad
.
timestamp
.
isin
(
mutual_shade
.
timestamp
)]
)
.
drop
([
'tilt'
,
'distance'
])
tilted_irrad
[
'svf'
]
=
svf
[
svf
.
DF_UID
.
isin
(
irrad
.
DF_UID
.
values
)]
.
set_index
(
'DF_UID'
)[
'SVF_unbiased'
]
.
to_xarray
()
tilted_irrad
[
'is_flat'
]
=
tilted_irrad
.
DF_UID
.
isin
(
flat_roofs
.
DF_UID
.
values
)
.
astype
(
int
)
# compute tilted irradiance for tilted and flat surfaces
# by multiplying mutual shading with is_flat (0, 1)
tilted_irrad
[
'tilted_irradiance'
]
=
(
tilted_irrad
.
partly_shading
*
tilted_irrad
.
poa_direct
*
(
1
-
mutual_shade_flat
.
shading
*
tilted_irrad
.
is_flat
)
+
tilted_irrad
.
svf
*
tilted_irrad
.
poa_sky_diffuse
*
(
1
-
mutual_shade_flat
.
SVF_shade
*
tilted_irrad
.
is_flat
)
+
tilted_irrad
.
poa_ground_diffuse
)
print
(
tilted_irrad
)
print
(
'Finished in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
# Compute yearly sum
tilted_irrad
[
'yearly_kWh_m2'
]
=
tilted_irrad
.
tilted_irradiance
.
sum
(
dim
=
[
'timestamp'
,
'day'
]
)
/
1000
## === SAVE OUTPUT FILE ==== ##
tt
=
time
.
time
()
print
(
'
\n
Saving output ...'
)
irrad_save
=
tilted_irrad
[[
'tilted_irradiance'
,
'yearly_kWh_m2'
]]
# reduce storage requirement
irrad_save
[
'tilted_irradiance'
]
=
irrad_save
[
'tilted_irradiance'
]
.
astype
(
'float32'
)
irrad_save
[
'yearly_kWh_m2'
]
=
irrad_save
[
'yearly_kWh_m2'
]
.
astype
(
'float32'
)
irrad_save
[
'time'
]
=
irrad
.
time
print
(
irrad_save
)
irrad_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