Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F118538745
compute_tilted_irrad.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
Fri, Jun 20, 19:07
Size
4 KB
Mime Type
text/x-python
Expires
Sun, Jun 22, 19:07 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
26888143
Attached To
R8800 solar_potential
compute_tilted_irrad.py
View Options
import
pandas
as
pd
import
xarray
as
xr
import
numpy
as
np
import
util
from
pvlib.tools
import
cosd
import
os
import
time
import
sys
## ===== INPUTS ========== ##
START
=
int
(
sys
.
argv
[
1
])
# index of the first line of the file
N_LINES
=
int
(
sys
.
argv
[
2
])
# number of lines to be read
INNAME
=
sys
.
argv
[
3
]
# GVA_[south/east/west]_10deg
## ===== CONSTANTS ===== ##
CHUNKSIZE
=
10000
N_DF_UIDs
=
51260
END
=
min
(
START
+
N_LINES
,
N_DF_UIDs
)
FLAT_TILT
=
10
FLAT_DIST
=
0.5
FLAT_THRS
=
10
workdir
=
'/scratch/walch/scenarios_GVA'
# WORKING DIRECTORY
PARTLY_SHADING_FP
=
os
.
path
.
join
(
workdir
,
'GVA_10deg_partly_shading_replaced_debiased.csv'
)
# PATH TO HOURLY UNSHADED FRACTION
POA_IRRAD_FP
=
os
.
path
.
join
(
workdir
,
'poa_irradiance_interp_GVA_flat_
%s
_cleaned.nc'
%
INNAME
)
# PATH TO POA RADIATION
SVF_FP
=
os
.
path
.
join
(
workdir
,
'GVA_10deg_SVF_replaced.csv'
)
# PATH TO SKY VIEW FACTOR
MUTUAL_SHADE_FP
=
os
.
path
.
join
(
workdir
,
'mutual_shading.nc'
)
# PATH TO MUTUAL SHADING
ROOFS_FP
=
os
.
path
.
join
(
workdir
,
'flat_roofs_GVA_
%s
.csv'
%
INNAME
)
# PATH TO ROOFTOP CHARACTERISTICS
OUTFILE_FP
=
os
.
path
.
join
(
workdir
,
'tilted_irrad_GVA_flat_
%s
.nc'
%
INNAME
)
# PATH TO OUTPUT FILE
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
()
shading
=
xr
.
open_mfdataset
(
PARTLY_SHADING_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
}
)
.
sortby
(
'DF_UID'
)
.
isel
(
DF_UID
=
range
(
START
,
END
))
irrad
=
xr
.
open_mfdataset
(
POA_IRRAD_FP
,
chunks
=
{
'DF_UID'
:
CHUNKSIZE
}
)
.
sortby
(
'DF_UID'
)
.
isel
(
DF_UID
=
range
(
START
,
END
))
svf
=
util
.
read_csv_rows
(
SVF_FP
,
START
,
N_LINES
)
mutual_shade
=
xr
.
open_dataset
(
MUTUAL_SHADE_FP
)
roofs
=
util
.
read_csv_rows
(
ROOFS_FP
,
START
,
N_LINES
,
usecols
=
[
'DF_UID'
,
'NEIGUNG'
,
'panel_tilt'
])
print
(
'Loaded all data in
%.3f
seconds'
%
(
time
.
time
()
-
tt
))
flat_roofs
=
roofs
[
roofs
.
NEIGUNG
<=
FLAT_THRS
]
## ===== COMPUTE MEAN IRRADIANCE ON ROOFTOPS ===== ##
print
(
'
\n
Computing mean irradiance on rooftops ...'
)
tt
=
time
.
time
()
tilted_irrad
=
xr
.
merge
(
[
shading
,
irrad
]
)
.
fillna
(
0
)
mutual_shade_flat
=
mutual_shade
.
sel
(
tilt
=
FLAT_TILT
,
distance
=
FLAT_DIST
,
timestamp
=
irrad
.
timestamp
)
.
drop
([
'tilt'
,
'distance'
])
tilted_irrad
[
'svf'
]
=
svf
.
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'
]
=
(
util
.
get_yearly_sum
(
tilted_irrad
,
'tilted_irradiance'
))
/
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
.
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