Skip to content

Commit a861c69

Browse files
committed
Merge branch 'king-deprecation' of https://github.com/cbcrespo/pvlib-python into king-deprecation
2 parents ef3459f + b3b8241 commit a861c69

10 files changed

Lines changed: 253 additions & 38 deletions

File tree

docs/examples/irradiance-transposition/plot_rtranpose_limitations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#
2929
# In this example we look at a single point in time and consider a full range
3030
# of possible GHI and POA global values as shown in figures 3 and 4 of [1]_.
31-
# Then we use :py:meth:`pvlib.irradiance.ghi_from_poa_driesse_2023` to estimate
31+
# Then we use :py:meth:`pvlib.irradiance.ghi_from_poa_driesse_2024` to estimate
3232
# the original GHI from POA global.
3333
#
3434
# References
@@ -45,7 +45,7 @@
4545

4646
from pvlib.irradiance import (erbs_driesse,
4747
get_total_irradiance,
48-
ghi_from_poa_driesse_2023,
48+
ghi_from_poa_driesse_2024,
4949
)
5050

5151
matplotlib.rcParams['axes.grid'] = True
@@ -92,7 +92,7 @@
9292

9393
poa_test = 200
9494

95-
ghi_hat = ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
95+
ghi_hat = ghi_from_poa_driesse_2024(surface_tilt, surface_azimuth,
9696
solar_zenith, solar_azimuth,
9797
poa_test,
9898
dni_extra,
@@ -156,7 +156,7 @@
156156
# out, other times not.
157157
#
158158

159-
result = ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
159+
result = ghi_from_poa_driesse_2024(surface_tilt, surface_azimuth,
160160
solar_zenith, solar_azimuth,
161161
poa_global,
162162
dni_extra,

docs/examples/irradiance-transposition/plot_rtranpose_year.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Recovering GHI from POA irradiance is termed "reverse transposition."
2222
#
2323
# In this example we start with a TMY file and calculate POA global irradiance.
24-
# Then we use :py:meth:`pvlib.irradiance.ghi_from_poa_driesse_2023` to estimate
24+
# Then we use :py:meth:`pvlib.irradiance.ghi_from_poa_driesse_2024` to estimate
2525
# the original GHI from POA global. Details of the method found in [1]_.
2626
#
2727
# Another method for reverse tranposition called GTI-DIRINT is also
@@ -49,7 +49,7 @@
4949
from pvlib import iotools, location
5050
from pvlib.irradiance import (get_extra_radiation,
5151
get_total_irradiance,
52-
ghi_from_poa_driesse_2023,
52+
ghi_from_poa_driesse_2024,
5353
aoi,
5454
)
5555

@@ -114,7 +114,7 @@
114114

115115
start = time.process_time()
116116

117-
df['ghi_rev'] = ghi_from_poa_driesse_2023(TILT, ORIENT,
117+
df['ghi_rev'] = ghi_from_poa_driesse_2024(TILT, ORIENT,
118118
solpos.apparent_zenith,
119119
solpos.azimuth,
120120
df.poa_global,

docs/sphinx/source/reference/irradiance/reverse-transposition.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Reverse transposition models
66
.. autosummary::
77
:toctree: ../generated/
88

9-
irradiance.ghi_from_poa_driesse_2023
9+
irradiance.ghi_from_poa_driesse_2024
1010
irradiance.gti_dirint

docs/sphinx/source/whatsnew/v0.15.2.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ Breaking Changes
1010

1111
Deprecations
1212
~~~~~~~~~~~~
13+
* Rename :py:func:`!pvlib.irradiance.ghi_from_poa_driesse_2023` to
14+
:py:func:`~pvlib.irradiance.ghi_from_poa_driesse_2024`. The year now reflects
15+
the publication date. The old name will be removed in v0.17.0.
16+
(:issue:`2774`, :pull:`2777`)
1317

1418

1519
Bug fixes
1620
~~~~~~~~~
21+
* Added test coverage for :py:func:`pvlib.irradiance.dirint` with
22+
``np.array`` and ``pd.Series`` inputs.
23+
(:issue:`2751`, :pull:`2752`)
1724
* Corrects a bug in :py:func:`pvlib.temperature.fuentes`. If inputs were
1825
data type integer, users can expect modeled cell temperature values to
1926
increase slightly.
@@ -26,16 +33,18 @@ Bug fixes
2633
represent the end of the averaging interval, consistent with ERA5
2734
conventions. (:issue:`2772`, :pull:`2773`)
2835

36+
* :py:func:`pvlib.iotools.read_nsrdb_psm4` now parses the file header with the
37+
:py:mod:`csv` module instead of a naive ``str.split(',')``, so quoted column
38+
names containing commas (e.g. the material names in spectral-on-demand files)
39+
are no longer split into spurious columns. (:issue:`2736`, :pull:`2771`)
2940

3041
Enhancements
3142
~~~~~~~~~~~~
32-
* Add the ``front_side_fraction`` parameter to
33-
:py:func:`pvlib.snow.loss_townsend` to support Townsend snow-loss
34-
workflows for bifacial systems. (:issue:`2755`, :pull:`2756`)
35-
36-
* Added mapping of the parameter ``"albedo"`` in
37-
:py:func:`~pvlib.iotools.get_nasa_power` when ``map_variables=True``
38-
(:pull:`2753`)
43+
* Add the following parameters to :py:func:`~pvlib.iotools.get_nasa_power`
44+
when ``map_variables=True``: ``temp_dew``, ``precipitable_water``,
45+
``relative_humidity``, ``ghi_extra``, ``dhi_clear``, ``longwave_down``,
46+
and ``albedo``.
47+
(:issue:`2731`, :pull:`2753`, :pull:`2762`)
3948

4049

4150
Documentation
@@ -67,7 +76,10 @@ Maintenance
6776
Contributors
6877
~~~~~~~~~~~~
6978
* :ghuser:`Omesh37`
79+
* :ghuser:`gaoflow`
7080
* Cliff Hansen (:ghuser:`cwhanse`)
7181
* :ghuser:`shethkajal7`
7282
* Arthur Onno (:ghuser:`ArthurOnnoTerabase`)
7383
* Adam R. Jensen (:ghuser:`AdamRJensen`)
84+
* Karl Hill (:ghuser:`karlhillx`)
85+
* Rajiv Daxini (:ghuser:`RDaxini`)

pvlib/iotools/nasa_power.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@
1414
'ALLSKY_SFC_SW_DWN': 'ghi',
1515
'ALLSKY_SFC_SW_DIFF': 'dhi',
1616
'ALLSKY_SFC_SW_DNI': 'dni',
17+
'ALLSKY_SRF_ALB': 'albedo',
18+
'ALLSKY_SFC_LW_DWN': 'longwave_down',
19+
'CLRSKY_SFC_SW_DIFF': 'dhi_clear',
20+
'CLRSKY_SFC_SW_DNI': 'dni_clear',
1721
'CLRSKY_SFC_SW_DWN': 'ghi_clear',
22+
'PS': 'pressure',
23+
'RH2M': 'relative_humidity',
1824
'T2M': 'temp_air',
25+
'T2MDEW': 'temp_dew',
26+
'TQV': 'precipitable_water',
27+
'TOA_SW_DWN': 'ghi_extra',
1928
'WS2M': 'wind_speed_2m',
2029
'WS10M': 'wind_speed',
21-
'ALLSKY_SRF_ALB': 'albedo',
2230
}
2331

2432

@@ -82,6 +90,12 @@ def get_nasa_power(latitude, longitude, start, end,
8290
requests.HTTPError
8391
Raises an error when an incorrect request is made.
8492
93+
Notes
94+
-----
95+
When ``map_variables=True`` the following unit conversions are applied:
96+
pressure is converted from kPa to Pa, and precipitable water
97+
is converted from kg/m² (mm) to cm.
98+
8599
Returns
86100
-------
87101
data : pd.DataFrame
@@ -150,5 +164,11 @@ def get_nasa_power(latitude, longitude, start, end,
150164
# Rename according to pvlib convention
151165
if map_variables:
152166
df = df.rename(columns=VARIABLE_MAP)
167+
# PS is returned in kPa; convert to Pa for pvlib compatibility.
168+
if 'pressure' in df.columns:
169+
df['pressure'] = df['pressure'] * 1000
170+
# TQV is returned in kg/m^2 (=mm); convert to cm for compatibility
171+
if 'precipitable_water' in df.columns:
172+
df['precipitable_water'] = df['precipitable_water'] / 10
153173

154174
return df, meta

pvlib/iotools/psm4.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
https://developer.nlr.gov/docs/solar/nsrdb/nsrdb-GOES-full-disc-v4-0-0-download/
77
"""
88

9+
import csv
910
import io
1011
from urllib.parse import urljoin
1112
import requests
@@ -723,11 +724,16 @@ def read_nsrdb_psm4(filename, map_variables=True):
723724
<https://web.archive.org/web/20170207203107/https://sam.nrel.gov/sites/default/files/content/documents/pdf/wfcsv.pdf>`_
724725
"""
725726
with tools._file_context_manager(filename) as fbuf:
727+
# The first 3 header lines are parsed with the csv module rather than a
728+
# naive str.split(',') so that quoted fields containing commas are kept
729+
# intact. Spectral-on-demand files, for instance, have column names
730+
# like '"GaAs (Bauhuis et al., 2009)"' whose embedded commas would
731+
# otherwise be split into spurious columns (see GH #2736).
726732
# The first 2 lines of the response are headers with metadata
727-
metadata_fields = fbuf.readline().split(',')
728-
metadata_values = fbuf.readline().split(',')
733+
metadata_fields = next(csv.reader([fbuf.readline()]))
734+
metadata_values = next(csv.reader([fbuf.readline()]))
729735
# get the column names so we can set the dtypes
730-
columns = fbuf.readline().split(',')
736+
columns = next(csv.reader([fbuf.readline()]))
731737
columns[-1] = columns[-1].strip() # strip trailing newline
732738
# Since the header has so many columns, excel saves blank cols in the
733739
# data below the header lines.

pvlib/irradiance.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pvlib import atmosphere, solarposition, tools
1717
import pvlib # used to avoid dni name collision in complete_irradiance
1818

19-
from pvlib._deprecation import deprecated, pvlibDeprecationWarning
19+
from pvlib._deprecation import pvlibDeprecationWarning, deprecated
2020
import warnings
2121

2222

@@ -132,7 +132,9 @@ def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
132132
# a better way to do it.
133133
if isinstance(datetime_or_doy, pd.DatetimeIndex):
134134
to_doy = tools._pandas_to_doy # won't be evaluated unless necessary
135-
def to_datetimeindex(x): return x # noqa: E306
135+
136+
def to_datetimeindex(x):
137+
return x # noqa: E306
136138
to_output = partial(pd.Series, index=datetime_or_doy)
137139
elif isinstance(datetime_or_doy, pd.Timestamp):
138140
to_doy = tools._pandas_to_doy
@@ -146,12 +148,14 @@ def to_datetimeindex(x): return x # noqa: E306
146148
tools._datetimelike_scalar_to_datetimeindex
147149
to_output = tools._scalar_out
148150
elif np.isscalar(datetime_or_doy): # ints and floats of various types
149-
def to_doy(x): return x # noqa: E306
151+
def to_doy(x):
152+
return x # noqa: E306
150153
to_datetimeindex = partial(tools._doy_to_datetimeindex,
151154
epoch_year=epoch_year)
152155
to_output = tools._scalar_out
153156
else: # assume that we have an array-like object of doy
154-
def to_doy(x): return x # noqa: E306
157+
def to_doy(x):
158+
return x # noqa: E306
155159
to_datetimeindex = partial(tools._doy_to_datetimeindex,
156160
epoch_year=epoch_year)
157161
to_output = tools._array_out
@@ -987,7 +991,7 @@ def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
987991

988992
@deprecated(
989993
since="0.15.2",
990-
removal="",
994+
removal="0.17.0",
991995
name="pvlib.irradiance.king",
992996
alternative="other diffuse transposition models in pvlib.irradiance",
993997
)
@@ -1448,7 +1452,7 @@ def _poa_from_ghi(surface_tilt, surface_azimuth,
14481452
Transposition function that includes decomposition of GHI using the
14491453
continuous Erbs-Driesse model.
14501454
1451-
Helper function for ghi_from_poa_driesse_2023.
1455+
Helper function for ghi_from_poa_driesse_2024.
14521456
'''
14531457
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023
14541458

@@ -1474,7 +1478,7 @@ def _ghi_from_poa(surface_tilt, surface_azimuth,
14741478
'''
14751479
Reverse transposition function that uses the scalar bisection from scipy.
14761480
1477-
Helper function for ghi_from_poa_driesse_2023.
1481+
Helper function for ghi_from_poa_driesse_2024.
14781482
'''
14791483
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023
14801484

@@ -1518,7 +1522,7 @@ def poa_error(ghi):
15181522
return ghi, conv, niter
15191523

15201524

1521-
def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
1525+
def ghi_from_poa_driesse_2024(surface_tilt, surface_azimuth,
15221526
solar_zenith, solar_azimuth,
15231527
poa_global,
15241528
dni_extra, airmass=None, albedo=0.25,
@@ -1620,6 +1624,14 @@ def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
16201624
return ghi
16211625

16221626

1627+
ghi_from_poa_driesse_2023 = deprecated(
1628+
since="0.15.2",
1629+
name="pvlib.irradiance.ghi_from_poa_driesse_2023",
1630+
alternative="pvlib.irradiance.ghi_from_poa_driesse_2024",
1631+
removal="0.17.0",
1632+
)(ghi_from_poa_driesse_2024)
1633+
1634+
16231635
def clearsky_index(ghi, ghi_clear, max_clearsky_index=2.0):
16241636
"""
16251637
Calculate the clearsky index.
@@ -1970,14 +1982,14 @@ def dirint(ghi, solar_zenith, times, pressure=101325., use_delta_kt_prime=True,
19701982
19711983
Returns
19721984
-------
1973-
dni : array-like
1974-
The modeled direct normal irradiance, as provided by the
1975-
DIRINT model. [Wm⁻²]
1985+
dni : pd.Series
1986+
Estimated direct normal irradiance. [Wm⁻²]
19761987
19771988
Notes
19781989
-----
1979-
DIRINT model requires time series data (ie. one of the inputs must
1980-
be a vector of length > 2).
1990+
The DIRINT model was developed for time series data with length > 2.
1991+
The implementation in pvlib assumes the data are periodic which may
1992+
affect the first and last DNI values.
19811993
19821994
References
19831995
----------
@@ -2115,6 +2127,7 @@ def _dirint_bins(times, kt_prime, zenith, w, delta_kt_prime):
21152127
-------
21162128
tuple of kt_prime_bin, zenith_bin, w_bin, delta_kt_prime_bin
21172129
"""
2130+
21182131
# @wholmgren: the following bin assignments use MATLAB's 1-indexing.
21192132
# Later, we'll subtract 1 to conform to Python's 0-indexing.
21202133

0 commit comments

Comments
 (0)