Skip to content

Commit 30266e8

Browse files
authored
Merge branch 'main' into replace_pytz_with_zoneinfo
2 parents 84c3fc4 + 935a77d commit 30266e8

13 files changed

Lines changed: 309 additions & 45 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: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ Deprecations
1212
~~~~~~~~~~~~
1313
* :py:attr:`pvlib.location.Location.pytz` is deprecated and will be removed in a future release. Use :py:attr:`~pvlib.location.Location.tz` instead.
1414
(:issue:`2343`, :pull:`2757`)
15+
* Rename :py:func:`!pvlib.irradiance.ghi_from_poa_driesse_2023` to
16+
:py:func:`~pvlib.irradiance.ghi_from_poa_driesse_2024`. The year now reflects
17+
the publication date. The old name will be removed in v0.17.0.
18+
(:issue:`2774`, :pull:`2777`)
1519

1620

1721
Bug fixes
1822
~~~~~~~~~
23+
* Added test coverage for :py:func:`pvlib.irradiance.dirint` with
24+
``np.array`` and ``pd.Series`` inputs.
25+
(:issue:`2751`, :pull:`2752`)
1926
* Corrects a bug in :py:func:`pvlib.temperature.fuentes`. If inputs were
2027
data type integer, users can expect modeled cell temperature values to
2128
increase slightly.
@@ -24,12 +31,22 @@ Bug fixes
2431
introduced in v0.15.1 (:pull:`2702`) that caused a broadcasting
2532
``ValueError`` when ``tracker_theta`` was a 2-D (or higher rank) array.
2633
(:issue:`2747`, :pull:`2749`)
34+
* Document that timestamps returned by :py:func:`~pvlib.iotools.get_era5`
35+
represent the end of the averaging interval, consistent with ERA5
36+
conventions. (:issue:`2772`, :pull:`2773`)
37+
38+
* :py:func:`pvlib.iotools.read_nsrdb_psm4` now parses the file header with the
39+
:py:mod:`csv` module instead of a naive ``str.split(',')``, so quoted column
40+
names containing commas (e.g. the material names in spectral-on-demand files)
41+
are no longer split into spurious columns. (:issue:`2736`, :pull:`2771`)
2742

2843
Enhancements
2944
~~~~~~~~~~~~
30-
* Added mapping of the parameter ``"albedo"`` in
31-
:py:func:`~pvlib.iotools.get_nasa_power` when ``map_variables=True``
32-
(:pull:`2753`)
45+
* Add the following parameters to :py:func:`~pvlib.iotools.get_nasa_power`
46+
when ``map_variables=True``: ``temp_dew``, ``precipitable_water``,
47+
``relative_humidity``, ``ghi_extra``, ``dhi_clear``, ``longwave_down``,
48+
and ``albedo``.
49+
(:issue:`2731`, :pull:`2753`, :pull:`2762`)
3350

3451

3552
Documentation
@@ -61,8 +78,11 @@ Maintenance
6178
Contributors
6279
~~~~~~~~~~~~
6380
* :ghuser:`Omesh37`
81+
* :ghuser:`gaoflow`
6482
* Cliff Hansen (:ghuser:`cwhanse`)
83+
* :ghuser:`shethkajal7`
6584
* Arthur Onno (:ghuser:`ArthurOnnoTerabase`)
6685
* Adam R. Jensen (:ghuser:`AdamRJensen`)
6786
* :ghuser:`JoLo90`
68-
87+
* Karl Hill (:ghuser:`karlhillx`)
88+
* Rajiv Daxini (:ghuser:`RDaxini`)

