Skip to content

Create function to calculate average photon energy #2140

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 37 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4cf9961
create
RDaxini Jul 20, 2024
a9d8dd9
Update spectrum.rst
RDaxini Jul 20, 2024
513d708
Update test_spectrum.py
RDaxini Jul 20, 2024
f376d59
Update mismatch.py
RDaxini Aug 1, 2024
5eb7c13
Update mismatch.py
RDaxini Aug 1, 2024
3420a92
Update mismatch.py
RDaxini Aug 1, 2024
c2049ee
Update mismatch.py
RDaxini Aug 2, 2024
afb06f4
docs, tests
RDaxini Aug 2, 2024
928c38c
docs, data checks, tests
RDaxini Aug 2, 2024
d63298a
Update mismatch.py
RDaxini Aug 2, 2024
3e46831
Update mismatch.py
RDaxini Aug 4, 2024
2f4b17e
Apply suggestions from code review
RDaxini Aug 5, 2024
5a66414
remove comments, inverse fraction
RDaxini Aug 5, 2024
ec5bc6c
remove comment
RDaxini Aug 5, 2024
2534ddd
Merge remote-tracking branch 'upstream/main' into calc_ape
RDaxini Aug 5, 2024
6cb9689
Update irradiance.py
RDaxini Aug 5, 2024
c9b4107
Merge remote-tracking branch 'upstream/main' into calc_ape
RDaxini Aug 8, 2024
1720d7d
Update test_irradiance.py
RDaxini Aug 8, 2024
a869f83
Update test_irradiance.py
RDaxini Aug 8, 2024
af63875
Update irradiance.py
RDaxini Aug 8, 2024
43ae7d3
mixed up my lambdas and gammas:(
RDaxini Aug 8, 2024
c2c373d
change variable name spectral_irr -> spectrum
RDaxini Aug 8, 2024
698d9d7
update variable name in docstring + error messages
RDaxini Aug 9, 2024
e9919f5
Update irradiance.py
RDaxini Aug 9, 2024
458bf16
Update test_irradiance.py
RDaxini Aug 12, 2024
ecba3eb
Apply suggestions from code review
RDaxini Aug 12, 2024
0b95307
Update irradiance.py
RDaxini Aug 12, 2024
39fe12c
Update v0.11.1.rst
RDaxini Aug 13, 2024
112747e
Update irradiance.py
RDaxini Aug 14, 2024
ddc70c5
Update irradiance.py
RDaxini Aug 14, 2024
a8e72d8
Update test_irradiance.py
RDaxini Aug 14, 2024
80bf690
Update test_mismatch.py
RDaxini Aug 14, 2024
1bafc90
Update v0.11.1.rst
RDaxini Aug 14, 2024
6a21228
Update irradiance.py
RDaxini Aug 14, 2024
c224e05
update output datatype and associated tests
RDaxini Aug 14, 2024
ace5a65
Update test_irradiance.py
RDaxini Aug 14, 2024
072eeeb
Update docs/sphinx/source/whatsnew/v0.11.1.rst
RDaxini Aug 14, 2024
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
3 changes: 2 additions & 1 deletion pvlib/spectrum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
spectral_factor_pvspec,
spectral_factor_jrc,
sr_to_qe,
qe_to_sr
qe_to_sr,
average_photon_energy
)
18 changes: 18 additions & 0 deletions pvlib/spectrum/mismatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import scipy.constants
from scipy.integrate import trapezoid
from scipy.interpolate import interp1d
from scipy import constants

from pathlib import Path
from warnings import warn
Expand Down Expand Up @@ -1100,3 +1101,20 @@ def qe_to_sr(qe, wavelength=None, normalize=False):
spectral_responsivity = normalize_max2one(spectral_responsivity)

return spectral_responsivity


def average_photon_energy(spectral_irr):
si = spectral_irr
hclambda = pd.Series((constants.h*constants.c)/(si.T.index*1e-9))
hclambda.index = si.T.index # set wavelength as the index
pfd = si.div(hclambda) # calculate the photon flux density

def integrate(e): # define a helper function
return trapezoid(e, x=e.T.index, axis=-1)

int_si = integrate(si) # integrate spectral irradiance wrt wavelength
int_pfd = integrate(pfd) # integrate photon flux density wrt wavelength

ape = (1/constants.elementary_charge)*int_si/int_pfd

return ape
15 changes: 15 additions & 0 deletions pvlib/tests/test_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,18 @@
assert_allclose(sr, sr_and_eqe_fixture["spectral_response"])
qe = spectrum.sr_to_qe(sr)
assert_allclose(qe, sr_and_eqe_fixture["quantum_efficiency"])


def test_average_photon_energy_series():
# test that the APE is calculated correctly with single spectrum
# series input

si = spectrum.get_reference_spectra()
si = si['global']

ape = spectrum.average_photon_energy(si)

expected = 1.45029

assert_allclose(ape, expected, rtol=1e-4)

Loading