Skip to content

Commit ef48363

Browse files
authored
make iotools package (#272)
* make iotools package and move tmy readers into it * fix api, add deprecations * whitespace at end of file * update whatsnew * define api in init instead of api.py * fix a few style errors * more style fixes
1 parent 38a52b1 commit ef48363

File tree

10 files changed

+621
-543
lines changed

10 files changed

+621
-543
lines changed

docs/sphinx/source/api.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,37 @@ Functions
294294
tracking.singleaxis
295295

296296

297+
.. _iotools:
298+
299+
IO Tools
300+
========
301+
302+
Functions for reading and writing data from a variety of file formats
303+
relevant to solar energy modeling.
304+
305+
.. autosummary::
306+
:toctree: generated/
307+
308+
iotools.read_tmy2
309+
iotools.read_tmy3
310+
311+
A :py:class:`~pvlib.location.Location` object may be created from metadata
312+
in some files.
313+
314+
.. autosummary::
315+
:toctree: generated/
316+
317+
location.Location.from_tmy
318+
319+
297320
TMY
298321
===
299322

323+
.. warning::
324+
325+
The :py:mod:`pvlib.tmy` module is deprecated; it will be removed
326+
in pvlib 0.7. Please see the :ref:`pvlib.iotools <iotools>` package.
327+
300328
Methods and functions for reading data from TMY files.
301329

302330
.. autosummary::

docs/sphinx/source/clearsky.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ We'll need these imports for the examples below.
4040

4141
In [1]: import pvlib
4242

43-
In [1]: from pvlib import clearsky, atmosphere, tmy, solarposition
43+
In [1]: from pvlib import clearsky, atmosphere, solarposition
4444

4545
In [1]: from pvlib.location import Location
4646

47+
In [1]: from pvlib.iotools import read_tmy3
48+
4749

4850
.. _location:
4951

@@ -214,7 +216,7 @@ wavelengths [Bir80]_, and is implemented in
214216

215217
In [1]: tmy_file = os.path.join(pvlib_data, '703165TY.csv') # TMY file
216218

217-
In [1]: tmy_data, tmy_header = tmy.readtmy3(tmy_file, coerce_year=1999) # read TMY data
219+
In [1]: tmy_data, tmy_header = read_tmy3(tmy_file, coerce_year=1999) # read TMY data
218220

219221
In [1]: tl_historic = clearsky.lookup_linke_turbidity(time=tmy_data.index,
220222
...: latitude=tmy_header['latitude'], longitude=tmy_header['longitude'])

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ date will require Python 3. (:issue:`501`)
1212

1313
API Changes
1414
~~~~~~~~~~~
15+
* Created the ``pvlib.iotools`` subpackage. (:issue:`29`, :issue:`261`)
16+
* Deprecated ``tmy``, ``tmy.readtmy2`` and ``tmy.readtmy3``;
17+
they will be removed in v0.7. Use the new :py:func:`pvlib.iotools.read_tmy2`
18+
and :py:func:`pvlib.iotools.read_tmy3` instead. (:issue:`261`)
1519

1620

1721
Enhancements

pvlib/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
from pvlib import irradiance
77
from pvlib import location
88
from pvlib import solarposition
9-
from pvlib import tmy
9+
from pvlib import iotools
1010
from pvlib import tracking
1111
from pvlib import pvsystem
1212
from pvlib import spa
1313
from pvlib import modelchain
1414
from pvlib import singlediode
15+
16+
# for backwards compatibility for pvlib.tmy module
17+
from pvlib import tmy

pvlib/iotools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from pvlib.iotools.tmy import read_tmy2 # noqa: F401
2+
from pvlib.iotools.tmy import read_tmy3 # noqa: F401

pvlib/iotools/tmy.py

Lines changed: 521 additions & 0 deletions
Large diffs are not rendered by default.

pvlib/test/test_location.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ def test_get_clearsky_valueerror():
232232

233233
def test_from_tmy_3():
234234
from test_tmy import tmy3_testfile
235-
from pvlib.tmy import readtmy3
236-
data, meta = readtmy3(tmy3_testfile)
235+
from pvlib.iotools import read_tmy3
236+
data, meta = read_tmy3(tmy3_testfile)
237237
loc = Location.from_tmy(meta, data)
238238
assert loc.name is not None
239239
assert loc.altitude != 0
@@ -243,8 +243,8 @@ def test_from_tmy_3():
243243

244244
def test_from_tmy_2():
245245
from test_tmy import tmy2_testfile
246-
from pvlib.tmy import readtmy2
247-
data, meta = readtmy2(tmy2_testfile)
246+
from pvlib.iotools import read_tmy2
247+
data, meta = read_tmy2(tmy2_testfile)
248248
loc = Location.from_tmy(meta, data)
249249
assert loc.name is not None
250250
assert loc.altitude != 0

pvlib/test/test_pvsystem.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from pandas.util.testing import assert_series_equal, assert_frame_equal
1212
from numpy.testing import assert_allclose
1313

14-
from pvlib import tmy
1514
from pvlib import pvsystem
1615
from pvlib import clearsky
1716
from pvlib import irradiance
@@ -23,9 +22,10 @@
2322

2423

2524
def test_systemdef_tmy3():
26-
pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(tmy)))
25+
from pvlib.iotools import tmy
26+
pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(pvsystem)))
2727
tmy3_testfile = os.path.join(pvlib_abspath, 'data', '703165TY.csv')
28-
tmy3_data, tmy3_metadata = tmy.readtmy3(tmy3_testfile)
28+
tmy3_data, tmy3_metadata = tmy.read_tmy3(tmy3_testfile)
2929
expected = {'tz': -9.0,
3030
'albedo': 0.1,
3131
'altitude': 7.0,
@@ -40,9 +40,10 @@ def test_systemdef_tmy3():
4040

4141

4242
def test_systemdef_tmy2():
43-
pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(tmy)))
43+
from pvlib.iotools import tmy
44+
pvlib_abspath = os.path.dirname(os.path.abspath(inspect.getfile(pvsystem)))
4445
tmy2_testfile = os.path.join(pvlib_abspath, 'data', '12839.tm2')
45-
tmy2_data, tmy2_metadata = tmy.readtmy2(tmy2_testfile)
46+
tmy2_data, tmy2_metadata = tmy.read_tmy2(tmy2_testfile)
4647

