def get_short_wave( utm33_x, utm33_y, day_no, temp_atm, cloud_cover, snow_depth, snow_density, prec_snow, time_hour, time_span_in_sec, temp_surface, albedo_prim, age_factor_tau=None, albedo_method="ueb"): ''' S [kJm^(-2)]is the net incident solar (short wave) radiation Method calculates albedo in two different ways for comparison and testing. In the end one is chose based on the method chosen. :param utm33_x, utm33_y: koordinat i UTM 33 :param day_no: Dagnummer :param temp_atm: [C] Air temperature :param SWE: snø i snømagasin :param prec_rain: [m] precipitation as liquid :param time_hour: [0-23] Hour of the day the time_span_in_sec ends :param time_span_in_sec: [sec] Time resolution in sec :param temp_surface: [C] Snøoverflate temperatur :param prec_snow: [m] New snow in meter :param albedo_prim: Primary albedo from last time step. Used in the albedo_walters routine. :param age_factor_tau: [-] Age factor in the UEB albedo routine. :param albedo_method: :return: S, s_inn, albedo, albedo_prim, age_factor_tau ''' if time_hour == 0: time_hour = 24 phi, thi, ddphi, ddthi = dc.lat_long_from_utm33(utm33_x,utm33_y, output= "both") thetaW = 0.4102*sin((2*pi/365)*(day_no-80)) # solar declination angleday angle, Walter 2005 # print("sol.decl.angle={0} on daynumber={1}".format(thetaW, day_no)) #theta <- vector("numeric", 365) #theta2 <- vector("numeric", 365) #for (day_no in 1:365)theta[day_no] <- 0.4092*cos((2*pi/365)*(day_no-173))#solar declination angleday angle, Liston 1995 #for (day_no in 1:365)theta2[day_no] <- 0.4102*sin((2*pi/365)*(day_no-80))#solar declination angleday angle theta = 0.4092*cos((2*pi/365.25)*(day_no-173)) # solar declination angleday angle, Liston 1995 theta2 = 2*pi/365.25*(day_no-80) r = 149598000 # distance from the sun R = 6378 # Radius of earth timezone = -4 * (fabs(thi) % 15) * thi/fabs(thi) # ang lengdegrad ikke epsilon = 0.4092 # rad(23.45) z_s = r*sin(theta2)*sin(epsilon) r_p = sqrt(r**2-z_s**2) nevner = (R-z_s*sin(phi))/(r_p*cos(phi)) if(nevner > -1) and (nevner < 1): # acos(m ha inn verdier ,(mellom-1,1) hvis <-1 s er det midnattsol > 1 er det m¯rketid. t0 = 1440/(2*pi)*acos((R-z_s*sin(phi))/(r_p*cos(phi))) that = t0+5 n = 720-10*sin(4*pi*(day_no-80)/365.25)+8*sin(2*pi*day_no/365.25) sr = (n-that+timezone)/60 #soloppgang ss = (n+that+timezone)/60 #solnedgang #sunhrs = ss-sr# antall soltimer #time_hour er tidsvariabel #Trise = -(1/0.2618)*cos(-tan(theta)*tan(phi))**-1 #Tset = (1/0.2618)*cos(-tan(theta)*tan(phi))**-1 #Trise = round(-sunhrs/2) #Tset = round(sunhrs/2) if nevner <= -1: # Midnattsol sr = 0. ss = 24. if nevner >= 1: # Mørketid sr = 12. ss = 12. #time_hour <- 22 TTList = {} # Values for transmissivity for every hr dingom = {} # Values for zenith angle (0 straight up) for tid in range(1, 24, 1): if (tid > sr) and (tid < ss): tom = tid-12 # Number of hours from solar noon. Solar noon is tom=0 cosarg = 0.2618 * tom # Radians pr hour dingom[tid] = acos(sin(phi)*sin(theta)+cos(phi)*cos(theta)*cos(cosarg)) # Dingmans zenith angle TTList[tid] = (0.6 + 0.2*sin((0.5*pi)-dingom[tid]))*(1.0-0.5*cloud_cover) # Inspirert av G. Liston 1995 transmissivitet # TTList[tid] = (0.6-0.2*sin(dingom[tid]))*(1.0-0.5*cloud_cover) #Inspirert av G. Liston 1995 transmissivitet # TTList[tid] = (0.6-0.2*sin(dingom[tid]))*(1.0-0.5*cloud_cover) #Inspirert av G. Liston 1995 transmissivitet if (tid < sr) or (tid > ss): # If time is outside sunrise-sunset TTList[tid] = 0. # Transmissivity = 0 when sun is below horizon. dingom[tid] = pi/2 # Angle below horizin is set to be on the horizon. # pi/2 minus zenith angle, initielt, ikke helt sikker. Blir veldig lav med init dingom lik pi/2 # blir på den annen side høy med init dingom lik 0. Albedo ser ganske fornuftig ut. if time_span_in_sec == 86400: Trans = TTList.values() # list zenith_angle = dingom.values() # list elif time_span_in_sec < 86400: # Midler transmissvitet og solvinkel For finere tidssoppløsning interv = list(range(time_hour-int(time_span_in_sec/3600)+1, time_hour, 1)) # aktuelle timer Trans = [TTList[i] for i in interv] # selection of transmisions in intervall zenith_angle = [dingom[i] for i in interv] else: print("Method doesnt work on time intervals greater than 24hrs") Trans = None zenith_angle = None # Mean values Trans = float( sum(Trans) / len(Trans) ) zenith_angle = float( sum(zenith_angle) / len(zenith_angle) ) if snow_depth == 0.: albedo = albedo_prim age_factor_tau = 0. else: # UEB albedo age_factor_tau, albedo_ueb \ = get_albedo_ueb(prec_snow, snow_depth, temp_surface, zenith_angle, time_span_in_sec, age_factor_tau=age_factor_tau) # Todd Walters albedo albedo_prim, albedo_walter \ = get_albedo_walter(prec_snow, snow_depth, snow_density, temp_atm, albedo_prim, time_span_in_sec, time_hour) # At this point I choose which albedo variant to use in calculating short wave radiation if albedo_method == "ueb": albedo = albedo_ueb elif albedo_method == "walter": albedo = albedo_walter else: print("No valid albedo method selected.") albedo = None #Solar radiation S0 = const.solar_constant #[J/m2/s] Solar constant pr sec S0 *= time_span_in_sec # solar constant pr time step S0 /=1000 # J to kJ s_inn = Trans * sin((pi/2)-zenith_angle) * S0 # S = (1-albedo) * s_inn # se likning Liston 1995, eq. 26 (Nett SW-radiation) return S, s_inn, albedo, albedo_prim, age_factor_tau
def get_short_wave(utm33_x, utm33_y, day_no, temp_atm, cloud_cover, snow_depth, snow_density, prec_snow, time_hour, time_span_in_sec, temp_surface, albedo_prim, age_factor_tau=None, albedo_method="ueb"): ''' S [kJm^(-2)]is the net incident solar (short wave) radiation Method calculates albedo in two different ways for comparison and testing. In the end one is chose based on the method chosen. :param utm33_x, utm33_y: koordinat i UTM 33 :param day_no: Dagnummer :param temp_atm: [C] Air temperature :param SWE: snø i snømagasin :param prec_rain: [m] precipitation as liquid :param time_hour: [0-23] Hour of the day the time_span_in_sec ends :param time_span_in_sec: [sec] Time resolution in sec :param temp_surface: [C] Snøoverflate temperatur :param prec_snow: [m] New snow in meter :param albedo_prim: Primary albedo from last time step. Used in the albedo_walters routine. :param age_factor_tau: [-] Age factor in the UEB albedo routine. :param albedo_method: :return: S, s_inn, albedo, albedo_prim, age_factor_tau ''' if time_hour == 0: time_hour = 24 phi, thi, ddphi, ddthi = dc.lat_long_from_utm33(utm33_x, utm33_y, output="both") thetaW = 0.4102 * sin( (2 * pi / 365) * (day_no - 80)) # solar declination angleday angle, Walter 2005 # print("sol.decl.angle={0} on daynumber={1}".format(thetaW, day_no)) #theta <- vector("numeric", 365) #theta2 <- vector("numeric", 365) #for (day_no in 1:365)theta[day_no] <- 0.4092*cos((2*pi/365)*(day_no-173))#solar declination angleday angle, Liston 1995 #for (day_no in 1:365)theta2[day_no] <- 0.4102*sin((2*pi/365)*(day_no-80))#solar declination angleday angle theta = 0.4092 * cos( (2 * pi / 365.25) * (day_no - 173)) # solar declination angleday angle, Liston 1995 theta2 = 2 * pi / 365.25 * (day_no - 80) r = 149598000 # distance from the sun R = 6378 # Radius of earth timezone = -4 * (fabs(thi) % 15) * thi / fabs(thi) # ang lengdegrad ikke epsilon = 0.4092 # rad(23.45) z_s = r * sin(theta2) * sin(epsilon) r_p = sqrt(r**2 - z_s**2) nevner = (R - z_s * sin(phi)) / (r_p * cos(phi)) if (nevner > -1) and (nevner < 1): # acos(m ha inn verdier ,(mellom-1,1) hvis <-1 s er det midnattsol > 1 er det m¯rketid. t0 = 1440 / (2 * pi) * acos((R - z_s * sin(phi)) / (r_p * cos(phi))) that = t0 + 5 n = 720 - 10 * sin(4 * pi * (day_no - 80) / 365.25) + 8 * sin( 2 * pi * day_no / 365.25) sr = (n - that + timezone) / 60 #soloppgang ss = (n + that + timezone) / 60 #solnedgang #sunhrs = ss-sr# antall soltimer #time_hour er tidsvariabel #Trise = -(1/0.2618)*cos(-tan(theta)*tan(phi))**-1 #Tset = (1/0.2618)*cos(-tan(theta)*tan(phi))**-1 #Trise = round(-sunhrs/2) #Tset = round(sunhrs/2) if nevner <= -1: # Midnattsol sr = 0. ss = 24. if nevner >= 1: # Mørketid sr = 12. ss = 12. #time_hour <- 22 TTList = {} # Values for transmissivity for every hr dingom = {} # Values for zenith angle (0 straight up) for tid in range(1, 24, 1): if (tid > sr) and (tid < ss): tom = tid - 12 # Number of hours from solar noon. Solar noon is tom=0 cosarg = 0.2618 * tom # Radians pr hour dingom[tid] = acos( sin(phi) * sin(theta) + cos(phi) * cos(theta) * cos(cosarg)) # Dingmans zenith angle TTList[tid] = (0.6 + 0.2 * sin((0.5 * pi) - dingom[tid])) * ( 1.0 - 0.5 * cloud_cover ) # Inspirert av G. Liston 1995 transmissivitet # TTList[tid] = (0.6-0.2*sin(dingom[tid]))*(1.0-0.5*cloud_cover) #Inspirert av G. Liston 1995 transmissivitet # TTList[tid] = (0.6-0.2*sin(dingom[tid]))*(1.0-0.5*cloud_cover) #Inspirert av G. Liston 1995 transmissivitet if (tid < sr) or (tid > ss): # If time is outside sunrise-sunset TTList[tid] = 0. # Transmissivity = 0 when sun is below horizon. dingom[ tid] = pi / 2 # Angle below horizin is set to be on the horizon. # pi/2 minus zenith angle, initielt, ikke helt sikker. Blir veldig lav med init dingom lik pi/2 # blir på den annen side høy med init dingom lik 0. Albedo ser ganske fornuftig ut. if time_span_in_sec == 86400: Trans = TTList.values() # list zenith_angle = dingom.values() # list elif time_span_in_sec < 86400: # Midler transmissvitet og solvinkel For finere tidssoppløsning interv = list( range(time_hour - int(time_span_in_sec / 3600) + 1, time_hour, 1)) # aktuelle timer Trans = [TTList[i] for i in interv] # selection of transmisions in intervall zenith_angle = [dingom[i] for i in interv] else: print("Method doesnt work on time intervals greater than 24hrs") Trans = None zenith_angle = None # Mean values Trans = float(sum(Trans) / len(Trans)) zenith_angle = float(sum(zenith_angle) / len(zenith_angle)) if snow_depth == 0.: albedo = albedo_prim age_factor_tau = 0. else: # UEB albedo age_factor_tau, albedo_ueb \ = get_albedo_ueb(prec_snow, snow_depth, temp_surface, zenith_angle, time_span_in_sec, age_factor_tau=age_factor_tau) # Todd Walters albedo albedo_prim, albedo_walter \ = get_albedo_walter(prec_snow, snow_depth, snow_density, temp_atm, albedo_prim, time_span_in_sec, time_hour) # At this point I choose which albedo variant to use in calculating short wave radiation if albedo_method == "ueb": albedo = albedo_ueb elif albedo_method == "walter": albedo = albedo_walter else: print("No valid albedo method selected.") albedo = None #Solar radiation S0 = const.solar_constant #[J/m2/s] Solar constant pr sec S0 *= time_span_in_sec # solar constant pr time step S0 /= 1000 # J to kJ s_inn = Trans * sin((pi / 2) - zenith_angle) * S0 # S = (1 - albedo) * s_inn # se likning Liston 1995, eq. 26 (Nett SW-radiation) return S, s_inn, albedo, albedo_prim, age_factor_tau
def irradiance_clear_sky(utm33_x, utm33_y, date_inn, time_span_in_sec=24*60*60): '''Clear sky irradiance in J/m2/s * time_span_in_sec. :param utm33_x, utm33_y: koordinat i UTM 33 :param date_inn: [datetime] :param time_span_in_sec: [sec] Time resolution in sec :return I_clear_sky: [J/m2] Energy over the time span we are looking at. ''' day_no = date_inn.timetuple().tm_yday # time given as the end of the time span time_hour = (date_inn + dt.timedelta(seconds=time_span_in_sec)).hour if time_hour == 0: time_hour = 24 phi, thi, ddphi, ddthi = dc.lat_long_from_utm33(utm33_x,utm33_y, output= "both") theta = 0.4092*math.cos((2*math.pi/365.25)*(day_no-173)) # solar declination angleday angle, Liston 1995 theta2 = 2*math.pi/365.25*(day_no-80) r = 149598000 # distance from the sun R = 6378 # Radius of earth timezone = -4 * (math.fabs(thi) % 15) * thi/math.fabs(thi) # ang lengdegrad ikke epsilon = 0.4092 # rad(23.45) z_s = r*math.sin(theta2)*math.sin(epsilon) r_p = math.sqrt(r**2-z_s**2) nevner = (R-z_s*math.sin(phi))/(r_p*math.cos(phi)) if(nevner > -1) and (nevner < 1): # acos(m ha inn verdier ,(mellom-1,1) hvis <-1 s er det midnattsol > 1 er det m¯rketid. t0 = 1440/(2*math.pi)*math.acos((R-z_s*math.sin(phi))/(r_p*math.cos(phi))) that = t0+5 n = 720-10*math.sin(4*math.pi*(day_no-80)/365.25)+8*math.sin(2*math.pi*day_no/365.25) sr = (n-that+timezone)/60 #soloppgang ss = (n+that+timezone)/60 #solnedgang if nevner <= -1: # Midnattsol sr = 0. ss = 24. if nevner >= 1: # Mørketid sr = 12. ss = 12. dingom = {} # Values for zenith angle (0 straight up) for tid in range(1, 24, 1): if (tid > sr) and (tid < ss): tom = tid-12 # Number of hours from solar noon. Solar noon is tom=0 cosarg = 0.2618 * tom # Radians pr hour dingom[tid] = math.acos(math.sin(phi)*math.sin(theta)+math.cos(phi)*math.cos(theta)*math.cos(cosarg)) # Dingmans zenith angle if (tid < sr) or (tid > ss): # If time is outside sunrise-sunset dingom[tid] = math.pi/2 # Angle below horizin is set to be on the horizon. if time_span_in_sec == 86400: zenith_angle = dingom.values() # list elif time_span_in_sec < 86400: # Midler transmissvitet og solvinkel For finere tidssoppløsning interv = list(range(time_hour-int(time_span_in_sec/3600)+1, time_hour, 1)) # aktuelle timer zenith_angle = [dingom[i] for i in interv] else: print("Method doesnt work on time intervals greater than 24hrs") zenith_angle = None # Mean values zenith_angle = float( sum(zenith_angle) / len(zenith_angle) ) #Solar radiation S0 = const.solar_constant #[J/m2/s] Solar constant pr sec S0 *= time_span_in_sec # solar constant pr time step S0 /=1000 # J to kJ I_clear_sky = math.sin((math.pi/2)-zenith_angle) * S0 return I_clear_sky
def irradiance_clear_sky(utm33_x, utm33_y, date_inn, time_span_in_sec=24 * 60 * 60): '''Clear sky irradiance in J/m2/s * time_span_in_sec. :param utm33_x, utm33_y: koordinat i UTM 33 :param date_inn: [datetime] :param time_span_in_sec: [sec] Time resolution in sec :return I_clear_sky: [J/m2] Energy over the time span we are looking at. ''' day_no = date_inn.timetuple().tm_yday # time given as the end of the time span time_hour = (date_inn + dt.timedelta(seconds=time_span_in_sec)).hour if time_hour == 0: time_hour = 24 phi, thi, ddphi, ddthi = dc.lat_long_from_utm33(utm33_x, utm33_y, output="both") theta = 0.4092 * math.cos( (2 * math.pi / 365.25) * (day_no - 173)) # solar declination angleday angle, Liston 1995 theta2 = 2 * math.pi / 365.25 * (day_no - 80) r = 149598000 # distance from the sun R = 6378 # Radius of earth timezone = -4 * (math.fabs(thi) % 15) * thi / math.fabs( thi) # ang lengdegrad ikke epsilon = 0.4092 # rad(23.45) z_s = r * math.sin(theta2) * math.sin(epsilon) r_p = math.sqrt(r**2 - z_s**2) nevner = (R - z_s * math.sin(phi)) / (r_p * math.cos(phi)) if (nevner > -1) and (nevner < 1): # acos(m ha inn verdier ,(mellom-1,1) hvis <-1 s er det midnattsol > 1 er det m¯rketid. t0 = 1440 / (2 * math.pi) * math.acos( (R - z_s * math.sin(phi)) / (r_p * math.cos(phi))) that = t0 + 5 n = 720 - 10 * math.sin(4 * math.pi * (day_no - 80) / 365.25) + 8 * math.sin( 2 * math.pi * day_no / 365.25) sr = (n - that + timezone) / 60 #soloppgang ss = (n + that + timezone) / 60 #solnedgang if nevner <= -1: # Midnattsol sr = 0. ss = 24. if nevner >= 1: # Mørketid sr = 12. ss = 12. dingom = {} # Values for zenith angle (0 straight up) for tid in range(1, 24, 1): if (tid > sr) and (tid < ss): tom = tid - 12 # Number of hours from solar noon. Solar noon is tom=0 cosarg = 0.2618 * tom # Radians pr hour dingom[tid] = math.acos( math.sin(phi) * math.sin(theta) + math.cos(phi) * math.cos(theta) * math.cos(cosarg)) # Dingmans zenith angle if (tid < sr) or (tid > ss): # If time is outside sunrise-sunset dingom[ tid] = math.pi / 2 # Angle below horizin is set to be on the horizon. if time_span_in_sec == 86400: zenith_angle = dingom.values() # list elif time_span_in_sec < 86400: # Midler transmissvitet og solvinkel For finere tidssoppløsning interv = list( range(time_hour - int(time_span_in_sec / 3600) + 1, time_hour, 1)) # aktuelle timer zenith_angle = [dingom[i] for i in interv] else: print("Method doesnt work on time intervals greater than 24hrs") zenith_angle = None # Mean values zenith_angle = float(sum(zenith_angle) / len(zenith_angle)) #Solar radiation S0 = const.solar_constant #[J/m2/s] Solar constant pr sec S0 *= time_span_in_sec # solar constant pr time step S0 /= 1000 # J to kJ I_clear_sky = math.sin((math.pi / 2) - zenith_angle) * S0 return I_clear_sky