Skip to content

Commit 3aa2c4d

Browse files
authored
Allow dates to be strings in iotools get functions (#1800)
* Update get functions * Update pvgis.py * Update whatsnew and add get_cams * Update whatsnews * Update v0.10.2.rst
1 parent c063992 commit 3aa2c4d

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Deprecations
1111

1212
Enhancements
1313
~~~~~~~~~~~~
14+
* Added support for dates to be specified as strings in the iotools get functions:
15+
:py:func:`pvlib.iotools.get_pvgis_hourly`, :py:func:`pvlib.iotools.get_cams`,
16+
:py:func:`pvlib.iotools.get_bsrn`, and :py:func:`pvlib.iotools.read_midc_raw_data_from_nrel`.
17+
(:pull:`1800`)
1418

1519

1620
Bug fixes
@@ -31,4 +35,4 @@ Requirements
3135

3236
Contributors
3337
~~~~~~~~~~~~
34-
38+
* Adam R. Jensen (:ghuser:`AdamRJensen`)

pvlib/iotools/bsrn.py

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def get_bsrn(station, start, end, username, password,
154154
# The FTP server uses lowercase station abbreviations
155155
station = station.lower()
156156

157+
# Use pd.to_datetime so that strings (e.g. '2021-01-01') are accepted
158+
start = pd.to_datetime(start)
159+
end = pd.to_datetime(end)
160+
157161
# Generate list files to download based on start/end (SSSMMYY.dat.gz)
158162
filenames = pd.date_range(
159163
start, end.replace(day=1) + pd.DateOffset(months=1), freq='1M')\

pvlib/iotools/midc.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ def read_midc_raw_data_from_nrel(site, start, end, variable_map={},
215215
----------
216216
site: string
217217
The MIDC station id.
218-
start: datetime
218+
start: datetime-like
219219
Start date for requested data.
220-
end: datetime
220+
end: datetime-like
221221
End date for requested data.
222222
variable_map: dict
223223
A dictionary mapping MIDC field names to pvlib names. Used to
@@ -247,8 +247,8 @@ def read_midc_raw_data_from_nrel(site, start, end, variable_map={},
247247
for more details and considerations.
248248
"""
249249
args = {'site': site,
250-
'begin': start.strftime('%Y%m%d'),
251-
'end': end.strftime('%Y%m%d')}
250+
'begin': pd.to_datetime(start).strftime('%Y%m%d'),
251+
'end': pd.to_datetime(end).strftime('%Y%m%d')}
252252
url = 'https://midcdmz.nrel.gov/apps/data_api.pl'
253253
# NOTE: just use requests.get(url, params=args) to build querystring
254254
# number of header columns and data columns do not always match,

pvlib/iotools/pvgis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def get_pvgis_hourly(latitude, longitude, start=None, end=None,
217217
if raddatabase is not None:
218218
params['raddatabase'] = raddatabase
219219
if start is not None:
220-
params['startyear'] = start if isinstance(start, int) else start.year
220+
params['startyear'] = start if isinstance(start, int) else pd.to_datetime(start).year # noqa: E501
221221
if end is not None:
222-
params['endyear'] = end if isinstance(end, int) else end.year
222+
params['endyear'] = end if isinstance(end, int) else pd.to_datetime(end).year # noqa: E501
223223
if peakpower is not None:
224224
params['peakpower'] = peakpower
225225

pvlib/iotools/sodapro.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def get_cams(latitude, longitude, start, end, email, identifier='mcclear',
4747
altitude=None, time_step='1h', time_ref='UT', verbose=False,
4848
integrated=False, label=None, map_variables=True,
4949
server=URL, timeout=30):
50-
"""
51-
Retrieve time-series of radiation and/or clear-sky global, beam, and
50+
"""Retrieve irradiance and clear-sky time series from CAMS.
51+
52+
Time-series of radiation and/or clear-sky global, beam, and
5253
diffuse radiation from CAMS (see [1]_). Data is retrieved from SoDa [2]_.
5354
5455
Time coverage: 2004-01-01 to two days ago
@@ -65,9 +66,9 @@ def get_cams(latitude, longitude, start, end, email, identifier='mcclear',
6566
in decimal degrees, between -90 and 90, north is positive (ISO 19115)
6667
longitude : float
6768
in decimal degrees, between -180 and 180, east is positive (ISO 19115)
68-
start: datetime like
69+
start: datetime-like
6970
First day of the requested period
70-
end: datetime like
71+
end: datetime-like
7172
Last day of the requested period
7273
email: str
7374
Email address linked to a SoDa account
@@ -177,8 +178,8 @@ def get_cams(latitude, longitude, start, end, email, identifier='mcclear',
177178
altitude = -999
178179

179180
# Start and end date should be in the format: yyyy-mm-dd
180-
start = start.strftime('%Y-%m-%d')
181-
end = end.strftime('%Y-%m-%d')
181+
start = pd.to_datetime(start).strftime('%Y-%m-%d')
182+
end = pd.to_datetime(end).strftime('%Y-%m-%d')
182183

183184
email = email.replace('@', '%2540') # Format email address
184185
identifier = 'get_{}'.format(identifier.lower()) # Format identifier str

pvlib/iotools/srml.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ def get_srml(station, start, end, filetype='PO', map_variables=True,
243243
----------
244244
station : str
245245
Two letter station abbreviation.
246-
start : datetime like
246+
start : datetime-like
247247
First day of the requested period
248-
end : datetime like
248+
end : datetime-like
249249
Last day of the requested period
250250
filetype : string, default: 'PO'
251251
SRML file type to gather. See notes for explanation.

0 commit comments

Comments
 (0)