From e46a60ffb55ba1a5ef5782054d6368ace9d76ba0 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Wed, 7 Jun 2023 12:48:07 +0200 Subject: [PATCH 01/24] Add function, tests and case example --- .../soiling/plot_greensboro_kimber_soiling.py | 7 +++---- pvlib/tests/test_tools.py | 20 +++++++++++++++++++ pvlib/tools.py | 15 ++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/docs/examples/soiling/plot_greensboro_kimber_soiling.py b/docs/examples/soiling/plot_greensboro_kimber_soiling.py index 6565679f6d..71e0e970cf 100644 --- a/docs/examples/soiling/plot_greensboro_kimber_soiling.py +++ b/docs/examples/soiling/plot_greensboro_kimber_soiling.py @@ -30,17 +30,16 @@ # step. from datetime import datetime -import pathlib from matplotlib import pyplot as plt from pvlib.iotools import read_tmy3 from pvlib.soiling import kimber -import pvlib +from pvlib.tools import dataset # get full path to the data directory -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +DATASET_DIR = dataset('723170TYA.CSV') # get TMY3 data with rain -greensboro, _ = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, +greensboro, _ = read_tmy3(DATASET_DIR, coerce_year=1990, map_variables=True) # get the rain data greensboro_rain = greensboro['Lprecip depth (mm)'] diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 4d5312088b..2eb039d2c4 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -2,6 +2,7 @@ from pvlib import tools import numpy as np +import pathlib @pytest.mark.parametrize('keys, input_dict, expected', [ @@ -95,3 +96,22 @@ def test_degrees_to_index_1(): 'latitude' or 'longitude' is passed.""" with pytest.raises(IndexError): # invalid value for coordinate argument tools._degrees_to_index(degrees=22.0, coordinate='width') + + +def test_dataset_passes(): + expected_dataset = '723170TYA.CSV' + assert tools.dataset(expected_dataset).endswith(expected_dataset) + assert tools.dataset(pathlib.Path(expected_dataset)) \ + .endswith(expected_dataset) + + +def test_dataset_fails_on_type(): + for input_value in (123456789.123, 10, np.array(5), None): + pytest.raises(TypeError, tools.dataset, input_value) + + +def test_dataset_fails_on_not_found(): + error_prompt = "Dataset has not been found in pvlib. " \ + "Please check dataset name." + with pytest.raises(IOError, match=error_prompt): + tools.dataset("_Texto_cualquiera.-formato-") diff --git a/pvlib/tools.py b/pvlib/tools.py index f6974cf3d3..fc663f74af 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -2,11 +2,14 @@ Collection of functions used in pvlib_python """ +import pvlib + import datetime as dt import numpy as np import pandas as pd import pytz import warnings +import os.path def cosd(angle): @@ -469,3 +472,15 @@ def _first_order_centered_difference(f, x0, dx=DX, args=()): # removal in scipy 1.12.0 df = f(x0+dx, *args) - f(x0-dx, *args) return df / 2 / dx + + +def dataset(dataset: str | os.PathLike): + """ + Return a filepath to a dataset bundled with PVLIB with name `dataset`. + This utility is intended to be used in tests and examples. + """ + dataset = os.path.join(pvlib.__path__[0], 'data', dataset) + if not os.path.exists(dataset): + raise IOError("Dataset has not been found in pvlib. " + "Please check dataset name.") + return dataset From 29c75544715f18658fc038cfb10776ae4af5d1ef Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:00:35 +0200 Subject: [PATCH 02/24] Fix type annotations --- pvlib/tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pvlib/tools.py b/pvlib/tools.py index fc663f74af..83bb5bcb01 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -474,11 +474,14 @@ def _first_order_centered_difference(f, x0, dx=DX, args=()): return df / 2 / dx -def dataset(dataset: str | os.PathLike): +def dataset(dataset): """ Return a filepath to a dataset bundled with PVLIB with name `dataset`. This utility is intended to be used in tests and examples. """ + if not isinstance(dataset, str) or not isinstance(dataset, os.PathLike): + raise TypeError + dataset = os.path.join(pvlib.__path__[0], 'data', dataset) if not os.path.exists(dataset): raise IOError("Dataset has not been found in pvlib. " From 725e299ef895694ddba7b2e889466ec1d6faa6b5 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:04:24 +0200 Subject: [PATCH 03/24] Yeet this stupid error --- pvlib/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tools.py b/pvlib/tools.py index 83bb5bcb01..fe1cb259f0 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -479,7 +479,7 @@ def dataset(dataset): Return a filepath to a dataset bundled with PVLIB with name `dataset`. This utility is intended to be used in tests and examples. """ - if not isinstance(dataset, str) or not isinstance(dataset, os.PathLike): + if not isinstance(dataset, str) and not isinstance(dataset, os.PathLike): raise TypeError dataset = os.path.join(pvlib.__path__[0], 'data', dataset) From 05dc263e246eae890cb01aa927bde5c1518b758b Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Thu, 8 Jun 2023 13:31:56 +0200 Subject: [PATCH 04/24] Remove unneeded feature --- pvlib/tests/test_tools.py | 5 ----- pvlib/tools.py | 3 --- 2 files changed, 8 deletions(-) diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 2eb039d2c4..c33aba1dac 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -105,11 +105,6 @@ def test_dataset_passes(): .endswith(expected_dataset) -def test_dataset_fails_on_type(): - for input_value in (123456789.123, 10, np.array(5), None): - pytest.raises(TypeError, tools.dataset, input_value) - - def test_dataset_fails_on_not_found(): error_prompt = "Dataset has not been found in pvlib. " \ "Please check dataset name." diff --git a/pvlib/tools.py b/pvlib/tools.py index fe1cb259f0..e5e8370f32 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -479,9 +479,6 @@ def dataset(dataset): Return a filepath to a dataset bundled with PVLIB with name `dataset`. This utility is intended to be used in tests and examples. """ - if not isinstance(dataset, str) and not isinstance(dataset, os.PathLike): - raise TypeError - dataset = os.path.join(pvlib.__path__[0], 'data', dataset) if not os.path.exists(dataset): raise IOError("Dataset has not been found in pvlib. " From b0f38d55624aaed468284894c95d59283c3bb59a Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:24:53 +0200 Subject: [PATCH 05/24] Renamed to locate_example_dataset Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> --- pvlib/tests/test_tools.py | 11 ++++++----- pvlib/tools.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index c33aba1dac..2149d8f88b 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -98,15 +98,16 @@ def test_degrees_to_index_1(): tools._degrees_to_index(degrees=22.0, coordinate='width') -def test_dataset_passes(): +def test_locate_example_dataset_passes(): expected_dataset = '723170TYA.CSV' - assert tools.dataset(expected_dataset).endswith(expected_dataset) - assert tools.dataset(pathlib.Path(expected_dataset)) \ + assert tools.locate_example_dataset(expected_dataset) \ + .endswith(expected_dataset) + assert tools.locate_example_dataset(pathlib.Path(expected_dataset)) \ .endswith(expected_dataset) -def test_dataset_fails_on_not_found(): +def test_locate_example_dataset_fails_on_not_found(): error_prompt = "Dataset has not been found in pvlib. " \ "Please check dataset name." with pytest.raises(IOError, match=error_prompt): - tools.dataset("_Texto_cualquiera.-formato-") + tools.locate_example_dataset("_Texto_cualquiera.-formato-") diff --git a/pvlib/tools.py b/pvlib/tools.py index e5e8370f32..3710dd14d2 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -474,7 +474,7 @@ def _first_order_centered_difference(f, x0, dx=DX, args=()): return df / 2 / dx -def dataset(dataset): +def locate_example_dataset(dataset): """ Return a filepath to a dataset bundled with PVLIB with name `dataset`. This utility is intended to be used in tests and examples. From b236fce4b467e87afb0a693822d3a0c5258497ec Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:45:45 +0200 Subject: [PATCH 06/24] Use pathlib & check existence of test files Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> --- pvlib/tests/test_tools.py | 14 ++++++++++---- pvlib/tools.py | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 2149d8f88b..c39feab788 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -1,5 +1,6 @@ import pytest +import pvlib from pvlib import tools import numpy as np import pathlib @@ -100,14 +101,19 @@ def test_degrees_to_index_1(): def test_locate_example_dataset_passes(): expected_dataset = '723170TYA.CSV' + assert pathlib.Path(pvlib.__path__[0], 'data', + expected_dataset).exists() assert tools.locate_example_dataset(expected_dataset) \ - .endswith(expected_dataset) + .name == expected_dataset assert tools.locate_example_dataset(pathlib.Path(expected_dataset)) \ - .endswith(expected_dataset) + .name == expected_dataset def test_locate_example_dataset_fails_on_not_found(): error_prompt = "Dataset has not been found in pvlib. " \ "Please check dataset name." - with pytest.raises(IOError, match=error_prompt): - tools.locate_example_dataset("_Texto_cualquiera.-formato-") + nonexistent_file = "_Texto_cualquiera.-formato-" + assert not pathlib.Path(pvlib.__path__[0], 'data', + nonexistent_file).exists() + with pytest.raises(ValueError, match=error_prompt): + tools.locate_example_dataset(nonexistent_file) diff --git a/pvlib/tools.py b/pvlib/tools.py index 3710dd14d2..cde08f6bd9 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -9,7 +9,7 @@ import pandas as pd import pytz import warnings -import os.path +import pathlib def cosd(angle): @@ -479,8 +479,8 @@ def locate_example_dataset(dataset): Return a filepath to a dataset bundled with PVLIB with name `dataset`. This utility is intended to be used in tests and examples. """ - dataset = os.path.join(pvlib.__path__[0], 'data', dataset) - if not os.path.exists(dataset): - raise IOError("Dataset has not been found in pvlib. " - "Please check dataset name.") + dataset = pathlib.Path(pvlib.__path__[0], 'data', dataset) + if not dataset.exists(): + raise ValueError("Dataset has not been found in pvlib. " + "Please check dataset name.") return dataset From 884f2defe0676bedcf2cd137718600aae6d16a2b Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:56:06 +0200 Subject: [PATCH 07/24] Add public documentation, hope it works Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> --- docs/sphinx/source/reference/iotools.rst | 7 +++++++ pvlib/tools.py | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/reference/iotools.rst b/docs/sphinx/source/reference/iotools.rst index 14271cf3ee..6e9a0b1823 100644 --- a/docs/sphinx/source/reference/iotools.rst +++ b/docs/sphinx/source/reference/iotools.rst @@ -47,3 +47,10 @@ in some files. location.Location.from_tmy location.Location.from_epw + +Functions for locating the example data files included in pvlib. + +.. autosummary:: + :toctree: generated/ + + tools.locate_example_dataset diff --git a/pvlib/tools.py b/pvlib/tools.py index cde08f6bd9..3632458c55 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -477,7 +477,22 @@ def _first_order_centered_difference(f, x0, dx=DX, args=()): def locate_example_dataset(dataset): """ Return a filepath to a dataset bundled with PVLIB with name `dataset`. - This utility is intended to be used in tests and examples. + This utility is intended to be used in tests and examples: + + .. ipython:: python + + import pvlib + pvlib.tools.locate_example_dataset('surfrad-slv16001.dat') + + Parameters + ---------- + dataset : str or PurePath + Name of dataset file + + Returns + ------- + path : PurePath + Path pointing to dataset file in PVLIB. """ dataset = pathlib.Path(pvlib.__path__[0], 'data', dataset) if not dataset.exists(): From dad683526bbe1cc434f9e85f3830a9543e040307 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:59:06 +0200 Subject: [PATCH 08/24] I forgot this assert :v Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> --- pvlib/tests/test_tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index c39feab788..aeb1e3caaa 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -107,6 +107,7 @@ def test_locate_example_dataset_passes(): .name == expected_dataset assert tools.locate_example_dataset(pathlib.Path(expected_dataset)) \ .name == expected_dataset + assert tools.locate_example_dataset(expected_dataset).exists() def test_locate_example_dataset_fails_on_not_found(): From 54905613067c002293e9977851c8913f6978ba55 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Fri, 9 Jun 2023 00:02:47 +0200 Subject: [PATCH 09/24] Update plot_greensboro_kimber_soiling.py Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> --- .../examples/soiling/plot_greensboro_kimber_soiling.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/examples/soiling/plot_greensboro_kimber_soiling.py b/docs/examples/soiling/plot_greensboro_kimber_soiling.py index 71e0e970cf..c4ebe5ce40 100644 --- a/docs/examples/soiling/plot_greensboro_kimber_soiling.py +++ b/docs/examples/soiling/plot_greensboro_kimber_soiling.py @@ -33,13 +33,13 @@ from matplotlib import pyplot as plt from pvlib.iotools import read_tmy3 from pvlib.soiling import kimber -from pvlib.tools import dataset +from pvlib.tools import locate_example_dataset -# get full path to the data directory -DATASET_DIR = dataset('723170TYA.CSV') +# get full path to the dataset file +tmy_filepath = locate_example_dataset('723170TYA.CSV') # get TMY3 data with rain -greensboro, _ = read_tmy3(DATASET_DIR, coerce_year=1990, +greensboro, _ = read_tmy3(tmy_filepath, coerce_year=1990, map_variables=True) # get the rain data greensboro_rain = greensboro['Lprecip depth (mm)'] @@ -64,3 +64,5 @@ plt.tight_layout() plt.show() + +# %% From eacedae087f640e697ce9dc6be10ac1870b00a3e Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Fri, 9 Jun 2023 08:56:26 +0200 Subject: [PATCH 10/24] Don't show examples backreference --- docs/sphinx/source/conf.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/sphinx/source/conf.py b/docs/sphinx/source/conf.py index cd2d6b379d..068d138aeb 100644 --- a/docs/sphinx/source/conf.py +++ b/docs/sphinx/source/conf.py @@ -365,6 +365,11 @@ def setup(app): # Modules for which function/class level galleries are created. In # this case only pvlib, could include others though. must be tuple of str 'doc_module': ('pvlib',), + + # objects to exclude from implicit backreferences + # https://sphinx-gallery.github.io/stable/configuration.html + # Section #add-mini-galleries-for-api-documentation + 'exclude_implicit_doc': {r'pvlib\.tools\.locate_example_dataset'}, } # supress warnings in gallery output # https://sphinx-gallery.github.io/stable/configuration.html From 28fe7debcee94da26bc397a4ed7f070af61a9876 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Fri, 9 Jun 2023 22:11:17 +0200 Subject: [PATCH 11/24] Update v0.10.0.rst (without user name since I'm already mentioned at #1764) --- docs/sphinx/source/whatsnew/v0.10.0.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sphinx/source/whatsnew/v0.10.0.rst b/docs/sphinx/source/whatsnew/v0.10.0.rst index a4406072f8..b47e5071cf 100644 --- a/docs/sphinx/source/whatsnew/v0.10.0.rst +++ b/docs/sphinx/source/whatsnew/v0.10.0.rst @@ -21,6 +21,9 @@ Deprecations Enhancements ~~~~~~~~~~~~ +* Add :py:func:`pvlib.tools.locate_example_dataset` to get example and test + files under `pvlib/data` path. + (:issue:`924`, :pull:`1763`) Bug fixes From aa91f28c09587df5f4c436557959f48207e6909f Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Jun 2023 10:51:51 +0200 Subject: [PATCH 12/24] Apply Kevin's implementation suggestions Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> --- pvlib/tests/test_tools.py | 16 ++++++++-------- pvlib/tools.py | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index aeb1e3caaa..50b17f3808 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -98,23 +98,23 @@ def test_degrees_to_index_1(): with pytest.raises(IndexError): # invalid value for coordinate argument tools._degrees_to_index(degrees=22.0, coordinate='width') - -def test_locate_example_dataset_passes(): +@pytest.mark.parametrize('location', [tuple(), ('data',)]) +def test_get_test_dataset_path_passes(location): expected_dataset = '723170TYA.CSV' assert pathlib.Path(pvlib.__path__[0], 'data', expected_dataset).exists() - assert tools.locate_example_dataset(expected_dataset) \ + assert tools.get_test_dataset_path(expected_dataset, *location) \ .name == expected_dataset - assert tools.locate_example_dataset(pathlib.Path(expected_dataset)) \ + assert tools.get_test_dataset_path(pathlib.Path(expected_dataset)) \ .name == expected_dataset - assert tools.locate_example_dataset(expected_dataset).exists() + assert tools.get_test_dataset_path(expected_dataset).exists() -def test_locate_example_dataset_fails_on_not_found(): - error_prompt = "Dataset has not been found in pvlib. " \ +def test_get_test_dataset_path_fails_on_not_found(): + error_prompt = "Dataset has not been found in pvlib at .*. " \ "Please check dataset name." nonexistent_file = "_Texto_cualquiera.-formato-" assert not pathlib.Path(pvlib.__path__[0], 'data', nonexistent_file).exists() with pytest.raises(ValueError, match=error_prompt): - tools.locate_example_dataset(nonexistent_file) + tools.get_test_dataset_path(nonexistent_file) diff --git a/pvlib/tools.py b/pvlib/tools.py index 3632458c55..133e122cd0 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -474,7 +474,7 @@ def _first_order_centered_difference(f, x0, dx=DX, args=()): return df / 2 / dx -def locate_example_dataset(dataset): +def get_test_dataset_path(dataset, location='data'): """ Return a filepath to a dataset bundled with PVLIB with name `dataset`. This utility is intended to be used in tests and examples: @@ -482,20 +482,28 @@ def locate_example_dataset(dataset): .. ipython:: python import pvlib - pvlib.tools.locate_example_dataset('surfrad-slv16001.dat') + pvlib.tools.get_test_dataset_path('surfrad-slv16001.dat') Parameters ---------- dataset : str or PurePath - Name of dataset file + Name of dataset file. + location : str or PurePath, default 'data' + PVLIB subfolder where dataset can be found. + This value can be: + +-------------------------+------------------------------+ + | ``location`` | Description | + +=========================+==============================+ + | ``'data'`` (default) | currently all files are here | + +-------------------------+------------------------------+ Returns ------- path : PurePath Path pointing to dataset file in PVLIB. """ - dataset = pathlib.Path(pvlib.__path__[0], 'data', dataset) + dataset = pathlib.Path(pvlib.__path__[0], location, dataset) if not dataset.exists(): - raise ValueError("Dataset has not been found in pvlib. " - "Please check dataset name.") + raise ValueError(f"Dataset has not been found in pvlib at {dataset}. " + "Please check dataset name and location.") return dataset From 5954a79276f73ef148af7c8c66a52b9d277a6a7c Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Jun 2023 11:23:33 +0200 Subject: [PATCH 13/24] Update plot_greensboro_kimber_soiling.py --- docs/examples/soiling/plot_greensboro_kimber_soiling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/soiling/plot_greensboro_kimber_soiling.py b/docs/examples/soiling/plot_greensboro_kimber_soiling.py index c4ebe5ce40..0e9deafa9a 100644 --- a/docs/examples/soiling/plot_greensboro_kimber_soiling.py +++ b/docs/examples/soiling/plot_greensboro_kimber_soiling.py @@ -33,10 +33,10 @@ from matplotlib import pyplot as plt from pvlib.iotools import read_tmy3 from pvlib.soiling import kimber -from pvlib.tools import locate_example_dataset +from pvlib.tools import get_test_dataset_path # get full path to the dataset file -tmy_filepath = locate_example_dataset('723170TYA.CSV') +tmy_filepath = get_test_dataset_path('723170TYA.CSV') # get TMY3 data with rain greensboro, _ = read_tmy3(tmy_filepath, coerce_year=1990, From 0e55f18be96a1b54854e2806e6e25b29d32defa9 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Jun 2023 11:47:59 +0200 Subject: [PATCH 14/24] Update iotools.rst --- docs/sphinx/source/reference/iotools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/source/reference/iotools.rst b/docs/sphinx/source/reference/iotools.rst index 6e9a0b1823..9fc5dea2f4 100644 --- a/docs/sphinx/source/reference/iotools.rst +++ b/docs/sphinx/source/reference/iotools.rst @@ -53,4 +53,4 @@ Functions for locating the example data files included in pvlib. .. autosummary:: :toctree: generated/ - tools.locate_example_dataset + tools.get_test_dataset_path From 311f7657b08c40b41e84da1d252e8d27697eaa24 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Jun 2023 12:14:52 +0200 Subject: [PATCH 15/24] Will this fix the table? --- pvlib/tools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pvlib/tools.py b/pvlib/tools.py index 133e122cd0..355a3a1ea1 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -491,6 +491,7 @@ def get_test_dataset_path(dataset, location='data'): location : str or PurePath, default 'data' PVLIB subfolder where dataset can be found. This value can be: + +-------------------------+------------------------------+ | ``location`` | Description | +=========================+==============================+ From 3a91cd72cd0374d5127c4e2726bd6118d7b8945a Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Jun 2023 12:25:58 +0200 Subject: [PATCH 16/24] This should be fine now --- docs/sphinx/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/source/conf.py b/docs/sphinx/source/conf.py index 068d138aeb..74234545d3 100644 --- a/docs/sphinx/source/conf.py +++ b/docs/sphinx/source/conf.py @@ -369,7 +369,7 @@ def setup(app): # objects to exclude from implicit backreferences # https://sphinx-gallery.github.io/stable/configuration.html # Section #add-mini-galleries-for-api-documentation - 'exclude_implicit_doc': {r'pvlib\.tools\.locate_example_dataset'}, + 'exclude_implicit_doc': {r'pvlib\.tools\.get_test_dataset_path'}, } # supress warnings in gallery output # https://sphinx-gallery.github.io/stable/configuration.html From 4a38b0e553e98273432373f1a73c98d27c39026c Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:52:21 +0200 Subject: [PATCH 17/24] Substitute occurrences of pvlib.__file__ or similar where appropiate --- .../adr-pvarray/plot_simulate_system.py | 8 +++----- .../plot_diffuse_fraction.py | 8 +++----- .../plot_seasonal_tilt.py | 8 +++----- .../plot_transposition_gain.py | 10 ++++------ .../soiling/plot_fig3A_hsu_soiling_example.py | 10 +++++----- docs/sphinx/source/user_guide/clearsky.rst | 16 ++++------------ pvlib/clearsky.py | 6 ++---- pvlib/location.py | 7 +++---- pvlib/pvsystem.py | 18 ++++++------------ pvlib/spectrum/mismatch.py | 6 ++---- pvlib/tests/test_tools.py | 1 + pvlib/tools.py | 2 +- 12 files changed, 37 insertions(+), 63 deletions(-) diff --git a/docs/examples/adr-pvarray/plot_simulate_system.py b/docs/examples/adr-pvarray/plot_simulate_system.py index b0abede934..112f1cd1d8 100644 --- a/docs/examples/adr-pvarray/plot_simulate_system.py +++ b/docs/examples/adr-pvarray/plot_simulate_system.py @@ -12,12 +12,11 @@ Author: Anton Driesse """ -import os import pandas as pd import matplotlib.pyplot as plt import pvlib -from pvlib import iotools, location +from pvlib import iotools, location, tools from pvlib.irradiance import get_total_irradiance from pvlib.pvarray import pvefficiency_adr @@ -26,10 +25,9 @@ # Read a TMY3 file containing weather data and select needed columns # -PVLIB_DIR = pvlib.__path__[0] -DATA_FILE = os.path.join(PVLIB_DIR, 'data', '723170TYA.CSV') +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') -tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990, +tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) df = pd.DataFrame({'ghi': tmy['ghi'], 'dhi': tmy['dhi'], 'dni': tmy['dni'], diff --git a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py index 30d1385f87..03eb943af3 100644 --- a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py +++ b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py @@ -14,20 +14,18 @@ # GHI into the diffuse and direct components. The separate components are # needed to estimate the total irradiance on a tilted surface. -import pathlib from matplotlib import pyplot as plt import pandas as pd from pvlib.iotools import read_tmy3 from pvlib.solarposition import get_solarposition -from pvlib import irradiance -import pvlib +from pvlib import irradiance, tools # For this example we use the Greensboro, North Carolina, TMY3 file which is # in the pvlib data directory. TMY3 are made from the median months from years # of data measured from 1990 to 2010. Therefore we change the timestamps to a # common year, 1990. -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' -greensboro, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +greensboro, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) # Many of the diffuse fraction estimation methods require the "true" zenith, so diff --git a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py index afe610f6d2..fb2cb9a92f 100644 --- a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py +++ b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py @@ -12,11 +12,9 @@ # to use a custom Mount class to use the Seasonal Tilt strategy # with :py:class:`~pvlib.modelchain.ModelChain`. -import pvlib -from pvlib import pvsystem, location, modelchain, iotools +from pvlib import pvsystem, location, modelchain, iotools, tools from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS import pandas as pd -import pathlib import matplotlib.pyplot as plt from dataclasses import dataclass @@ -43,8 +41,8 @@ def get_orientation(self, solar_zenith, solar_azimuth): # First let's grab some weather data and make sure our mount produces tilts # like we expect: -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' -tmy, metadata = iotools.read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) # shift from TMY3 right-labeled index to left-labeled index: tmy.index = tmy.index - pd.Timedelta(hours=1) diff --git a/docs/examples/irradiance-transposition/plot_transposition_gain.py b/docs/examples/irradiance-transposition/plot_transposition_gain.py index 4ce558b47c..80435ac80a 100644 --- a/docs/examples/irradiance-transposition/plot_transposition_gain.py +++ b/docs/examples/irradiance-transposition/plot_transposition_gain.py @@ -19,21 +19,19 @@ # insolation is calculated for each strategy to show how orientation affects # seasonal irradiance collection. -import pvlib from pvlib import location from pvlib import irradiance from pvlib import tracking +from pvlib import tools from pvlib.iotools import read_tmy3 import pandas as pd from matplotlib import pyplot as plt -import pathlib -# get full path to the data directory -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +# get full path to the example file +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') # get TMY3 dataset -tmy, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, - map_variables=True) +tmy, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) # TMY3 datasets are right-labeled (AKA "end of interval") which means the last # interval of Dec 31, 23:00 to Jan 1 00:00 is labeled Jan 1 00:00. When rolling # up hourly irradiance to monthly insolation, a spurious January value is diff --git a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py index 9103fa0207..1eb51835d6 100644 --- a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py +++ b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py @@ -21,18 +21,18 @@ # PM2.5 and PM10 data come from the EPA. First, let's read in the # weather data and run the HSU soiling model: -import pathlib from matplotlib import pyplot as plt from pvlib import soiling import pvlib import pandas as pd -# get full path to the data directory -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +# get full path to the example file +soiling_hsu_filepath = \ + pvlib.tools.get_test_dataset_path('soiling_hsu_example_inputs.csv') # read rainfall, PM2.5, and PM10 data from file -imperial_county = pd.read_csv(DATA_DIR / 'soiling_hsu_example_inputs.csv', - index_col=0, parse_dates=True) +imperial_county = pd.read_csv(soiling_hsu_filepath, index_col=0, + parse_dates=True) rainfall = imperial_county['rain'] depo_veloc = {'2_5': 0.0009, '10': 0.004} # default values from [1] (m/s) rain_accum_period = pd.Timedelta('1h') # default diff --git a/docs/sphinx/source/user_guide/clearsky.rst b/docs/sphinx/source/user_guide/clearsky.rst index 7d45a38159..933646b4e4 100644 --- a/docs/sphinx/source/user_guide/clearsky.rst +++ b/docs/sphinx/source/user_guide/clearsky.rst @@ -30,8 +30,6 @@ We'll need these imports for the examples below. .. ipython:: - In [1]: import os - In [1]: import itertools In [1]: import matplotlib.pyplot as plt @@ -40,7 +38,7 @@ We'll need these imports for the examples below. In [1]: import pvlib - In [1]: from pvlib import clearsky, atmosphere, solarposition + In [1]: from pvlib import clearsky, atmosphere, solarposition, tools In [1]: from pvlib.location import Location @@ -130,13 +128,9 @@ the year. You could run it in a loop to create plots for all months. In [1]: import calendar - In [1]: import os - In [1]: import h5py - In [1]: pvlib_path = os.path.dirname(os.path.abspath(pvlib.clearsky.__file__)) - - In [1]: filepath = os.path.join(pvlib_path, 'data', 'LinkeTurbidities.h5') + In [1]: filepath = tools.get_test_dataset_path('LinkeTurbidities.h5') In [1]: def plot_turbidity_map(month, vmin=1, vmax=100): ...: plt.figure(); @@ -210,13 +204,11 @@ wavelengths [Bir80]_, and is implemented in .. ipython:: - In [1]: pvlib_data = os.path.join(os.path.dirname(pvlib.__file__), 'data') - In [1]: mbars = 100 # conversion factor from mbars to Pa - In [1]: tmy_file = os.path.join(pvlib_data, '703165TY.csv') # TMY file + In [1]: tmy_file_path = tools.get_test_dataset_path('703165TY.csv') # TMY file - In [1]: tmy_data, tmy_header = read_tmy3(tmy_file, coerce_year=1999, map_variables=True) + In [1]: tmy_data, tmy_header = read_tmy3(tmy_file_path, coerce_year=1999, map_variables=True) In [1]: tl_historic = clearsky.lookup_linke_turbidity(time=tmy_data.index, ...: latitude=tmy_header['latitude'], longitude=tmy_header['longitude']) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index ffc7ac9b55..d204931f6d 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -3,7 +3,6 @@ to calculate clear sky GHI, DNI, and DHI. """ -import os from collections import OrderedDict import calendar @@ -14,7 +13,7 @@ import h5py from pvlib import atmosphere, tools -from pvlib.tools import _degrees_to_index +from pvlib.tools import _degrees_to_index, get_test_dataset_path def ineichen(apparent_zenith, airmass_absolute, linke_turbidity, @@ -189,8 +188,7 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, # 1st column: 179.9583 W, 2nd column: 179.875 W if filepath is None: - pvlib_path = os.path.dirname(os.path.abspath(__file__)) - filepath = os.path.join(pvlib_path, 'data', 'LinkeTurbidities.h5') + filepath = get_test_dataset_path('LinkeTurbidities.h5') latitude_index = _degrees_to_index(latitude, coordinate='latitude') longitude_index = _degrees_to_index(longitude, coordinate='longitude') diff --git a/pvlib/location.py b/pvlib/location.py index 6e8e89ee00..6748baa024 100644 --- a/pvlib/location.py +++ b/pvlib/location.py @@ -4,7 +4,6 @@ # Will Holmgren, University of Arizona, 2014-2016. -import os import datetime import pandas as pd @@ -12,7 +11,8 @@ import h5py from pvlib import solarposition, clearsky, atmosphere, irradiance -from pvlib.tools import _degrees_to_index +from pvlib.tools import _degrees_to_index, get_test_dataset_path + class Location: """ @@ -426,8 +426,7 @@ def lookup_altitude(latitude, longitude): """ - pvlib_path = os.path.dirname(os.path.abspath(__file__)) - filepath = os.path.join(pvlib_path, 'data', 'Altitude.h5') + filepath = get_test_dataset_path('Altitude.h5') latitude_index = _degrees_to_index(latitude, coordinate='latitude') longitude_index = _degrees_to_index(longitude, coordinate='longitude') diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index d136089b10..5393f2dc10 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -7,7 +7,6 @@ import functools import io import itertools -import os from urllib.request import urlopen import numpy as np from scipy import constants @@ -20,7 +19,7 @@ from pvlib import (atmosphere, iam, inverter, irradiance, singlediode as _singlediode, temperature) -from pvlib.tools import _build_kwargs, _build_args +from pvlib.tools import _build_kwargs, _build_args, get_test_dataset_path # a dict of required parameter names for each DC power model @@ -2371,24 +2370,19 @@ def retrieve_sam(name=None, path=None): if name is not None: name = name.lower() - data_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), 'data') if name == 'cecmod': - csvdata = os.path.join( - data_path, 'sam-library-cec-modules-2019-03-05.csv') + csvdata = 'sam-library-cec-modules-2019-03-05.csv' elif name == 'sandiamod': - csvdata = os.path.join( - data_path, 'sam-library-sandia-modules-2015-6-30.csv') + csvdata = 'sam-library-sandia-modules-2015-6-30.csv' elif name == 'adrinverter': - csvdata = os.path.join( - data_path, 'adr-library-cec-inverters-2019-03-05.csv') + csvdata = 'adr-library-cec-inverters-2019-03-05.csv' elif name in ['cecinverter', 'sandiainverter']: # Allowing either, to provide for old code, # while aligning with current expectations - csvdata = os.path.join( - data_path, 'sam-library-cec-inverters-2019-03-05.csv') + csvdata = 'sam-library-cec-inverters-2019-03-05.csv' else: raise ValueError(f'invalid name {name}') + csvdata = get_test_dataset_path(csvdata) elif path is not None: if path.startswith('http'): response = urlopen(path) diff --git a/pvlib/spectrum/mismatch.py b/pvlib/spectrum/mismatch.py index 5db4649ddd..5d3c464653 100644 --- a/pvlib/spectrum/mismatch.py +++ b/pvlib/spectrum/mismatch.py @@ -6,7 +6,6 @@ import numpy as np import pandas as pd from scipy.interpolate import interp1d -import os def get_example_spectral_response(wavelength=None): @@ -117,10 +116,9 @@ def get_am15g(wavelength=None): ''' # Contributed by Anton Driesse (@adriesse), PV Performance Labs. Aug. 2022 - pvlib_path = pvlib.__path__[0] - filepath = os.path.join(pvlib_path, 'data', 'astm_g173_am15g.csv') + am15g_file = pvlib.tools.get_test_dataset_path('astm_g173_am15g.csv') - am15g = pd.read_csv(filepath, index_col=0).squeeze() + am15g = pd.read_csv(am15g_file, index_col=0).squeeze() if wavelength is not None: interpolator = interp1d(am15g.index, am15g, diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 50b17f3808..842a2896ba 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -98,6 +98,7 @@ def test_degrees_to_index_1(): with pytest.raises(IndexError): # invalid value for coordinate argument tools._degrees_to_index(degrees=22.0, coordinate='width') + @pytest.mark.parametrize('location', [tuple(), ('data',)]) def test_get_test_dataset_path_passes(location): expected_dataset = '723170TYA.CSV' diff --git a/pvlib/tools.py b/pvlib/tools.py index 355a3a1ea1..0ca074cda0 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -491,7 +491,7 @@ def get_test_dataset_path(dataset, location='data'): location : str or PurePath, default 'data' PVLIB subfolder where dataset can be found. This value can be: - + +-------------------------+------------------------------+ | ``location`` | Description | +=========================+==============================+ From f5bfcf6114bc0261418a87a5dc7225927093180a Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:35:34 +0200 Subject: [PATCH 18/24] Revert "Substitute occurrences of pvlib.__file__ or similar where appropiate" This reverts commit 4a38b0e553e98273432373f1a73c98d27c39026c. --- .../adr-pvarray/plot_simulate_system.py | 8 +++++--- .../plot_diffuse_fraction.py | 8 +++++--- .../plot_seasonal_tilt.py | 8 +++++--- .../plot_transposition_gain.py | 10 ++++++---- .../soiling/plot_fig3A_hsu_soiling_example.py | 10 +++++----- docs/sphinx/source/user_guide/clearsky.rst | 16 ++++++++++++---- pvlib/clearsky.py | 6 ++++-- pvlib/location.py | 7 ++++--- pvlib/pvsystem.py | 18 ++++++++++++------ pvlib/spectrum/mismatch.py | 6 ++++-- pvlib/tests/test_tools.py | 1 - pvlib/tools.py | 2 +- 12 files changed, 63 insertions(+), 37 deletions(-) diff --git a/docs/examples/adr-pvarray/plot_simulate_system.py b/docs/examples/adr-pvarray/plot_simulate_system.py index 112f1cd1d8..b0abede934 100644 --- a/docs/examples/adr-pvarray/plot_simulate_system.py +++ b/docs/examples/adr-pvarray/plot_simulate_system.py @@ -12,11 +12,12 @@ Author: Anton Driesse """ +import os import pandas as pd import matplotlib.pyplot as plt import pvlib -from pvlib import iotools, location, tools +from pvlib import iotools, location from pvlib.irradiance import get_total_irradiance from pvlib.pvarray import pvefficiency_adr @@ -25,9 +26,10 @@ # Read a TMY3 file containing weather data and select needed columns # -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +PVLIB_DIR = pvlib.__path__[0] +DATA_FILE = os.path.join(PVLIB_DIR, 'data', '723170TYA.CSV') -tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, +tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990, map_variables=True) df = pd.DataFrame({'ghi': tmy['ghi'], 'dhi': tmy['dhi'], 'dni': tmy['dni'], diff --git a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py index 03eb943af3..30d1385f87 100644 --- a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py +++ b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py @@ -14,18 +14,20 @@ # GHI into the diffuse and direct components. The separate components are # needed to estimate the total irradiance on a tilted surface. +import pathlib from matplotlib import pyplot as plt import pandas as pd from pvlib.iotools import read_tmy3 from pvlib.solarposition import get_solarposition -from pvlib import irradiance, tools +from pvlib import irradiance +import pvlib # For this example we use the Greensboro, North Carolina, TMY3 file which is # in the pvlib data directory. TMY3 are made from the median months from years # of data measured from 1990 to 2010. Therefore we change the timestamps to a # common year, 1990. -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') -greensboro, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, +DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +greensboro, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, map_variables=True) # Many of the diffuse fraction estimation methods require the "true" zenith, so diff --git a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py index fb2cb9a92f..afe610f6d2 100644 --- a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py +++ b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py @@ -12,9 +12,11 @@ # to use a custom Mount class to use the Seasonal Tilt strategy # with :py:class:`~pvlib.modelchain.ModelChain`. -from pvlib import pvsystem, location, modelchain, iotools, tools +import pvlib +from pvlib import pvsystem, location, modelchain, iotools from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS import pandas as pd +import pathlib import matplotlib.pyplot as plt from dataclasses import dataclass @@ -41,8 +43,8 @@ def get_orientation(self, solar_zenith, solar_azimuth): # First let's grab some weather data and make sure our mount produces tilts # like we expect: -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') -tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, +DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +tmy, metadata = iotools.read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, map_variables=True) # shift from TMY3 right-labeled index to left-labeled index: tmy.index = tmy.index - pd.Timedelta(hours=1) diff --git a/docs/examples/irradiance-transposition/plot_transposition_gain.py b/docs/examples/irradiance-transposition/plot_transposition_gain.py index 80435ac80a..4ce558b47c 100644 --- a/docs/examples/irradiance-transposition/plot_transposition_gain.py +++ b/docs/examples/irradiance-transposition/plot_transposition_gain.py @@ -19,19 +19,21 @@ # insolation is calculated for each strategy to show how orientation affects # seasonal irradiance collection. +import pvlib from pvlib import location from pvlib import irradiance from pvlib import tracking -from pvlib import tools from pvlib.iotools import read_tmy3 import pandas as pd from matplotlib import pyplot as plt +import pathlib -# get full path to the example file -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +# get full path to the data directory +DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' # get TMY3 dataset -tmy, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) +tmy, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, + map_variables=True) # TMY3 datasets are right-labeled (AKA "end of interval") which means the last # interval of Dec 31, 23:00 to Jan 1 00:00 is labeled Jan 1 00:00. When rolling # up hourly irradiance to monthly insolation, a spurious January value is diff --git a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py index 1eb51835d6..9103fa0207 100644 --- a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py +++ b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py @@ -21,18 +21,18 @@ # PM2.5 and PM10 data come from the EPA. First, let's read in the # weather data and run the HSU soiling model: +import pathlib from matplotlib import pyplot as plt from pvlib import soiling import pvlib import pandas as pd -# get full path to the example file -soiling_hsu_filepath = \ - pvlib.tools.get_test_dataset_path('soiling_hsu_example_inputs.csv') +# get full path to the data directory +DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' # read rainfall, PM2.5, and PM10 data from file -imperial_county = pd.read_csv(soiling_hsu_filepath, index_col=0, - parse_dates=True) +imperial_county = pd.read_csv(DATA_DIR / 'soiling_hsu_example_inputs.csv', + index_col=0, parse_dates=True) rainfall = imperial_county['rain'] depo_veloc = {'2_5': 0.0009, '10': 0.004} # default values from [1] (m/s) rain_accum_period = pd.Timedelta('1h') # default diff --git a/docs/sphinx/source/user_guide/clearsky.rst b/docs/sphinx/source/user_guide/clearsky.rst index ae0c609f5a..e32351ee6b 100644 --- a/docs/sphinx/source/user_guide/clearsky.rst +++ b/docs/sphinx/source/user_guide/clearsky.rst @@ -30,6 +30,8 @@ We'll need these imports for the examples below. .. ipython:: + In [1]: import os + In [1]: import itertools In [1]: import matplotlib.pyplot as plt @@ -38,7 +40,7 @@ We'll need these imports for the examples below. In [1]: import pvlib - In [1]: from pvlib import clearsky, atmosphere, solarposition, tools + In [1]: from pvlib import clearsky, atmosphere, solarposition In [1]: from pvlib.location import Location @@ -128,9 +130,13 @@ the year. You could run it in a loop to create plots for all months. In [1]: import calendar + In [1]: import os + In [1]: import h5py - In [1]: filepath = tools.get_test_dataset_path('LinkeTurbidities.h5') + In [1]: pvlib_path = os.path.dirname(os.path.abspath(pvlib.clearsky.__file__)) + + In [1]: filepath = os.path.join(pvlib_path, 'data', 'LinkeTurbidities.h5') In [1]: def plot_turbidity_map(month, vmin=1, vmax=100): ...: plt.figure(); @@ -204,11 +210,13 @@ wavelengths [Bir80]_, and is implemented in .. ipython:: + In [1]: pvlib_data = os.path.join(os.path.dirname(pvlib.__file__), 'data') + In [1]: mbars = 100 # conversion factor from mbars to Pa - In [1]: tmy_file_path = tools.get_test_dataset_path('703165TY.csv') # TMY file + In [1]: tmy_file = os.path.join(pvlib_data, '703165TY.csv') # TMY file - In [1]: tmy_data, tmy_header = read_tmy3(tmy_file_path, coerce_year=1999, map_variables=True) + In [1]: tmy_data, tmy_header = read_tmy3(tmy_file, coerce_year=1999, map_variables=True) In [1]: tl_historic = clearsky.lookup_linke_turbidity(time=tmy_data.index, ...: latitude=tmy_header['latitude'], longitude=tmy_header['longitude']) diff --git a/pvlib/clearsky.py b/pvlib/clearsky.py index d204931f6d..ffc7ac9b55 100644 --- a/pvlib/clearsky.py +++ b/pvlib/clearsky.py @@ -3,6 +3,7 @@ to calculate clear sky GHI, DNI, and DHI. """ +import os from collections import OrderedDict import calendar @@ -13,7 +14,7 @@ import h5py from pvlib import atmosphere, tools -from pvlib.tools import _degrees_to_index, get_test_dataset_path +from pvlib.tools import _degrees_to_index def ineichen(apparent_zenith, airmass_absolute, linke_turbidity, @@ -188,7 +189,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None, # 1st column: 179.9583 W, 2nd column: 179.875 W if filepath is None: - filepath = get_test_dataset_path('LinkeTurbidities.h5') + pvlib_path = os.path.dirname(os.path.abspath(__file__)) + filepath = os.path.join(pvlib_path, 'data', 'LinkeTurbidities.h5') latitude_index = _degrees_to_index(latitude, coordinate='latitude') longitude_index = _degrees_to_index(longitude, coordinate='longitude') diff --git a/pvlib/location.py b/pvlib/location.py index 6748baa024..6e8e89ee00 100644 --- a/pvlib/location.py +++ b/pvlib/location.py @@ -4,6 +4,7 @@ # Will Holmgren, University of Arizona, 2014-2016. +import os import datetime import pandas as pd @@ -11,8 +12,7 @@ import h5py from pvlib import solarposition, clearsky, atmosphere, irradiance -from pvlib.tools import _degrees_to_index, get_test_dataset_path - +from pvlib.tools import _degrees_to_index class Location: """ @@ -426,7 +426,8 @@ def lookup_altitude(latitude, longitude): """ - filepath = get_test_dataset_path('Altitude.h5') + pvlib_path = os.path.dirname(os.path.abspath(__file__)) + filepath = os.path.join(pvlib_path, 'data', 'Altitude.h5') latitude_index = _degrees_to_index(latitude, coordinate='latitude') longitude_index = _degrees_to_index(longitude, coordinate='longitude') diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index d9d86a7244..bdab5d604d 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -7,6 +7,7 @@ import functools import io import itertools +import os from urllib.request import urlopen import numpy as np from scipy import constants @@ -19,7 +20,7 @@ from pvlib import (atmosphere, iam, inverter, irradiance, singlediode as _singlediode, spectrum, temperature) -from pvlib.tools import _build_kwargs, _build_args, get_test_dataset_path +from pvlib.tools import _build_kwargs, _build_args # a dict of required parameter names for each DC power model @@ -2370,19 +2371,24 @@ def retrieve_sam(name=None, path=None): if name is not None: name = name.lower() + data_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), 'data') if name == 'cecmod': - csvdata = 'sam-library-cec-modules-2019-03-05.csv' + csvdata = os.path.join( + data_path, 'sam-library-cec-modules-2019-03-05.csv') elif name == 'sandiamod': - csvdata = 'sam-library-sandia-modules-2015-6-30.csv' + csvdata = os.path.join( + data_path, 'sam-library-sandia-modules-2015-6-30.csv') elif name == 'adrinverter': - csvdata = 'adr-library-cec-inverters-2019-03-05.csv' + csvdata = os.path.join( + data_path, 'adr-library-cec-inverters-2019-03-05.csv') elif name in ['cecinverter', 'sandiainverter']: # Allowing either, to provide for old code, # while aligning with current expectations - csvdata = 'sam-library-cec-inverters-2019-03-05.csv' + csvdata = os.path.join( + data_path, 'sam-library-cec-inverters-2019-03-05.csv') else: raise ValueError(f'invalid name {name}') - csvdata = get_test_dataset_path(csvdata) elif path is not None: if path.startswith('http'): response = urlopen(path) diff --git a/pvlib/spectrum/mismatch.py b/pvlib/spectrum/mismatch.py index c854b37411..a7e7cf0851 100644 --- a/pvlib/spectrum/mismatch.py +++ b/pvlib/spectrum/mismatch.py @@ -6,6 +6,7 @@ import numpy as np import pandas as pd from scipy.interpolate import interp1d +import os from warnings import warn @@ -118,9 +119,10 @@ def get_am15g(wavelength=None): ''' # Contributed by Anton Driesse (@adriesse), PV Performance Labs. Aug. 2022 - am15g_file = pvlib.tools.get_test_dataset_path('astm_g173_am15g.csv') + pvlib_path = pvlib.__path__[0] + filepath = os.path.join(pvlib_path, 'data', 'astm_g173_am15g.csv') - am15g = pd.read_csv(am15g_file, index_col=0).squeeze() + am15g = pd.read_csv(filepath, index_col=0).squeeze() if wavelength is not None: interpolator = interp1d(am15g.index, am15g, diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 842a2896ba..50b17f3808 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -98,7 +98,6 @@ def test_degrees_to_index_1(): with pytest.raises(IndexError): # invalid value for coordinate argument tools._degrees_to_index(degrees=22.0, coordinate='width') - @pytest.mark.parametrize('location', [tuple(), ('data',)]) def test_get_test_dataset_path_passes(location): expected_dataset = '723170TYA.CSV' diff --git a/pvlib/tools.py b/pvlib/tools.py index 0ca074cda0..355a3a1ea1 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -491,7 +491,7 @@ def get_test_dataset_path(dataset, location='data'): location : str or PurePath, default 'data' PVLIB subfolder where dataset can be found. This value can be: - + +-------------------------+------------------------------+ | ``location`` | Description | +=========================+==============================+ From 8c78cb443e3bfe040e169cbfaf31c0fb7dc56cb7 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:36:11 +0200 Subject: [PATCH 19/24] Revert "Will this fix the table?" This reverts commit 311f7657b08c40b41e84da1d252e8d27697eaa24. --- pvlib/tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pvlib/tools.py b/pvlib/tools.py index 355a3a1ea1..133e122cd0 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -491,7 +491,6 @@ def get_test_dataset_path(dataset, location='data'): location : str or PurePath, default 'data' PVLIB subfolder where dataset can be found. This value can be: - +-------------------------+------------------------------+ | ``location`` | Description | +=========================+==============================+ From 6215608d66fe6a4d922502a28aa7263707879827 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:41:36 +0200 Subject: [PATCH 20/24] Delete custom path behaviour, rename to get_example_dataset_path Co-Authored-By: Kevin Anderson <57452607+kandersolar@users.noreply.github.com> Co-Authored-By: Will Holmgren --- docs/sphinx/source/conf.py | 2 +- docs/sphinx/source/reference/iotools.rst | 2 +- pvlib/tests/test_tools.py | 12 ++++++------ pvlib/tools.py | 20 ++++++-------------- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/docs/sphinx/source/conf.py b/docs/sphinx/source/conf.py index 74234545d3..80cd67fbfc 100644 --- a/docs/sphinx/source/conf.py +++ b/docs/sphinx/source/conf.py @@ -369,7 +369,7 @@ def setup(app): # objects to exclude from implicit backreferences # https://sphinx-gallery.github.io/stable/configuration.html # Section #add-mini-galleries-for-api-documentation - 'exclude_implicit_doc': {r'pvlib\.tools\.get_test_dataset_path'}, + 'exclude_implicit_doc': {r'pvlib\.tools\.get_example_dataset_path'}, } # supress warnings in gallery output # https://sphinx-gallery.github.io/stable/configuration.html diff --git a/docs/sphinx/source/reference/iotools.rst b/docs/sphinx/source/reference/iotools.rst index 0268cba2ae..bb1635f4bf 100644 --- a/docs/sphinx/source/reference/iotools.rst +++ b/docs/sphinx/source/reference/iotools.rst @@ -51,4 +51,4 @@ Functions for locating the example data files included in pvlib. .. autosummary:: :toctree: generated/ - tools.get_test_dataset_path + tools.get_example_dataset_path diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 50b17f3808..7ac05836c9 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -99,22 +99,22 @@ def test_degrees_to_index_1(): tools._degrees_to_index(degrees=22.0, coordinate='width') @pytest.mark.parametrize('location', [tuple(), ('data',)]) -def test_get_test_dataset_path_passes(location): +def test_get_example_dataset_path_passes(location): expected_dataset = '723170TYA.CSV' assert pathlib.Path(pvlib.__path__[0], 'data', expected_dataset).exists() - assert tools.get_test_dataset_path(expected_dataset, *location) \ + assert tools.get_example_dataset_path(expected_dataset, *location) \ .name == expected_dataset - assert tools.get_test_dataset_path(pathlib.Path(expected_dataset)) \ + assert tools.get_example_dataset_path(pathlib.Path(expected_dataset)) \ .name == expected_dataset - assert tools.get_test_dataset_path(expected_dataset).exists() + assert tools.get_example_dataset_path(expected_dataset).exists() -def test_get_test_dataset_path_fails_on_not_found(): +def test_get_example_dataset_path_fails_on_not_found(): error_prompt = "Dataset has not been found in pvlib at .*. " \ "Please check dataset name." nonexistent_file = "_Texto_cualquiera.-formato-" assert not pathlib.Path(pvlib.__path__[0], 'data', nonexistent_file).exists() with pytest.raises(ValueError, match=error_prompt): - tools.get_test_dataset_path(nonexistent_file) + tools.get_example_dataset_path(nonexistent_file) diff --git a/pvlib/tools.py b/pvlib/tools.py index 133e122cd0..2b18e2c3af 100644 --- a/pvlib/tools.py +++ b/pvlib/tools.py @@ -474,36 +474,28 @@ def _first_order_centered_difference(f, x0, dx=DX, args=()): return df / 2 / dx -def get_test_dataset_path(dataset, location='data'): +def get_example_dataset_path(dataset): """ Return a filepath to a dataset bundled with PVLIB with name `dataset`. - This utility is intended to be used in tests and examples: + This utility is intended to be used in examples: .. ipython:: python import pvlib - pvlib.tools.get_test_dataset_path('surfrad-slv16001.dat') + pvlib.tools.get_example_dataset_path('surfrad-slv16001.dat') Parameters ---------- dataset : str or PurePath Name of dataset file. - location : str or PurePath, default 'data' - PVLIB subfolder where dataset can be found. - This value can be: - +-------------------------+------------------------------+ - | ``location`` | Description | - +=========================+==============================+ - | ``'data'`` (default) | currently all files are here | - +-------------------------+------------------------------+ Returns ------- path : PurePath - Path pointing to dataset file in PVLIB. + Path pointing to an example dataset file in PVLIB. """ - dataset = pathlib.Path(pvlib.__path__[0], location, dataset) + dataset = pathlib.Path(pvlib.__path__[0], 'data', dataset) if not dataset.exists(): raise ValueError(f"Dataset has not been found in pvlib at {dataset}. " - "Please check dataset name and location.") + "Please check dataset name.") return dataset From aa08e09cbed8d90f15dfcf962261fce54a3417ba Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:52:14 +0200 Subject: [PATCH 21/24] Use function in tests only --- docs/examples/adr-pvarray/plot_simulate_system.py | 8 +++----- .../irradiance-decomposition/plot_diffuse_fraction.py | 7 +++---- .../irradiance-transposition/plot_seasonal_tilt.py | 9 ++++----- .../plot_transposition_gain.py | 11 +++++------ .../soiling/plot_fig3A_hsu_soiling_example.py | 11 ++++++----- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/docs/examples/adr-pvarray/plot_simulate_system.py b/docs/examples/adr-pvarray/plot_simulate_system.py index b0abede934..112f1cd1d8 100644 --- a/docs/examples/adr-pvarray/plot_simulate_system.py +++ b/docs/examples/adr-pvarray/plot_simulate_system.py @@ -12,12 +12,11 @@ Author: Anton Driesse """ -import os import pandas as pd import matplotlib.pyplot as plt import pvlib -from pvlib import iotools, location +from pvlib import iotools, location, tools from pvlib.irradiance import get_total_irradiance from pvlib.pvarray import pvefficiency_adr @@ -26,10 +25,9 @@ # Read a TMY3 file containing weather data and select needed columns # -PVLIB_DIR = pvlib.__path__[0] -DATA_FILE = os.path.join(PVLIB_DIR, 'data', '723170TYA.CSV') +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') -tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990, +tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) df = pd.DataFrame({'ghi': tmy['ghi'], 'dhi': tmy['dhi'], 'dni': tmy['dni'], diff --git a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py index 30d1385f87..dd12f13a52 100644 --- a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py +++ b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py @@ -14,20 +14,19 @@ # GHI into the diffuse and direct components. The separate components are # needed to estimate the total irradiance on a tilted surface. -import pathlib from matplotlib import pyplot as plt import pandas as pd from pvlib.iotools import read_tmy3 from pvlib.solarposition import get_solarposition from pvlib import irradiance -import pvlib +from pvlib import tools # For this example we use the Greensboro, North Carolina, TMY3 file which is # in the pvlib data directory. TMY3 are made from the median months from years # of data measured from 1990 to 2010. Therefore we change the timestamps to a # common year, 1990. -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' -greensboro, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +greensboro, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) # Many of the diffuse fraction estimation methods require the "true" zenith, so diff --git a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py index afe610f6d2..722891fe4a 100644 --- a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py +++ b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py @@ -12,11 +12,9 @@ # to use a custom Mount class to use the Seasonal Tilt strategy # with :py:class:`~pvlib.modelchain.ModelChain`. -import pvlib -from pvlib import pvsystem, location, modelchain, iotools +from pvlib import pvsystem, location, modelchain, iotools, tools from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS import pandas as pd -import pathlib import matplotlib.pyplot as plt from dataclasses import dataclass @@ -43,9 +41,10 @@ def get_orientation(self, solar_zenith, solar_azimuth): # First let's grab some weather data and make sure our mount produces tilts # like we expect: -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' -tmy, metadata = iotools.read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) + # shift from TMY3 right-labeled index to left-labeled index: tmy.index = tmy.index - pd.Timedelta(hours=1) weather = pd.DataFrame({ diff --git a/docs/examples/irradiance-transposition/plot_transposition_gain.py b/docs/examples/irradiance-transposition/plot_transposition_gain.py index 4ce558b47c..ef7c57a110 100644 --- a/docs/examples/irradiance-transposition/plot_transposition_gain.py +++ b/docs/examples/irradiance-transposition/plot_transposition_gain.py @@ -19,21 +19,20 @@ # insolation is calculated for each strategy to show how orientation affects # seasonal irradiance collection. -import pvlib from pvlib import location from pvlib import irradiance from pvlib import tracking +from pvlib import tools from pvlib.iotools import read_tmy3 import pandas as pd from matplotlib import pyplot as plt -import pathlib -# get full path to the data directory -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +# get full path to the example file +tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') # get TMY3 dataset -tmy, metadata = read_tmy3(DATA_DIR / '723170TYA.CSV', coerce_year=1990, - map_variables=True) +tmy, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) + # TMY3 datasets are right-labeled (AKA "end of interval") which means the last # interval of Dec 31, 23:00 to Jan 1 00:00 is labeled Jan 1 00:00. When rolling # up hourly irradiance to monthly insolation, a spurious January value is diff --git a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py index 9103fa0207..eda827f0ed 100644 --- a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py +++ b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py @@ -21,18 +21,19 @@ # PM2.5 and PM10 data come from the EPA. First, let's read in the # weather data and run the HSU soiling model: -import pathlib from matplotlib import pyplot as plt from pvlib import soiling import pvlib import pandas as pd -# get full path to the data directory -DATA_DIR = pathlib.Path(pvlib.__file__).parent / 'data' +# get full path to the example file +soiling_hsu_filepath = \ + pvlib.tools.get_test_dataset_path('soiling_hsu_example_inputs.csv') # read rainfall, PM2.5, and PM10 data from file -imperial_county = pd.read_csv(DATA_DIR / 'soiling_hsu_example_inputs.csv', - index_col=0, parse_dates=True) +imperial_county = pd.read_csv(soiling_hsu_filepath, index_col=0, + parse_dates=True) + rainfall = imperial_county['rain'] depo_veloc = {'2_5': 0.0009, '10': 0.004} # default values from [1] (m/s) rain_accum_period = pd.Timedelta('1h') # default From 61571be6184d074ed8093fec80635db7c009e6be Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:54:03 +0200 Subject: [PATCH 22/24] Forgot to update tests --- pvlib/tests/test_tools.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pvlib/tests/test_tools.py b/pvlib/tests/test_tools.py index 7ac05836c9..367a295a6c 100644 --- a/pvlib/tests/test_tools.py +++ b/pvlib/tests/test_tools.py @@ -98,13 +98,11 @@ def test_degrees_to_index_1(): with pytest.raises(IndexError): # invalid value for coordinate argument tools._degrees_to_index(degrees=22.0, coordinate='width') -@pytest.mark.parametrize('location', [tuple(), ('data',)]) -def test_get_example_dataset_path_passes(location): + +def test_get_example_dataset_path_passes(): expected_dataset = '723170TYA.CSV' assert pathlib.Path(pvlib.__path__[0], 'data', expected_dataset).exists() - assert tools.get_example_dataset_path(expected_dataset, *location) \ - .name == expected_dataset assert tools.get_example_dataset_path(pathlib.Path(expected_dataset)) \ .name == expected_dataset assert tools.get_example_dataset_path(expected_dataset).exists() From caec4f458c50ff274268c55c18430fc2e2bdc5a7 Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Sun, 18 Jun 2023 20:15:51 +0200 Subject: [PATCH 23/24] solve stupid errors --- docs/examples/adr-pvarray/plot_simulate_system.py | 2 +- .../irradiance-decomposition/plot_diffuse_fraction.py | 2 +- docs/examples/irradiance-transposition/plot_seasonal_tilt.py | 2 +- .../irradiance-transposition/plot_transposition_gain.py | 2 +- docs/examples/soiling/plot_fig3A_hsu_soiling_example.py | 2 +- docs/examples/soiling/plot_greensboro_kimber_soiling.py | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/examples/adr-pvarray/plot_simulate_system.py b/docs/examples/adr-pvarray/plot_simulate_system.py index 112f1cd1d8..315492f2ba 100644 --- a/docs/examples/adr-pvarray/plot_simulate_system.py +++ b/docs/examples/adr-pvarray/plot_simulate_system.py @@ -25,7 +25,7 @@ # Read a TMY3 file containing weather data and select needed columns # -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +tmy3_filepath = tools.get_example_dataset_path('723170TYA.CSV') tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) diff --git a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py index dd12f13a52..03d2966cf8 100644 --- a/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py +++ b/docs/examples/irradiance-decomposition/plot_diffuse_fraction.py @@ -25,7 +25,7 @@ # in the pvlib data directory. TMY3 are made from the median months from years # of data measured from 1990 to 2010. Therefore we change the timestamps to a # common year, 1990. -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +tmy3_filepath = tools.get_example_dataset_path('723170TYA.CSV') greensboro, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) diff --git a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py index 722891fe4a..a46e81619e 100644 --- a/docs/examples/irradiance-transposition/plot_seasonal_tilt.py +++ b/docs/examples/irradiance-transposition/plot_seasonal_tilt.py @@ -41,7 +41,7 @@ def get_orientation(self, solar_zenith, solar_azimuth): # First let's grab some weather data and make sure our mount produces tilts # like we expect: -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +tmy3_filepath = tools.get_example_dataset_path('723170TYA.CSV') tmy, metadata = iotools.read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) diff --git a/docs/examples/irradiance-transposition/plot_transposition_gain.py b/docs/examples/irradiance-transposition/plot_transposition_gain.py index ef7c57a110..047eac0e11 100644 --- a/docs/examples/irradiance-transposition/plot_transposition_gain.py +++ b/docs/examples/irradiance-transposition/plot_transposition_gain.py @@ -28,7 +28,7 @@ from matplotlib import pyplot as plt # get full path to the example file -tmy3_filepath = tools.get_test_dataset_path('723170TYA.CSV') +tmy3_filepath = tools.get_example_dataset_path('723170TYA.CSV') # get TMY3 dataset tmy, metadata = read_tmy3(tmy3_filepath, coerce_year=1990, map_variables=True) diff --git a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py index eda827f0ed..ddd499321b 100644 --- a/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py +++ b/docs/examples/soiling/plot_fig3A_hsu_soiling_example.py @@ -28,7 +28,7 @@ # get full path to the example file soiling_hsu_filepath = \ - pvlib.tools.get_test_dataset_path('soiling_hsu_example_inputs.csv') + pvlib.tools.get_example_dataset_path('soiling_hsu_example_inputs.csv') # read rainfall, PM2.5, and PM10 data from file imperial_county = pd.read_csv(soiling_hsu_filepath, index_col=0, diff --git a/docs/examples/soiling/plot_greensboro_kimber_soiling.py b/docs/examples/soiling/plot_greensboro_kimber_soiling.py index 0e9deafa9a..6d8a2c8ca4 100644 --- a/docs/examples/soiling/plot_greensboro_kimber_soiling.py +++ b/docs/examples/soiling/plot_greensboro_kimber_soiling.py @@ -33,10 +33,10 @@ from matplotlib import pyplot as plt from pvlib.iotools import read_tmy3 from pvlib.soiling import kimber -from pvlib.tools import get_test_dataset_path +from pvlib.tools import get_example_dataset_path # get full path to the dataset file -tmy_filepath = get_test_dataset_path('723170TYA.CSV') +tmy_filepath = get_example_dataset_path('723170TYA.CSV') # get TMY3 data with rain greensboro, _ = read_tmy3(tmy_filepath, coerce_year=1990, From e8c615e4591b62166cdb34dd4cc829f25585242b Mon Sep 17 00:00:00 2001 From: echedey-ls <80125792+echedey-ls@users.noreply.github.com> Date: Thu, 3 Aug 2023 12:23:58 +0200 Subject: [PATCH 24/24] Update whatsnew entries --- docs/sphinx/source/whatsnew/v0.10.0.rst | 3 --- docs/sphinx/source/whatsnew/v0.10.2.rst | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.10.0.rst b/docs/sphinx/source/whatsnew/v0.10.0.rst index 5af3b3dc50..4a55e61428 100644 --- a/docs/sphinx/source/whatsnew/v0.10.0.rst +++ b/docs/sphinx/source/whatsnew/v0.10.0.rst @@ -74,9 +74,6 @@ Enhancements ~~~~~~~~~~~~ * Added `map_variables` parameter to :py:func:`pvlib.iotools.read_srml` and :py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`) -* Add :py:func:`pvlib.tools.locate_example_dataset` to get example and test - files under `pvlib/data` path. - (:issue:`924`, :pull:`1763`) * Added two new irradiance decomposition models: :py:func:`pvlib.irradiance.orgill_hollands` (:pull:`1730`) and :py:func:`pvlib.irradiance.louche` (:pull:`1705`). * The return values of :py:func:`pvlib.pvsystem.calcparams_desoto`, diff --git a/docs/sphinx/source/whatsnew/v0.10.2.rst b/docs/sphinx/source/whatsnew/v0.10.2.rst index dacfe27f53..6801232616 100644 --- a/docs/sphinx/source/whatsnew/v0.10.2.rst +++ b/docs/sphinx/source/whatsnew/v0.10.2.rst @@ -17,7 +17,9 @@ Enhancements (:pull:`1800`) * Added option to infer threshold values for :py:func:`pvlib.clearsky.detect_clearsky` (:issue:`1808`, :pull:`1784`) - +* Add :py:func:`pvlib.tools.locate_example_dataset` to get example and test + files under `pvlib/data` path. + (:issue:`924`, :pull:`1763`) Bug fixes ~~~~~~~~~ @@ -43,3 +45,4 @@ Contributors * Adam R. Jensen (:ghuser:`AdamRJensen`) * Abigail Jones (:ghuser:`ajonesr`) * Taos Transue (:ghuser:`reepoi`) +* Echedey Luis (:ghuser:`echedey-ls`)