pvlib/iotools/era5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
102102
Returns
103103
-------
104104
data : pd.DataFrame
105-
Time series data. The index corresponds to the start of the interval.
105+
Time series data. The index corresponds to the end of the interval.
106106
meta : dict
107107
Metadata.
108108

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: 37 additions & 21 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 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
@@ -944,15 +948,18 @@ def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
944948
945949
References
946950
----------
947-
.. [1] Reindl, D. T., Beckmann, W. A., Duffie, J. A., 1990a. Diffuse
948-
fraction correlations. Solar Energy 45(1), 1-7.
949-
:doi:`10.1016/0038-092X(90)90060-P`
950-
.. [2] Reindl, D. T., Beckmann, W. A., Duffie, J. A., 1990b. Evaluation of
951-
hourly tilted surface radiation models. Solar Energy 45(1), 9-17.
951+
.. [1] D. T. Reindl, "Estimating diffuse radiation on horizontal surfaces
952+
and total radiation on tilted surfaces," M.S. thesis, University of
953+
Wisconsin-Madison, Madison, WI, USA, 1988. Available:
954+
https://web.archive.org/web/20240709013622/https://minds.wisconsin.edu/bitstream/handle/1793/47852/0001.pdf
955+
.. [2] D. T. Reindl, W. A. Beckmann, and J. A. Duffie, "Evaluation of
956+
hourly tilted surface radiation models," Solar Energy, vol. 45,
957+
no. 1, pp. 9–17, 1990.
952958
:doi:`10.1016/0038-092X(90)90061-G`
953-
.. [3] Loutzenhiser P. G. et. al., 2007. Empirical validation of models to
959+
.. [3] P. G. Loutzenhiser, H. Manz, C. Felsmann, P. A. Strachan,
960+
T. Frank, and G. M. Maxwell, "Empirical validation of models to
954961
compute solar irradiance on inclined surfaces for building energy
955-
simulation. Solar Energy 81(2), 254-267
962+
simulation," Solar Energy, vol. 81, no. 2, pp. 254267, 2007.
956963
:doi:`10.1016/j.solener.2006.03.009`
957964
'''
958965

@@ -1075,7 +1082,7 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
10751082
airmass : numeric
10761083
Relative (not pressure-corrected) airmass values. If AM is a
10771084
DataFrame it must be of the same size as all other DataFrame
1078-
inputs. AM must be >=0 (careful using the 1/sec(z) model of AM
1085+
inputs. AM must be >=0 (careful using the 1/cos(z) model of AM
10791086
generation). [unitless]
10801087
10811088
model : string, default 'allsitescomposite1990'
@@ -1335,7 +1342,7 @@ def perez_driesse(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
13351342
airmass : numeric, optional
13361343
Relative (not pressure-corrected) airmass values. If ``airmass`` is a
13371344
DataFrame it must be of the same size as all other DataFrame
1338-
inputs. AM must be >=0 (careful using the 1/sec(z) model of AM
1345+
inputs. AM must be >=0 (careful using the 1/cos(z) model of AM
13391346
generation). [unitless]
13401347
13411348
return_components: bool (optional, default=False)
@@ -1442,7 +1449,7 @@ def _poa_from_ghi(surface_tilt, surface_azimuth,
14421449
Transposition function that includes decomposition of GHI using the
14431450
continuous Erbs-Driesse model.
14441451
1445-
Helper function for ghi_from_poa_driesse_2023.
1452+
Helper function for ghi_from_poa_driesse_2024.
14461453
'''
14471454
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023
14481455

@@ -1468,7 +1475,7 @@ def _ghi_from_poa(surface_tilt, surface_azimuth,
14681475
'''
14691476
Reverse transposition function that uses the scalar bisection from scipy.
14701477
1471-
Helper function for ghi_from_poa_driesse_2023.
1478+
Helper function for ghi_from_poa_driesse_2024.
14721479
'''
14731480
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023
14741481

@@ -1512,7 +1519,7 @@ def poa_error(ghi):
15121519
return ghi, conv, niter
15131520

15141521

1515-
def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
1522+
def ghi_from_poa_driesse_2024(surface_tilt, surface_azimuth,
15161523
solar_zenith, solar_azimuth,
15171524
poa_global,
15181525
dni_extra, airmass=None, albedo=0.25,
@@ -1614,6 +1621,14 @@ def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
16141621
return ghi
16151622

16161623

1624+
ghi_from_poa_driesse_2023 = deprecated(
1625+
since="0.15.2",
1626+
name="pvlib.irradiance.ghi_from_poa_driesse_2023",
1627+
alternative="pvlib.irradiance.ghi_from_poa_driesse_2024",
1628+
removal="0.17.0",
1629+
)(ghi_from_poa_driesse_2024)
1630+
1631+
16171632
def clearsky_index(ghi, ghi_clear, max_clearsky_index=2.0):
16181633
"""
16191634
Calculate the clearsky index.
@@ -1964,14 +1979,14 @@ def dirint(ghi, solar_zenith, times, pressure=101325., use_delta_kt_prime=True,
19641979
19651980
Returns
19661981
-------
1967-
dni : array-like
1968-
The modeled direct normal irradiance, as provided by the
1969-
DIRINT model. [Wm⁻²]
1982+
dni : pd.Series
1983+
Estimated direct normal irradiance. [Wm⁻²]
19701984
19711985
Notes
19721986
-----
1973-
DIRINT model requires time series data (ie. one of the inputs must
1974-
be a vector of length > 2).
1987+
The DIRINT model was developed for time series data with length > 2.
1988+
The implementation in pvlib assumes the data are periodic which may
1989+
affect the first and last DNI values.
19751990
19761991
References
19771992
----------
@@ -2109,6 +2124,7 @@ def _dirint_bins(times, kt_prime, zenith, w, delta_kt_prime):
21092124
-------
21102125
tuple of kt_prime_bin, zenith_bin, w_bin, delta_kt_prime_bin
21112126
"""
2127+
21122128
# @wholmgren: the following bin assignments use MATLAB's 1-indexing.
21132129
# Later, we'll subtract 1 to conform to Python's 0-indexing.
21142130

0 commit comments

Comments
 (0)