Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pvlib/atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ def gueymard94_pw(temp_air, relative_humidity):
1294-1300.
"""

T = temp_air + 273.15 # Convert to Kelvin
RH = relative_humidity
T = temp_air + 273.15 # Convert to Kelvin # noqa: N806
RH = relative_humidity # noqa: N806

theta = T / 273.15

Expand Down Expand Up @@ -473,7 +473,7 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
_coefficients['cigs'] = (
0.85252, -0.022314, -0.0047216, 0.13666, 0.013342, -0.0008945)
_coefficients['asi'] = (
1.12094, -0.047620, -0.0083627, -0.10443, 0.098382,-0.0033818)
1.12094, -0.047620, -0.0083627, -0.10443, 0.098382, -0.0033818)

if module_type is not None and coefficients is None:
coefficients = _coefficients[module_type.lower()]
Expand Down
44 changes: 25 additions & 19 deletions pvlib/clearsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
import pandas as pd

from pvlib import tools, atmosphere, solarposition, irradiance
from pvlib import atmosphere, tools


def ineichen(apparent_zenith, airmass_absolute, linke_turbidity,
Expand Down Expand Up @@ -204,7 +204,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,

lt_h5_file = tables.open_file(filepath)
try:
lts = lt_h5_file.root.LinkeTurbidity[latitude_index, longitude_index, :]
lts = lt_h5_file.root.LinkeTurbidity[latitude_index,
longitude_index, :]
except IndexError:
raise IndexError('Latitude should be between 90 and -90, '
'longitude between -180 and 180.')
Expand Down Expand Up @@ -364,8 +365,9 @@ def haurwitz(apparent_zenith):

cos_zenith = tools.cosd(apparent_zenith.values)
clearsky_ghi = np.zeros_like(apparent_zenith.values)
clearsky_ghi[cos_zenith>0] = 1098.0 * cos_zenith[cos_zenith>0] * \
np.exp(-0.059/cos_zenith[cos_zenith>0])
cos_zen_gte_0 = cos_zenith > 0
clearsky_ghi[cos_zen_gte_0] = (1098.0 * cos_zenith[cos_zen_gte_0] *
np.exp(-0.059/cos_zenith[cos_zen_gte_0]))

df_out = pd.DataFrame(index=apparent_zenith.index,
data=clearsky_ghi,
Expand Down Expand Up @@ -675,14 +677,14 @@ def detect_clearsky(measured, clearsky, times, window_length,
if len(unique_deltas) == 1:
sample_interval = unique_deltas[0]
else:
raise NotImplementedError('algorithm does not yet support unequal ' \
raise NotImplementedError('algorithm does not yet support unequal '
'times. consider resampling your data.')

samples_per_window = int(window_length / sample_interval)

# generate matrix of integers for creating windows with indexing
from scipy.linalg import hankel
H = hankel(np.arange(samples_per_window),
H = hankel(np.arange(samples_per_window), # noqa: N806
np.arange(samples_per_window-1, len(times)))

# calculate measurement statistics
Expand Down Expand Up @@ -729,14 +731,16 @@ def detect_clearsky(measured, clearsky, times, window_length,
previous_alpha = alpha
clear_meas = measured[clear_samples]
clear_clear = clearsky[clear_samples]

def rmse(alpha):
return np.sqrt(np.mean((clear_meas - alpha*clear_clear)**2))

alpha = minimize_scalar(rmse).x
if round(alpha*10000) == round(previous_alpha*10000):
break
else:
import warnings
warnings.warn('failed to converge after %s iterations' \
warnings.warn('failed to converge after %s iterations'
% max_iterations, RuntimeWarning)

# be polite about returning the same type as was input
Expand Down Expand Up @@ -765,17 +769,18 @@ def bird(zenith, airmass_relative, aod380, aod500, precipitable_water,

Based on NREL Excel implementation by Daryl R. Myers [1, 2].

Bird and Hulstrom define the zenith as the "angle between a line to the sun
and the local zenith". There is no distinction in the paper between solar
zenith and apparent (or refracted) zenith, but the relative airmass is
defined using the Kasten 1966 expression, which requires apparent zenith.
Although the formulation for calculated zenith is never explicitly defined
in the report, since the purpose was to compare existing clear sky models
with "rigorous radiative transfer models" (RTM) it is possible that apparent
zenith was obtained as output from the RTM. However, the implentation
presented in PVLIB is tested against the NREL Excel implementation by Daryl
Myers which uses an analytical expression for solar zenith instead of
apparent zenith.
Bird and Hulstrom define the zenith as the "angle between a line to
the sun and the local zenith". There is no distinction in the paper
between solar zenith and apparent (or refracted) zenith, but the
relative airmass is defined using the Kasten 1966 expression, which
requires apparent zenith. Although the formulation for calculated
zenith is never explicitly defined in the report, since the purpose
was to compare existing clear sky models with "rigorous radiative
transfer models" (RTM) it is possible that apparent zenith was
obtained as output from the RTM. However, the implentation presented
in PVLIB is tested against the NREL Excel implementation by Daryl
Myers which uses an analytical expression for solar zenith instead
of apparent zenith.

Parameters
----------
Expand Down Expand Up @@ -824,7 +829,8 @@ def bird(zenith, airmass_relative, aod380, aod500, precipitable_water,

`SERI/TR-642-761 <http://rredc.nrel.gov/solar/pubs/pdfs/tr-642-761.pdf>`_

`Error Reports <http://rredc.nrel.gov/solar/models/clearsky/error_reports.html>`_
`Error Reports
<http://rredc.nrel.gov/solar/models/clearsky/error_reports.html>`_
"""
etr = dni_extra # extraradiation
ze_rad = np.deg2rad(zenith) # zenith in radians
Expand Down
33 changes: 20 additions & 13 deletions pvlib/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,19 +574,19 @@ def isobaric_to_ambient_temperature(self, data):
Temperature in K
"""

P = data['pressure'] / 100.0
Tiso = data['temperature_iso']
Td = data['temperature_dew_iso'] - 273.15
P = data['pressure'] / 100.0 # noqa: N806
Tiso = data['temperature_iso'] # noqa: N806
Td = data['temperature_dew_iso'] - 273.15 # noqa: N806

# saturation water vapor pressure
e = 6.11 * 10**((7.5 * Td) / (Td + 273.3))

# saturation water vapor mixing ratio
w = 0.622 * (e / (P - e))

T = Tiso - ((2.501 * 10.**6) / 1005.7) * w
temperature = Tiso - ((2.501 * 10.**6) / 1005.7) * w

return T
return temperature

def uv_to_speed(self, data):
"""
Expand Down Expand Up @@ -670,13 +670,19 @@ def __init__(self, resolution='half', set_type='best'):
'wind_speed_gust': 'Wind_speed_gust_surface',
'wind_speed_u': 'u-component_of_wind_isobaric',
'wind_speed_v': 'v-component_of_wind_isobaric',
'total_clouds': 'Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average',
'low_clouds': 'Total_cloud_cover_low_cloud_Mixed_intervals_Average',
'mid_clouds': 'Total_cloud_cover_middle_cloud_Mixed_intervals_Average',
'high_clouds': 'Total_cloud_cover_high_cloud_Mixed_intervals_Average',
'boundary_clouds': 'Total_cloud_cover_boundary_layer_cloud_Mixed_intervals_Average',
'total_clouds':
'Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average',
'low_clouds':
'Total_cloud_cover_low_cloud_Mixed_intervals_Average',
'mid_clouds':
'Total_cloud_cover_middle_cloud_Mixed_intervals_Average',
'high_clouds':
'Total_cloud_cover_high_cloud_Mixed_intervals_Average',
'boundary_clouds': ('Total_cloud_cover_boundary_layer_cloud_'
'Mixed_intervals_Average'),
'convect_clouds': 'Total_cloud_cover_convective_cloud',
'ghi_raw': 'Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average', }
'ghi_raw': ('Downward_Short-Wave_Radiation_Flux_'
'surface_Mixed_intervals_Average')}

