Skip to content

Commit f16e53e

Browse files
authored
style fixes (#559)
* style fixes * more style fixes * clean up merge
1 parent 7195548 commit f16e53e

File tree

12 files changed

+153
-143
lines changed

12 files changed

+153
-143
lines changed

pvlib/atmosphere.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def gueymard94_pw(temp_air, relative_humidity):
317317
1294-1300.
318318
"""
319319

320-
T = temp_air + 273.15 # Convert to Kelvin
321-
RH = relative_humidity
320+
T = temp_air + 273.15 # Convert to Kelvin # noqa: N806
321+
RH = relative_humidity # noqa: N806
322322

323323
theta = T / 273.15
324324

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

478478
if module_type is not None and coefficients is None:
479479
coefficients = _coefficients[module_type.lower()]

pvlib/clearsky.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313
import pandas as pd
1414

15-
from pvlib import tools, atmosphere, solarposition, irradiance
15+
from pvlib import atmosphere, tools
1616

1717

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

205205
lt_h5_file = tables.open_file(filepath)
206206
try:
207-
lts = lt_h5_file.root.LinkeTurbidity[latitude_index, longitude_index, :]
207+
lts = lt_h5_file.root.LinkeTurbidity[latitude_index,
208+
longitude_index, :]
208209
except IndexError:
209210
raise IndexError('Latitude should be between 90 and -90, '
210211
'longitude between -180 and 180.')
@@ -364,8 +365,9 @@ def haurwitz(apparent_zenith):
364365

365366
cos_zenith = tools.cosd(apparent_zenith.values)
366367
clearsky_ghi = np.zeros_like(apparent_zenith.values)
367-
clearsky_ghi[cos_zenith>0] = 1098.0 * cos_zenith[cos_zenith>0] * \
368-
np.exp(-0.059/cos_zenith[cos_zenith>0])
368+
cos_zen_gte_0 = cos_zenith > 0
369+
clearsky_ghi[cos_zen_gte_0] = (1098.0 * cos_zenith[cos_zen_gte_0] *
370+
np.exp(-0.059/cos_zenith[cos_zen_gte_0]))
369371

370372
df_out = pd.DataFrame(index=apparent_zenith.index,
371373
data=clearsky_ghi,
@@ -675,14 +677,14 @@ def detect_clearsky(measured, clearsky, times, window_length,
675677
if len(unique_deltas) == 1:
676678
sample_interval = unique_deltas[0]
677679
else:
678-
raise NotImplementedError('algorithm does not yet support unequal ' \
680+
raise NotImplementedError('algorithm does not yet support unequal '
679681
'times. consider resampling your data.')
680682

681683
samples_per_window = int(window_length / sample_interval)
682684

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

688690
# calculate measurement statistics
@@ -729,14 +731,16 @@ def detect_clearsky(measured, clearsky, times, window_length,
729731
previous_alpha = alpha
730732
clear_meas = measured[clear_samples]
731733
clear_clear = clearsky[clear_samples]
734+
732735
def rmse(alpha):
733736
return np.sqrt(np.mean((clear_meas - alpha*clear_clear)**2))
737+
734738
alpha = minimize_scalar(rmse).x
735739
if round(alpha*10000) == round(previous_alpha*10000):
736740
break
737741
else:
738742
import warnings
739-
warnings.warn('failed to converge after %s iterations' \
743+
warnings.warn('failed to converge after %s iterations'
740744
% max_iterations, RuntimeWarning)
741745

742746
# be polite about returning the same type as was input
@@ -765,17 +769,18 @@ def bird(zenith, airmass_relative, aod380, aod500, precipitable_water,
765769
766770
Based on NREL Excel implementation by Daryl R. Myers [1, 2].
767771
768-
Bird and Hulstrom define the zenith as the "angle between a line to the sun
769-
and the local zenith". There is no distinction in the paper between solar
770-
zenith and apparent (or refracted) zenith, but the relative airmass is
771-
defined using the Kasten 1966 expression, which requires apparent zenith.
772-
Although the formulation for calculated zenith is never explicitly defined
773-
in the report, since the purpose was to compare existing clear sky models
774-
with "rigorous radiative transfer models" (RTM) it is possible that apparent
775-
zenith was obtained as output from the RTM. However, the implentation
776-
presented in PVLIB is tested against the NREL Excel implementation by Daryl
777-
Myers which uses an analytical expression for solar zenith instead of
778-
apparent zenith.
772+
Bird and Hulstrom define the zenith as the "angle between a line to
773+
the sun and the local zenith". There is no distinction in the paper
774+
between solar zenith and apparent (or refracted) zenith, but the
775+
relative airmass is defined using the Kasten 1966 expression, which
776+
requires apparent zenith. Although the formulation for calculated
777+
zenith is never explicitly defined in the report, since the purpose
778+
was to compare existing clear sky models with "rigorous radiative
779+
transfer models" (RTM) it is possible that apparent zenith was
780+
obtained as output from the RTM. However, the implentation presented
781+
in PVLIB is tested against the NREL Excel implementation by Daryl
782+
Myers which uses an analytical expression for solar zenith instead
783+
of apparent zenith.
779784
780785
Parameters
781786
----------
@@ -824,7 +829,8 @@ def bird(zenith, airmass_relative, aod380, aod500, precipitable_water,
824829
825830
`SERI/TR-642-761 <http://rredc.nrel.gov/solar/pubs/pdfs/tr-642-761.pdf>`_
826831
827-
`Error Reports <http://rredc.nrel.gov/solar/models/clearsky/error_reports.html>`_
832+
`Error Reports
833+
<http://rredc.nrel.gov/solar/models/clearsky/error_reports.html>`_
828834
"""
829835
etr = dni_extra # extraradiation
830836
ze_rad = np.deg2rad(zenith) # zenith in radians

pvlib/forecast.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,19 @@ def isobaric_to_ambient_temperature(self, data):
574574
Temperature in K
575575
"""
576576

577-
P = data['pressure'] / 100.0
578-
Tiso = data['temperature_iso']
579-
Td = data['temperature_dew_iso'] - 273.15
577+
P = data['pressure'] / 100.0 # noqa: N806
578+
Tiso = data['temperature_iso'] # noqa: N806
579+
Td = data['temperature_dew_iso'] - 273.15 # noqa: N806
580580

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

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

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

589-
return T
589+
return temperature
590590

591591
def uv_to_speed(self, data):
592592
"""
@@ -670,13 +670,19 @@ def __init__(self, resolution='half', set_type='best'):
670670
'wind_speed_gust': 'Wind_speed_gust_surface',
671671
'wind_speed_u': 'u-component_of_wind_isobaric',
672672
'wind_speed_v': 'v-component_of_wind_isobaric',
673-
'total_clouds': 'Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average',
674-
'low_clouds': 'Total_cloud_cover_low_cloud_Mixed_intervals_Average',
675-
'mid_clouds': 'Total_cloud_cover_middle_cloud_Mixed_intervals_Average',
676-
'high_clouds': 'Total_cloud_cover_high_cloud_Mixed_intervals_Average',
677-
'boundary_clouds': 'Total_cloud_cover_boundary_layer_cloud_Mixed_intervals_Average',
673+
'total_clouds':
674+
'Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average',
675+
'low_clouds':
676+
'Total_cloud_cover_low_cloud_Mixed_intervals_Average',
677+
'mid_clouds':
678+
'Total_cloud_cover_middle_cloud_Mixed_intervals_Average',
679+
'high_clouds':
680+
'Total_cloud_cover_high_cloud_Mixed_intervals_Average',
681+
'boundary_clouds': ('Total_cloud_cover_boundary_layer_cloud_'
682+
'Mixed_intervals_Average'),
678683
'convect_clouds': 'Total_cloud_cover_convective_cloud',
679-
'ghi_raw': 'Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average', }
684+
'ghi_raw': ('Downward_Short-Wave_Radiation_Flux_'
685+
'surface_Mixed_intervals_Average')}
680686

