-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Split test_spectrum.py #2151
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
Merged
Merged
Split test_spectrum.py #2151
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c3f52a
Split test_spectrum.py files
RDaxini 27702b2
Merge remote-tracking branch 'upstream/main' into restructure_test_sp…
RDaxini a2374e8
fix conftest import
RDaxini e7e7fcb
Update test_mismatch.py
RDaxini 6120a7f
Merge remote-tracking branch 'upstream/main' into restructure_test_sp…
RDaxini e56699f
Update v0.11.1.rst
RDaxini 3729860
create pvlib\tests\spectrum\conftest.py
RDaxini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import pytest | ||
from numpy.testing import assert_allclose, assert_approx_equal, assert_equal | ||
import pandas as pd | ||
import numpy as np | ||
from pvlib import spectrum | ||
from pvlib._deprecation import pvlibDeprecationWarning | ||
|
||
from ..conftest import assert_series_equal, fail_on_pvlib_version | ||
|
||
|
||
@fail_on_pvlib_version('0.12') | ||
def test_get_am15g(): | ||
# test that the reference spectrum is read and interpolated correctly | ||
with pytest.warns(pvlibDeprecationWarning, | ||
match="get_reference_spectra instead"): | ||
e = spectrum.get_am15g() | ||
assert_equal(len(e), 2002) | ||
assert_equal(np.sum(e.index), 2761442) | ||
assert_approx_equal(np.sum(e), 1002.88, significant=6) | ||
|
||
wavelength = [270, 850, 950, 1200, 1201.25, 4001] | ||
expected = [0.0, 0.893720, 0.147260, 0.448250, 0.4371025, 0.0] | ||
|
||
with pytest.warns(pvlibDeprecationWarning, | ||
match="get_reference_spectra instead"): | ||
e = spectrum.get_am15g(wavelength) | ||
assert_equal(len(e), len(wavelength)) | ||
assert_allclose(e, expected, rtol=1e-6) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"reference_identifier,expected_sums", | ||
[ | ||
( | ||
"ASTM G173-03", # reference_identifier | ||
{ # expected_sums | ||
"extraterrestrial": 1356.15, | ||
"global": 1002.88, | ||
"direct": 887.65, | ||
}, | ||
), | ||
], | ||
) | ||
def test_get_reference_spectra(reference_identifier, expected_sums): | ||
# test reading of a standard spectrum | ||
standard = spectrum.get_reference_spectra(standard=reference_identifier) | ||
assert set(standard.columns) == expected_sums.keys() | ||
assert standard.index.name == "wavelength" | ||
assert standard.index.is_monotonic_increasing is True | ||
expected_sums = pd.Series(expected_sums) # convert prior to comparison | ||
assert_series_equal(np.sum(standard, axis=0), expected_sums, atol=1e-2) | ||
|
||
|
||
def test_get_reference_spectra_custom_wavelengths(): | ||
# test that the spectrum is interpolated correctly when custom wavelengths | ||
# are specified | ||
# only checked for ASTM G173-03 reference spectrum | ||
wavelength = [270, 850, 951.634, 1200, 4001] | ||
expected_sums = pd.Series( | ||
{"extraterrestrial": 2.23266, "global": 1.68952, "direct": 1.58480} | ||
) # for given ``wavelength`` | ||
standard = spectrum.get_reference_spectra( | ||
wavelength, standard="ASTM G173-03" | ||
) | ||
assert_equal(len(standard), len(wavelength)) | ||
# check no NaN values were returned | ||
assert not standard.isna().any().any() # double any to return one value | ||
assert_series_equal(np.sum(standard, axis=0), expected_sums, atol=1e-4) | ||
|
||
|
||
def test_get_reference_spectra_invalid_reference(): | ||
# test that an invalid reference identifier raises a ValueError | ||
with pytest.raises(ValueError, match="Invalid standard identifier"): | ||
spectrum.get_reference_spectra(standard="invalid") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.