From 6dc8d48e514e9f8451fbcec52862a0ebe1931db5 Mon Sep 17 00:00:00 2001 From: ramaroesilva Date: Wed, 24 Dec 2025 10:30:43 +0000 Subject: [PATCH] Handle flake8 issues in part of the codebase. --- pvlib/clearsky.py | 6 ++++-- pvlib/iotools/acis.py | 7 +++---- pvlib/iotools/midc.py | 6 ++++-- pvlib/irradiance.py | 9 ++++++--- pvlib/singlediode.py | 28 +++++++++++++++++----------- pvlib/solarposition.py | 6 ++++-- pvlib/spa.py | 15 ++++++++++----- pvlib/spectrum/mismatch.py | 2 -- pvlib/temperature.py | 1 - 9 files changed, 48 insertions(+), 32 deletions(-) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index 8cc867e020..92e2387207 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -668,9 +668,11 @@ def _clearsky_get_threshold(sample_interval): window_length = np.interp(sample_interval, data_freq, [50, 60, 90, 120]) mean_diff = np.interp(sample_interval, data_freq, [75, 75, 75, 75]) max_diff = np.interp(sample_interval, data_freq, [60, 65, 75, 90]) - lower_line_length = np.interp(sample_interval, data_freq, [-45,-45,-45,-45]) + lower_line_length = np.interp(sample_interval, data_freq, + [-45, -45, -45, -45]) upper_line_length = np.interp(sample_interval, data_freq, [80, 80, 80, 80]) - var_diff = np.interp(sample_interval, data_freq, [0.005, 0.01, 0.032, 0.07]) + var_diff = np.interp(sample_interval, data_freq, + [0.005, 0.01, 0.032, 0.07]) slope_dev = np.interp(sample_interval, data_freq, [50, 60, 75, 96]) return (window_length, mean_diff, max_diff, lower_line_length, diff --git a/pvlib/iotools/acis.py b/pvlib/iotools/acis.py index 634af07933..8a4c7e4efc 100644 --- a/pvlib/iotools/acis.py +++ b/pvlib/iotools/acis.py @@ -55,7 +55,7 @@ def _get_acis(start, end, params, map_variables, url, **kwargs): metadata = payload['meta'] try: - # for StnData endpoint, unpack combination "ll" into lat, lon + # for StnData endpoint, unpack combination "ll" into lat, lon metadata['lon'], metadata['lat'] = metadata.pop('ll') except KeyError: pass @@ -244,7 +244,6 @@ def get_acis_nrcc(latitude, longitude, start, end, grid, map_variables=True, return df, meta - def get_acis_mpe(latitude, longitude, start, end, map_variables=True, url="https://data.rcc-acis.org/GridData", **kwargs): """ @@ -453,7 +452,7 @@ def get_acis_available_stations(latitude_range, longitude_range, ------- stations : pandas.DataFrame A dataframe of station metadata, one row per station. - The ``sids`` column contains IDs that can be used with + The ``sids`` column contains IDs that can be used with :py:func:`get_acis_station_data`. Raises @@ -489,7 +488,7 @@ def get_acis_available_stations(latitude_range, longitude_range, params = { "bbox": bbox, "meta": ("name,state,sids,sid_dates,ll,elev," - "uid,county,climdiv,tzo,network"), + "uid,county,climdiv,tzo,network"), } if start is not None and end is not None: params['elems'] = ['maxt', 'mint', 'avgt', 'obst', diff --git a/pvlib/iotools/midc.py b/pvlib/iotools/midc.py index c0dfd370eb..bdfd9bb1f1 100644 --- a/pvlib/iotools/midc.py +++ b/pvlib/iotools/midc.py @@ -108,7 +108,8 @@ def _format_index(data): - """Create DatetimeIndex for the Dataframe localized to the timezone provided + """ + Create DatetimeIndex for the Dataframe localized to the timezone provided as the label of the second (time) column. Parameters @@ -132,7 +133,8 @@ def _format_index(data): def _format_index_raw(data): - """Create DatetimeIndex for the Dataframe localized to the timezone provided + """ + Create DatetimeIndex for the Dataframe localized to the timezone provided as the label of the third column. Parameters diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 667592834b..cda4ea4460 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -132,7 +132,8 @@ 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 - def to_datetimeindex(x): return x # noqa: E306 + def to_datetimeindex(x): # noqa: E306 + return x to_output = partial(pd.Series, index=datetime_or_doy) elif isinstance(datetime_or_doy, pd.Timestamp): to_doy = tools._pandas_to_doy @@ -146,12 +147,14 @@ def to_datetimeindex(x): return x # noqa: E306 tools._datetimelike_scalar_to_datetimeindex to_output = tools._scalar_out elif np.isscalar(datetime_or_doy): # ints and floats of various types - def to_doy(x): return x # noqa: E306 + def to_doy(x): # noqa: E306 + return x 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 - def to_doy(x): return x # noqa: E306 + def to_doy(x): # noqa: E306 + return x to_datetimeindex = partial(tools._doy_to_datetimeindex, epoch_year=epoch_year) to_output = tools._array_out diff --git a/pvlib/singlediode.py b/pvlib/singlediode.py index f4fb98d956..7558f4bfc7 100644 --- a/pvlib/singlediode.py +++ b/pvlib/singlediode.py @@ -782,8 +782,9 @@ def _lambertw_v_from_i(current, photocurrent, saturation_current, # Explicit solutions where Gsh=0 if np.any(idx_z): - V[idx_z] = a[idx_z] * np.log1p((IL[idx_z] - I[idx_z]) / I0[idx_z]) - \ - I[idx_z] * Rs[idx_z] + V[idx_z] = \ + a[idx_z] * np.log1p((IL[idx_z] - I[idx_z]) / I0[idx_z]) - \ + I[idx_z] * Rs[idx_z] # Only compute using LambertW if there are cases with Gsh>0 if np.any(idx_p): @@ -865,17 +866,21 @@ def _lambertw_i_from_v(voltage, photocurrent, saturation_current, # Explicit solutions where Rs=0 if np.any(idx_z): - I[idx_z] = IL[idx_z] - I0[idx_z] * np.expm1(V[idx_z] / a[idx_z]) - \ - Gsh[idx_z] * V[idx_z] + I[idx_z] = \ + IL[idx_z] - I0[idx_z] * np.expm1(V[idx_z] / a[idx_z]) - \ + Gsh[idx_z] * V[idx_z] # Only compute using LambertW if there are cases with Rs>0 # Does NOT handle possibility of overflow, github issue 298 if np.any(idx_p): # LambertW argument, cannot be float128, may overflow to np.inf - argW = Rs[idx_p] * I0[idx_p] / ( - a[idx_p] * (Rs[idx_p] * Gsh[idx_p] + 1.)) * \ - np.exp((Rs[idx_p] * (IL[idx_p] + I0[idx_p]) + V[idx_p]) / - (a[idx_p] * (Rs[idx_p] * Gsh[idx_p] + 1.))) + argW = ( + Rs[idx_p] * I0[idx_p] + / (a[idx_p] * (Rs[idx_p] * Gsh[idx_p] + 1.)) + * np.exp( + (Rs[idx_p] * (IL[idx_p] + I0[idx_p]) + V[idx_p]) + / (a[idx_p] * (Rs[idx_p] * Gsh[idx_p] + 1.)) + )) # lambertw typically returns complex value with zero imaginary part # may overflow to np.inf @@ -884,9 +889,10 @@ def _lambertw_i_from_v(voltage, photocurrent, saturation_current, # Eqn. 2 in Jain and Kapoor, 2004 # I = -V/(Rs + Rsh) - (a/Rs)*lambertwterm + Rsh*(IL + I0)/(Rs + Rsh) # Recast in terms of Gsh=1/Rsh for better numerical stability. - I[idx_p] = (IL[idx_p] + I0[idx_p] - V[idx_p] * Gsh[idx_p]) / \ - (Rs[idx_p] * Gsh[idx_p] + 1.) - ( - a[idx_p] / Rs[idx_p]) * lambertwterm + I[idx_p] = \ + (IL[idx_p] + I0[idx_p] - V[idx_p] * Gsh[idx_p]) / \ + (Rs[idx_p] * Gsh[idx_p] + 1.) - (a[idx_p] / Rs[idx_p]) * \ + lambertwterm if output_is_scalar: return I.item() diff --git a/pvlib/solarposition.py b/pvlib/solarposition.py index 2b8a43e9d0..4ddf1438c4 100644 --- a/pvlib/solarposition.py +++ b/pvlib/solarposition.py @@ -1053,7 +1053,8 @@ def equation_of_time_spencer71(dayofyear): Myers [4]_ and printed in both the Fourier paper from the Sundial Mailing List and R. Hulstrom's [5]_ book. - .. _Fourier paper: http://www.mail-archive.com/sundial@uni-koeln.de/msg01050.html + .. _Fourier paper: + http://www.mail-archive.com/sundial@uni-koeln.de/msg01050.html Parameters ---------- @@ -1101,7 +1102,8 @@ def equation_of_time_pvcdrom(dayofyear): `PVCDROM`_ is a website by Solar Power Lab at Arizona State University (ASU) - .. _PVCDROM: http://www.pveducation.org/pvcdrom/2-properties-sunlight/solar-time + .. _PVCDROM: + http://www.pveducation.org/pvcdrom/2-properties-sunlight/solar-time Parameters ---------- diff --git a/pvlib/spa.py b/pvlib/spa.py index 6297e88c35..abf1b1e3fe 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -402,9 +402,11 @@ def nocompile(*args, **kwargs): @jcompile('float64(int64, int64, int64, int64, int64, int64, int64)', nopython=True) def julian_day_dt(year, month, day, hour, minute, second, microsecond): - """This is the original way to calculate the julian day from the NREL paper. + """ + This is the original way to calculate the julian day from the NREL paper. However, it is much faster to convert to unix/epoch time and then convert - to julian day. Note that the date must be UTC.""" + to julian day. Note that the date must be UTC. + """ if month <= 2: year = year-1 month = month+12 @@ -461,6 +463,7 @@ def sum_mult_cos_add_mult(arr, x): s += arr[row, 0] * np.cos(arr[row, 1] + arr[row, 2] * x) return s + @jcompile('float64(float64)', nopython=True) def heliocentric_longitude(jme): l0 = sum_mult_cos_add_mult(L0, jme) @@ -475,6 +478,7 @@ def heliocentric_longitude(jme): l = np.rad2deg(l_rad) return l % 360 + @jcompile('float64(float64)', nopython=True) def heliocentric_latitude(jme): b0 = sum_mult_cos_add_mult(B0, jme) @@ -762,9 +766,10 @@ def topocentric_elevation_angle_without_atmosphere(observer_latitude, @jcompile('float64(float64, float64, float64, float64)', nopython=True) -def atmospheric_refraction_correction(local_pressure, local_temp, - topocentric_elevation_angle_wo_atmosphere, - atmos_refract): +def atmospheric_refraction_correction( + local_pressure, local_temp, + topocentric_elevation_angle_wo_atmosphere, + atmos_refract): # switch sets delta_e when the sun is below the horizon switch = topocentric_elevation_angle_wo_atmosphere >= -1.0 * ( 0.26667 + atmos_refract) diff --git a/pvlib/spectrum/mismatch.py b/pvlib/spectrum/mismatch.py index b4385e255a..aac402ce49 100644 --- a/pvlib/spectrum/mismatch.py +++ b/pvlib/spectrum/mismatch.py @@ -9,8 +9,6 @@ import pandas as pd from scipy.integrate import trapezoid -from warnings import warn - def calc_spectral_mismatch_field(sr, e_sun, e_ref=None): """ diff --git a/pvlib/temperature.py b/pvlib/temperature.py index cb487ee77b..6485e8c010 100644 --- a/pvlib/temperature.py +++ b/pvlib/temperature.py @@ -6,7 +6,6 @@ import numpy as np import pandas as pd from pvlib.tools import sind -from pvlib._deprecation import warn_deprecated from pvlib.tools import _get_sample_intervals import scipy import scipy.constants