681687
self.output_variables = [
682688
'temp_air',
@@ -716,7 +722,7 @@ def process_data(self, data, cloud_cover='total_clouds', **kwargs):
716722
return data[self.output_variables]
717723

718724

719-
class HRRR_ESRL(ForecastModel):
725+
class HRRR_ESRL(ForecastModel): # noqa: N801
720726
"""
721727
Subclass of the ForecastModel class representing
722728
NOAA/GSD/ESRL's HRRR forecast model.
@@ -925,7 +931,8 @@ def __init__(self, set_type='best'):
925931
'low_clouds': 'Low_cloud_cover_low_cloud',
926932
'mid_clouds': 'Medium_cloud_cover_middle_cloud',
927933
'high_clouds': 'High_cloud_cover_high_cloud',
928-
'condensation_height': 'Geopotential_height_adiabatic_condensation_lifted'}
934+
'condensation_height':
935+
'Geopotential_height_adiabatic_condensation_lifted'}
929936

930937
self.output_variables = [
931938
'temp_air',

pvlib/irradiance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
125125
# a better way to do it.
126126
if isinstance(datetime_or_doy, pd.DatetimeIndex):
127127
to_doy = tools._pandas_to_doy # won't be evaluated unless necessary
128-
to_datetimeindex = lambda x: datetime_or_doy
128+
def to_datetimeindex(x): return x # noqa: E306
129129
to_output = partial(pd.Series, index=datetime_or_doy)
130130
elif isinstance(datetime_or_doy, pd.Timestamp):
131131
to_doy = tools._pandas_to_doy
@@ -139,12 +139,12 @@ def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
139139
tools._datetimelike_scalar_to_datetimeindex
140140
to_output = tools._scalar_out
141141
elif np.isscalar(datetime_or_doy): # ints and floats of various types
142-
to_doy = lambda x: datetime_or_doy
142+
def to_doy(x): return x # noqa: E306
143143
to_datetimeindex = partial(tools._doy_to_datetimeindex,
144144
epoch_year=epoch_year)
145145
to_output = tools._scalar_out
146146
else: # assume that we have an array-like object of doy
147-
to_doy = lambda x: datetime_or_doy
147+
def to_doy(x): return x # noqa: E306
148148
to_datetimeindex = partial(tools._doy_to_datetimeindex,
149149
epoch_year=epoch_year)
150150
to_output = tools._array_out
@@ -1972,7 +1972,7 @@ def _gti_dirint_lt_90(poa_global, aoi, aoi_lt_90, solar_zenith, solar_azimuth,
19721972
# we are here because we ran out of coeffs to loop over and
19731973
# therefore we have exceeded max_iterations
19741974
import warnings
1975-
failed_points = best_diff[aoi_lt_90][best_diff_lte_1_lt_90 == False]
1975+
failed_points = best_diff[aoi_lt_90][~best_diff_lte_1_lt_90]
19761976
warnings.warn(
19771977
('%s points failed to converge after %s iterations. best_diff:\n%s'
19781978
% (len(failed_points), max_iterations, failed_points)),

pvlib/modelchain.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ def basic_chain(times, latitude, longitude,
116116
raise ValueError('orientation_strategy or surface_tilt and '
117117
'surface_azimuth must be provided')
118118

119-
times = times
120-
121119
if altitude is None and pressure is None:
122120
altitude = 0.
123121
pressure = 101325.
@@ -126,12 +124,9 @@ def basic_chain(times, latitude, longitude,
126124
elif pressure is None:
127125
pressure = atmosphere.alt2pres(altitude)
128126

129-
solar_position = solarposition.get_solarposition(times, latitude,
130-
longitude,
131-
altitude=altitude,
132-
pressure=pressure,
133-
method=solar_position_method,
134-
**kwargs)
127+
solar_position = solarposition.get_solarposition(
128+
times, latitude, longitude, altitude=altitude, pressure=pressure,
129+
method=solar_position_method, **kwargs)
135130

136131
# possible error with using apparent zenith with some models
137132
airmass = atmosphere.get_relative_airmass(
@@ -372,12 +367,11 @@ def dc_model(self, model):
372367
if model in DC_MODEL_PARAMS.keys():
373368
# validate module parameters
374369
missing_params = DC_MODEL_PARAMS[model] - \
375-
set(self.system.module_parameters.keys())
376-
if missing_params: # some parameters are not in module.keys()
370+
set(self.system.module_parameters.keys())
371+
if missing_params: # some parameters are not in module.keys()
377372
raise ValueError(model + ' selected for the DC model but '
378-
'one or more required parameters '
379-
'are missing : ' +
380-
str(missing_params))
373+
'one or more required parameters are '
374+
'missing : ' + str(missing_params))
381375
if model == 'sapm':
382376
self._dc_model = self.sapm
383377
elif model == 'desoto':

pvlib/pvsystem.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from __future__ import division
77

88
from collections import OrderedDict
9-
import os
109
import io
10+
import os
1111
try:
1212
from urllib2 import urlopen
1313
except ImportError:
@@ -16,10 +16,9 @@
1616
import numpy as np
1717
import pandas as pd
1818

19-
from pvlib import tools
19+
from pvlib import atmosphere, irradiance, tools, singlediode as _singlediode
2020
from pvlib.tools import _build_kwargs
2121
from pvlib.location import Location
22-
from pvlib import irradiance, atmosphere, singlediode as _singlediode
2322

2423

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

338337
return calcparams_desoto(effective_irradiance, temp_cell, **kwargs)
339338

@@ -361,7 +360,7 @@ def calcparams_pvsyst(self, effective_irradiance, temp_cell):
361360
'R_s', 'alpha_sc', 'EgRef',
362361
'irrad_ref', 'temp_ref',
363362
'cells_in_series'],
364-
self.module_parameters)
363+
self.module_parameters)
365364

366365
return calcparams_pvsyst(effective_irradiance, temp_cell, **kwargs)
367366

@@ -511,7 +510,7 @@ def first_solar_spectral_loss(self, pw, airmass_absolute):
511510
"""
512511

513512
if 'first_solar_spectral_coefficients' in \
514-
self.module_parameters.keys():
513+
self.module_parameters.keys():
515514
coefficients = \
516515
self.module_parameters['first_solar_spectral_coefficients']
517516
module_type = None
@@ -552,7 +551,6 @@ def _infer_cell_type(self):
552551
'mc-Si': 'multisi',
553552
'c-Si': 'multisi',
554553
'Si-Film': 'asi',
555-
'CdTe': 'cdte',
556554
'EFG mc-Si': 'multisi',
557555
'GaAs': None,
558556
'a-Si / mono-Si': 'monosi'}
@@ -1133,7 +1131,7 @@ def calcparams_desoto(effective_irradiance, temp_cell,
11331131
* EgRef = 1.121
11341132
* dEgdT = -0.0002677
11351133
1136-
>>> M = np.polyval([-1.26E-4, 2.816E-3, -0.024459, 0.086257, 0.918093],
1134+
>>> M = np.polyval([-1.26E-4, 2.816E-3, -0.024459, 0.086257, 0.9181],
11371135
... AMa) # doctest: +SKIP
11381136
11391137
Source: [1]
@@ -1210,7 +1208,7 @@ def calcparams_desoto(effective_irradiance, temp_cell,
12101208
# equivalent to the product of S (irradiance reaching a module's cells) *
12111209
# M (spectral adjustment factor) as described in [1].
12121210
IL = effective_irradiance / irrad_ref * \
1213-
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
1211+
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
12141212
I0 = (I_o_ref * ((Tcell_K / Tref_K) ** 3) *
12151213
(np.exp(EgRef / (k*(Tref_K)) - (E_g / (k*(Tcell_K))))))
12161214
# Note that the equation for Rsh differs from [1]. In [1] Rsh is given as
@@ -1346,16 +1344,17 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
13461344
nNsVth = gamma * k / q * cells_in_series * Tcell_K
13471345

13481346
IL = effective_irradiance / irrad_ref * \
1349-
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
1347+
(I_L_ref + alpha_sc * (Tcell_K - Tref_K))
13501348

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

1354-
Rsh_tmp = (R_sh_ref - R_sh_0 * np.exp(-R_sh_exp)) / (1.0 - np.exp(-R_sh_exp))
1352+
Rsh_tmp = \
1353+
(R_sh_ref - R_sh_0 * np.exp(-R_sh_exp)) / (1.0 - np.exp(-R_sh_exp))
13551354
Rsh_base = np.maximum(0.0, Rsh_tmp)
13561355

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

13601359
Rs = R_s
13611360

@@ -1723,8 +1722,7 @@ def sapm_celltemp(poa_global, wind_speed, temp_air,
17231722

17241723
if isinstance(model, str):
17251724
model = temp_models[model.lower()]
1726-
elif isinstance(model, list):
1727-
model = model
1725+
17281726
elif isinstance(model, (dict, pd.Series)):
17291727
model = [model['a'], model['b'], model['deltaT']]
17301728

0 commit comments

Comments
 (0)