diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..3dd6782 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,3 @@ +^.*\.Rproj$ +^\.Rproj\.user$ + ^data-raw$ diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..e866db6 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,17 @@ +Package: mars +Title: Mars Solar Radiation +Version: 0.0.0.9000 +Authors@R: + person(given = "Georges", + family = "Labreche", + role = c("aut", "cre"), + email = "georges@opendatakosovo.org", + comment = structure("YOUR-ORCID-ID", .Names = "ORCID")) +Description: A set of functions to calculate solar irradiance and insolation on Mars horizontal and inclined surfaces. +License: What license it uses +Encoding: UTF-8 +LazyData: true +RoxygenNote: 7.0.0 +Suggests: + testthat, + covr \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..602440d --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,49 @@ +# Generated by roxygen2: do not edit by hand + +export(G_b) +export(G_bh) +export(G_bi) +export(G_dh) +export(G_di) +export(G_h) +export(G_i) +export(G_ob) +export(G_obh) +export(H_ali) +export(H_bi) +export(H_dh) +export(H_di) +export(H_h) +export(H_hbh) +export(H_i) +export(H_obh) +export(I_ali) +export(I_bh) +export(I_bi) +export(I_dh) +export(I_di) +export(I_h) +export(I_i) +export(I_obh) +export(Z) +export(albedo) +export(constrain_solar_time_range) +export(declination) +export(f) +export(f_all_Zs) +export(f_all_taus) +export(is_irradiated) +export(is_polar_day) +export(is_polar_night) +export(sunrise) +export(sunrise_for_horizontal_surface) +export(sunrise_for_inclined_surface) +export(sunrise_for_inclined_surface_oriented_east) +export(sunrise_for_inclined_surface_oriented_equator) +export(sunrise_for_inclined_surface_oriented_west) +export(sunset) +export(sunset_for_horizontal_surface) +export(sunset_for_inclined_surface) +export(sunset_for_inclined_surface_oriented_east) +export(sunset_for_inclined_surface_oriented_equator) +export(sunset_for_inclined_surface_oriented_west) diff --git a/R/G_ali.R b/R/G_ali.R new file mode 100644 index 0000000..0d1700b --- /dev/null +++ b/R/G_ali.R @@ -0,0 +1,19 @@ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param T_s +#' @param Z +#' @param tau +#' @param al +#' @param beta +#' @param nfft +#' +#' @return +G_ali = function(Ls, phi, longitude, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, nfft){ + + Gali = al * Gh_eq(Ls=Ls, phi=phi, longitude=longitude, Z=Z, tau=tau, al=al, nfft=nfft) * sin((beta*pi/180) / 2)^2 + return(Gali) +} + diff --git a/functions/G_b.R b/R/G_b.R similarity index 60% rename from functions/G_b.R rename to R/G_b.R index abba925..3fac958 100644 --- a/functions/G_b.R +++ b/R/G_b.R @@ -9,26 +9,27 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 -library(here) - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Check if there is irradiance based on the givent moment. -is_irradiated = dget(here("utils", "is_irradiated.R")) - # Equation 14 (1990): Beam irradiance on Mars surface [W/m2] # Ls - Areocentric Longitude. # Z - Sun Zenith Angle. # tau - Optical Depth. -function(Ls, phi=NULL, T_s=NULL, Z=Z_eq(Ls, T_s, phi, nfft), tau, nfft){ - if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, Z=Z, nfft=nfft)){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param T_s +#' @param z +#' @param tau +#' @param nfft +#' +#' @return +#' @export +G_b = function(Ls, phi=NULL, T_s=NULL, z=Z(Ls, T_s, phi, nfft), tau, nfft){ + + if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, z=z, nfft=nfft)){ return(0) }else{ - Gob_eq(Ls) * exp(-tau / cos(Z*pi/180)) + G_ob(Ls) * exp(-tau / cos(z*pi/180)) } } \ No newline at end of file diff --git a/functions/G_bh.R b/R/G_bh.R similarity index 59% rename from functions/G_bh.R rename to R/G_bh.R index 6261fa5..679a7e4 100644 --- a/functions/G_bh.R +++ b/R/G_bh.R @@ -6,17 +6,6 @@ # FIXME: Update this function so that it figures out if its a polar night or day. -library(here) - -# Equation 4: Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Check if there is irradiance based on the givent moment. -is_irradiated = dget(here("utils", "is_irradiated.R")) - # Equation 18: Beam irradiance on Mars horizontal surface [W/m2]. # # Ls - Areocentric longitude [deg]. @@ -26,11 +15,25 @@ is_irradiated = dget(here("utils", "is_irradiated.R")) # tau - Optical depth. # al - NOT NEEDED - Included for looping convenience with other functions. # nfft - Net flux calculation type. -function(Ls, phi, longitude=NULL, T_s, Z=Z_eq(Ls, T_s, phi, nfft), tau, al=NULL, nfft){ - if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, Z=Z, nfft=nfft)){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param T_s +#' @param z +#' @param tau +#' @param al +#' @param nfft +#' +#' @return +#' @export +G_bh = function(Ls, phi, longitude=NULL, T_s, z=Z(Ls, T_s, phi, nfft), tau, al=NULL, nfft){ + + if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, z=z, nfft=nfft)){ return(0) }else{ - Gob_eq(Ls) * cos(Z * pi/180) * exp(-tau / cos(Z*pi/180)) + G_ob(Ls) * cos(z * pi/180) * exp(-tau / cos(z*pi/180)) } } \ No newline at end of file diff --git a/functions/G_bi.R b/R/G_bi.R similarity index 74% rename from functions/G_bi.R rename to R/G_bi.R index e432fe7..645396e 100644 --- a/functions/G_bi.R +++ b/R/G_bi.R @@ -8,22 +8,20 @@ # FIXME: Update this function so that it figures out if its a polar night or day. -library(here) - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 6 (1990): Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Equation 14 (1990): Direct beam irradiance on the Mars surface normal to the solar rays [W/m2]. -Gb_eq = dget(here("functions", "G_b.R")) - -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - - -function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, gamma_c, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param T_s +#' @param z +#' @param tau +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +G_bi = function(Ls, phi, T_s, z=Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, gamma_c, nfft){ if(gamma_c > 180 || gamma_c < -180){ stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") @@ -53,7 +51,7 @@ function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, ga # Equation 6 (1993): Solar Azimuth Angle [deg] x = sin(phi*pi/180) * cos(delta) * cos(omega_deg*pi/180) y = cos(phi*pi/180) * sin(delta) - z = sin(Z*pi/180) + z = sin(z*pi/180) # From (32) in (1993): It is solar noon when omega is 0 deg. This translates to gamma_s = 0 deg. # The following operation will result in a value very close to 1 but not exactly 1 if it is @@ -64,8 +62,8 @@ function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, ga one = function(x){ return( ifelse(x > 0, - ifelse(x > 1 && x < 1+1e-5, 1, x), # If x is positive. - ifelse(x < -1 && x > -1-1e-5, 1, x)) # If x is negative. + ifelse(x > 1 && x < 1+1e-5, 1, x), # If x is positive. + ifelse(x < -1 && x > -1-1e-5, 1, x)) # If x is negative. ) } @@ -76,8 +74,8 @@ function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, ga gamma_s = acos(op) * 180/pi # [deg] # Alternatively, Equation 7 (1993): Solar Azimuth Angle [deg] - # x = sin(phi*pi/180) * cos(Z*pi/180) - sin(delta) - # y = cos(phi*pi/180) * sin(Z*pi/180) + # x = sin(phi*pi/180) * cos(z*pi/180) - sin(delta) + # y = cos(phi*pi/180) * sin(z*pi/180) # # gamma_s = acos(x / y) * 180/pi # [deg] @@ -91,13 +89,13 @@ function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, ga #TODO: Double check this, why wouldn't the paper use squared instead of multiply the by the same value? # Check with (24) in (1993). j = sin(gamma_s * pi/180) * sin(gamma_s * pi/180) - teta = acos(sin(Z * pi/180) * (i + j))# [rad] + teta = acos(sin(z * pi/180) * (i + j))# [rad] }else{ # (13) in (1993): Inclined surface. # (27) in (1993): Surface facing the equator. - i = cos(beta * pi/180) * cos(Z * pi/180) - j = sin(beta * pi/180) * sin(Z * pi/180) * cos((gamma_s - gamma_c) * pi/180) # Does not matter when beta = 0 because it leads to j = 0. + i = cos(beta * pi/180) * cos(z * pi/180) + j = sin(beta * pi/180) * sin(z * pi/180) * cos((gamma_s - gamma_c) * pi/180) # Does not matter when beta = 0 because it leads to j = 0. teta = acos(i + j) # [rad] } @@ -107,7 +105,7 @@ function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, beta, ga # Sun Angle of Incidence [rad] on an inclined surface. teta = sun_angle_of_incidence() - Gbi = Gb_eq(Ls=Ls, Z=Z, tau=tau) * cos(teta) + Gbi = G_b(Ls=Ls, z=z, tau=tau) * cos(teta) return(Gbi) } \ No newline at end of file diff --git a/functions/G_dh.R b/R/G_dh.R similarity index 51% rename from functions/G_dh.R rename to R/G_dh.R index abdeeab..aa9c955 100644 --- a/functions/G_dh.R +++ b/R/G_dh.R @@ -9,22 +9,6 @@ # FIXME: Update this function so that it figures out if its a polar night or day. -library(here) - -# Equation 17 (1990): Global irradiance on Mars horizontal surface [W/m2]. -Gh_eq = dget(here("functions", "G_h.R")) - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Equation 18 (1990): Beam irradiance on Mars horizontal surface [W/m2]. -Gbh_eq = dget(here("functions", "G_bh.R")) - -# Check if there is irradiance based on the givent moment. -is_irradiated = dget(here("utils", "is_irradiated.R")) - -source(here("functions", "albedo.R")) - # Equation 16 (1990): The solar irradiance components on a horizontal Martian surface [W/m2]. # # Ls - Areocentric longitude [deg]. @@ -35,12 +19,26 @@ source(here("functions", "albedo.R")) # - 1 for f_89. # - 2 for f_90. # - 3 for f_analytical. -function(Ls, phi, longitude, T_s=NULL, Z=Z_eq(Ls, T_s, phi, nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), nfft){ - if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, Z=Z, nfft=nfft)){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param T_s +#' @param z +#' @param tau +#' @param al +#' @param nfft +#' +#' @return +#' @export +G_dh = function(Ls, phi, longitude, T_s=NULL, z=Z(Ls, T_s, phi, nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), nfft){ + + if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, z=z, nfft=nfft)){ return(0) }else{ - G_dh = Gh_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, Z=Z, tau=tau, al=al, nfft=nfft) - Gbh_eq(Ls=Ls, phi=phi, T_s=T_s, Z=Z, tau=tau, nfft=nfft) - return(G_dh) + Gdh = G_h(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, z=z, tau=tau, al=al, nfft=nfft) - G_bh(Ls=Ls, phi=phi, T_s=T_s, z=z, tau=tau, nfft=nfft) + return(Gdh) } } \ No newline at end of file diff --git a/R/G_di.R b/R/G_di.R new file mode 100644 index 0000000..ae45bcd --- /dev/null +++ b/R/G_di.R @@ -0,0 +1,19 @@ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param T_s +#' @param z +#' @param tau +#' @param al +#' @param beta +#' @param nfft +#' +#' @return +#' @export +G_di = function(Ls, phi, longitude, T_s, z=Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, nfft){ + + G_di = Gdh_eq(Ls=Ls, phi=phi, longitude=longitude, z=z, tau=tau, al=al, nfft=nfft) * cos((beta*pi/180) / 2)^2 + return(G_di) +} \ No newline at end of file diff --git a/functions/G_h.R b/R/G_h.R similarity index 57% rename from functions/G_h.R rename to R/G_h.R index 8037227..2c06741 100644 --- a/functions/G_h.R +++ b/R/G_h.R @@ -4,23 +4,6 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 -library(here) - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# The normalized net flux function. -source(here("functions", "f.R")) - -# Albedo. -source(here("functions", "albedo.R")) - -# Check if there is irradiance based on the givent moment. -is_irradiated = dget(here("utils", "is_irradiated.R")) - # Equation 17 (1990): Global irradiance on Mars horizontal surface [W/m2]. # Ls - Areocentric longitude [deg]. # phi - Planetary latitude [deg]. @@ -34,28 +17,40 @@ is_irradiated = dget(here("utils", "is_irradiated.R")) # - 3 for f_analytical. # # FIXME: Error check that albedo value is given and not calculated when using look up table for net_flux. -function(Ls, phi, longitude, T_s=NULL, Z=Z_eq(Ls, T_s, phi, nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), nfft){ - +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param T_s +#' @param z +#' @param tau +#' @param al +#' @param nfft +#' +#' @return +#' @export +G_h = function(Ls, phi, longitude, T_s=NULL, z=Z(Ls, T_s, phi, nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), nfft){ - if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, Z=Z, nfft=nfft)){ + if(!is_irradiated(Ls=Ls, phi=phi, T_s=T_s, z=z, nfft=nfft)){ return(0) }else{ if(nfft == 1){ - net_flux = f(Z=Z, tau=tau, al=al, pub_year=1989) + net_flux = f(z=z, tau=tau, al=al, pub_year=1989) }else if(nfft == 2){ - net_flux = f(Z=Z, tau=tau, al=al, pub_year=1990) + net_flux = f(z=z, tau=tau, al=al, pub_year=1990) }else if(nfft == 3){ - net_flux = f(Z=Z, tau=tau, al=al) + net_flux = f(z=z, tau=tau, al=al) }else{ stop("Unsupported net flux function type. Should be 1 for the original 1989 lookup table publication, 2 for the 1990/1991 lookup table update, or 3 for the analytical expression.") } - G_h = Gob_eq(Ls) * cos(Z*pi/180) * (net_flux / (1-al)) + Gh = G_ob(Ls) * cos(z*pi/180) * (net_flux / (1-al)) - return(G_h) + return(Gh) } } \ No newline at end of file diff --git a/functions/G_i.R b/R/G_i.R similarity index 61% rename from functions/G_i.R rename to R/G_i.R index 0d2043d..4393f0c 100644 --- a/functions/G_i.R +++ b/R/G_i.R @@ -8,17 +8,6 @@ # FIXME: Update this function so that it figures out if its a polar night or day. -library(here) - -# Equation 6 (1990): Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -Gbi_eq = dget(here("functions", "G_bi.R")) -Gdi_eq = dget(here("functions", "G_di.R")) -Gali_eq = dget(here("functions", "G_ali.R"))# - -source(here("functions", "albedo.R")) - # Equation 3 (1994): Global irradiance on an inclined surface. # # Ls - Areocentric longitude [deg]. @@ -34,15 +23,30 @@ source(here("functions", "albedo.R")) # - 1 for f_89. # - 2 for f_90. # - 3 for f_analytical. -function(Ls, phi, longitude, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param T_s +#' @param z +#' @param tau +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +G_i = function(Ls, phi, longitude, T_s, z=Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ if(gamma_c > 180 || gamma_c < -180){ stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") } - a = Gbi_eq(Ls=Ls, phi=phi, T_s=T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau=tau, beta=beta, gamma_c=gamma_c, nfft=nfft) - b = Gdi_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau=tau, al=al, beta=beta, nfft=nfft) - c = Gali_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau=tau, al=al, beta=beta, nfft=nfft) + a = Gbi_eq(Ls=Ls, phi=phi, T_s=T_s, z=Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau=tau, beta=beta, gamma_c=gamma_c, nfft=nfft) + b = Gdi_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, z=Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau=tau, al=al, beta=beta, nfft=nfft) + c = Gali_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, z=Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau=tau, al=al, beta=beta, nfft=nfft) Gi = a + b + c diff --git a/R/G_ob.R b/R/G_ob.R new file mode 100644 index 0000000..8c78a1c --- /dev/null +++ b/R/G_ob.R @@ -0,0 +1,21 @@ +# Constants. +Ls_P = 248 # Periphelion. +e = 0.093377 # Mars orbit eccentricity. +Mb = 590 # Mean beam irradiance at the top of the Martian atmosphere. + +#' Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. +#' +#' Source: +#' Appelbaum, Joseph & Flood, Dennis. (1990). +#' Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. +#' https://www.researchgate.net/publication/256334925_Solar_radiation_on_Mars +#' +#' @param Ls Areocentric longitude. +#' +#' @return Beam irradiance [W/m2]. +#' @export +G_ob = function(Ls){ + + Gob = Mb * (1 + e*cos((Ls-Ls_P)*pi/180))^2 / (1-e^2)^2 + return(Gob) +} diff --git a/functions/G_obh.R b/R/G_obh.R similarity index 58% rename from functions/G_obh.R rename to R/G_obh.R index 8f674ad..b84b767 100644 --- a/functions/G_obh.R +++ b/R/G_obh.R @@ -4,11 +4,18 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 # -library(here) - -Gob_eq = dget(here("functions", "G_ob.R")) -Z_eq = dget(here("functions", "Z.R")) - -function(Ls, phi=NULL, T_s=NULL, Z=Z_eq(Ls, T_s, phi, nfft), nfft=1){ - Gob_eq(Ls) * cos(Z*pi/180) +#' Title +#' +#' @param Ls +#' @param phi +#' @param T_s +#' @param z +#' @param nfft +#' +#' @return +#' @export +G_obh = function(Ls, phi=NULL, T_s=NULL, z=Z(Ls, T_s, phi, nfft), nfft=1){ + + Gobh = G_ob(Ls) * cos(z*pi/180) + return(Gobh) } \ No newline at end of file diff --git a/R/H_ali.R b/R/H_ali.R new file mode 100644 index 0000000..49f0024 --- /dev/null +++ b/R/H_ali.R @@ -0,0 +1,26 @@ + +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +H_ali = function(Ls, phi, longitude, tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ + + if(gamma_c > 180 || gamma_c < -180){ + stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") + } + + # H_alii is obtained by integrating I_ali over the period from sunrise to sunset. + Hali = I_ali(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=0, T_end=24, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) + + # Return result. + return(Hali) +} \ No newline at end of file diff --git a/functions/H_bh.R b/R/H_bh.R similarity index 58% rename from functions/H_bh.R rename to R/H_bh.R index 92da93c..7084275 100644 --- a/functions/H_bh.R +++ b/R/H_bh.R @@ -7,12 +7,22 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 # -library(here) -# Global hourly insolation on Mars horizontal surface [W/m2-h]. -Ibh_eq = dget(here("functions", "I_bh.R")) - -function(Ls, phi, tau, al=NULL, nfft){ - # H_bh is obtained by integrating I_bh over the period from sunrise to sunset. - Ibh_eq(Ls, phi, tau, 0, 24, NULL, nfft) +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param al +#' @param nfft +#' +#' @return +#' @export +H_hbh = function(Ls, phi, tau, al=NULL, nfft){ + + # Hbh is obtained by integrating Ibh over the period from sunrise to sunset. + Hbh = I_bh(Ls, phi, tau, 0, 24, NULL, nfft) + + # Return result. + return(Hbh) } \ No newline at end of file diff --git a/R/H_bi.R b/R/H_bi.R new file mode 100644 index 0000000..669ebfe --- /dev/null +++ b/R/H_bi.R @@ -0,0 +1,24 @@ + +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +H_bi = function(Ls, phi, tau, beta, gamma_c, nfft){ + + if(gamma_c > 180 || gamma_c < -180){ + stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") + } + + # Hbi is obtained by integrating Ibi over the period from sunrise to sunset. + Hbi = I_bi(Ls=Ls, phi=phi, tau=tau, T_start=0, T_end=24, beta=beta, gamma_c=gamma_c, nfft=nfft) + + # Return result. + return(Hbi) +} \ No newline at end of file diff --git a/functions/H_dh.R b/R/H_dh.R similarity index 67% rename from functions/H_dh.R rename to R/H_dh.R index ae56c98..fedf933 100644 --- a/functions/H_dh.R +++ b/R/H_dh.R @@ -8,12 +8,21 @@ # https://ntrs.nasa.gov/?R=19890018252 # -library(here) - -# Diffuse hourly insolation on Mars horizontal surface [Wh/m2]. -Idh_eq = dget(here("functions", "I_dh.R")) - -function(Ls, phi, tau, al, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param al +#' @param nfft +#' +#' @return +#' @export +H_dh = function(Ls, phi, tau, al, nfft){ + # Integrate I_dh over the period from sunrise to sunset. - Idh_eq(Ls, phi, tau, 0, 24, al, nfft) + Hdh = I_dh(Ls, phi, tau, 0, 24, al, nfft) + + # Return result. + return(Hdh) } \ No newline at end of file diff --git a/R/H_di.R b/R/H_di.R new file mode 100644 index 0000000..88c2342 --- /dev/null +++ b/R/H_di.R @@ -0,0 +1,25 @@ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +H_di = function(Ls, phi, longitude, tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ + + if(gamma_c > 180 || gamma_c < -180){ + stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") + } + + # Hdi is obtained by integrating Idi over the period from sunrise to sunset. + Hdi = I_di(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=0, T_end=24, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) + + # Return result. + return(Hdi) +} \ No newline at end of file diff --git a/functions/H_h.R b/R/H_h.R similarity index 58% rename from functions/H_h.R rename to R/H_h.R index c6a41ba..4b34526 100644 --- a/functions/H_h.R +++ b/R/H_h.R @@ -7,14 +7,21 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 # +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param al +#' @param nfft +#' +#' @return +#' @export +H_h = function(Ls, phi, tau, al=0.1, nfft){ -library(here) - -# Global hourly insolation on Mars horizontal surface [W/m2-h]. -Ih_eq = dget(here("functions", "I_h.R")) - -function(Ls, phi, tau, al=0.1, nfft){ - # H_h is obtained by integrating I_h over the period from sunrise to sunset. - H_h = Ih_eq(Ls, phi, tau, 0, 24, al, nfft) - return(H_h) + # Hh is obtained by integrating Ih over the period from sunrise to sunset. + Hh = I_h(Ls, phi, tau, 0, 24, al, nfft) + + # Return result. + return(Hh) } \ No newline at end of file diff --git a/functions/H_i.R b/R/H_i.R similarity index 57% rename from functions/H_i.R rename to R/H_i.R index eaee271..ce428d8 100644 --- a/functions/H_i.R +++ b/R/H_i.R @@ -9,22 +9,28 @@ # Journal of Propulsion and Power. 12. 10.2514/3.24044 # https://ntrs.nasa.gov/?R=19950004977 # - -library(here) - -# Global hourly insolation on Mars inclined surface [W/m2-h]. -Ii_eq = dget(here("functions", "I_i.R")) - -source(here("functions", "albedo.R")) - -function(Ls, phi, longitude, tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +H_i = function(Ls, phi, longitude, tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ + if(gamma_c > 180 || gamma_c < -180){ stop("Surface azimuth angle gamma_c must between -180 and 180 degrees with zero south, east negative, and west positive.") } - # H_i is obtained by integrating I_i over the period from sunrise to sunset. - H_i = Ii_eq(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=0, T_end=24, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) + # Hi is obtained by integrating Ii over the period from sunrise to sunset. + Hi = I_i(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=0, T_end=24, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) # Return result. - return(H_i) + return(Hi) } \ No newline at end of file diff --git a/functions/H_obh.R b/R/H_obh.R similarity index 74% rename from functions/H_obh.R rename to R/H_obh.R index 357e5ad..4df10c5 100644 --- a/functions/H_obh.R +++ b/R/H_obh.R @@ -4,16 +4,15 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 # - -library(here) - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - -function(Ls, phi){ +#' Title +#' +#' @param Ls +#' @param phi +#' +#' @return +#' @export +H_obh = function(Ls, phi){ + # Convert phi into radians. phi = phi * pi/180 @@ -29,7 +28,8 @@ function(Ls, phi){ c = sin(phi) * sin(delta) d = cos(phi) * cos(delta) * sin(omega_ss) - H_obh = a * (b * c + d) + Hobh = a * (b * c + d) - return(H_obh) + # Return result. + return(Hobh) } diff --git a/functions/I_ali.R b/R/I_ali.R similarity index 57% rename from functions/I_ali.R rename to R/I_ali.R index c0912af..dca90c8 100644 --- a/functions/I_ali.R +++ b/R/I_ali.R @@ -1,13 +1,21 @@ -library(here) -Gali_eq = dget(here("functions", "G_ali.R")) -source(here("functions", "albedo.R")) - -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) - -function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param T_start +#' @param T_end +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +I_ali = function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ # Step 1: Constrain T_start and T_end based on sunrise and sunset times. @@ -26,7 +34,7 @@ function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longit # Step 2: Calculate insolation. interand = function(T_s){ - Gali = Gali_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, beta=beta, nfft=nfft) + Gali = G_ali(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, beta=beta, nfft=nfft) return(Gali) } diff --git a/functions/I_bh.R b/R/I_bh.R similarity index 62% rename from functions/I_bh.R rename to R/I_bh.R index d4b1c94..520f742 100644 --- a/functions/I_bh.R +++ b/R/I_bh.R @@ -6,21 +6,22 @@ # -library(here) - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) - # Equation 19 (1990): Beam hourly insolation on Mars horizontal surface. # # al - NOT NEEDED - Included for looping convenience with other functions. -function(Ls, phi, tau, T_start, T_end, al=NULL, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param T_start +#' @param T_end +#' @param al +#' @param nfft +#' +#' @return +#' @export +I_bh = function(Ls, phi, tau, T_start, T_end, al=NULL, nfft){ # Step 1: Constrain T_start and T_end based on sunrise and sunset times. @@ -42,18 +43,18 @@ function(Ls, phi, tau, T_start, T_end, al=NULL, nfft){ # The interand for Equation 19 (1990). interand = function(T_s){ - Z = Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft) + z = Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft) - a = Gob_eq(Ls) - b = cos(Z*pi/180) - c = exp(-tau / cos(Z*pi/180)) + a = G_ob(Ls) + b = cos(z*pi/180) + c = exp(-tau / cos(z*pi/180)) a * b * c } # Equation 19 (1990): Beam hourly insolation on Mars horizontal surface. - I_bh = integrate(interand, T_start, T_end) + Ibh = integrate(interand, T_start, T_end) - return(I_bh$value) + return(Ibh$value) } diff --git a/R/I_bi.R b/R/I_bi.R new file mode 100644 index 0000000..d604fa4 --- /dev/null +++ b/R/I_bi.R @@ -0,0 +1,46 @@ +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param T_start +#' @param T_end +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +I_bi = function(Ls, phi, tau, T_start, T_end, beta, gamma_c, nfft){ + + if(gamma_c > 180 || gamma_c < -180){ + stop("Surface azimuth angle gamma_c must between -180° and +180° with zero south, east negative, and west positive.") + } + + # Step 1: Constrain T_start and T_end based on sunrise and sunset times. + + # Apply solar time range constraint. + T_range = constrain_solar_time_range(Ls, phi, T_start, T_end, beta, gamma_c) + + # No solar irradiance within the contrained time range. + if(is.null(T_range)){ + return(0) + + }else{ + # Constrain the time range. + T_start = T_range$T_start + T_end = T_range$T_end + } + + # Step 2: Calculate insolation. + + interand = function(T_s){ + Gbi = G_bi(Ls=Ls, phi=phi, T_s=T_s, tau=tau, beta=beta, gamma_c=gamma_c, nfft=nfft) + return(Gbi) + } + + Ibi = integrate(interand, T_start, T_end) + + # Return integration result. + return(Ibi$value) +} diff --git a/R/I_dh.R b/R/I_dh.R new file mode 100644 index 0000000..385324c --- /dev/null +++ b/R/I_dh.R @@ -0,0 +1,24 @@ +# Diffuse hourly insolation on Mars horizontal surface [Wh/m2]. +# +# Based on equations presented in the following publication: +# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. +# https://ntrs.nasa.gov/?R=19890018252 +# + +#' Title +#' +#' @param Ls +#' @param phi +#' @param tau +#' @param T_start +#' @param T_end +#' @param al +#' @param nfft +#' +#' @return +#' @export +I_dh = function(Ls, phi, tau, T_start, T_end, al, nfft){ + + Ih = I_h(Ls, phi, tau, T_start, T_end, al, nfft) - I_bh(Ls, phi, tau, T_start, T_end, al, nfft) + return(Ih) +} \ No newline at end of file diff --git a/R/I_di.R b/R/I_di.R new file mode 100644 index 0000000..c8012cf --- /dev/null +++ b/R/I_di.R @@ -0,0 +1,50 @@ + + +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param T_start +#' @param T_end +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +I_di = function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ + + if(gamma_c > 180 || gamma_c < -180){ + stop("Surface azimuth angle gamma_c must between -180° and +180° with zero south, east negative, and west positive.") + } + + # Step 1: Constrain T_start and T_end based on sunrise and sunset times. + + # Apply solar time range constraint. + T_range = constrain_solar_time_range(Ls, phi, T_start, T_end, beta, gamma_c) + + # No solar irradiance within the contrained time range. + if(is.null(T_range)){ + return(0) + + }else{ + # Constrain the time range. + T_start = T_range$T_start + T_end = T_range$T_end + } + + # Step 2: Calculate insolation. + + interand = function(T_s){ + Gdi = G_di(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, beta=beta, nfft=nfft) + return(Gdi) + } + + Idi = integrate(interand, T_start, T_end) + + # Return integration result. + return(Idi$value) +} diff --git a/functions/I_h.R b/R/I_h.R similarity index 59% rename from functions/I_h.R rename to R/I_h.R index 460737b..59c8c7e 100644 --- a/functions/I_h.R +++ b/R/I_h.R @@ -4,19 +4,24 @@ # Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. # https://ntrs.nasa.gov/?R=19890018252 # -library(here) -# Equation 17 (1990): Global irradiance on Mars horizontal surface [W/m2]. -Gh_eq = dget(here("functions", "G_h.R")) -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) -# Albedo function. -source(here("functions", "albedo.R")) - - -function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param T_start +#' @param T_end +#' @param al +#' @param nfft +#' +#' @return +#' @export +I_h = function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), nfft){ + # Step 1: Constrain T_start and T_end based on sunrise and sunset times. # Apply solar time range constraint. @@ -36,12 +41,12 @@ function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longit # The interand for Equation 19 (1990). interand = function(T_s){ - G_h = Gh_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, nfft=nfft) - return(G_h) + Gh = G_h(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, nfft=nfft) + return(Gh) } # Global hourly insolation on Mars horizontal surface. - I_h = integrate(interand, T_start, T_end) + Ih = integrate(interand, T_start, T_end) - return(I_h$value) + return(Ih$value) } diff --git a/functions/I_i.R b/R/I_i.R similarity index 58% rename from functions/I_i.R rename to R/I_i.R index 8a3b433..2fac630 100644 --- a/functions/I_i.R +++ b/R/I_i.R @@ -6,20 +6,26 @@ # Journal of Propulsion and Power. 12. 10.2514/3.24044 # https://www.researchgate.net/publication/24286713_Solar_radiation_on_Mars_Tracking_photovoltaic_array # -library(here) -# Equation 3 (1994): Global irradiance on Mars inclined surface [W/m2]. -Gi_eq = dget(here("functions", "G_i.R")) - -source(here("functions", "albedo.R")) - -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) - -function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param longitude +#' @param tau +#' @param T_start +#' @param T_end +#' @param al +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +I_i = function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degres with zero south, east negative, and west positive.") + stop("Surface azimuth angle gamma_c must between -180° and +180 with zero south, east negative, and west positive.") } # Step 1: Constrain T_start and T_end based on sunrise and sunset times. @@ -41,13 +47,13 @@ function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longit # The interand for Equation 19 (1990). interand = function(T_s){ - G_i = Gi_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) - return(G_i) + Gi = G_i(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) + return(Gi) } # Global hourly insolation on Mars inclined surface. - I_i = integrate(interand, T_start, T_end) + Ii = integrate(interand, T_start, T_end) # Return integration result. - return(I_i$value) + return(Ii$value) } diff --git a/R/I_obh.R b/R/I_obh.R new file mode 100644 index 0000000..0ad1654 --- /dev/null +++ b/R/I_obh.R @@ -0,0 +1,48 @@ +# Equation 11 (1990): Beam insolation on a horizotal surface at the top of Mars atmosphere [Wh/m2]. +# +# Based on equations presented in the following publication: +# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. +# https://ntrs.nasa.gov/?R=19890018252 +# +#' Title +#' +#' @param Ls +#' @param phi +#' @param T_start +#' @param T_end +#' @param nfft +#' +#' @return +#' @export +I_obh = function(Ls, phi, T_start, T_end, nfft){ + + # Step 1: Constrain T_start and T_end based on sunrise and sunset times. + + # Apply solar time range constraint. + T_range = constrain_solar_time_range(Ls, phi, T_start, T_end) + + # No solar irradiance within the contrained time range. + if(is.null(T_range)){ + return(0) + + }else{ + # Constrain the time range. + T_start = T_range$T_start + T_end = T_range$T_end + } + + # Step 2: Calculate insolation. + + # The interand for Equation 11 (1990). + interand = function(T_s){ + z = Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft) + + x = G_ob(Ls) * cos(z*pi/180) + return(x) + } + + # Equation 11 (1990): Beam insolation on a horizotal surface at the top of Mars atmosphere [Wh/m2]. + Iobh = integrate(interand, T_start, T_end) + + return(Iobh$value) +} \ No newline at end of file diff --git a/R/Z.R b/R/Z.R new file mode 100644 index 0000000..4e505e3 --- /dev/null +++ b/R/Z.R @@ -0,0 +1,52 @@ +#' Equation 6: Zenith angle of the incident solar radiation [deg]. +#' +#' Source: Equation 6 in Appelbaum, Joseph & Flood, Dennis. (1990). +#' +#' @param Ls Areocentric longitude [deg]. +#' @param T_s Solar time [h] +#' @param phi Planetary latitude [deg]. +#' @param nfft Net flux function type. +#' +#' @return +#' @export +Z = function(Ls, T_s, phi, nfft){ + + # Equation 7: Declination angle [rad]. + delta = declination(Ls) + + # Equation 8: Hour angle [deg]. + omega = 15 * T_s - 180 + + # Equation 6: Zenith angle of the incident solar radiation [deg]. + a = sin(phi*pi/180) * sin(delta) + b = cos(phi*pi/180) * cos(delta) * cos(omega * pi/180) + + z = acos(a + b) * 180/pi + + # We have to round the zenith angle to a power of ten because the + # normalized net flux function only takes predetermined Z angle values. + if(nfft == 1){ + + # Round in multiples of 10. + z = round(z, -1) + + # There is no column for Z = 90° in thenormalized net flux function table. + # In case Z = 90°, replace it with 85°. + v = unlist(z) + z = relist(replace(v, v==90, 85), skeleton=z) + + }else if(nfft == 2){ + # Round in multiples of 5. + z = round(z/5) * 5 + + # There is no column for z = 90° in thenormalized net flux function table. + # In case z = 90°, replace it with 85. + v = unlist(z) + z = relist(replace(v, v==90, 85), skeleton=z) + + }else if(nfft != 3){ + stop(paste("Unsupported net flux function type, should be 1 for f_89, 2 for f_90, or 3 for f: ", nfft)) + } + + return(z) +} \ No newline at end of file diff --git a/functions/albedo.R b/R/albedo.R similarity index 53% rename from functions/albedo.R rename to R/albedo.R index 17eaedd..8264c68 100644 --- a/functions/albedo.R +++ b/R/albedo.R @@ -1,27 +1,25 @@ -# Table I (Update 1991): The albedo function. -# -# Based on following publication: -# Appelbaum, Joseph & Landis, Geoffrey & Sherman, I. (1991). Solar radiation on Mars—Update 1991. Solar Energy. 50. 35-51. 10.1016/0038-092X(93)90006-A: -# https://www.researchgate.net/publication/223850868_Solar_radiation_on_Mars-Update_1991 +#df_albedo = load(file="data/albedo.rda") -# FIXME: Equation 3 (Update 1991) -library(here) - -# Avoid initialized the albedo data frame more than once. -if(!exists("albedo_df")){ - albedo_df = read.csv(here("data/albedo/", "albedo_1991_update.csv")) - - # Rename column labels (beta/phi). Use 'm' for minus/negative and 'p' for plus/positive - colnames(albedo_df) = gsub("X\\.", "m", colnames(albedo_df)) - colnames(albedo_df) = gsub("X", "p", colnames(albedo_df)) - colnames(albedo_df) = gsub("p0", "0", colnames(albedo_df)) -} - -# The albedo function. -# latitude (phi) - From -90 to 90 [deg]. -# longitude - From -180 to 180 [deg]. -# tau - Optical depth. +#' The albedo function. +#' +#' Calculate the albedo value given geographical location and tau factor. +#' +#' Source: Table I - The albedo function. +#' Appelbaum, Joseph & Landis, Geoffrey & Sherman, I. (1991). +#' Solar radiation on Mars — Update 1991. Solar Energy. 50. 35-51. 10.1016/0038-092X(93)90006-A: +#' https://www.researchgate.net/publication/223850868_Solar_radiation_on_Mars-Update_1991 +#' +#' @param latitude Planetary latitude, from -90° to io +90°. +#' @param longitude Planetary longitude, from -180° to 180°. +#' @param tau Optical depth. +#' @param force_multiple_ten +#' +#' @return +#' @export +#' +#' albedo = function(latitude, longitude, tau, force_multiple_ten=FALSE){ + if(longitude < -180 || longitude > 180){ stop("Longitude must be a value between -180° and 180°.") @@ -48,7 +46,8 @@ albedo = function(latitude, longitude, tau, force_multiple_ten=FALSE){ } # Get the albedo. - al = albedo_df[albedo_df$Longitude == longitude, ][latitude][1,1] + # FIXME: df_albedo[df_albedo$Longitude == longitude, latitude] + al = df_albedo[df_albedo$Longitude == longitude, ][latitude][1,1] # For periods with dust storms, introduce the following albedo function from (3) in (1991 Update): if(tau > 0.5){ @@ -56,4 +55,4 @@ albedo = function(latitude, longitude, tau, force_multiple_ten=FALSE){ } return(al) -} +} \ No newline at end of file diff --git a/utils/constrain_solar_time_range.R b/R/constrain_solar_time_range.R similarity index 87% rename from utils/constrain_solar_time_range.R rename to R/constrain_solar_time_range.R index fe89923..19f98d2 100644 --- a/utils/constrain_solar_time_range.R +++ b/R/constrain_solar_time_range.R @@ -1,21 +1,21 @@ # # Constrain T_start and T_end based on sunrise and sunset times. -# -library(here) - -# Sunrise. -source(here("utils", "sunrise.R")) - -# Sunset. -source(here("utils", "sunset.R")) +#FIXME: Refactor to daylight_range without T_start and T_end. -# Polar day. -is_polar_day = dget(here("utils", "is_polar_day.R")) -# Polar night. -is_polar_night = dget(here("utils", "is_polar_night.R")) - -function(Ls, phi, T_start, T_end, beta=NULL, gamma_c=NULL){ +#' Title +#' +#' @param Ls +#' @param phi +#' @param T_start +#' @param T_end +#' @param beta +#' @param gamma_c +#' +#' @return +#' @export +constrain_solar_time_range = function(Ls, phi, T_start, T_end, beta=NULL, gamma_c=NULL){ + if(T_start >= T_end){ stop("Solar start time cannot be after or equal to the solar end time.") } diff --git a/utils/declination.R b/R/declination.R similarity index 67% rename from utils/declination.R rename to R/declination.R index 06fe4ce..6ee77d4 100644 --- a/utils/declination.R +++ b/R/declination.R @@ -1,17 +1,21 @@ -# Equation 7 (1990): The declination angle. -# Definition and constraints taken from (1993). - # Mars obliquity of rotation axis [deg]. delta_0 = 24.936 -# Declination, the angular position of the Sun at solar noon with respect to the plane of the equator. -# -# For Mars: -24.936 deg <= delta <= 24.936 deg. -# -# 0 deg at vernal (Ls = 0) and autumnal equinoxes (Ls = 180) -# +24.936 deg at summer solstice (Ls = 90) and -24.936 at at winter solstice (Ls = 270). -# +#' Declination angle: the angular position of the Sun at solar noon with respect to the plane of the equator. +#' +#' For Mars: -24.936° <= delta <= 24.936°. +#' 0 deg at vernal (Ls 0°) and autumnal equinoxes (Ls 180°) +#' +24.936 deg at summer solstice (Ls 90) and -24.936 at at winter solstice (Ls 270°). +#' +#' Source: Equation 7 (1990) +#' +#' @param Ls Areocentric longitude [deg]. +#' @param unit +#' +#' @return Declination angle in radians or degrees. +#' @export declination = function(Ls, unit=1){ + if(!unit %in% c(1, 2)){ stop("Declination angle unit option must either be 1 for radians or 2 for degrees.") } diff --git a/R/f.R b/R/f.R new file mode 100644 index 0000000..265c609 --- /dev/null +++ b/R/f.R @@ -0,0 +1,231 @@ +# The function. +# +# nfft - Net flux function implementation type. +# - 1 for f_89. +# - 2 for f_90. +# - 3 for f_analytical. +#' Title +#' +#' @param nfft +#' +#' @return +#' @export +f_all_taus = function(nfft){ + + if(nfft==1){ + as.numeric(rownames(df_netflux_0p1_1990)) + + }else if(nfft==2){ + as.numeric(rownames(df_netflux_0p1_1991)) + + }else{ + stop("Unsupported net flux type, should be 1 for the original 1989 publication or 1990 for the 1990 update") + } +} + +# The function. +# +# nfft - Net flux function implementation type. +# - 1 for f_89. +# - 2 for f_90. +# - 3 for f_analytical. +#' Title +#' +#' @param nfft +#' +#' @return +#' @export +f_all_Zs = function(nfft){ + + if(nfft==1){ + as.numeric(gsub("X", "", colnames(df_netflux_0p1_1990))) + + }else if(nfft==2){ + as.numeric(gsub("X", "", colnames(df_netflux_0p1_1991))) + + }else{ + stop("Unsupported net flux type, should be 1 for the original 1989 publication or 1990 for the 1990 update") + } +} + +#' The coefficient lookup function. +#' +#' Source: Table IV - Normalized Net Flux Function Coefficients in Appelbaum, Joseph & Flood, Dennis (1990) Update 1990. +#' +#' @param i +#' @param j +#' @param k +#' +#' @return +p = function(i, j, k){ + + if(k==0){ + coefficient = df_netflux_k0_1990[j+1, paste("X", i, sep="")] + }else if(k==1){ + coefficient = df_netflux_k1_1990[j+1, paste("X", i, sep="")] + }else{ + stop("Unsupported k value.") + } + + return(coefficient) +} + +#' The normalized net flux function's lookup table lookup. +#' +#' The net solar flux integrated over the solar spectrum on the Martian +#' surface was calculated by Pollack based on multiple wavelength and +#' multiple scattering of the solar radiation. +#' +#' Source: Table III in Appelbaum, Joseph & Flood, Dennis. (1990). +#' +#' @param z Zenith angle [deg]. +#' @param tau Optical depth. +#' @param al Albedo, can only be 0.1. +#' +#' @return Normalized net flux. +f_89 = function(z, tau, al=0.1){ + + if(al != 0.1){ + stop("The albedo can only be 0.1 when using f_89 table lookup.") + } + + return( + unlist( # Unlist in case a sequence of Zs are given instead of a single value (i.e. in the case of integrations). + df_netflux_0p1_1990[df_netflux_0p1_1990$tau == toString(tau), paste("X", z, sep="")], + use.names=FALSE + ) + ) +} + +#' The normalized net flux function's lookup table lookup. +#' +#' Source: Solar radiation on Mars: Update 1990. +#' Table III (a) and (b) for an albedo of 0.1. +#' Table IV (a) and (b) for an albedo of 0.4. +#' +#' @param z Zenith angle [deg]. +#' @param tau Optical depth. +#' @param al Albedo, can be 0.1 or 0.4. +#' +#' @return Normalized net flux. +f_90 = function(z, tau, al=0.1){ + + nnff_df = NULL + + if(al == 0.1){ + nnff_df = df_netflux_0p1_1991 + + }else if(al == 0.4){ + nnff_df = df_netflux_0p4_1991 + + }else{ + stop("The albedo can only be 0.1 or 0.4 when using f_90 table lookup.") + } + + return( + unlist( # Unlist in case a sequence of Zs are given instead of a single value (i.e. in the case of integrations). + nnff_df[nnff_df$tau == toString(tau), paste("X", z, sep="")], + use.names=FALSE + ) + ) +} + + +#' The analytical expression of the normalized net flux function. +#' +#' The mean error is about 0.7 percent for the full range. For zenith angles up to 40° the error is much smaller. +#' The largest error is for zenith angle of 80° and 85° and for tau greater than 5. The maximum error is about 7 percent. +#' At these large angles and opacities, the error has a minor effect on the calculated daily insolations. +#' +#' Source: Equation 20? in Appelbaum, Joseph & Flood, Dennis (1990) - Update 1990. +#' +#' @param z Zenith angle [deg]. +#' @param tau Optical depth. +#' @param al Albedo. +#' +#' @return Normalized net flux. +f_analytical = function(z, tau, al=0.1){ + + # Check for and warn against parameters that would result in lagest errors (max. 7%). + if(tau > 5){ + # TODO: Make warning. + message(paste("Large error encountered with tau = ", tau, " greater than 5 (maximum error is 7%). ", + "Consider using the f_89 and f_90 table lookup implementation of the normalized net flux function instead of its analytical expression.", + sep="") + ) + } + + + # Use ifelse in case this function is being invoked from an integration in which case Z can be a vector instead of a scalar. + # If Z is a scalar and we use if() then the following issue will occur: "the condition has length > 1 and only the first element will be used." + warning_msg = ifelse(z >= 80, paste("Possibly large error encountered with z = ", z, "° (maximum error is 7% for Z = 80° or Z = 85°). ", + "Consider using the f_89 and f_90 table lookup implementation of the normalized net flux function instead of its analytical expression.\n", + sep=""), "") + + # handle warning message. + for(w_msg in warning_msg){ + if(w_msg != ""){ + # TODO: Make warning. + message(w_msg) + } + } + + psum = 0 + for(i in seq(0,5,1)){ + for(j in seq(0,5,1)){ + for(k in seq(0,1,1)){ + psum = psum + p(i, j, k) * tau^i * (z/100)^j * al^k + } + } + } + + return(psum * (1-al)) +} + + + +#' he analytical expression of the normalized net flux function. +#' +#' Source: Equation 20 (1990). +#' +#' @param z Zenith angle [deg]. +#' @param tau Optical depth. +#' @param al Albedo (ranges from 0.1 to 0.4). +#' @param pub_year +#' +#' @return Normalized net flux. +#' @export +f = function(z, tau, al=0.1, pub_year=NULL){ + + net_flux = NULL + + if(is.null(pub_year)){ + net_flux = f_analytical(z, tau, al) + + }else if(pub_year == 1989){ + net_flux = f_89(z, tau, al) + + }else if(pub_year == 1990){ + net_flux = f_90(z, tau, al) + + }else{ + stop("Usupported publication year, should either be 1989 for the original pulication or 1990 for its 1990 update") + } + + # Check if given Z results in NULL net flux. + if(is.null(net_flux)){ + stop(paste("Sun zenith angle z = ", z ,"° is not available in the net flux look-up table. Consider using the analytical function instead.", sep="")) + + } + + # Check if given tau results in NA net flux. + # Use ifelse in case this function is being invoked from an integration in which case net_flux can be a vector instead of a scalar. + isNAs = ifelse(is.na(net_flux), TRUE, FALSE) + for(isNA in isNAs){ + if(isTRUE(isNA)){ + stop(paste("Optical depth tau factor tau = ", tau," is not available in the net flux look-up table. Consider using the analytical function instead.", sep="")) + } + } + + return(net_flux) +} \ No newline at end of file diff --git a/utils/is_irradiated.R b/R/is_irradiated.R similarity index 57% rename from utils/is_irradiated.R rename to R/is_irradiated.R index 8dbfa96..67fe220 100644 --- a/utils/is_irradiated.R +++ b/R/is_irradiated.R @@ -1,30 +1,25 @@ -# Check if there is solar irradiance at the given location and moment. - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Equation 8 (1993): Sunrise. -sunrise = dget(here("utils", "sunrise.R")) - -# Equation 9 (1990): Sunset. -sunset = dget(here("utils", "sunset.R")) - -# Polar day. -is_polar_day = dget(here("utils", "is_polar_day.R")) - -# Polar night. -is_polar_night = dget(here("utils", "is_polar_night.R")) - # TODO: Write a test script. -# TODO: Incline beta and gamma as parameter? -function(Ls, phi, T_s, Z=Z_eq(Ls, T_s, phi, nfft), beta=NULL, gamma_c=NULL, nfft){ - - if(isTRUE(identical(Z, numeric(0)))){ - stop("One of the following is required: i. Sun zenith angle Z [deg] or ii. Both latitude phi [deg] and solar time T_s [h].") +#' Check if there is solar irradiance at the given location and moment. +#' +#' @param Ls +#' @param phi +#' @param T_s +#' @param z +#' @param beta +#' @param gamma_c +#' @param nfft +#' +#' @return +#' @export +is_irradiated = function(Ls, phi, T_s, z=Z(Ls, T_s, phi, nfft), beta=NULL, gamma_c=NULL, nfft){ + + + if(isTRUE(identical(z, numeric(0)))){ + stop("One of the following is required: i. Sun zenith angle z [deg] or ii. Both latitude phi [deg] and solar time T_s [h].") # FIXME: Is this needed? - }else if(!is.null(phi) && !is.null(T_s) && Z != Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft)){ - message("Sun zenith angle Z [deg] has been provided, ignoring given latitude phi [deg] and solar time T_s [h].") + }else if(!is.null(phi) && !is.null(T_s) && z != Z(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft)){ + message("Sun zenith angle z [deg] has been provided, ignoring given latitude phi [deg] and solar time T_s [h].") }else if(is.null(phi) && !is.null(T_s) || !is.null(phi) && is.null(T_s)) { message("A latitude phi [deg] or a solar time T_s [h] has been given but not needed because a Sun zenith angle Z [deg] has been given as well.") @@ -55,9 +50,9 @@ function(Ls, phi, T_s, Z=Z_eq(Ls, T_s, phi, nfft), beta=NULL, gamma_c=NULL, nfft } # FIXME: Use ifelse function to support scalar? - # Only do this check if a Z scalar is given rather than a vector (e.g. from integrating to calculate daily insolation) - if(length(Z) == 1){ - if(Z >= 90){ + # Only do this check if a z scalar is given rather than a vector (e.g. from integrating to calculate daily insolation) + if(length(z) == 1){ + if(z >= 90){ return(FALSE) }else{ return(TRUE) diff --git a/utils/is_polar_day.R b/R/is_polar_day.R similarity index 81% rename from utils/is_polar_day.R rename to R/is_polar_day.R index 8a78afd..b14ab5b 100644 --- a/utils/is_polar_day.R +++ b/R/is_polar_day.R @@ -1,7 +1,12 @@ -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - -function(Ls, phi){ +#' Title +#' +#' @param Ls +#' @param phi +#' +#' @return +#' @export +is_polar_day = function(Ls, phi){ + # Equation 7 (1990): Declination angle [rad]. delta = declination(Ls) diff --git a/utils/is_polar_night.R b/R/is_polar_night.R similarity index 81% rename from utils/is_polar_night.R rename to R/is_polar_night.R index 715f539..8ddf15c 100644 --- a/utils/is_polar_night.R +++ b/R/is_polar_night.R @@ -1,7 +1,12 @@ -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - -function(Ls, phi){ +#' Title +#' +#' @param Ls +#' @param phi +#' +#' @return +#' @export +is_polar_night = function(Ls, phi){ + # Equation 7 (1990): Declination angle [rad]. delta = declination(Ls) diff --git a/functions/plots/diurnal_insolation_plot.R b/R/plots/diurnal_insolation_plot.R similarity index 100% rename from functions/plots/diurnal_insolation_plot.R rename to R/plots/diurnal_insolation_plot.R diff --git a/functions/plots/diurnal_irradiance_plot.R b/R/plots/diurnal_irradiance_plot.R similarity index 100% rename from functions/plots/diurnal_irradiance_plot.R rename to R/plots/diurnal_irradiance_plot.R diff --git a/functions/plots/grouped_lines.R b/R/plots/grouped_lines.R similarity index 100% rename from functions/plots/grouped_lines.R rename to R/plots/grouped_lines.R diff --git a/functions/plots/mer_tau_lines.R b/R/plots/mer_tau_lines.R similarity index 100% rename from functions/plots/mer_tau_lines.R rename to R/plots/mer_tau_lines.R diff --git a/functions/plots/phoenix_tau_lines.R b/R/plots/phoenix_tau_lines.R similarity index 100% rename from functions/plots/phoenix_tau_lines.R rename to R/plots/phoenix_tau_lines.R diff --git a/functions/plots/vl_tau_lines.R b/R/plots/vl_tau_lines.R similarity index 100% rename from functions/plots/vl_tau_lines.R rename to R/plots/vl_tau_lines.R diff --git a/utils/sunrise.R b/R/sunrise.R similarity index 67% rename from utils/sunrise.R rename to R/sunrise.R index a8e437c..aaebe00 100644 --- a/utils/sunrise.R +++ b/R/sunrise.R @@ -3,20 +3,18 @@ # 1. For surface oriented towards the equator, gamma_c = 0 or 180/-180 # 2. For vertical surface (when Beta=90) -library(here) - -# From (1993): -# (19) for inclined and (25) for vertical surface. -# (20) for inclined and (26) for vertical surface. -source(here("utils", "xy_for_inclined_surface.R")) - -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - # (30) in (1993). # Angles in rad. # TODO: Make this a hidden function. # FIXME: Not exactly what is in (21) to determine omega_rad. +#' Title +#' +#' @param phi +#' @param beta +#' @param delta +#' +#' @return +#' @export sunrise_for_inclined_surface_oriented_equator = function(phi, beta, delta){ # (8) in (1993). @@ -37,7 +35,17 @@ sunrise_for_inclined_surface_oriented_equator = function(phi, beta, delta){ # (15) from (1993). # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return +#' @export sunrise_for_inclined_surface_oriented_east = function(phi, beta, gamma_c, delta){ + omega_rad_1 = sunrise_for_horizontal_surface(phi=phi, delta=delta) #print(paste("omega_rad_1", omega_rad_1)) @@ -60,7 +68,17 @@ sunrise_for_inclined_surface_oriented_east = function(phi, beta, gamma_c, delta) # (17) from (1993). # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return +#' @export sunrise_for_inclined_surface_oriented_west = function(phi, beta, gamma_c, delta){ + omega_rad_1 = sunrise_for_horizontal_surface(phi=phi, delta=delta) x = x_for_inclined_surface(phi=phi, beta=beta, gamma_c=gamma_c) @@ -79,6 +97,13 @@ sunrise_for_inclined_surface_oriented_west = function(phi, beta, gamma_c, delta) # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param delta +#' +#' @return +#' @export sunrise_for_horizontal_surface = function(phi, delta){ # Equation 8 (1993): Sunrise hour angle [rad]. @@ -89,6 +114,15 @@ sunrise_for_horizontal_surface = function(phi, delta){ # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return +#' @export sunrise_for_inclined_surface = function(phi, beta, gamma_c, delta){ # Inclination angle is 0 degrees, this is equivalent to a horizontal surface. @@ -122,6 +156,16 @@ sunrise_for_inclined_surface = function(phi, beta, gamma_c, delta){ # - 1 for radians. # - 2 for degrees. # - 3 for solar hour. +#' Title +#' +#' @param Ls +#' @param phi +#' @param beta +#' @param gamma_c +#' @param unit +#' +#' @return +#' @export sunrise = function(Ls, phi, beta=NULL, gamma_c=NULL, unit=1){ if(!unit %in% c(1, 2, 3)){ @@ -188,101 +232,4 @@ sunrise = function(Ls, phi, beta=NULL, gamma_c=NULL, unit=1){ # This should not happen. stop("An unknown error has occurred.") } -} - -####################################### -# Testing code. To eventually remove. # -####################################### - -# Ls = 100 -# -# d = declination(Ls) -# -# for(p in seq(-30, 30, 10)){ -# for(b in seq(5, 35, 5)){ -# # for(g in seq(-180, 180, 5)){ -# # for(b in c(35)){ -# for(g in c(1)){ -# # omega_sr = sunrise(Ls=Ls, phi=p, unit=1, beta=NULL, gamma_c=NULL) -# # omega_sr_i = sunrise(Ls=Ls, phi=p, unit=1, beta=b, gamma_c=g) -# # -# # T_sr = (omega_sr*180/pi + 180) / 15 -# # T_sr_i = (omega_sr_i*180/pi + 180) / 15 -# # -# # if(T_sr != T_sr_i){ -# # cat("\n\n=====================================") -# # cat(paste("\n\nbeta:", b, ", gamma_c:", g)) -# # cat(paste("\nT_sr:", T_sr, ", T_sr_i:", T_sr_i)) -# # } -# -# sr_east = sunrise_for_inclined_surface_oriented_east(phi=p*pi/180, beta=b*pi/180, gamma_c=g*pi/180, delta=d) -# sr_west = sunrise_for_inclined_surface_oriented_west(phi=p*pi/180, beta=b*pi/180, gamma_c=g*pi/180, delta=d) -# -# if(sr_east != sr_west){ -# print(paste("sr_east", sr_east, " sr_west:", sr_west)) -# } -# } -# } -# } - -# beta: 35 , gamma_c: 30 -# T_sr: -1.586734831866 , T_sr_i: -0.996317209799962 - - -####################################### -# Testing code. To eventually remove. # -####################################### - -# Ls = 5 -# p = -40 -# b = -40 -# d = declination(Ls) -# -# orientation_angles = seq(-180, 180, 1) -# #orientation_angles = seq(-1, 1, 1) -# sunrise_hours = c() -# -# for(g in orientation_angles){ -# sr = sunrise(Ls=Ls, phi=p, beta=b, gamma_c=g, unit=3) -# sunrise_hours = c(sunrise_hours, sr) -# } -# -# -# dev.new() -# plot(orientation_angles, sunrise_hours, -# type="l", lty=1, lwd=3, -# ylab="<-- EARLIER | LATER -->", -# xlab="<-- EAST | WEST -->") - - -####################################### -# Testing code. To eventually remove. # -####################################### - -# "Ls: 5 - phi/beta: -60 - gamma_c: 180 - sunrise_c: 6.24 - sunrise_e: 6.24" -# "Ls: 5 - phi/beta: -50 - gamma_c: 180 - sunrise_c: 6.17 - sunrise_e: 6.17" -# "Ls: 5 - phi/beta: -40 - gamma_c: 180 - sunrise_c: 6.8 - sunrise_e: 6.12" -# "Ls: 5 - phi/beta: -30 - gamma_c: 180 - sunrise_c: 6.24 - sunrise_e: 6.08" - -# Ls = 5 -# p = -40 -# b = -40 -# d = declination(Ls) -# g = 180 -# sr = sunrise(Ls=Ls, phi=p, beta=b, gamma_c=g, unit=3) -# print(sr) - -####################################### -# Testing code. To eventually remove. # -####################################### - -# Warning message: -# In sqrt(x^2 - y^2 + 1) : NaNs produced - -# Ls = 80 -# p = 30 -# b = 80 -# g = 165 #165, 165, 170, 175, 180 -# -# sr = sunrise(Ls=Ls, phi=p, beta=b, gamma_c=g, unit=3) -# print(sr) \ No newline at end of file +} \ No newline at end of file diff --git a/utils/sunset.R b/R/sunset.R similarity index 76% rename from utils/sunset.R rename to R/sunset.R index 2ee9894..b57e770 100644 --- a/utils/sunset.R +++ b/R/sunset.R @@ -1,20 +1,15 @@ -# Get the moment in which the sunset occurs. # FIXME: -# 1. Basd logic when gamma_c = 0 and Beta > 0. - -library(here) - -# From (1993): -# (19) for inclined and (25) for vertical surface. -# (20) for inclined and (26) for vertical surface. -source(here("utils", "xy_for_inclined_surface.R")) - -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - -# Angles in rad. -# TODO: Make this a hidden function. +# 1. Bad logic when gamma_c = 0 and Beta > 0. + +#' Get the moment in which the sunset occurs. +#' +#' @param phi +#' @param delta +#' +#' @return +#' @export sunset_for_horizontal_surface = function(phi, delta){ + # (9) in (1993): Sunset hour angle [rad]. omega_rad = acos(-tan(delta) * tan(phi)) @@ -22,11 +17,21 @@ sunset_for_horizontal_surface = function(phi, delta){ return(omega_rad) } -# (31) in (1993). + # Angles in rad. # TODO: Make this a hidden function. -# Doesn't work for all cases, see Ls = 300, phi = 20, and beta = 45. +# FIXME: Doesn't work for all cases, see Ls = 300, phi = 20, and beta = 45. +# +#' (31) in (1993). +#' +#' @param phi +#' @param beta +#' @param delta +#' +#' @return +#' @export sunset_for_inclined_surface_oriented_equator = function(phi, beta, delta){ + # (9) in (1993). omega_rad_1 = sunset_for_horizontal_surface(phi=phi, delta=delta) @@ -46,7 +51,18 @@ sunset_for_inclined_surface_oriented_equator = function(phi, beta, delta){ # (16) from (1993). # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return +#' @export sunset_for_inclined_surface_oriented_east = function(phi, beta, gamma_c, delta){ + + omega_rad_1 = sunset_for_horizontal_surface(phi=phi, delta=delta) x = x_for_inclined_surface(phi=phi, beta=beta, gamma_c=gamma_c) @@ -65,7 +81,17 @@ sunset_for_inclined_surface_oriented_east = function(phi, beta, gamma_c, delta){ # (18) from (1993). # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return +#' @export sunset_for_inclined_surface_oriented_west = function(phi, beta, gamma_c, delta){ + omega_rad_1 = sunset_for_horizontal_surface(phi=phi, delta=delta) x = x_for_inclined_surface(phi=phi, beta=beta, gamma_c=gamma_c) @@ -83,6 +109,15 @@ sunset_for_inclined_surface_oriented_west = function(phi, beta, gamma_c, delta){ # Angles in rad. # TODO: Make this a hidden function. +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return +#' @export sunset_for_inclined_surface = function(phi, beta, gamma_c, delta){ # Inclination angle is 0 degrees, this is equivalent to a horizontal surface. @@ -116,6 +151,16 @@ sunset_for_inclined_surface = function(phi, beta, gamma_c, delta){ # - 1 for radians. # - 2 for degrees. # - 3 for solar hour. +#' Title +#' +#' @param Ls +#' @param phi +#' @param beta +#' @param gamma_c +#' @param unit +#' +#' @return +#' @export sunset = function(Ls, phi, beta=NULL, gamma_c=NULL, unit=1){ if(!unit %in% c(1, 2, 3)){ @@ -183,53 +228,3 @@ sunset = function(Ls, phi, beta=NULL, gamma_c=NULL, unit=1){ stop("An unknown error has occurred.") } } - -####################################### -# Testing code. To eventually remove. # -####################################### -# Ls = 100 -# phi = 2 -# -# for(b in seq(0, 35, 5)){ -# for(g in seq(-180, 180, 5)){ -# # for(b in c(35)){ -# # for(g in c(30)){ -# omega_ss = sunset(Ls=Ls, phi=phi, unit=1, beta=NULL, gamma_c=NULL) -# omega_ss_i = sunset(Ls=Ls, phi=phi, unit=1, beta=b, gamma_c=g) -# -# T_ss = (omega_ss*180/pi + 180) / 15 -# T_ss_i = (omega_ss_i*180/pi + 180) / 15 -# -# if(T_ss != T_ss_i){ -# cat("\n\n=====================================") -# cat(paste("\n\nbeta:", b, ", gamma_c:", g)) -# cat(paste("\nT_ss:", T_ss, ", T_ss_i:", T_ss_i)) -# } -# } -# } - - -####################################### -# Testing code. To eventually remove. # -####################################### - -# Ls = 300 -# p = 20 -# b = 45 -# d = declination(Ls) -# -# orientation_angles = seq(-180, 180, 1) -# sunset_hours = c() -# -# for(g in orientation_angles){ -# sr = sunset(Ls, p, unit=3, beta=b, gamma_c=g) -# sunset_hours = c(sunset_hours, sr) -# } -# -# -# dev.new() -# plot(orientation_angles, sunset_hours, -# type="l", lty=1, lwd=3, -# ylab="<-- EARLIER | LATER -->", -# xlab="<-- EAST | WEST -->") - diff --git a/functions/T_d.R b/R/tmp/T_d.R similarity index 100% rename from functions/T_d.R rename to R/tmp/T_d.R diff --git a/functions/f_all_Zs.R b/R/tmp/done/f_all_Zs.R similarity index 100% rename from functions/f_all_Zs.R rename to R/tmp/done/f_all_Zs.R diff --git a/functions/f_all_taus.R b/R/tmp/done/f_all_taus.R similarity index 100% rename from functions/f_all_taus.R rename to R/tmp/done/f_all_taus.R diff --git a/functions/f_build_coefficients_df.R b/R/tmp/done/f_build_coefficients_df.R similarity index 100% rename from functions/f_build_coefficients_df.R rename to R/tmp/done/f_build_coefficients_df.R diff --git a/functions/f_build_df.R b/R/tmp/done/f_build_df.R similarity index 100% rename from functions/f_build_df.R rename to R/tmp/done/f_build_df.R diff --git a/functions/tau.R b/R/tmp/tau.R similarity index 100% rename from functions/tau.R rename to R/tmp/tau.R diff --git a/utils/xy_for_inclined_surface.R b/R/xy_for_inclined_surface.R similarity index 83% rename from utils/xy_for_inclined_surface.R rename to R/xy_for_inclined_surface.R index ea4f06d..5f03e41 100644 --- a/utils/xy_for_inclined_surface.R +++ b/R/xy_for_inclined_surface.R @@ -1,6 +1,15 @@ # From (1993): (19) for inclined and (25) for vertical surface. # Angles in rad. # TODO: Make this a hidden function. + + +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' +#' @return x_for_inclined_surface = function(phi, beta, gamma_c){ # FIXME: For vertical surface, i.e. beta = 90. Need gamma_s?!?! @@ -18,6 +27,16 @@ x_for_inclined_surface = function(phi, beta, gamma_c){ # From (1993): (20) for inclined and (26) for vertical surface. # Angles in rad. # TODO: Make this a hidden function. + + +#' Title +#' +#' @param phi +#' @param beta +#' @param gamma_c +#' @param delta +#' +#' @return y_for_inclined_surface = function(phi, beta, gamma_c, delta){ # a is zero for a vertical surface, i.e. beta = 90 deg. See (26) from (1993) diff --git a/data-raw/albedo.R b/data-raw/albedo.R new file mode 100644 index 0000000..35ba9da --- /dev/null +++ b/data-raw/albedo.R @@ -0,0 +1,13 @@ +library(here) +library(devtools) + +# Read albedo CSV file. +df_albedo = read.csv(here("data-raw/csv", "albedo_1991_update.csv")) + +# Rename column labels (beta/phi). Use 'm' for minus/negative and 'p' for plus/positive. +colnames(df_albedo) = gsub("X\\.", "m", colnames(df_albedo)) +colnames(df_albedo) = gsub("X", "p", colnames(df_albedo)) +colnames(df_albedo) = gsub("p0", "0", colnames(df_albedo)) + +# Make binary data. +use_data(df_albedo, overwrite=TRUE) \ No newline at end of file diff --git a/data/albedo/albedo_1991_update.csv b/data-raw/csv/albedo_1991_update.csv similarity index 100% rename from data/albedo/albedo_1991_update.csv rename to data-raw/csv/albedo_1991_update.csv diff --git a/data/normalized_net_flux_function/table_III_1990.csv b/data-raw/csv/netflux_al_0-1_table_iii_1990.csv similarity index 100% rename from data/normalized_net_flux_function/table_III_1990.csv rename to data-raw/csv/netflux_al_0-1_table_iii_1990.csv diff --git a/data/normalized_net_flux_function/al_0-1_table_III_1991_update.csv b/data-raw/csv/netflux_al_0-1_table_iii_1991_update.csv similarity index 100% rename from data/normalized_net_flux_function/al_0-1_table_III_1991_update.csv rename to data-raw/csv/netflux_al_0-1_table_iii_1991_update.csv diff --git a/data/normalized_net_flux_function/al_0-4_table_III_1991_update.csv b/data-raw/csv/netflux_al_0-4_table_iii_1991_update.csv similarity index 100% rename from data/normalized_net_flux_function/al_0-4_table_III_1991_update.csv rename to data-raw/csv/netflux_al_0-4_table_iii_1991_update.csv diff --git a/data/normalized_net_flux_function/k0_coefficients_1990_update.csv b/data-raw/csv/netflux_k0_coefficients_1990_update.csv similarity index 100% rename from data/normalized_net_flux_function/k0_coefficients_1990_update.csv rename to data-raw/csv/netflux_k0_coefficients_1990_update.csv diff --git a/data/normalized_net_flux_function/k1_coefficients_1990_update.csv b/data-raw/csv/netflux_k1_coefficients_1990_update.csv similarity index 100% rename from data/normalized_net_flux_function/k1_coefficients_1990_update.csv rename to data-raw/csv/netflux_k1_coefficients_1990_update.csv diff --git a/data/mer/1tau440_5106_20181207a.lbl b/data-raw/mer/1tau440_5106_20181207a.lbl similarity index 100% rename from data/mer/1tau440_5106_20181207a.lbl rename to data-raw/mer/1tau440_5106_20181207a.lbl diff --git a/data/mer/1tau440_5106_20181207a.tab.txt b/data-raw/mer/1tau440_5106_20181207a.tab.txt similarity index 100% rename from data/mer/1tau440_5106_20181207a.tab.txt rename to data-raw/mer/1tau440_5106_20181207a.tab.txt diff --git a/data-raw/net_flux.R b/data-raw/net_flux.R new file mode 100644 index 0000000..8035eff --- /dev/null +++ b/data-raw/net_flux.R @@ -0,0 +1,20 @@ +library(here) +library(devtools) + +# Read CSV files and make binary data files. +df_netflux_0p1_1990 = read.csv(here("data-raw/csv", "netflux_al_0-1_table_iii_1990.csv")) +use_data(df_netflux_0p1_1990, overwrite=TRUE) + +df_netflux_0p1_1991 = read.csv(here("data-raw/csv", "netflux_al_0-1_table_iii_1991_update.csv")) +use_data(df_netflux_0p1_1991, overwrite=TRUE) + +df_netflux_0p4_1991 = read.csv(here("data-raw/csv", "netflux_al_0-4_table_iii_1991_update.csv")) +use_data(df_netflux_0p4_1991, overwrite=TRUE) + +df_netflux_k0_1990 = read.csv(here("data-raw/csv", "netflux_k0_coefficients_1990_update.csv")) +df_netflux_k0_1990 = df_netflux_k0_1990[-c(1)] +use_data(df_netflux_k0_1990, overwrite=TRUE) + +df_netflux_k1_1990 = read.csv(here("data-raw/csv", "netflux_k1_coefficients_1990_update.csv")) +df_netflux_k1_1990 = df_netflux_k1_1990[-c(1)] +use_data(df_netflux_k1_1990, overwrite=TRUE) \ No newline at end of file diff --git a/data/opportunity_status/oppy_energy_divergences.csv b/data-raw/opportunity_status/oppy_energy_divergences.csv similarity index 100% rename from data/opportunity_status/oppy_energy_divergences.csv rename to data-raw/opportunity_status/oppy_energy_divergences.csv diff --git a/data/opportunity_status/oppy_status.csv b/data-raw/opportunity_status/oppy_status.csv similarity index 100% rename from data/opportunity_status/oppy_status.csv rename to data-raw/opportunity_status/oppy_status.csv diff --git a/data/df_albedo.rda b/data/df_albedo.rda new file mode 100644 index 0000000..2783c4d Binary files /dev/null and b/data/df_albedo.rda differ diff --git a/data/df_netflux_0p1_1990.rda b/data/df_netflux_0p1_1990.rda new file mode 100644 index 0000000..a2c4945 Binary files /dev/null and b/data/df_netflux_0p1_1990.rda differ diff --git a/data/df_netflux_0p1_1991.rda b/data/df_netflux_0p1_1991.rda new file mode 100644 index 0000000..9e67a92 Binary files /dev/null and b/data/df_netflux_0p1_1991.rda differ diff --git a/data/df_netflux_0p4_1991.rda b/data/df_netflux_0p4_1991.rda new file mode 100644 index 0000000..ceca326 Binary files /dev/null and b/data/df_netflux_0p4_1991.rda differ diff --git a/data/df_netflux_k0_1990.rda b/data/df_netflux_k0_1990.rda new file mode 100644 index 0000000..8059e69 Binary files /dev/null and b/data/df_netflux_k0_1990.rda differ diff --git a/data/df_netflux_k1_1990.rda b/data/df_netflux_k1_1990.rda new file mode 100644 index 0000000..8f08d3a Binary files /dev/null and b/data/df_netflux_k1_1990.rda differ diff --git a/functions/G_ali.R b/functions/G_ali.R deleted file mode 100644 index 882a80c..0000000 --- a/functions/G_ali.R +++ /dev/null @@ -1,15 +0,0 @@ -library(here) - -# Equation 6 (1990): Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Equation 17 (1990): Global irradiance on Mars horizontal surface [W/m2]. -Gh_eq = dget(here("functions", "G_h.R")) - -source(here("functions", "albedo.R")) - -function(Ls, phi, longitude, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, nfft){ - Gali = al * Gh_eq(Ls=Ls, phi=phi, longitude=longitude, Z=Z, tau=tau, al=al, nfft=nfft) * sin((beta*pi/180) / 2)^2 - return(Gali) -} - diff --git a/functions/G_di.R b/functions/G_di.R deleted file mode 100644 index ae4222c..0000000 --- a/functions/G_di.R +++ /dev/null @@ -1,14 +0,0 @@ -library(here) - -# Equation 6 (1990): Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Equation 16 (1990): Diffuse irrafiance on a horizontal Martian surface [W/m2]. -Gdh_eq = dget(here("functions", "G_dh.R")) - -source(here("functions", "albedo.R")) - -function(Ls, phi, longitude, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, nfft){ - G_di = Gdh_eq(Ls=Ls, phi=phi, longitude=longitude, Z=Z, tau=tau, al=al, nfft=nfft) * cos((beta*pi/180) / 2)^2 - return(G_di) -} \ No newline at end of file diff --git a/functions/G_h_beta.old.R b/functions/G_h_beta.old.R deleted file mode 100644 index f9cd255..0000000 --- a/functions/G_h_beta.old.R +++ /dev/null @@ -1,136 +0,0 @@ -# Equation 3 (1994): Global irradiance on Mars inclined surface [W/m2]. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis & Norambuena, Marcos. (1994). -# Solar radiation on Mars: Tracking photovoltaic array. -# Journal of Propulsion and Power. 12. 10.2514/3.24044 -# https://ntrs.nasa.gov/?R=19950004977 - -# FIXME: Update this function so that it figures out if its a polar night or day. - -library(here) - -# Equation 6 (1990): Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Equation 14 (1990): Direct beam irradiance on the Mars surface normal to the solar rays [W/m2]. -Gb_eq = dget(here("functions", "G_b.R")) - -# Equation 16 (1990): Diffuse irrafiance on a horizontal Martian surface [W/m2]. -Gdh_eq = dget(here("functions", "G_dh.R")) - -# Equation 17 (1990): Global irradiance on Mars horizontal surface [W/m2]. -Gh_eq = dget(here("functions", "G_h.R")) - -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - -# Equation 3 (1994): Global irradiance on an inclined surface. -# -# Ls - Areocentric longitude [deg]. -# omega - Hour angle value [h]. -# - An integer belonging to [6, 18] if using net flux function f_89 or f_90 (nfft 1 or 2). -# - An interger belonging to [0, 24] if using net flux function f_analytical (nfft 3). -# phi - Latitude [deg]. -# tau - Optical depth. -# al - Albedo -# beta - Slope/Tilt angle [deg]. -# gamma_c - Sun surface azimuth angle (i.e. orientation angle) [deg]. -# nfft - Net flux function implementation type. -# - 1 for f_89. -# - 2 for f_90. -# - 3 for f_analytical. -function(Ls, phi, T_s, Z=Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft), tau, al, beta, gamma_c, nfft){ - - if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") - } - - # Equation 7 (1990): Declination angle [rad]. - delta = declination(Ls) - - # Equation 8 (1990): Hour angle [deg]. - # From Appelbaum, Joseph & Flood, Dennis. (1990): - # The ratio of Mars to Earth length of day is 24.65/24. - # It is convenient, for calculation purposes, to define a Mars hour - # by dividing the Martian day into 24 hr. Using the same relationship - # between the Mars solar time T and the hour angle as for the Earth. - omega_deg = 15 * T_s - 180 - - # Equation 6 (1993): Solar Azimuth Angle [deg] - solar_azimuth_angle = function(){ - x = sin(phi*pi/180) * cos(delta) * cos(omega_deg*pi/180) - y = cos(phi*pi/180) * sin(delta) - z = sin(Z*pi/180) - - gamma_s = acos((x - y) / z) * 180/pi # [deg] - - # Alternatively, Equation 7 (1993): Solar Azimuth Angle [deg] - # x = sin(phi*pi/180) * cos(Z*pi/180) - sin(delta) - # y = cos(phi*pi/180) * sin(Z*pi/180) - # - # gamma_s = acos(x / y) * 180/pi # [deg] - - return(gamma_s) - } - - # Set to omega to exactly zero when omega near zero instead because sometimes it is essentially zero with values like -2.8421709430404e-14 deg. - for(i in 1:length(omega_deg)){ - if(omega_deg[i] > -0.1 && omega_deg[i] < 0.1){ - omega_deg[i] = 0 - } - } - - # From (32) in (1993): It is solar noon when omega is 0 deg. This translates to gamma_s = 0 deg. - gamma_s = ifelse(omega_deg == 0, 0, solar_azimuth_angle()) - - - # Sun Angle of Incidence [rad]. - # Equation 13 (1993): Inclined surface. - # FIXME: Equation 23 (1993): Vertical surface. - # Equation 27 (1993): Facing the equator. - # Equation 29 (1993): Beta = 0. - sun_angle_of_incidence = function(){ - # if(beta == 0){ # Equation 29 (1993): Beta = 0. - # return(NULL) - # - # }else if(beta == 90){ #Equation 29 (1993): Beta = 0. - # return(NULL) - # - # }else if(gamma_c == 0){ # Equation 27 (1993): Facing the equator. - # return(NULL) - # - # }else{ - # # Inclined surface. - # i = cos(beta * pi/180) * cos(Z * pi/180) - # j = sin(beta * pi/180) * sin(Z * pi/180) * cos((gamma_s - gamma_c) * pi/180) # Does not matter when beta = 0 because it leads to j = 0. - # teta = acos(i + j) # [rad] - # } - - # Inclined surface. - i = cos(beta * pi/180) * cos(Z * pi/180) - j = sin(beta * pi/180) * sin(Z * pi/180) * cos((gamma_s - gamma_c) * pi/180) # Does not matter when beta = 0 because it leads to j = 0. - teta = acos(i + j) # [rad] - - return(teta) - } - - - # Sun Angle of Incidence [rad] on an inclined surface. - teta = sun_angle_of_incidence() - - # Equation 3 (1993): The global irradiance Gh_beta on an inclined surface with an angle beta. - a = Gb_eq(Ls=Ls, Z=Z, tau=tau) * cos(teta) - b = Gdh_eq(Ls=Ls, Z=Z, tau=tau, al=al, nfft=nfft) * cos((beta*pi/180) / 2)^2 - c = al * Gh_eq(Ls=Ls, Z=Z, tau=tau, al=al, nfft=nfft) * sin((beta*pi/180) / 2)^2 - - # FIXME: Use this to account for polar nights and polar days as well as sunrise and sunset times. - # a = Gb_eq(Ls=Ls, phi=phi, T_s=T_s, tau=tau, nfft=nfft) * cos(teta) - # b = Gdh_eq(Ls=Ls, phi=phi, T_s=T_s, tau=tau, al=al, nfft=nfft) * cos((beta*pi/180) / 2)^2 - # c = al * Gh_eq(Ls=Ls, phi=phi, T_s=T_s, tau=tau, al=al, nfft=nfft) * sin((beta*pi/180) / 2)^2 - - Gh_beta = a + b + c - - return(Gh_beta) -} - diff --git a/functions/G_ob.R b/functions/G_ob.R deleted file mode 100644 index db3d2dd..0000000 --- a/functions/G_ob.R +++ /dev/null @@ -1,16 +0,0 @@ -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. -# https://www.researchgate.net/publication/256334925_Solar_radiation_on_Mars - -Ls_P = 248 # PERIPHELION - Dust Storm Season. -e = 0.093377 # Mars orbit eccentricity. -Mb = 590 # Mean beam irradiance at the top of the Martian atmosphere. - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -# -# Ls - Areocentric Longitude. -function(Ls){ - Mb * ( (1 + e*cos( (Ls-Ls_P)* pi/180 ))^2 / (1-e^2)^2 ) -} diff --git a/functions/H_ali.R b/functions/H_ali.R deleted file mode 100644 index 7cc5c58..0000000 --- a/functions/H_ali.R +++ /dev/null @@ -1,17 +0,0 @@ -library(here) - -Iali_eq = dget(here("functions", "I_ali.R")) - -source(here("functions", "albedo.R")) - -function(Ls, phi, longitude, tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ - if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") - } - - # H_alii is obtained by integrating I_ali over the period from sunrise to sunset. - H_ali = Iali_eq(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=0, T_end=24, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) - - # Return result. - return(H_ali) -} \ No newline at end of file diff --git a/functions/H_bi.R b/functions/H_bi.R deleted file mode 100644 index 44324b0..0000000 --- a/functions/H_bi.R +++ /dev/null @@ -1,15 +0,0 @@ -library(here) - -Ibi_eq = dget(here("functions", "I_bi.R")) - -function(Ls, phi, tau, beta, gamma_c, nfft){ - if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") - } - - # H_bi is obtained by integrating I_bi over the period from sunrise to sunset. - H_bi = Ibi_eq(Ls=Ls, phi=phi, tau=tau, T_start=0, T_end=24, beta=beta, gamma_c=gamma_c, nfft=nfft) - - # Return result. - return(H_bi) -} \ No newline at end of file diff --git a/functions/H_di.R b/functions/H_di.R deleted file mode 100644 index 3de9659..0000000 --- a/functions/H_di.R +++ /dev/null @@ -1,17 +0,0 @@ -library(here) - -Idi_eq = dget(here("functions", "I_di.R")) - -source(here("functions", "albedo.R")) - -function(Ls, phi, longitude, tau, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ - if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degress with zero south, east negative, and west positive.") - } - - # H_di is obtained by integrating I_di over the period from sunrise to sunset. - H_di = Idi_eq(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=0, T_end=24, al=al, beta=beta, gamma_c=gamma_c, nfft=nfft) - - # Return result. - return(H_di) -} \ No newline at end of file diff --git a/functions/I_bi.R b/functions/I_bi.R deleted file mode 100644 index e52de43..0000000 --- a/functions/I_bi.R +++ /dev/null @@ -1,40 +0,0 @@ -library(here) - -Gbi_eq = dget(here("functions", "G_bi.R")) - -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) - -function(Ls, phi, tau, T_start, T_end, beta, gamma_c, nfft){ - - if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degres with zero south, east negative, and west positive.") - } - - # Step 1: Constrain T_start and T_end based on sunrise and sunset times. - - # Apply solar time range constraint. - T_range = constrain_solar_time_range(Ls, phi, T_start, T_end, beta, gamma_c) - - # No solar irradiance within the contrained time range. - if(is.null(T_range)){ - return(0) - - }else{ - # Constrain the time range. - T_start = T_range$T_start - T_end = T_range$T_end - } - - # Step 2: Calculate insolation. - - interand = function(T_s){ - G_bi = Gbi_eq(Ls=Ls, phi=phi, T_s=T_s, tau=tau, beta=beta, gamma_c=gamma_c, nfft=nfft) - return(G_bi) - } - - I_bi = integrate(interand, T_start, T_end) - - # Return integration result. - return(I_bi$value) -} diff --git a/functions/I_dh.R b/functions/I_dh.R deleted file mode 100644 index 4cf9b6b..0000000 --- a/functions/I_dh.R +++ /dev/null @@ -1,17 +0,0 @@ -# Diffuse hourly insolation on Mars horizontal surface [Wh/m2]. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. -# https://ntrs.nasa.gov/?R=19890018252 -# -library(here) - -# Global hourly insolation on Mars horizontal surface [Wh/m2]. -Ih_eq = dget(here("functions", "I_h.R")) - -# Equation 19 (1990): Beam hourly insolation on Mars horizontal surface [Wh/m2]. -Ibh_eq = dget(here("functions", "I_bh.R")) - -function(Ls, phi, tau, T_start, T_end, al, nfft){ - Ih_eq(Ls, phi, tau, T_start, T_end, al, nfft) - Ibh_eq(Ls, phi, tau, T_start, T_end, al, nfft) -} \ No newline at end of file diff --git a/functions/I_di.R b/functions/I_di.R deleted file mode 100644 index 6dd74b2..0000000 --- a/functions/I_di.R +++ /dev/null @@ -1,42 +0,0 @@ -library(here) - -Gdi_eq = dget(here("functions", "G_di.R")) - -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) - -source(here("functions", "albedo.R")) - -function(Ls, phi, longitude, tau, T_start, T_end, al=albedo(latitude=phi, longitude=longitude, tau=tau), beta, gamma_c, nfft){ - - if(gamma_c > 180 || gamma_c < -180){ - stop("Surface azimuth angle gamma_c must between -180 and 180 degres with zero south, east negative, and west positive.") - } - - # Step 1: Constrain T_start and T_end based on sunrise and sunset times. - - # Apply solar time range constraint. - T_range = constrain_solar_time_range(Ls, phi, T_start, T_end, beta, gamma_c) - - # No solar irradiance within the contrained time range. - if(is.null(T_range)){ - return(0) - - }else{ - # Constrain the time range. - T_start = T_range$T_start - T_end = T_range$T_end - } - - # Step 2: Calculate insolation. - - interand = function(T_s){ - G_di = Gdi_eq(Ls=Ls, phi=phi, longitude=longitude, T_s=T_s, tau=tau, al=al, beta=beta, nfft=nfft) - return(G_di) - } - - I_di = integrate(interand, T_start, T_end) - - # Return integration result. - return(I_di$value) -} diff --git a/functions/I_obh.R b/functions/I_obh.R deleted file mode 100644 index 43d7623..0000000 --- a/functions/I_obh.R +++ /dev/null @@ -1,72 +0,0 @@ -# Equation 11 (1990): Beam insolation on a horizotal surface at the top of Mars atmosphere [Wh/m2]. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. -# https://ntrs.nasa.gov/?R=19890018252 -# - -library(here) - -# Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2]. -Gob_eq = dget(here("functions", "G_ob.R")) - -# Equation 6: Zenith angle of the incident solar radiation [deg]. -Z_eq = dget(here("functions", "Z.R")) - -# Constrain T_start and T_end based on sunrise and sunset times. -constrain_solar_time_range = dget(here("utils", "constrain_solar_time_range.R")) - -function(Ls, phi, T_start, T_end, nfft){ - - # Step 1: Constrain T_start and T_end based on sunrise and sunset times. - - # Apply solar time range constraint. - T_range = constrain_solar_time_range(Ls, phi, T_start, T_end) - - # No solar irradiance within the contrained time range. - if(is.null(T_range)){ - return(0) - - }else{ - # Constrain the time range. - T_start = T_range$T_start - T_end = T_range$T_end - } - - # Step 2: Calculate insolation. - - # # Equation 8 (1990): Hour angle [deg]. - # # From Appelbaum, Joseph & Flood, Dennis. (1990): - # # The ratio of Mars to Earth length of day is 24.65/24. - # # It is convenient, for calculation purposes, to define a Mar hour - # # by dividing the Martian day into 24 hr. Using the same relationship - # # between the Mars solar time T and the hour angle as for the Earth. - # omega_start = 15 * T_start - 180 - # omega_end = 15 * T_end - 180 - # - # # Equation 7 (1990): Declination angle [rad]. - # delta = declination(Ls) - # - # # Equation 12 (1990): Beam insolation on a horizotal surface at the top of Mars atmosphere [Wh/m2]. - # w = (12/pi) * Gob_eq(Ls) # FIXME: Should this be 12.33/pi ? - # x = (2 * pi * (omega_end - omega_start)) / 360 - # y = sin(phi * pi/180) * sin(delta) - # z = cos(phi * pi/180) * cos(delta) * (sin(omega_end * pi/180) - sin(omega_start * pi/180)) - # - # Iobh = w * (x * y + z) - - # The interand for Equation 11 (1990). - interand = function(T_s){ - Z = Z_eq(Ls=Ls, T_s=T_s, phi=phi, nfft=nfft) - - a = Gob_eq(Ls) - b = cos(Z*pi/180) - - a * b - } - - # Equation 11 (1990): Beam insolation on a horizotal surface at the top of Mars atmosphere [Wh/m2]. - I_obh = integrate(interand, T_start, T_end) - - return(I_obh$value) -} \ No newline at end of file diff --git a/functions/Z.R b/functions/Z.R deleted file mode 100644 index c61c2ea..0000000 --- a/functions/Z.R +++ /dev/null @@ -1,65 +0,0 @@ -# Equation 6: Zenith angle of the incident solar radiation [deg]. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. -# https://ntrs.nasa.gov/?R=19890018252 - -# Equation 7 (1990): The declination angle. -source(here("utils", "declination.R")) - -# Ls - Areocentric longitude [deg]. -# T_s - Solar time [h]. An integer belonging to [6, 18] if using f_89.R or f_90.R. -# phi - Latitude [deg]. -# nfft - Net flux function type. -function(Ls, T_s, phi, nfft){ - - ######################################## - # Equation 7: Declination angle [rad]. # - ######################################## - delta = declination(Ls) - - ################################# - # Equation 8: Hour angle [deg]. # - ################################# - # From Appelbaum, Joseph & Flood, Dennis. (1990): - # The ratio of Mars to Earth length of day is 24.65/24. - # It is convenient, for calculation purposes, to define a Mar hour - # by dividing the Martian day into 24 hr. Using the same relationship - # between the Mars solar time T and the hour angle as for the Earth. - omega = 15 * T_s - 180 - - ################################################################## - # Equation 6: Zenith angle of the incident solar radiation [deg] # - ################################################################## - a = sin(phi*pi/180) * sin(delta) - b = cos(phi*pi/180) * cos(delta) * cos(omega * pi/180) - - Z = acos(a + b) * 180/pi - - # We have to round the zenith angle to a power of ten because the - # normalized net flux function only takes predetermined Z angle values. - if(nfft == 1){ - - # Round in multiples of 10. - Z = round(Z, -1) - - # There is no column for Z=90 in thenormalized net flux function table. - # In case Z=90, replace it with 85. - v = unlist(Z) - Z = relist(replace(v, v==90, 85), skeleton=Z) - - }else if(nfft == 2){ - # Round in multiples of 5. - Z = round(Z/5) * 5 - - # There is no column for Z=90 in thenormalized net flux function table. - # In case Z=90, replace it with 85. - v = unlist(Z) - Z = relist(replace(v, v==90, 85), skeleton=Z) - - }else if(nfft != 3){ - stop(paste("Unsupported net flux function type, should be 1 for f_89, 2 for f_90, or 3 for f: ", nfft)) - } - - return(Z) -} \ No newline at end of file diff --git a/functions/f.R b/functions/f.R deleted file mode 100644 index 3992cbb..0000000 --- a/functions/f.R +++ /dev/null @@ -1,213 +0,0 @@ -# Equation 20 (1990): The analytical expression of the normalized net flux function. -# -# From Appelbaum, Joseph & Flood, Dennis (1990) - Update 1990: -# The mean error is about 0.7 percent for the full range. For zenith angles up to 40° the error is much smaller. -# The largest error is for zenith angle of 80° and 85° and for τ greater than 5. The maximum error is about 7 percent. -# At these large angles and opacities, the error has a minor effect on the calculated daily insolations. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars: Update 1990. NASA STI/Recon Technical Report N. 91. 15117-. -# https://www.researchgate.net/publication/259222079_Solar_radiation_on_Mars_Update_1990 - -library(here) - -f_build_df = dget(here("functions", "f_build_df.R")) - -f_build_coefficients_df = dget(here("functions", "f_build_coefficients_df.R")) - -if(!exists("k0_coeffs")){ - k0_coeffs = f_build_coefficients_df(k=0) -} - -if(!exists("k1_coeffs")){ - k1_coeffs = f_build_coefficients_df(k=1) -} - -# build a dataframe representation of Table III referenced in Appelbaum, Joseph & Flood, Dennis. (1990): -if(!exists("nnff_0p1_89")){ - nnff_0p1_89 = f_build_df(al=0.1, pub_year=1989) -} - -# Build dataframe representation of Table III and IV referenced in Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars: Update 1990. -if(!exists("nnff_0p1_90")){ - nnff_0p1_90 = f_build_df(al=0.1, pub_year=1990) -} - -if(!exists("nnff_0p4_90")){ - nnff_0p4_90 = f_build_df(al=0.4, pub_year=1990) -} - -# The coefficient lookup function. -# See Table IV - Normalized Net Flux Function Coefficients in Appelbaum, Joseph & Flood, Dennis (1990) Update 1990. -p = function(i, j, k){ - if(k==0){ - coefficient = k0_coeffs[j+1, paste("X", i, sep="")] - }else if(k==1){ - coefficient = k1_coeffs[j+1, paste("X", i, sep="")] - }else{ - stop("Unsupported k value.") - } - - return(coefficient) -} - -# The normalized net flux function's lookup table lookup. -# -# Uses a looktup Table III published in "Solar radiation on Mars" -# -# From Appelbaum, Joseph & Flood, Dennis. (1990): -# The net solar flux integrated over the solar spectrum on the Martian -# surface was calculated by Pollack basd on multiple wavelength and -# multiple scattering of the solar radiation. Derived data from this -# calculation are shown Table III by the normalized net flux function -# f(Z, tau) where the parameters are the zenith angle Z and the optical -# depth tau. This table pertains to an albedo of 0.1 but can be used -# for higher albedo values to a first approximation. -# -# Based on the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. -# https://www.researchgate.net/publication/256334925_Solar_radiation_on_Mars -# -# Z - Zenith angle [deg]. -# tau - Optical depth tau factor. -# al - Albedo. Can only be 0.1 for 1989 data. -f_89 = function(Z, tau, al=0.1){ - - nnff_df = NULL - - if(al == 0.1){ - nnff_df = nnff_0p1_89 - - }else{ - stop("The albedo can only be 0.1 when using f_89 table lookup.") - } - - return( - unlist( # Unlist in case a sequence of Zs are given instead of a single value (i.e. in the case of integrations). - nnff_df[nnff_df$tau == toString(tau), paste("X", Z, sep="")], - use.names=FALSE - ) - ) -} - -# The normalized net flux function's lookup table lookup. -# -# Uses the looktup table published in "Solar radiation on Mars: Update 1990." -# - Table III (a) and (b) for an albedo of 0.1. -# - Table IV (a) and (b) for an albedo of 0.4 -# -# Based on the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars: Update 1990. NASA STI/Recon Technical Report N. 91. 15117-. -# https://www.researchgate.net/publication/259222079_Solar_radiation_on_Mars_Update_1990 -# -# Z - Zenith angle [deg]. -# tau - Optical depth tau factor. -# al - Albedo. Can be 0.1 or 0.4 for 1990 data. -f_90 = function(Z, tau, al=0.1){ - - nnff_df = NULL - - if(al == 0.1){ - nnff_df = nnff_0p1_90 - - }else if(al == 0.4){ - nnff_df = nnff_0p4_90 - - }else{ - stop("The albedo can only be 0.1 or 0.4 when using f_90 table lookup.") - } - - return( - unlist( # Unlist in case a sequence of Zs are given instead of a single value (i.e. in the case of integrations). - nnff_df[nnff_df$tau == toString(tau), paste("X", Z, sep="")], - use.names=FALSE - ) - ) -} - -# Equation 20. The analytical expression of the normalized net flux function. -# -# From Appelbaum, Joseph & Flood, Dennis (1990) - Update 1990: -# The mean error is about 0.7 percent for the full range. For zenith angles up to 40° the error is much smaller. -# The largest error is for zenith angle of 80° and 85° and for τ greater than 5. The maximum error is about 7 percent. -# At these large angles and opacities, the error has a minor effect on the calculated daily insolations. -# -# Based on equations presented in the following publication: -# Appelbaum, Joseph & Flood, Dennis. (1990). Solar radiation on Mars: Update 1990. NASA STI/Recon Technical Report N. 91. 15117-. -# https://www.researchgate.net/publication/259222079_Solar_radiation_on_Mars_Update_1990 -# -f_analytical = function(Z, tau, al=0.1){ - # Check for and warn against parameters that would result in lagest errors (max. 7%). - if(tau > 5){ - # TODO: Make warning. - message(paste("Large error encountered with τ = ", tau, " greater than 5 (maximum error is 7%). ", - "Consider using the f_89 and f_90 table lookup implementation of the normalized net flux function instead of its analytical expression.", - sep="") - ) - } - - - # Use ifelse in case this function is being invoked from an integration in which case Z can be a vector instead of a scalar. - # If Z is a scalar and we use if() then the following issue will occur: "the condition has length > 1 and only the first element will be used." - warning_msg = ifelse(Z >= 80, paste("Possibly large error encountered with Z = ", Z, "° (maximum error is 7% for Z = 80° or Z = 85°). ", - "Consider using the f_89 and f_90 table lookup implementation of the normalized net flux function instead of its analytical expression.\n", - sep=""), "") - - # handle warning message. - for(w_msg in warning_msg){ - if(w_msg != ""){ - # TODO: Make warning. - message(w_msg) - } - } - - psum = 0 - for(i in seq(0,5,1)){ - for(j in seq(0,5,1)){ - for(k in seq(0,1,1)){ - psum = psum + p(i, j, k) * tau^i * (Z/100)^j * al^k - } - } - } - - return(psum * (1-al)) -} - - -# The net flux function. -# Z - Zenith angle [deg]. -# tau - Optical depth tau factor. -# al - Albedo (ranges from 0.1 to 0.4). -f = function(Z, tau, al=0.1, pub_year=NULL){ - net_flux = NULL - - if(is.null(pub_year)){ - net_flux = f_analytical(Z, tau, al) - - }else if(pub_year == 1989){ - net_flux = f_89(Z, tau, al) - - }else if(pub_year == 1990){ - net_flux = f_90(Z, tau, al) - - }else{ - stop("Usupported publication year, should either be 1989 for the original pulication or 1990 for its 1990 update") - } - - # Check if given Z results in NULL net flux. - if(is.null(net_flux)){ - stop(paste("Sun zenith angle Z = ", Z ,"° is not available in the net flux look-up table. Consider using the analytical function instead.", sep="")) - - } - - # Check if given tau results in NA net flux. - # Use ifelse in case this function is being invoked from an integration in which case net_flux can be a vector instead of a scalar. - isNAs = ifelse(is.na(net_flux), TRUE, FALSE) - for(isNA in isNAs){ - if(isTRUE(isNA)){ - stop(paste("Optical depth tau factor τ = ", tau," is not available in the net flux look-up table. Consider using the analytical function instead.", sep="")) - } - } - - return(net_flux) -} \ No newline at end of file diff --git a/man/G_ali.Rd b/man/G_ali.Rd new file mode 100644 index 0000000..3d924b2 --- /dev/null +++ b/man/G_ali.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_ali.R +\name{G_ali} +\alias{G_ali} +\title{Title} +\usage{ +G_ali( + Ls, + phi, + longitude, + T_s, + Z = Z_eq(Ls = Ls, T_s = T_s, phi = phi, nfft = nfft), + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{T_s}{} + +\item{Z}{} + +\item{tau}{} + +\item{al}{} + +\item{beta}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_b.Rd b/man/G_b.Rd new file mode 100644 index 0000000..07342bb --- /dev/null +++ b/man/G_b.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_b.R +\name{G_b} +\alias{G_b} +\title{Title} +\usage{ +G_b(Ls, phi = NULL, T_s = NULL, z = Z(Ls, T_s, phi, nfft), tau, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_bh.Rd b/man/G_bh.Rd new file mode 100644 index 0000000..193ef00 --- /dev/null +++ b/man/G_bh.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_bh.R +\name{G_bh} +\alias{G_bh} +\title{Title} +\usage{ +G_bh( + Ls, + phi, + longitude = NULL, + T_s, + z = Z(Ls, T_s, phi, nfft), + tau, + al = NULL, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_bi.Rd b/man/G_bi.Rd new file mode 100644 index 0000000..82ffcdc --- /dev/null +++ b/man/G_bi.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_bi.R +\name{G_bi} +\alias{G_bi} +\title{Title} +\usage{ +G_bi( + Ls, + phi, + T_s, + z = Z(Ls = Ls, T_s = T_s, phi = phi, nfft = nfft), + tau, + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_dh.Rd b/man/G_dh.Rd new file mode 100644 index 0000000..c0f7019 --- /dev/null +++ b/man/G_dh.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_dh.R +\name{G_dh} +\alias{G_dh} +\title{Title} +\usage{ +G_dh( + Ls, + phi, + longitude, + T_s = NULL, + z = Z(Ls, T_s, phi, nfft), + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_di.Rd b/man/G_di.Rd new file mode 100644 index 0000000..b761567 --- /dev/null +++ b/man/G_di.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_di.R +\name{G_di} +\alias{G_di} +\title{Title} +\usage{ +G_di( + Ls, + phi, + longitude, + T_s, + z = Z(Ls = Ls, T_s = T_s, phi = phi, nfft = nfft), + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{al}{} + +\item{beta}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_h.Rd b/man/G_h.Rd new file mode 100644 index 0000000..a9ee4ab --- /dev/null +++ b/man/G_h.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_h.R +\name{G_h} +\alias{G_h} +\title{Title} +\usage{ +G_h( + Ls, + phi, + longitude, + T_s = NULL, + z = Z(Ls, T_s, phi, nfft), + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_i.Rd b/man/G_i.Rd new file mode 100644 index 0000000..2df2389 --- /dev/null +++ b/man/G_i.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_i.R +\name{G_i} +\alias{G_i} +\title{Title} +\usage{ +G_i( + Ls, + phi, + longitude, + T_s, + z = Z(Ls = Ls, T_s = T_s, phi = phi, nfft = nfft), + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{T_s}{} + +\item{z}{} + +\item{tau}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/G_ob.Rd b/man/G_ob.Rd new file mode 100644 index 0000000..7356d5c --- /dev/null +++ b/man/G_ob.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_ob.R +\name{G_ob} +\alias{G_ob} +\title{Equation 4 (1990): Beam irridiance at the top of the Martian atmosphere [W/m2].} +\usage{ +G_ob(Ls) +} +\arguments{ +\item{Ls}{Areocentric longitude.} +} +\value{ +Beam irradiance [W/m2]. +} +\description{ +Source: + Appelbaum, Joseph & Flood, Dennis. (1990). + Solar radiation on Mars. Solar Energy. 45. 353–363. 10.1016/0038-092X(90)90156-7. + https://www.researchgate.net/publication/256334925_Solar_radiation_on_Mars +} diff --git a/man/G_obh.Rd b/man/G_obh.Rd new file mode 100644 index 0000000..63504c2 --- /dev/null +++ b/man/G_obh.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/G_obh.R +\name{G_obh} +\alias{G_obh} +\title{Title} +\usage{ +G_obh(Ls, phi = NULL, T_s = NULL, z = Z(Ls, T_s, phi, nfft), nfft = 1) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{T_s}{} + +\item{z}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_ali.Rd b/man/H_ali.Rd new file mode 100644 index 0000000..093aca8 --- /dev/null +++ b/man/H_ali.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_ali.R +\name{H_ali} +\alias{H_ali} +\title{Title} +\usage{ +H_ali( + Ls, + phi, + longitude, + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_bi.Rd b/man/H_bi.Rd new file mode 100644 index 0000000..87f878d --- /dev/null +++ b/man/H_bi.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_bi.R +\name{H_bi} +\alias{H_bi} +\title{Title} +\usage{ +H_bi(Ls, phi, tau, beta, gamma_c, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_dh.Rd b/man/H_dh.Rd new file mode 100644 index 0000000..98bf9cc --- /dev/null +++ b/man/H_dh.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_dh.R +\name{H_dh} +\alias{H_dh} +\title{Title} +\usage{ +H_dh(Ls, phi, tau, al, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_di.Rd b/man/H_di.Rd new file mode 100644 index 0000000..8352599 --- /dev/null +++ b/man/H_di.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_di.R +\name{H_di} +\alias{H_di} +\title{Title} +\usage{ +H_di( + Ls, + phi, + longitude, + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_h.Rd b/man/H_h.Rd new file mode 100644 index 0000000..03464f2 --- /dev/null +++ b/man/H_h.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_h.R +\name{H_h} +\alias{H_h} +\title{Title} +\usage{ +H_h(Ls, phi, tau, al = 0.1, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_hbh.Rd b/man/H_hbh.Rd new file mode 100644 index 0000000..9ffde25 --- /dev/null +++ b/man/H_hbh.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_bh.R +\name{H_hbh} +\alias{H_hbh} +\title{Title} +\usage{ +H_hbh(Ls, phi, tau, al = NULL, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_i.Rd b/man/H_i.Rd new file mode 100644 index 0000000..8180986 --- /dev/null +++ b/man/H_i.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_i.R +\name{H_i} +\alias{H_i} +\title{Title} +\usage{ +H_i( + Ls, + phi, + longitude, + tau, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/H_obh.Rd b/man/H_obh.Rd new file mode 100644 index 0000000..58aecca --- /dev/null +++ b/man/H_obh.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/H_obh.R +\name{H_obh} +\alias{H_obh} +\title{Title} +\usage{ +H_obh(Ls, phi) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_ali.Rd b/man/I_ali.Rd new file mode 100644 index 0000000..3e406d5 --- /dev/null +++ b/man/I_ali.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_ali.R +\name{I_ali} +\alias{I_ali} +\title{Title} +\usage{ +I_ali( + Ls, + phi, + longitude, + tau, + T_start, + T_end, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_bh.Rd b/man/I_bh.Rd new file mode 100644 index 0000000..7e304d7 --- /dev/null +++ b/man/I_bh.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_bh.R +\name{I_bh} +\alias{I_bh} +\title{Title} +\usage{ +I_bh(Ls, phi, tau, T_start, T_end, al = NULL, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_bi.Rd b/man/I_bi.Rd new file mode 100644 index 0000000..bcac85c --- /dev/null +++ b/man/I_bi.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_bi.R +\name{I_bi} +\alias{I_bi} +\title{Title} +\usage{ +I_bi(Ls, phi, tau, T_start, T_end, beta, gamma_c, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_dh.Rd b/man/I_dh.Rd new file mode 100644 index 0000000..3b29701 --- /dev/null +++ b/man/I_dh.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_dh.R +\name{I_dh} +\alias{I_dh} +\title{Title} +\usage{ +I_dh(Ls, phi, tau, T_start, T_end, al, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_di.Rd b/man/I_di.Rd new file mode 100644 index 0000000..df8b83a --- /dev/null +++ b/man/I_di.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_di.R +\name{I_di} +\alias{I_di} +\title{Title} +\usage{ +I_di( + Ls, + phi, + longitude, + tau, + T_start, + T_end, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_h.Rd b/man/I_h.Rd new file mode 100644 index 0000000..67838b4 --- /dev/null +++ b/man/I_h.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_h.R +\name{I_h} +\alias{I_h} +\title{Title} +\usage{ +I_h( + Ls, + phi, + longitude, + tau, + T_start, + T_end, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{al}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_i.Rd b/man/I_i.Rd new file mode 100644 index 0000000..34b4be6 --- /dev/null +++ b/man/I_i.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_i.R +\name{I_i} +\alias{I_i} +\title{Title} +\usage{ +I_i( + Ls, + phi, + longitude, + tau, + T_start, + T_end, + al = albedo(latitude = phi, longitude = longitude, tau = tau), + beta, + gamma_c, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{longitude}{} + +\item{tau}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{al}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/I_obh.Rd b/man/I_obh.Rd new file mode 100644 index 0000000..c1d8f3b --- /dev/null +++ b/man/I_obh.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/I_obh.R +\name{I_obh} +\alias{I_obh} +\title{Title} +\usage{ +I_obh(Ls, phi, T_start, T_end, nfft) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/Z.Rd b/man/Z.Rd new file mode 100644 index 0000000..c2d512e --- /dev/null +++ b/man/Z.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Z.R +\name{Z} +\alias{Z} +\title{Equation 6: Zenith angle of the incident solar radiation [deg].} +\usage{ +Z(Ls, T_s, phi, nfft) +} +\arguments{ +\item{Ls}{Areocentric longitude [deg].} + +\item{T_s}{Solar time [h]} + +\item{phi}{Planetary latitude [deg].} + +\item{nfft}{Net flux function type.} +} +\value{ + +} +\description{ +Source: Equation 6 in Appelbaum, Joseph & Flood, Dennis. (1990). +} diff --git a/man/albedo.Rd b/man/albedo.Rd new file mode 100644 index 0000000..5cff2a2 --- /dev/null +++ b/man/albedo.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/albedo.R +\name{albedo} +\alias{albedo} +\title{The albedo function.} +\usage{ +albedo(latitude, longitude, tau, force_multiple_ten = FALSE) +} +\arguments{ +\item{latitude}{Planetary latitude, from -90° to io +90°.} + +\item{longitude}{Planetary longitude, from -180° to 180°.} + +\item{tau}{Optical depth.} + +\item{force_multiple_ten}{} +} +\value{ + +} +\description{ +Calculate the albedo value given geographical location and tau factor. +} +\details{ +Source: Table I - The albedo function. + Appelbaum, Joseph & Landis, Geoffrey & Sherman, I. (1991). + Solar radiation on Mars — Update 1991. Solar Energy. 50. 35-51. 10.1016/0038-092X(93)90006-A: + https://www.researchgate.net/publication/223850868_Solar_radiation_on_Mars-Update_1991 +} diff --git a/man/constrain_solar_time_range.Rd b/man/constrain_solar_time_range.Rd new file mode 100644 index 0000000..34624f0 --- /dev/null +++ b/man/constrain_solar_time_range.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/constrain_solar_time_range.R +\name{constrain_solar_time_range} +\alias{constrain_solar_time_range} +\title{Title} +\usage{ +constrain_solar_time_range( + Ls, + phi, + T_start, + T_end, + beta = NULL, + gamma_c = NULL +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{T_start}{} + +\item{T_end}{} + +\item{beta}{} + +\item{gamma_c}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/declination.Rd b/man/declination.Rd new file mode 100644 index 0000000..bad552c --- /dev/null +++ b/man/declination.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/declination.R +\name{declination} +\alias{declination} +\title{Declination angle: the angular position of the Sun at solar noon with respect to the plane of the equator.} +\usage{ +declination(Ls, unit = 1) +} +\arguments{ +\item{Ls}{Areocentric longitude [deg].} + +\item{unit}{} +} +\value{ +Declination angle in radians or degrees. +} +\description{ +For Mars: -24.936° <= delta <= 24.936°. +0 deg at vernal (Ls 0°) and autumnal equinoxes (Ls 180°) ++24.936 deg at summer solstice (Ls 90) and -24.936 at at winter solstice (Ls 270°). +} +\details{ +Source: Equation 7 (1990) +} diff --git a/man/f.Rd b/man/f.Rd new file mode 100644 index 0000000..30fd11b --- /dev/null +++ b/man/f.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{f} +\alias{f} +\title{he analytical expression of the normalized net flux function.} +\usage{ +f(z, tau, al = 0.1, pub_year = NULL) +} +\arguments{ +\item{z}{Zenith angle [deg].} + +\item{tau}{Optical depth.} + +\item{al}{Albedo (ranges from 0.1 to 0.4).} + +\item{pub_year}{} +} +\value{ +Normalized net flux. +} +\description{ +Source: Equation 20 (1990). +} diff --git a/man/f_89.Rd b/man/f_89.Rd new file mode 100644 index 0000000..b1aef2c --- /dev/null +++ b/man/f_89.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{f_89} +\alias{f_89} +\title{The normalized net flux function's lookup table lookup.} +\usage{ +f_89(z, tau, al = 0.1) +} +\arguments{ +\item{z}{Zenith angle [deg].} + +\item{tau}{Optical depth.} + +\item{al}{Albedo, can only be 0.1.} +} +\value{ +Normalized net flux. +} +\description{ +The net solar flux integrated over the solar spectrum on the Martian +surface was calculated by Pollack based on multiple wavelength and +multiple scattering of the solar radiation. +} +\details{ +Source: Table III in Appelbaum, Joseph & Flood, Dennis. (1990). +} diff --git a/man/f_90.Rd b/man/f_90.Rd new file mode 100644 index 0000000..931e501 --- /dev/null +++ b/man/f_90.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{f_90} +\alias{f_90} +\title{The normalized net flux function's lookup table lookup.} +\usage{ +f_90(z, tau, al = 0.1) +} +\arguments{ +\item{z}{Zenith angle [deg].} + +\item{tau}{Optical depth.} + +\item{al}{Albedo, can be 0.1 or 0.4.} +} +\value{ +Normalized net flux. +} +\description{ +Source: Solar radiation on Mars: Update 1990. + Table III (a) and (b) for an albedo of 0.1. + Table IV (a) and (b) for an albedo of 0.4. +} diff --git a/man/f_all_Zs.Rd b/man/f_all_Zs.Rd new file mode 100644 index 0000000..1ec1096 --- /dev/null +++ b/man/f_all_Zs.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{f_all_Zs} +\alias{f_all_Zs} +\title{Title} +\usage{ +f_all_Zs(nfft) +} +\arguments{ +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/f_all_taus.Rd b/man/f_all_taus.Rd new file mode 100644 index 0000000..654675b --- /dev/null +++ b/man/f_all_taus.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{f_all_taus} +\alias{f_all_taus} +\title{Title} +\usage{ +f_all_taus(nfft) +} +\arguments{ +\item{nfft}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/f_analytical.Rd b/man/f_analytical.Rd new file mode 100644 index 0000000..e939675 --- /dev/null +++ b/man/f_analytical.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{f_analytical} +\alias{f_analytical} +\title{The analytical expression of the normalized net flux function.} +\usage{ +f_analytical(z, tau, al = 0.1) +} +\arguments{ +\item{z}{Zenith angle [deg].} + +\item{tau}{Optical depth.} + +\item{al}{Albedo.} +} +\value{ +Normalized net flux. +} +\description{ +The mean error is about 0.7 percent for the full range. For zenith angles up to 40° the error is much smaller. +The largest error is for zenith angle of 80° and 85° and for tau greater than 5. The maximum error is about 7 percent. +At these large angles and opacities, the error has a minor effect on the calculated daily insolations. +} +\details{ +Source: Equation 20? in Appelbaum, Joseph & Flood, Dennis (1990) - Update 1990. +} diff --git a/man/is_irradiated.Rd b/man/is_irradiated.Rd new file mode 100644 index 0000000..5697a2a --- /dev/null +++ b/man/is_irradiated.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is_irradiated.R +\name{is_irradiated} +\alias{is_irradiated} +\title{Check if there is solar irradiance at the given location and moment.} +\usage{ +is_irradiated( + Ls, + phi, + T_s, + z = Z(Ls, T_s, phi, nfft), + beta = NULL, + gamma_c = NULL, + nfft +) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{T_s}{} + +\item{z}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{nfft}{} +} +\value{ + +} +\description{ +Check if there is solar irradiance at the given location and moment. +} diff --git a/man/is_polar_day.Rd b/man/is_polar_day.Rd new file mode 100644 index 0000000..939e522 --- /dev/null +++ b/man/is_polar_day.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is_polar_day.R +\name{is_polar_day} +\alias{is_polar_day} +\title{Title} +\usage{ +is_polar_day(Ls, phi) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/is_polar_night.Rd b/man/is_polar_night.Rd new file mode 100644 index 0000000..7b99889 --- /dev/null +++ b/man/is_polar_night.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is_polar_night.R +\name{is_polar_night} +\alias{is_polar_night} +\title{Title} +\usage{ +is_polar_night(Ls, phi) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/p.Rd b/man/p.Rd new file mode 100644 index 0000000..562f4e2 --- /dev/null +++ b/man/p.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/f.R +\name{p} +\alias{p} +\title{The coefficient lookup function.} +\usage{ +p(i, j, k) +} +\arguments{ +\item{i}{} + +\item{j}{} + +\item{k}{} +} +\value{ + +} +\description{ +Source: Table IV - Normalized Net Flux Function Coefficients in Appelbaum, Joseph & Flood, Dennis (1990) Update 1990. +} diff --git a/man/sunrise.Rd b/man/sunrise.Rd new file mode 100644 index 0000000..50beade --- /dev/null +++ b/man/sunrise.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunrise.R +\name{sunrise} +\alias{sunrise} +\title{Title} +\usage{ +sunrise(Ls, phi, beta = NULL, gamma_c = NULL, unit = 1) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{unit}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunrise_for_horizontal_surface.Rd b/man/sunrise_for_horizontal_surface.Rd new file mode 100644 index 0000000..16bca9a --- /dev/null +++ b/man/sunrise_for_horizontal_surface.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunrise.R +\name{sunrise_for_horizontal_surface} +\alias{sunrise_for_horizontal_surface} +\title{Title} +\usage{ +sunrise_for_horizontal_surface(phi, delta) +} +\arguments{ +\item{phi}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunrise_for_inclined_surface.Rd b/man/sunrise_for_inclined_surface.Rd new file mode 100644 index 0000000..8f2c101 --- /dev/null +++ b/man/sunrise_for_inclined_surface.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunrise.R +\name{sunrise_for_inclined_surface} +\alias{sunrise_for_inclined_surface} +\title{Title} +\usage{ +sunrise_for_inclined_surface(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunrise_for_inclined_surface_oriented_east.Rd b/man/sunrise_for_inclined_surface_oriented_east.Rd new file mode 100644 index 0000000..3b06088 --- /dev/null +++ b/man/sunrise_for_inclined_surface_oriented_east.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunrise.R +\name{sunrise_for_inclined_surface_oriented_east} +\alias{sunrise_for_inclined_surface_oriented_east} +\title{Title} +\usage{ +sunrise_for_inclined_surface_oriented_east(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunrise_for_inclined_surface_oriented_equator.Rd b/man/sunrise_for_inclined_surface_oriented_equator.Rd new file mode 100644 index 0000000..bd3ef82 --- /dev/null +++ b/man/sunrise_for_inclined_surface_oriented_equator.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunrise.R +\name{sunrise_for_inclined_surface_oriented_equator} +\alias{sunrise_for_inclined_surface_oriented_equator} +\title{Title} +\usage{ +sunrise_for_inclined_surface_oriented_equator(phi, beta, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunrise_for_inclined_surface_oriented_west.Rd b/man/sunrise_for_inclined_surface_oriented_west.Rd new file mode 100644 index 0000000..597f4ea --- /dev/null +++ b/man/sunrise_for_inclined_surface_oriented_west.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunrise.R +\name{sunrise_for_inclined_surface_oriented_west} +\alias{sunrise_for_inclined_surface_oriented_west} +\title{Title} +\usage{ +sunrise_for_inclined_surface_oriented_west(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunset.Rd b/man/sunset.Rd new file mode 100644 index 0000000..43b0658 --- /dev/null +++ b/man/sunset.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunset.R +\name{sunset} +\alias{sunset} +\title{Title} +\usage{ +sunset(Ls, phi, beta = NULL, gamma_c = NULL, unit = 1) +} +\arguments{ +\item{Ls}{} + +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{unit}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunset_for_horizontal_surface.Rd b/man/sunset_for_horizontal_surface.Rd new file mode 100644 index 0000000..fca1e94 --- /dev/null +++ b/man/sunset_for_horizontal_surface.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunset.R +\name{sunset_for_horizontal_surface} +\alias{sunset_for_horizontal_surface} +\title{Get the moment in which the sunset occurs.} +\usage{ +sunset_for_horizontal_surface(phi, delta) +} +\arguments{ +\item{phi}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Get the moment in which the sunset occurs. +} diff --git a/man/sunset_for_inclined_surface.Rd b/man/sunset_for_inclined_surface.Rd new file mode 100644 index 0000000..b3617cd --- /dev/null +++ b/man/sunset_for_inclined_surface.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunset.R +\name{sunset_for_inclined_surface} +\alias{sunset_for_inclined_surface} +\title{Title} +\usage{ +sunset_for_inclined_surface(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunset_for_inclined_surface_oriented_east.Rd b/man/sunset_for_inclined_surface_oriented_east.Rd new file mode 100644 index 0000000..3620dc5 --- /dev/null +++ b/man/sunset_for_inclined_surface_oriented_east.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunset.R +\name{sunset_for_inclined_surface_oriented_east} +\alias{sunset_for_inclined_surface_oriented_east} +\title{Title} +\usage{ +sunset_for_inclined_surface_oriented_east(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/sunset_for_inclined_surface_oriented_equator.Rd b/man/sunset_for_inclined_surface_oriented_equator.Rd new file mode 100644 index 0000000..d33d42f --- /dev/null +++ b/man/sunset_for_inclined_surface_oriented_equator.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunset.R +\name{sunset_for_inclined_surface_oriented_equator} +\alias{sunset_for_inclined_surface_oriented_equator} +\title{(31) in (1993).} +\usage{ +sunset_for_inclined_surface_oriented_equator(phi, beta, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{delta}{} +} +\value{ + +} +\description{ +(31) in (1993). +} diff --git a/man/sunset_for_inclined_surface_oriented_west.Rd b/man/sunset_for_inclined_surface_oriented_west.Rd new file mode 100644 index 0000000..d892095 --- /dev/null +++ b/man/sunset_for_inclined_surface_oriented_west.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sunset.R +\name{sunset_for_inclined_surface_oriented_west} +\alias{sunset_for_inclined_surface_oriented_west} +\title{Title} +\usage{ +sunset_for_inclined_surface_oriented_west(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/x_for_inclined_surface.Rd b/man/x_for_inclined_surface.Rd new file mode 100644 index 0000000..bc8e610 --- /dev/null +++ b/man/x_for_inclined_surface.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/xy_for_inclined_surface.R +\name{x_for_inclined_surface} +\alias{x_for_inclined_surface} +\title{Title} +\usage{ +x_for_inclined_surface(phi, beta, gamma_c) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} +} +\value{ + +} +\description{ +Title +} diff --git a/man/y_for_inclined_surface.Rd b/man/y_for_inclined_surface.Rd new file mode 100644 index 0000000..b4fbc9a --- /dev/null +++ b/man/y_for_inclined_surface.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/xy_for_inclined_surface.R +\name{y_for_inclined_surface} +\alias{y_for_inclined_surface} +\title{Title} +\usage{ +y_for_inclined_surface(phi, beta, gamma_c, delta) +} +\arguments{ +\item{phi}{} + +\item{beta}{} + +\item{gamma_c}{} + +\item{delta}{} +} +\value{ + +} +\description{ +Title +} diff --git a/mars-solar-radiation.Rproj b/mars-solar-radiation.Rproj index 8e3c2eb..21a4da0 100644 --- a/mars-solar-radiation.Rproj +++ b/mars-solar-radiation.Rproj @@ -11,3 +11,7 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/test/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl1_table_ii_1993.csv b/tests/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl1_table_ii_1993.csv similarity index 100% rename from test/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl1_table_ii_1993.csv rename to tests/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl1_table_ii_1993.csv diff --git a/test/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl2_table_ii_1993.csv b/tests/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl2_table_ii_1993.csv similarity index 100% rename from test/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl2_table_ii_1993.csv rename to tests/data/daily_insolation_on_an_inclined_surface_for_beta_equals_phi_at_vl2_table_ii_1993.csv diff --git a/test/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl1_table_iii_1993.csv b/tests/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl1_table_iii_1993.csv similarity index 100% rename from test/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl1_table_iii_1993.csv rename to tests/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl1_table_iii_1993.csv diff --git a/test/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl2_table_iii_1993.csv b/tests/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl2_table_iii_1993.csv similarity index 100% rename from test/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl2_table_iii_1993.csv rename to tests/data/daily_insolation_on_optimal_inclined_angle_beta_at_vl2_table_iii_1993.csv diff --git a/test/data/discretized_tau_at_vl1_fig_3_1991_update.csv b/tests/data/discretized_tau_at_vl1_fig_3_1991_update.csv similarity index 100% rename from test/data/discretized_tau_at_vl1_fig_3_1991_update.csv rename to tests/data/discretized_tau_at_vl1_fig_3_1991_update.csv diff --git a/test/data/discretized_tau_at_vl2_fig_3_1991_update.csv b/tests/data/discretized_tau_at_vl2_fig_3_1991_update.csv similarity index 100% rename from test/data/discretized_tau_at_vl2_fig_3_1991_update.csv rename to tests/data/discretized_tau_at_vl2_fig_3_1991_update.csv diff --git a/test/data/sunrise_beta_equals_phi_table_I_1993.csv b/tests/data/sunrise_beta_equals_phi_table_I_1993.csv similarity index 100% rename from test/data/sunrise_beta_equals_phi_table_I_1993.csv rename to tests/data/sunrise_beta_equals_phi_table_I_1993.csv diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..37a8948 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,2 @@ +library(testthat) +test_check("mars") \ No newline at end of file diff --git a/test/data.R b/tests/testthat/data.R similarity index 100% rename from test/data.R rename to tests/testthat/data.R diff --git a/test/test_Gh.R b/tests/testthat/test_Gh.R similarity index 69% rename from test/test_Gh.R rename to tests/testthat/test_Gh.R index acc666d..c53cd58 100644 --- a/test/test_Gh.R +++ b/tests/testthat/test_Gh.R @@ -1,17 +1,11 @@ - -library(here) -library(testthat) - -Gh_eq = dget(here("functions", "G_h.R")) - -test_that("I_h: Global irradiance on Mars horizontal surface with different normalized net flux functions.", { +test_that("G_h: Global irradiance on Mars horizontal surface with different normalized net flux functions.", { # Test parameters. Ls = 122 # Areocentric longitude. phi = 22.3 # Planetaryz latitude. al = 0.1 # Albedo. # Solar zenith angle. - Z_seq = c( + z_seq = c( seq(0, 80, 10), 85) @@ -21,13 +15,13 @@ test_that("I_h: Global irradiance on Mars horizontal surface with different norm seq(2.5, 3, 0.5), 5, 6) - for(Z in Z_seq){ + for(z in z_seq){ for(tau in tau_seq){ # Calculate global irradiances. - Gh_nfft_lookup_1 = Gh_eq(Ls=Ls, phi=phi, Z=Z, tau=tau, al=al, nfft=1) - Gh_nfft_lookup_2 = Gh_eq(Ls=Ls, phi=phi, Z=Z, tau=tau, al=al, nfft=2) - Gh_nfft_analytical = Gh_eq(Ls=Ls, phi=phi, Z=Z, tau=tau, al=al, nfft=3) + Gh_nfft_lookup_1 = G_h(Ls=Ls, phi=phi, z=z, tau=tau, al=al, nfft=1) + Gh_nfft_lookup_2 = G_h(Ls=Ls, phi=phi, z=z, tau=tau, al=al, nfft=2) + Gh_nfft_analytical = G_h(Ls=Ls, phi=phi, z=z, tau=tau, al=al, nfft=3) # Test assert equality. expect_equal(Gh_nfft_lookup_1, Gh_nfft_lookup_2, tolerance=4, scale=1) diff --git a/test/test_I_bh.R b/tests/testthat/test_I_bh.R similarity index 87% rename from test/test_I_bh.R rename to tests/testthat/test_I_bh.R index 5cf1191..b53d078 100644 --- a/test/test_I_bh.R +++ b/tests/testthat/test_I_bh.R @@ -7,10 +7,6 @@ # Expected results taken from: # TABLE V. - HOURLY AND DAILY BEAM INSOLATION ON A HORIZONTAL SURFACE AT MARS SURFACE. -library(testthat) -library(here) - -Ibh_eq = dget(here("functions", "I_bh.R")) phi = 22.3 al = 0.1 @@ -41,7 +37,7 @@ expected_results = list( c(3, 2, 1, 0, 0, 0, 0) )) -test_that("Equation 19 (1990): I_bh.", { +test_that("I_bh.", { expected_result_index = 1 for(expected_result in expected_results){ @@ -55,7 +51,7 @@ test_that("Equation 19 (1990): I_bh.", { Ibh_expected = expected_result[hour_index, 2] # Calculated output. - Ibh = Ibh_eq(Ls=Ls, phi=phi, tau=tau, T_start=T_start, T_end=T_start+1, al=al, nfft=nfft) + Ibh = I_bh(Ls=Ls, phi=phi, tau=tau, T_start=T_start, T_end=T_start+1, al=al, nfft=nfft) # Test assertion expect_equal(Ibh, Ibh_expected, tolerance=tolerance, scale=1) diff --git a/test/test_I_dh.R b/tests/testthat/test_I_dh.R similarity index 90% rename from test/test_I_dh.R rename to tests/testthat/test_I_dh.R index a290d7d..bc3faa0 100644 --- a/test/test_I_dh.R +++ b/tests/testthat/test_I_dh.R @@ -7,9 +7,7 @@ # Expected results taken from: # TABLE VI. - HOURLY AND DAILY DIFFUSE INSOLATION ON A HORIZONTAL SURFACE AT MARS SURFACE. -library(here) -Idh_eq = dget(here("functions", "I_dh.R")) tolerance = 11 al = 0.1 nfft = 3 @@ -48,7 +46,7 @@ test_that("I_dh.", { hour_index = 1 for(T_start in 12:18){ - Idh = Idh_eq(Ls=Ls, phi=22.3, tau=tau, T_start=T_start, T_end=T_start+1, al=al, nfft=nfft) + Idh = I_dh(Ls=Ls, phi=22.3, tau=tau, T_start=T_start, T_end=T_start+1, al=al, nfft=nfft) Idh_expected = expected_result[hour_index, 2] expect_equal(Idh, Idh_expected, tolerance=tolerance, scale=1) diff --git a/test/test_I_h.R b/tests/testthat/test_I_h.R similarity index 90% rename from test/test_I_h.R rename to tests/testthat/test_I_h.R index 7ab0c42..5901984 100644 --- a/test/test_I_h.R +++ b/tests/testthat/test_I_h.R @@ -7,11 +7,6 @@ # Expected results taken from: # TABLE IV. - HOURLY AND DAILY GLOBAL INSOLATION ON A HORIZONTAL SURFACE AT MARS SURFACE. -library(here) -library(testthat) - -Ih_eq = dget(here("functions", "I_h.R")) - # Expected hourly I_h for different areocentric longitudes. # Test for the 1 hour time ranges at 12-13, 13-14, 14-15, 15-16, 16-17, 17-18, and 18-19. expected_results = list( @@ -57,7 +52,7 @@ test_that("I_h: Hourly global insolation on a horizontal surface at mars surface hour_index = 1 for(T_start in 12:18){ - Ih = Ih_eq(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=T_start, T_end=T_start+1, al=al, nfft=nfft) + Ih = I_h(Ls=Ls, phi=phi, longitude=longitude, tau=tau, T_start=T_start, T_end=T_start+1, al=al, nfft=nfft) Ih_expected = expected_result[hour_index, 2] diff --git a/test/test_I_obh.R b/tests/testthat/test_I_obh.R similarity index 86% rename from test/test_I_obh.R rename to tests/testthat/test_I_obh.R index f8eb6c5..3a633d2 100644 --- a/test/test_I_obh.R +++ b/tests/testthat/test_I_obh.R @@ -7,11 +7,6 @@ # Expected results taken from: # TABLE II. - HOURLY AND DAILY BEAM IN SOLATION ON A HORIZONTAL SURFACE AT TOP OF MARS ATMOSPHERE -library(testthat) -library(here) - -Iobh_eq = dget(here("functions", "I_obh.R")) - phi = 22.3 nfft = 3 @@ -26,7 +21,7 @@ expected_results = list( "249" = c(496, 455, 376, 263, 126, 8, 0), "299" = c(478, 439, 364, 257, 127, 19, 0)) -test_that("Equation 11 (1990): I_obh.", { +test_that("I_obh.", { expected_result_index = 1 for(expected_result in expected_results){ @@ -34,7 +29,7 @@ test_that("Equation 11 (1990): I_obh.", { hour_index = 1 for(T_start in 12:18){ - Iobh = Iobh_eq(Ls=Ls, phi=phi, T_start=T_start, T_end=T_start+1, nfft=nfft) + Iobh = I_obh(Ls=Ls, phi=phi, T_start=T_start, T_end=T_start+1, nfft=nfft) Iobh_expected = expected_result[hour_index] expect_equal(Iobh, Iobh_expected, tolerance=tolerance, scale=1) diff --git a/test/test_albedo.R b/tests/testthat/test_albedo.R similarity index 94% rename from test/test_albedo.R rename to tests/testthat/test_albedo.R index 79eed14..db91b57 100644 --- a/test/test_albedo.R +++ b/tests/testthat/test_albedo.R @@ -1,7 +1,4 @@ -library(testthat) -library(here) - -source(here("functions", "albedo.R")) +context("Albedo") # From Table I in (1991 Update). test_that("Mars surface albedo.", { diff --git a/test/test_declination.R b/tests/testthat/test_declination.R similarity index 86% rename from test/test_declination.R rename to tests/testthat/test_declination.R index c8b68dc..3b244a5 100644 --- a/test/test_declination.R +++ b/tests/testthat/test_declination.R @@ -1,7 +1,4 @@ -library(testthat) -library(here) - -declination = dget(here("utils", "declination.R")) +context("Declination") test_that("Declination (delta).", { tolerance = 0 diff --git a/test/test_f.R b/tests/testthat/test_f.R similarity index 74% rename from test/test_f.R rename to tests/testthat/test_f.R index 236b801..e2af151 100644 --- a/test/test_f.R +++ b/tests/testthat/test_f.R @@ -1,12 +1,8 @@ - -library(testthat) -library(here) - -source(here("functions", "f.R")) +context("Normalized net flux function") # Assert equals test function. assert = function(x, al, pub_year){ - net_flux = f(Z=x["Z"], tau=x["tau"], al=al, pub_year=pub_year) + net_flux = f(z=x["z"], tau=x["tau"], al=al, pub_year=pub_year) expect_equal(unname(x["netflux"]), net_flux, tolerance=0, scale=1) } @@ -21,12 +17,12 @@ test_that("I_h: Global irradiance on Mars horizontal surface with different norm al = 0.1 # Albedo. - for(Z in Z_seq){ + for(z in Z_seq){ for(tau in tau_seq){ # Calculate global irradiances. - net_flux_1989 = f(Z=Z, tau=tau, al=al, pub_year=1989) - net_flux_1990 = f(Z=Z, tau=tau, al=al, pub_year=1990) + net_flux_1989 = f(z=z, tau=tau, al=al, pub_year=1989) + net_flux_1990 = f(z=z, tau=tau, al=al, pub_year=1990) # Test assert equality. # Normalized net flux values in lookup tables 1989 and 1990 are not exactly equal all the time @@ -40,7 +36,7 @@ test_that("f function - 1990 Update: albedo 0.1.", { # Expected results. expected_results = data.frame( - "Z" = c( 0, 10, 15, 20, 25, 30, 35, 40, 45, 50), + "z" = c( 0, 10, 15, 20, 25, 30, 35, 40, 45, 50), "tau" = c(0.15, 0.55, 1.25, 1.75, 2.20, 3.00, 3.60, 4.50, 5.00, 6.00), "netflux" = c(.875, .802, .678, .592, .518, .411, .337, .257, .212, .154)) @@ -53,7 +49,7 @@ test_that("f function - 1990 Update: albedo 0.4.", { # Expected results. expected_results = data.frame( - "Z" = c( 40, 45, 50, 55, 60, 65, 70, 75, 80, 85), + "z" = c( 40, 45, 50, 55, 60, 65, 70, 75, 80, 85), "tau" = c(0.15, 0.55, 1.25, 1.75, 2.20, 3.00, 3.60, 4.50, 5.00, 6.00), "netflux" = c(.582, .519, .404, .324, .256, .182, .137, .099, .078, .054)) @@ -65,7 +61,7 @@ test_that("f function - 1990 Update: albedo 0.4.", { test_that("f function - analytical: albedo 0.1.", { # Test input parameters. - Z_seq = seq(0, 85, 5) + z_seq = seq(0, 85, 5) tau_seq = c( seq(0.1, 2, 0.05) @@ -77,15 +73,15 @@ test_that("f function - analytical: albedo 0.1.", { al = 0.1 # Albedo # Analytical function should return net flux that is approximately equal to those found in the lookup tables - for(Z in Z_seq){ + for(z in z_seq){ for(tau in tau_seq){ - net_flux_lookup = f(Z=Z, tau=tau, al=al, pub_year=1990) - net_flux_analytical = f(Z=Z, tau=tau, al=al) + net_flux_lookup = f(z=z, tau=tau, al=al, pub_year=1990) + net_flux_analytical = f(z=z, tau=tau, al=al) # Larger divergences for high values of Z. # Maximum error is 7% for Z = 80° or Z = 85°. # Adjust acceptale tolerance accordingly. - tolerance = ifelse(Z >= 65, 0.0471, 0.0171) + tolerance = ifelse(z >= 65, 0.0471, 0.0171) expect_equal(net_flux_lookup, net_flux_analytical, tolerance=tolerance, scale=1) } @@ -96,7 +92,7 @@ test_that("f function - analytical: albedo 0.1.", { test_that("f function - analytical: albedo 0.4.", { # Test input parameters. - Z_seq = seq(0, 85, 5) + z_seq = seq(0, 85, 5) tau_seq = c( seq(0.1, 2, 0.05) @@ -108,15 +104,15 @@ test_that("f function - analytical: albedo 0.4.", { al = 0.4 # Albedo # Analytical function should return net flux that is approximately equal to those found in the lookup tables - for(Z in Z_seq){ + for(z in z_seq){ for(tau in tau_seq){ - net_flux_lookup = f(Z=Z, tau=tau, al=al, pub_year=1990) - net_flux_analytical = f(Z=Z, tau=tau, al=al) + net_flux_lookup = f(z=z, tau=tau, al=al, pub_year=1990) + net_flux_analytical = f(z=z, tau=tau, al=al) - # Larger divergences for high values of Z. - # Maximum error is 7% for Z = 80° or Z = 85°. + # Larger divergences for high values of z. + # Maximum error is 7% for z = 80° or z = 85°. # Adjust acceptale tolerance accordingly. - tolerance = ifelse(Z >= 65, 0.0471, 0.0171) + tolerance = ifelse(z >= 65, 0.0471, 0.0171) expect_equal(net_flux_lookup, net_flux_analytical, tolerance=tolerance, scale=1) } diff --git a/test/test_sunrise.R b/tests/testthat/test_sunrise.R similarity index 98% rename from test/test_sunrise.R rename to tests/testthat/test_sunrise.R index bdef299..6268bab 100644 --- a/test/test_sunrise.R +++ b/tests/testthat/test_sunrise.R @@ -1,7 +1,4 @@ -library(testthat) -library(here) - -source(here("utils", "sunrise.R")) +context("Sunrise") # For a given planetary latitude, the sunrise time is expected to be the same throughout the entire year # for all orientations when on a horizontal surface. diff --git a/test/run_tests.R b/tests/tmp/run_tests.R similarity index 100% rename from test/run_tests.R rename to tests/tmp/run_tests.R diff --git a/test/test_H_ali.R b/tests/tmp/test_H_ali.R similarity index 100% rename from test/test_H_ali.R rename to tests/tmp/test_H_ali.R diff --git a/test/test_H_bh.R b/tests/tmp/test_H_bh.R similarity index 100% rename from test/test_H_bh.R rename to tests/tmp/test_H_bh.R diff --git a/test/test_H_bi.R b/tests/tmp/test_H_bi.R similarity index 100% rename from test/test_H_bi.R rename to tests/tmp/test_H_bi.R diff --git a/test/test_H_dh.R b/tests/tmp/test_H_dh.R similarity index 100% rename from test/test_H_dh.R rename to tests/tmp/test_H_dh.R diff --git a/test/test_H_di.R b/tests/tmp/test_H_di.R similarity index 100% rename from test/test_H_di.R rename to tests/tmp/test_H_di.R diff --git a/test/test_H_h.R b/tests/tmp/test_H_h.R similarity index 100% rename from test/test_H_h.R rename to tests/tmp/test_H_h.R diff --git a/test/test_H_i.R b/tests/tmp/test_H_i.R similarity index 100% rename from test/test_H_i.R rename to tests/tmp/test_H_i.R diff --git a/test/test_H_obh.R b/tests/tmp/test_H_obh.R similarity index 100% rename from test/test_H_obh.R rename to tests/tmp/test_H_obh.R