4748
expected = {'tz': -5,
4849
'albedo': 0.1,

pvlib/test/test_tmy.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,60 @@
22
import os
33

44
from pandas.util.testing import network
5+
import pytest
6+
7+
from pvlib._deprecation import pvlibDeprecationWarning
8+
from pvlib.iotools import tmy
9+
10+
from conftest import fail_on_pvlib_version
11+
512

613
test_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
714
tmy3_testfile = os.path.join(test_dir, '../data/703165TY.csv')
815
tmy2_testfile = os.path.join(test_dir, '../data/12839.tm2')
916

10-
from pvlib import tmy
17+
18+
@fail_on_pvlib_version('0.7')
19+
def test_deprecated_07():
20+
with pytest.warns(pvlibDeprecationWarning):
21+
from pvlib.tmy import readtmy2
22+
readtmy2(tmy2_testfile)
23+
with pytest.warns(pvlibDeprecationWarning):
24+
from pvlib.tmy import readtmy3
25+
readtmy3(tmy3_testfile)
1126

1227

13-
def test_readtmy3():
14-
tmy.readtmy3(tmy3_testfile)
28+
def test_read_tmy3():
29+
tmy.read_tmy3(tmy3_testfile)
30+
1531

1632
@network
17-
def test_readtmy3_remote():
33+
def test_read_tmy3_remote():
1834
url = 'http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2005/data/tmy3/703165TYA.CSV'
19-
tmy.readtmy3(url)
20-
21-
def test_readtmy3_recolumn():
22-
data, meta = tmy.readtmy3(tmy3_testfile)
35+
tmy.read_tmy3(url)
36+
37+
38+
def test_read_tmy3_recolumn():
39+
data, meta = tmy.read_tmy3(tmy3_testfile)
2340
assert 'GHISource' in data.columns
24-
25-
def test_readtmy3_norecolumn():
26-
data, meta = tmy.readtmy3(tmy3_testfile, recolumn=False)
41+
42+
43+
def test_read_tmy3_norecolumn():
44+
data, meta = tmy.read_tmy3(tmy3_testfile, recolumn=False)
2745
assert 'GHI source' in data.columns
28-
29-
def test_readtmy3_coerce_year():
46+
47+
48+
def test_read_tmy3_coerce_year():
3049
coerce_year = 1987
31-
data, meta = tmy.readtmy3(tmy3_testfile, coerce_year=coerce_year)
50+
data, meta = tmy.read_tmy3(tmy3_testfile, coerce_year=coerce_year)
3251
assert (data.index.year == 1987).all()
33-
34-
def test_readtmy3_no_coerce_year():
52+
53+
54+
def test_read_tmy3_no_coerce_year():
3555
coerce_year = None
36-
data, meta = tmy.readtmy3(tmy3_testfile, coerce_year=coerce_year)
56+
data, meta = tmy.read_tmy3(tmy3_testfile, coerce_year=coerce_year)
3757
assert 1997 and 1999 in data.index.year
38-
39-
def test_readtmy2():
40-
tmy.readtmy2(tmy2_testfile)
41-
58+
59+
60+
def test_read_tmy2():
61+
tmy.read_tmy2(tmy2_testfile)

0 commit comments

Comments
 (0)