Skip to content

Add function to retrieve example dataset paths #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e46a60f
Add function, tests and case example
echedey-ls Jun 7, 2023
29c7554
Fix type annotations
echedey-ls Jun 7, 2023
725e299
Yeet this stupid error
echedey-ls Jun 7, 2023
05dc263
Remove unneeded feature
echedey-ls Jun 8, 2023
b0f38d5
Renamed to locate_example_dataset
echedey-ls Jun 8, 2023
b236fce
Use pathlib & check existence of test files
echedey-ls Jun 8, 2023
884f2de
Add public documentation, hope it works
echedey-ls Jun 8, 2023
dad6835
I forgot this assert :v
echedey-ls Jun 8, 2023
5490561
Update plot_greensboro_kimber_soiling.py
echedey-ls Jun 8, 2023
eacedae
Don't show examples backreference
echedey-ls Jun 9, 2023
28fe7de
Update v0.10.0.rst (without user name since I'm already mentioned at …
echedey-ls Jun 9, 2023
aa91f28
Apply Kevin's implementation suggestions
echedey-ls Jun 10, 2023
5954a79
Update plot_greensboro_kimber_soiling.py
echedey-ls Jun 10, 2023
0e55f18
Update iotools.rst
echedey-ls Jun 10, 2023
311f765
Will this fix the table?
echedey-ls Jun 10, 2023
3a91cd7
This should be fine now
echedey-ls Jun 10, 2023
4a38b0e
Substitute occurrences of pvlib.__file__ or similar where appropiate
echedey-ls Jun 10, 2023
5e1a33c
Merge branch 'main' into dataset-retrieve-function
echedey-ls Jun 10, 2023
64e8700
Merge branch 'main' into dataset-retrieve-function
echedey-ls Jun 14, 2023
f5bfcf6
Revert "Substitute occurrences of pvlib.__file__ or similar where app…
echedey-ls Jun 18, 2023
8c78cb4
Revert "Will this fix the table?"
echedey-ls Jun 18, 2023
6215608
Delete custom path behaviour, rename to get_example_dataset_path
echedey-ls Jun 18, 2023
aa08e09
Use function in tests only
echedey-ls Jun 18, 2023
61571be
Forgot to update tests
echedey-ls Jun 18, 2023
caec4f4
solve stupid errors
echedey-ls Jun 18, 2023
586381a
Merge branch 'main' into dataset-retrieve-function
echedey-ls Aug 3, 2023
e8c615e
Update whatsnew entries
echedey-ls Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/examples/soiling/plot_greensboro_kimber_soiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)']
Expand Down
15 changes: 15 additions & 0 deletions pvlib/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pvlib import tools
import numpy as np
import pathlib


@pytest.mark.parametrize('keys, input_dict, expected', [
Expand Down Expand Up @@ -95,3 +96,17 @@ 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_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-")
15 changes: 15 additions & 0 deletions pvlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
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