self.output_variables = [
'temp_air',
Expand Down Expand Up @@ -716,7 +722,7 @@ def process_data(self, data, cloud_cover='total_clouds', **kwargs):
return data[self.output_variables]


class HRRR_ESRL(ForecastModel):
class HRRR_ESRL(ForecastModel): # noqa: N801
"""
Subclass of the ForecastModel class representing
NOAA/GSD/ESRL's HRRR forecast model.
Expand Down Expand Up @@ -925,7 +931,8 @@ def __init__(self, set_type='best'):
'low_clouds': 'Low_cloud_cover_low_cloud',
'mid_clouds': 'Medium_cloud_cover_middle_cloud',
'high_clouds': 'High_cloud_cover_high_cloud',
'condensation_height': 'Geopotential_height_adiabatic_condensation_lifted'}
'condensation_height':
'Geopotential_height_adiabatic_condensation_lifted'}

self.output_variables = [
'temp_air',
Expand Down
8 changes: 4 additions & 4 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
# a better way to do it.
if isinstance(datetime_or_doy, pd.DatetimeIndex):
to_doy = tools._pandas_to_doy # won't be evaluated unless necessary
to_datetimeindex = lambda x: datetime_or_doy
def to_datetimeindex(x): return x # noqa: E306
to_output = partial(pd.Series, index=datetime_or_doy)
elif isinstance(datetime_or_doy, pd.Timestamp):
to_doy = tools._pandas_to_doy
Expand All @@ -139,12 +139,12 @@ def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
tools._datetimelike_scalar_to_datetimeindex
to_output = tools._scalar_out
elif np.isscalar(datetime_or_doy): # ints and floats of various types
to_doy = lambda x: datetime_or_doy
def to_doy(x): return x # noqa: E306
to_datetimeindex = partial(tools._doy_to_datetimeindex,
epoch_year=epoch_year)
to_output = tools._scalar_out
else: # assume that we have an array-like object of doy
to_doy = lambda x: datetime_or_doy
def to_doy(x): return x # noqa: E306
to_datetimeindex = partial(tools._doy_to_datetimeindex,
epoch_year=epoch_year)
to_output = tools._array_out
Expand Down Expand Up @@ -1972,7 +1972,7 @@ def _gti_dirint_lt_90(poa_global, aoi, aoi_lt_90, solar_zenith, solar_azimuth,
# we are here because we ran out of coeffs to loop over and
# therefore we have exceeded max_iterations
import warnings
failed_points = best_diff[aoi_lt_90][best_diff_lte_1_lt_90 == False]
failed_points = best_diff[aoi_lt_90][~best_diff_lte_1_lt_90]
warnings.warn(
('%s points failed to converge after %s iterations. best_diff:\n%s'
% (len(failed_points), max_iterations, failed_points)),
Expand Down
20 changes: 7 additions & 13 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ def basic_chain(times, latitude, longitude,
raise ValueError('orientation_strategy or surface_tilt and '
'surface_azimuth must be provided')

times = times

if altitude is None and pressure is None:
altitude = 0.
pressure = 101325.
Expand All @@ -126,12 +124,9 @@ def basic_chain(times, latitude, longitude,
elif pressure is None:
pressure = atmosphere.alt2pres(altitude)

solar_position = solarposition.get_solarposition(times, latitude,
longitude,
altitude=altitude,
pressure=pressure,
method=solar_position_method,
**kwargs)
solar_position = solarposition.get_solarposition(
times, latitude, longitude, altitude=altitude, pressure=pressure,
method=solar_position_method, **kwargs)

# possible error with using apparent zenith with some models
airmass = atmosphere.get_relative_airmass(
Expand Down Expand Up @@ -372,12 +367,11 @@ def dc_model(self, model):
if model in DC_MODEL_PARAMS.keys():
# validate module parameters
missing_params = DC_MODEL_PARAMS[model] - \
set(self.system.module_parameters.keys())
if missing_params: # some parameters are not in module.keys()
set(self.system.module_parameters.keys())
if missing_params: # some parameters are not in module.keys()
raise ValueError(model + ' selected for the DC model but '
'one or more required parameters '
'are missing : ' +
str(missing_params))
'one or more required parameters are '
'missing : ' + str(missing_params))
if model == 'sapm':
self._dc_model = self.sapm
elif model == 'desoto':
Expand Down
28 changes: 13 additions & 15 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from __future__ import division

from collections import OrderedDict
import os
import io
import os
try:
from urllib2 import urlopen
except ImportError:
Expand All @@ -16,10 +16,9 @@
import numpy as np
import pandas as pd

from pvlib import tools
from pvlib import atmosphere, irradiance, tools, singlediode as _singlediode
from pvlib.tools import _build_kwargs
from pvlib.location import Location
from pvlib import irradiance, atmosphere, singlediode as _singlediode


# a dict of required parameter names for each DC power model
Expand Down Expand Up @@ -333,7 +332,7 @@ def calcparams_desoto(self, effective_irradiance, temp_cell, **kwargs):
kwargs = _build_kwargs(['a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref',
'R_s', 'alpha_sc', 'EgRef', 'dEgdT',
'irrad_ref', 'temp_ref'],
self.module_parameters)
self.module_parameters)

return calcparams_desoto(effective_irradiance, temp_cell, **kwargs)

Expand Down Expand Up @@ -361,7 +360,7 @@ def calcparams_pvsyst(self, effective_irradiance, temp_cell):
'R_s', 'alpha_sc', 'EgRef',
'irrad_ref', 'temp_ref',
'cells_in_series'],
self.module_parameters)
self.module_parameters)

return calcparams_pvsyst(effective_irradiance, temp_cell, **kwargs)

Expand Down Expand Up @@ -511,7 +510,7 @@ def first_solar_spectral_loss(self, pw, airmass_absolute):
"""

if 'first_solar_spectral_coefficients' in \
self.module_parameters.keys():
self.module_parameters.keys():
coefficients = \
self.module_parameters['first_solar_spectral_coefficients']
module_type = None
Expand Down Expand Up @@ -552,7 +551,6 @@ def _infer_cell_type(self):
'mc-Si': 'multisi',
'c-Si': 'multisi',
'Si-Film': 'asi',
'CdTe': 'cdte',
'EFG mc-Si': 'multisi',
'GaAs': None,
'a-Si / mono-Si': 'monosi'}
Expand Down Expand Up @@ -1133,7 +1131,7 @@ def calcparams_desoto(effective_irradiance, temp_cell,
* EgRef = 1.121
* dEgdT = -0.0002677

>>> M = np.polyval([-1.26E-4, 2.816E-3, -0.024459, 0.086257, 0.918093],
>>> M = np.polyval([-1.26E-4, 2.816E-3, -0.024459, 0.086257, 0.9181],
... AMa) # doctest: +SKIP

Source: [1]
Expand Down Expand Up @@ -1210,7 +1208,7 @@ def calcparams_desoto(effective_irradiance, temp_cell,
# equivalent to the product of S (irradiance reaching a module's cells) *
# M (spectral adjustment factor) as described in [1].
IL = effective_irradiance / irrad_ref * \
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
I0 = (I_o_ref * ((Tcell_K / Tref_K) ** 3) *
(np.exp(EgRef / (k*(Tref_K)) - (E_g / (k*(Tcell_K))))))
# Note that the equation for Rsh differs from [1]. In [1] Rsh is given as
Expand Down Expand Up @@ -1346,16 +1344,17 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
nNsVth = gamma * k / q * cells_in_series * Tcell_K

IL = effective_irradiance / irrad_ref * \
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))

I0 = I_o_ref * ((Tcell_K / Tref_K) ** 3) * \
(np.exp((q * EgRef) / (k * gamma) * (1 / Tref_K - 1 / Tcell_K)))
(np.exp((q * EgRef) / (k * gamma) * (1 / Tref_K - 1 / Tcell_K)))

Rsh_tmp = (R_sh_ref - R_sh_0 * np.exp(-R_sh_exp)) / (1.0 - np.exp(-R_sh_exp))
Rsh_tmp = \
(R_sh_ref - R_sh_0 * np.exp(-R_sh_exp)) / (1.0 - np.exp(-R_sh_exp))
Rsh_base = np.maximum(0.0, Rsh_tmp)

Rsh = Rsh_base + (R_sh_0 - Rsh_base) * \
np.exp(-R_sh_exp * effective_irradiance / irrad_ref)
np.exp(-R_sh_exp * effective_irradiance / irrad_ref)

Rs = R_s

Expand Down Expand Up @@ -1723,8 +1722,7 @@ def sapm_celltemp(poa_global, wind_speed, temp_air,

if isinstance(model, str):
model = temp_models[model.lower()]
elif isinstance(model, list):
model = model

elif isinstance(model, (dict, pd.Series)):
model = [model['a'], model['b'], model['deltaT']]

Expand Down
Loading