Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data['poa_sky_diffuse'] = pvlib.irradiance.perez(
surface_tilt=self.powerplant.tilt,
surface_azimuth=self.powerplant.azimuth,
dhi=data['dhi'],
dni=data['dni'],
dni_extra=data['dni_extra'],
solar_zenith=data['zenith'],
solar_azimuth=data['azimuth'],
airmass=data['airmass'])
# Set NaN values to zero
data['poa_sky_diffuse'][
pd.isnull(data['poa_sky_diffuse'])] = 0
# Determine the diffuse irradiation from ground reflection in plane
data['poa_ground_diffuse'] = pvlib.irradiance.grounddiffuse(
ghi=data['dirhi'] + data['dhi'],
albedo=self.powerplant.albedo,
surface_tilt=self.powerplant.tilt)
# Determine total in-plane irradiance
data = pd.concat(
[data, pvlib.irradiance.globalinplane(
aoi=data['aoi'],
dni=data['dni'],
poa_sky_diffuse=data['poa_sky_diffuse'],
poa_ground_diffuse=data['poa_ground_diffuse'])],
axis=1, join='inner')
return data
DataFrame with columns 'apparent_zenith', 'zenith',
'apparent_elevation'.
dni_extra: None or numeric, default None
If None, will be calculated from times.
kwargs
Extra parameters passed to the relevant functions. Climatological
values are assumed in many cases. See source code for details!
Returns
-------
clearsky : DataFrame
Column names are: ``ghi, dni, dhi``.
"""
if dni_extra is None:
dni_extra = irradiance.get_extra_radiation(times)
try:
pressure = kwargs.pop('pressure')
except KeyError:
pressure = atmosphere.alt2pres(self.altitude)
if solar_position is None:
solar_position = self.get_solarposition(times, pressure=pressure,
**kwargs)
apparent_zenith = solar_position['apparent_zenith']
apparent_elevation = solar_position['apparent_elevation']
if model == 'ineichen':
try:
linke_turbidity = kwargs.pop('linke_turbidity')
'''
import pytz
import pvlib
lat = self.latitude
lon = self.longitude
elev = self.elevation
datetime = pd.to_datetime(self.datetime)
tz = self.timezone
try: # make sure the data is tz-localized.
datetimetz = datetime.tz_localize(pytz.FixedOffset(tz*60)) # either use pytz.FixedOffset (in minutes) or 'Etc/GMT+5'
except: # data is tz-localized already. Just put it in local time.
datetimetz = datetime.tz_convert(pytz.FixedOffset(tz*60))
# get solar position zenith and azimuth based on site metadata
#solpos = pvlib.irradiance.solarposition.get_solarposition(datetimetz,lat,lon,elev)
solpos = pvlib.irradiance.solarposition.get_solarposition(datetimetz-pd.Timedelta(minutes = 30),lat,lon,elev)
self.solpos = solpos # save solar position for each timestamp
# get 1-axis tracker tracker_theta, surface_tilt and surface_azimuth
trackingdata = pvlib.tracking.singleaxis(solpos['zenith'], solpos['azimuth'], axis_tilt, axis_azimuth, limit_angle, backtrack, gcr)
# save tracker tilt information to metdata.tracker_theta, metdata.surface_tilt and metdata.surface_azimuth
self.tracker_theta = trackingdata['tracker_theta'].tolist()
self.surface_tilt = trackingdata['surface_tilt'].tolist()
self.surface_azimuth = trackingdata['surface_azimuth'].tolist()
# undo the 30 minute timestamp offset put in by solpos
trackingdata.index = trackingdata.index + pd.Timedelta(minutes = 30)
# round tracker_theta to increments of angledelta
def _roundArbitrary(x, base = angledelta):
# round to nearest 'base' value.
# mask NaN's to avoid rounding error message
return base * (x.dropna()/float(base)).round()
surface_azimuth : float or pd.Series
aoi : pd.Series
apparent_zenith : pd.Series
Solar apparent zenith
azimuth : pd.Series
Solar azimuth
ghi : pd.Series
dni : pd.Series
dhi : pd.Series
Returns
-------
poa_effective : pd.Series
"""
dni_extra = pvlib.irradiance.get_extra_radiation(apparent_zenith.index)
poa_sky_diffuse = pvlib.irradiance.get_sky_diffuse(
surface_tilt, surface_azimuth,
apparent_zenith, azimuth,
dni, ghi, dhi,
dni_extra=dni_extra,
model='haydavies')
poa_ground_diffuse = pvlib.irradiance.get_ground_diffuse(
surface_tilt, ghi, albedo=0.25)
aoi_modifier = pvlib.iam.physical(aoi)
beam_effective = dni * aoi_modifier
poa_effective = beam_effective + poa_sky_diffuse + poa_ground_diffuse
# aoi, tilt, azi is not defined for tracking systems
# when sun is below horizon. replace nan with 0
poa_effective = poa_effective.where(aoi.notna(), other=0.)
return poa_effective