Skip to content

Commit

Permalink
Add initial OC inference and fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markcampanelli committed May 7, 2024
1 parent d2d2c97 commit f99918c
Show file tree
Hide file tree
Showing 17 changed files with 4,422 additions and 128 deletions.
21 changes: 21 additions & 0 deletions pvfit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@
ODR_SUCCESS_CODES = ("1", "2", "3") # In ones place.
ODR_NUMERICAL_ERROR_CODE = "6" # In ten-thousands place.
ODR_NOT_FULL_RANK_ERROR_CODE = "2" # In tens place.


# Reference values, esp. Standard Test Condition (STC).

# Temperature.

# STC temperature in degrees Celsius.
T_degC_stc = 25.0

# STC temperature in Kelvin.
T_K_stc = scipy.constants.convert_temperature(T_degC_stc, "Celsius", "Kelvin")

# Total irradiance.

# Hemispherical irradiance at STC (ASTM G-173-03, includes specified sun orientation,
# plane orientation, spectrum, etc.).
E_hemispherical_tilted_W_per_m2_stc = 1000.0

# Direct irradiance at STC (ASTM G-173-03, includes specified sun orientation,
# plane orientation, spectrum, etc.).
E_direct_normal_W_per_m2_stc = 900.0
15 changes: 15 additions & 0 deletions pvfit/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ def test_h_J_s():
def test_T_degC_abs_zero():
assert isinstance(common.T_degC_abs_zero, float)
assert common.T_degC_abs_zero == -273.15


def test_T_degC_stc():
assert isinstance(common.T_degC_stc, float)
assert common.T_degC_stc == 25.0


def test_T_K_stc():
assert isinstance(common.T_K_stc, float)
assert common.T_K_stc == 298.15


def test_E_hemispherical_tilted_W_per_m2_stc():
assert isinstance(common.E_hemispherical_tilted_W_per_m2_stc, float)
assert common.E_hemispherical_tilted_W_per_m2_stc == 1000.0
32 changes: 16 additions & 16 deletions pvfit/measurement/spectral_correction/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def extrapolate_spectral_irradiance(
*,
spectral_irradiance: SpectralIrradiance,
extrapolant: Union[SpectralIrradiance, SpectralIrradianceWithTail],
G_total_W_per_m2: Optional[FloatArray] = None,
E_total_W_per_m2: Optional[FloatArray] = None,
) -> Union[SpectralIrradiance, SpectralIrradianceWithTail]:
"""
Extend the ends of a given spectral irradiance curve(s) by a given complete spectral
Expand Down Expand Up @@ -241,7 +241,7 @@ def extrapolate_spectral_irradiance(
side="left",
)
]
G_total_subinterval_lower = spectral_irradiance.get_G_total_subinterval_W_per_m2(
E_total_subinterval_lower = spectral_irradiance.get_E_total_subinterval_W_per_m2(
lambda_min_nm=lambda_lower_min, lambda_max_nm=lambda_lower_max
)

Expand All @@ -267,15 +267,15 @@ def extrapolate_spectral_irradiance(
E_lower, -1, extrapolant_interpolator(lambda_lower_max), axis=-1
)

G_total_lower = SpectralIrradiance(
E_total_lower = SpectralIrradiance(
lambda_nm=lambda_lower, E_W_per_m2_nm=E_lower
).G_total_W_per_m2
).E_total_W_per_m2

extrapolant_scaling_lower = G_total_subinterval_lower / G_total_lower
extrapolant_scaling_lower = E_total_subinterval_lower / E_total_lower
else:
lambda_lower = numpy.empty([lambda_lower_min])
E_lower = spectral_irradiance.E_W_per_m2_nm[..., 0]
G_total_lower = numpy.zeros_like(E_lower)
E_total_lower = numpy.zeros_like(E_lower)
extrapolant_scaling_lower = 0.0

# Match integrals of upper overlap.
Expand All @@ -289,7 +289,7 @@ def extrapolate_spectral_irradiance(
- 1
]
lambda_upper_max = lambda_max
G_total_subinterval_upper = spectral_irradiance.get_G_total_subinterval_W_per_m2(
E_total_subinterval_upper = spectral_irradiance.get_E_total_subinterval_W_per_m2(
lambda_min_nm=lambda_upper_min, lambda_max_nm=lambda_upper_max
)

Expand All @@ -315,15 +315,15 @@ def extrapolate_spectral_irradiance(
E_upper, -1, extrapolant_interpolator(lambda_upper_max), axis=-1
)

G_total_upper = SpectralIrradiance(
E_total_upper = SpectralIrradiance(
lambda_nm=lambda_upper, E_W_per_m2_nm=E_upper
).G_total_W_per_m2
).E_total_W_per_m2

extrapolant_scaling_upper = G_total_subinterval_upper / G_total_upper
extrapolant_scaling_upper = E_total_subinterval_upper / E_total_upper
else:
lambda_upper = numpy.empty([lambda_upper_max])
E_upper = spectral_irradiance.E_W_per_m2_nm[..., -1]
G_total_upper = numpy.zeros_like(E_upper)
E_total_upper = numpy.zeros_like(E_upper)
extrapolant_scaling_upper = 0.0

# Stitch together spectra.
Expand Down Expand Up @@ -366,25 +366,25 @@ def extrapolate_spectral_irradiance(
spectral_irradiance_extended = SpectralIrradianceWithTail(
lambda_nm=lambda_nm,
E_W_per_m2_nm=E_W_per_m2_nm,
G_tail_W_per_m2=extrapolant_scaling_upper * extrapolant.G_tail_W_per_m2,
E_tail_W_per_m2=extrapolant_scaling_upper * extrapolant.E_tail_W_per_m2,
)
else:
spectral_irradiance_extended = SpectralIrradiance(
lambda_nm=lambda_nm,
E_W_per_m2_nm=E_W_per_m2_nm,
)

if G_total_W_per_m2 is not None:
if E_total_W_per_m2 is not None:
# Scale extended spectral irradiance to provided total irradiance.
total_scaling = G_total_W_per_m2 / spectral_irradiance_extended.G_total_W_per_m2
total_scaling = E_total_W_per_m2 / spectral_irradiance_extended.E_total_W_per_m2

if isinstance(spectral_irradiance_extended, SpectralIrradianceWithTail):
spectral_irradiance_extended = SpectralIrradianceWithTail(
lambda_nm=spectral_irradiance_extended.lambda_nm,
E_W_per_m2_nm=numpy.expand_dims(total_scaling, -1)
* spectral_irradiance_extended.E_W_per_m2_nm,
G_tail_W_per_m2=total_scaling
* spectral_irradiance_extended.G_tail_W_per_m2,
E_tail_W_per_m2=total_scaling
* spectral_irradiance_extended.E_tail_W_per_m2,
)
else:
spectral_irradiance_extended = SpectralIrradiance(
Expand Down
Loading

0 comments on commit f99918c

Please sign in to comment.