Created
November 24, 2020 22:45
-
-
Save mikofski/98cc9a3f1e819d76023952360717fa57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pvlib | |
import pandas as pd | |
from matplotlib import pyplot as plt | |
import seaborn as sns | |
sns.set() | |
plt.ion() | |
INVERTERS = pvlib.pvsystem.retrieve_sam('CECInverter') | |
INVERTER_10K = INVERTERS['SMA_America__SB10000TL_US__240V_'] | |
CECMODS = pvlib.pvsystem.retrieve_sam('CECMod') | |
CECMOD_POLY = CECMODS['Canadian_Solar_Inc__CS6X_300P'] | |
CECMOD_MONO = CECMODS['Canadian_Solar_Inc__CS6X_300M'] | |
LATITUDE, LONGITUDE = 40.5137, -108.5449 | |
NREL_API_KEY = os.getenv('NREL_API_KEY', 'DEMO_KEY') | |
EMAIL = os.getenv('EMAIL', '[email protected]') | |
YEARS = [2015, 2016, 2017, 2018, 2019] | |
EDAILY = [] | |
for year in YEARS: | |
header, data = pvlib.iotools.get_psm3(LATITUDE, LONGITUDE, NREL_API_KEY, EMAIL, names=str(year)) | |
# get solar position | |
TIMES = data.index | |
sp = pvlib.solarposition.get_solarposition( | |
TIMES, LATITUDE, LONGITUDE) | |
solar_zenith = sp.apparent_zenith.values | |
solar_azimuth = sp.azimuth.values | |
dni = data.DNI.values | |
ghi = data.GHI.values | |
dhi = data.DHI.values | |
surface_albedo = data['Surface Albedo'].values | |
temp_air = data.Temperature.values | |
dni_extra = pvlib.irradiance.get_extra_radiation(TIMES).values | |
tracker = pvlib.tracking.singleaxis(solar_zenith, solar_azimuth) | |
surface_tilt = tracker['surface_tilt'] | |
surface_azimuth = tracker['surface_azimuth'] | |
poa_sky_diffuse = pvlib.irradiance.get_sky_diffuse( | |
surface_tilt, surface_azimuth, solar_zenith, solar_azimuth, | |
dni, ghi, dhi, dni_extra=dni_extra, model='haydavies') | |
aoi = tracker['aoi'] | |
poa_ground_diffuse = pvlib.irradiance.get_ground_diffuse( | |
surface_tilt, ghi, albedo=surface_albedo) | |
poa = pvlib.irradiance.poa_components( | |
aoi, dni, poa_sky_diffuse, poa_ground_diffuse) | |
poa_direct = poa['poa_direct'] | |
poa_diffuse = poa['poa_diffuse'] | |
poa_global = poa['poa_global'] | |
iam = pvlib.iam.ashrae(aoi) | |
effective_irradiance = poa_direct*iam + poa_diffuse | |
temp_cell = pvlib.temperature.pvsyst_cell(poa_global, temp_air) | |
# this is the magic | |
cecparams = pvlib.pvsystem.calcparams_cec( | |
effective_irradiance, temp_cell, | |
CECMOD_MONO.alpha_sc, CECMOD_MONO.a_ref, | |
CECMOD_MONO.I_L_ref, CECMOD_MONO.I_o_ref, | |
CECMOD_MONO.R_sh_ref, CECMOD_MONO.R_s, CECMOD_MONO.Adjust) | |
mpp = pvlib.pvsystem.max_power_point(*cecparams, method='newton') | |
mpp = pd.DataFrame(mpp, index=TIMES) | |
Edaily = mpp.p_mp.resample('D').sum() | |
EDAILY.append(Edaily) | |
yield_daily = pd.concat(EDAILY) / 300.0 / 24 * 100 | |
yield_daily.plot() | |
plt.ylabel('Daily DC Capacity [%]') | |
plt.title('Multiyear data') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment