[Python-modules-commits] [python-pysolar] 20/42: Completely implemented REST2, but needs testing and better code organization

Wolfgang Borgert debacle at moszumanska.debian.org
Fri Oct 3 23:37:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag 0.6
in repository python-pysolar.

commit e6d9fb6f8f50f67712dcfeedb443869f865444ad
Author: Brandon Stafford <brandon at pingswept.org>
Date:   Tue Apr 8 22:02:13 2014 -0400

    Completely implemented REST2, but needs testing and better code organization
---
 Pysolar/rest.py | 111 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 66 insertions(+), 45 deletions(-)

diff --git a/Pysolar/rest.py b/Pysolar/rest.py
index 5cc1042..3a8c2ca 100644
--- a/Pysolar/rest.py
+++ b/Pysolar/rest.py
@@ -17,29 +17,7 @@
 #    You should have received a copy of the GNU General Public License along
 #    with Pysolar. If not, see <http://www.gnu.org/licenses/>.
 
-from collections import defaultdict
-
-nestable_dict = lambda: defaultdict(nestable_dict)
-
-transmittance = nestable_dict()
-
-transmittance["rayleigh"]["high-frequency"] = lambda m: (1 + 1.8169 * m + 0.033454 * m ** 2)/(1 + 2.063 * m + 0.31978 * m ** 2)
-transmittance["rayleigh"]["low-frequency"] = lambda m: (1 - 0.010394 * m)/(1 - 0.00011042 * m ** 2)
-
-transmittance["gas"]["high-frequency"] = lambda m: (1 + 0.95885 * m + 0.012871 * m ** 2)/(1 + 0.96321 * m + 0.015455 * m ** 2)
-transmittance["gas"]["low-frequency"] = lambda m: (1 + 0.27284 * m - 0.00063699 * m ** 2)/(1 + 0.30306 * m)
-
-transmittance["ozone"]["high-frequency"] = lambda uo, m: 1 # fake
-transmittance["ozone"]["low-frequency"] = lambda uo, m: 1
-
-transmittance["nitrogen_dioxide"]["high-frequency"] = lambda un, m: 1 # fake
-transmittance["nitrogen_dioxide"]["low-frequency"] = lambda un, m: 1
-
-transmittance["water"]["high-frequency"] = lambda w, m: 1 # fake
-transmittance["water"]["low-frequency"] = lambda w, m: 1 # fake
-
-transmittance["aerosol"]["high-frequency"] = lambda a, b, m: 1 # fake
-transmittance["aerosol"]["low-frequency"] = lambda a, b, m: 1 # fake
+import math
 
 optical_mass = {}
 
@@ -48,6 +26,12 @@ optical_mass["ozone"] = lambda p, m: m
 optical_mass["water"] = lambda p, m: m
 optical_mass["aerosol"] = lambda p, m: m
 
+albedo = {} # single-scattering albedo used to calculate aerosol scattering transmittance
+
+albedo["high-frequency"] = 0.92
+albedo["low-frequency"] = 0.84
+
+rhogi = 0.150 # mean ground albedo from [Gueymard, 2008], Table 1
 
 E0n = {"high-frequency": 635.4, # extra-atmospheric irradiance, 290-700 nm (UV and visible)
        "low-frequency":  709.7} # extra-atmospheric irradiance, 700-4000 nm (short infrared)
@@ -56,7 +40,12 @@ def GetAerosolForwardScatteranceFactor(altitude_deg):
 	Z = 90 - altitude_deg
 	return 1 - math.e ** (-0.6931 - 1.8326 * math.cos(math.radians(Z)))
 
+def GetAerosolOpticalDepth(turbidity_beta, effective_wavelength, turbidity_alpha):
+	# returns tau_a
+	return turbidity_beta * effective_wavelength ** -turbidity_alpha
+
 def GetAerosolScatteringCorrectionFactor(band, ma, tau_a):
+	# returns F
 	if band == "high-frequency":
 		g0 = (3.715 + 0.368 * ma + 0.036294 * ma ** 2)/(1 + 0.0009391 * ma ** 2)
 		g1 = (-0.164 - 0.72567 * ma + 0.20701 * ma ** 2)/(1 + 0.001901 * ma ** 2)
@@ -68,22 +57,40 @@ def GetAerosolScatteringCorrectionFactor(band, ma, tau_a):
 		h2 = (0.8889 - 0.55063 * ma + 0.50152 * ma ** 2)/(1 + 0.14865 * ma ** 1.5)
 		return (h0 + h1 * tau_a)/(1 + h2 * tau_a)
 
+def GetAerosolTransmittance(band, ma, tau_a):
+	# returns Ta
+	return math.exp(-ma * tau_a)
+
+def GetAerosolScatteringTransmittance(band, ma, tau_a):
+	# returns Tas
+	return math.exp(-ma * albedo[band] * tau_a)
+
+def GetBeamBroadbandIrradiance(Ebn, altitude_deg):
+	Z = 90 - altitude_deg
+	return Ebn * math.cos(math.radians(Z))
+
 def GetDiffuseIrradiance():
 	return GetDiffuseIrradianceByBand("high-frequency") + GetDiffuseIrradianceByBand("low-frequency")
 
-def GetDiffuseIrradianceByBand(band, air_mass=1.66):
+def GetDiffuseIrradianceByBand(band, air_mass=1.66, turbidity_alpha=1.3, turbidity_beta=0.6):
 	Z = 90 - altitude_deg
-	To =
-	Tg =
-	Tn =
-	Tw =
-	Tr =
-	Ta =
-	Tas =
-	Br = GetRayleighExtinctionForwardScatteringFraction(air_mass, layer)
+	effective_wavelength = GetEffectiveAerosolWavelength(band, turbidity_alpha)
+	tau_a = GetAerosolOpticalDepth(turbidity_beta, effective_wavelength, turbidity_alpha)
+	rhosi = GetSkyAlbedo(band, turbidity_alpha, turbidity_beta)
+
+	To = GetOzoneTransmittance(band, optical_mass["ozone"])
+	Tg = GetGasTransmittance(band, optical_mass["rayleigh"])
+	Tn = GetNitrogenTransmittance(band, 1.66)
+	Tw = GetWaterVaporTransmittance(band, 1.66)
+	TR = GetRayleighTransmittance(band, optical_mass["rayleigh"])
+	Ta = GetAerosolTransmittance(band, ma, tau_a)
+	Tas = GetAerosolScatteringTransmittance(band, ma, tau_a)
+
+	BR = GetRayleighExtinctionForwardScatteringFraction(band, air_mass)
 	Ba = GetAerosolForwardScatteranceFactor(altitude_deg)
-	F =
-	Edp = To * Tg * Tn * Tw * (Br * (1 - Tr) * Ta ** 0.25 + Ba * F * Tr * (1 - Tas ** 0.25)) * E0n[band]
+	F = GetAerosolScatteringCorrectionFactor(band, ma, tau_a)
+
+	Edp = To * Tg * Tn * Tw * (BR * (1 - TR) * Ta ** 0.25 + Ba * F * TR * (1 - Tas ** 0.25)) * E0n[band]
 	Edd = rhogi * rhosi * (Eb + Edp)/(1 - rhogi * rhosi)
 	return Edp + Edd
 
@@ -91,14 +98,16 @@ def GetDirectNormalIrradiance(air_mass=1.66, pressure_millibars=1013.25, ozone_a
 	return GetDirectNormalIrradianceByBand("high-frequency") + GetDirectNormalIrradianceByBand("low-frequency")
 
 def GetDirectNormalIrradianceByBand(band, air_mass=1.66, pressure_millibars=1013.25, ozone_atm_cm=0.35, nitrogen_atm_cm=0.0002, precipitable_water_cm=5.0, turbidity_alpha=1.3, turbidity_beta=0.6):
+	effective_wavelength = GetEffectiveAerosolWavelength(band, turbidity_alpha)
+	tau_a = GetAerosolOpticalDepth(turbidity_beta, effective_wavelength, turbidity_alpha)
 
-	Tr = transmittance["rayleigh"][band](optical_mass["rayleigh"](pressure_millibars, air_mass))
-	Tg = transmittance["gas"][band](optical_mass["rayleigh"](pressure_millibars, air_mass))
-	To = transmittance["ozone"][band](ozone_atm_cm, optical_mass["ozone"](pressure_millibars, air_mass))
-	Tn = transmittance["nitrogen_dioxide"][band](nitrogen_atm_cm, optical_mass["water"](pressure_millibars, air_mass)) # is water_optical_mass really used for nitrogen calc?
-	Tw = transmittance["water"][band](precipitable_water_cm, optical_mass["water"](pressure_millibars, air_mass))
-	Ta = transmittance["aerosol"][band](turbidity_alpha, turbidity_beta, optical_mass["aerosol"](pressure_millibars, air_mass))
-	return E0n[band] * Tr * Tg * To * Tn * Tw * Ta
+	TR = GetRayleighTransmittance(band, optical_mass["rayleigh"])
+	Tg = GetGasTransmittance(band, optical_mass["rayleigh"])
+	To = GetOzoneTransmittance(band, optical_mass["ozone"])
+	Tn = GetNitrogenTransmittance(band, optical_mass["water"]) # is water_optical_mass really used for nitrogen calc?
+	Tw = GetWaterVaporTransmittance(band, optical_mass["water"])
+	Ta = GetAerosolTransmittance(band, optical_mass["aerosol"], tau_a)
+	return E0n[band] * TR * Tg * To * Tn * Tw * Ta
 
 def GetEffectiveAerosolWavelength(band, turbidity_alpha):
 	ua = optical_mass["aerosol"]
@@ -117,9 +126,14 @@ def GetEffectiveAerosolWavelength(band, turbidity_alpha):
 		e3 = -0.70003 - 0.73587 * a2 + 0.51509 * a2 ** 2)/(1 + 4.7665 * a2)
 		return (e0 + e1 * ua + e2 * ua ** 2)/(1 + e3 * ua ** 2)
 
-def GetGlobalIrradiance(direct_normal_irradiance, altitude_deg, diffuse_irradiance):
-	Z = 90 - altitude_deg
-	return direct_normal_irradiance * math.cos(math.radians(Z)) + diffuse_irradiance
+def GetGasTransmittance(band, m):
+	if band == "high-frequency":
+		return (1 + 0.95885 * m + 0.012871 * m ** 2)/(1 + 0.96321 * m + 0.015455 * m ** 2)
+	else:
+		return (1 + 0.27284 * m - 0.00063699 * m ** 2)/(1 + 0.30306 * m)
+
+def GetBroadbandGlobalIrradiance(Ebn, altitude_deg, Ed):
+	return GetBeamBroadbandIrradiance(Ebn, altitude_deg) + Ed
 
 def GetNitrogenTransmittance(band, un, m):
 	if band == "high-frequency":
@@ -139,12 +153,19 @@ def GetOzoneTransmittance(band, uo, m):
 	else:
 		return 1.0
 
-def GetRayleighExtinctionForwardScatteringFraction(air_mass, band):
+def GetRayleighExtinctionForwardScatteringFraction(band, air_mass):
+	# returns BR
 	if band == "high-frequency":
 		return 0.5 * (0.89013 - 0.049558 * air_mass + 0.000045721 * air_mass ** 2)
 	else:
 		return 0.5
 
+def GetRayleighTransmittance(band, m):
+	if band == "high-frequency":
+		return (1 + 1.8169 * m + 0.033454 * m ** 2)/(1 + 2.063 * m + 0.31978 * m ** 2)
+	else:
+		return (1 - 0.010394 * m)/(1 - 0.00011042 * m ** 2)
+
 def GetSkyAlbedo(band, turbidity_alpha, turbidity_beta):
 	if band == "high-frequency":
 		a1 = turbidity_alpha # just renaming to keep equations short

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pysolar.git



More information about the Python-modules-commits mailing list