evapotranspiration 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/evapotranspiration/conversion.rb +12 -4
- data/lib/evapotranspiration/fao.rb +55 -54
- data/lib/evapotranspiration/validation.rb +1 -1
- data/lib/evapotranspiration/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe22de7f8fb700fe5944060729cc7532a6e8b6c5
|
|
4
|
+
data.tar.gz: 5279f9560e1bfcac668151c803caab6f44209d56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 141d14c443b79e2636212c2bd187323e8a38b641fbba4f376f3b0534a07e9f4c9f9a10e2d66e412d46f903021ffea279eb3d00867bba6a4f1d5838a3ea4fa17f
|
|
7
|
+
data.tar.gz: 88f97d5e363d2abe28a7ecd53a4758cc13e6cc3c25af23e4696ba6b73172b8632cce9d578199875c2fe53e416c2880de5d45b8416021d2468ee5de24d05dd008
|
|
@@ -6,7 +6,7 @@ module Evapotranspiration
|
|
|
6
6
|
# @param celsius [Float] Degrees Celsius
|
|
7
7
|
# @return [Float] Degrees Kelvin
|
|
8
8
|
def self.celsius_to_kelvin(celsius)
|
|
9
|
-
celsius + 273.15
|
|
9
|
+
celsius.to_f + 273.15
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
# Convert temperature in degrees Kelvin to degrees Celsius
|
|
@@ -14,7 +14,7 @@ module Evapotranspiration
|
|
|
14
14
|
# @param kelvin [Float] Degrees Kelvin
|
|
15
15
|
# @return [Float] Degrees Celsius
|
|
16
16
|
def self.kelvin_to_celsius(kelvin)
|
|
17
|
-
kelvin - 273.15
|
|
17
|
+
kelvin.to_f - 273.15
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Convert angular degrees to radians
|
|
@@ -22,7 +22,7 @@ module Evapotranspiration
|
|
|
22
22
|
# @param degrees [Float] Value in degrees to be converted
|
|
23
23
|
# @return [Float] Value in radians
|
|
24
24
|
def self.deg_to_rad(degrees)
|
|
25
|
-
degrees * (Math::PI / 180.0)
|
|
25
|
+
degrees.to_f * (Math::PI / 180.0)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# Convert radians to angular degrees
|
|
@@ -30,7 +30,15 @@ module Evapotranspiration
|
|
|
30
30
|
# @param radians [Float] Value in radians to be converted
|
|
31
31
|
# @return [Float] Value in angular degrees
|
|
32
32
|
def self.rad_to_deg(radians)
|
|
33
|
-
radians * (180.0 / Math::PI)
|
|
33
|
+
radians.to_f * (180.0 / Math::PI)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Convert km/hr to m/s
|
|
37
|
+
#
|
|
38
|
+
# @param kph [Float] Kilometers per hour
|
|
39
|
+
# @return [Float] Meters per second
|
|
40
|
+
def self.kph_to_mps(kph)
|
|
41
|
+
(kph.to_f * 1000) / 3600
|
|
34
42
|
end
|
|
35
43
|
|
|
36
44
|
end
|
|
@@ -24,8 +24,8 @@ module Evapotranspiration
|
|
|
24
24
|
# @param altitude [Float] Elevation/altitude above sea level (m)
|
|
25
25
|
# @return [Float] atmospheric pressure (kPa)
|
|
26
26
|
def self.atm_pressure(altitude)
|
|
27
|
-
tmp = (293.0 - (0.0065 * altitude)) / 293.0
|
|
28
|
-
return (tmp ** 5.26) * 101.3
|
|
27
|
+
tmp = (293.0 - (0.0065 * altitude.to_f)) / 293.0
|
|
28
|
+
return (tmp.to_f ** 5.26) * 101.3
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# Estimate actual vapour pressure (*ea*) from minimum temperature.
|
|
@@ -44,7 +44,7 @@ module Evapotranspiration
|
|
|
44
44
|
# @param tmin [Float] Daily minimum temperature (deg C)
|
|
45
45
|
# @return [Float] Actual vapour pressure (kPa)
|
|
46
46
|
def self.avp_from_tmin(tmin)
|
|
47
|
-
return 0.611 * Math.exp((17.27 * tmin) / (tmin + 237.3))
|
|
47
|
+
return 0.611 * Math.exp((17.27 * tmin.to_f) / (tmin.to_f + 237.3))
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
# Estimate actual vapour pressure (*ea*) from saturation vapour pressure and
|
|
@@ -60,9 +60,9 @@ module Evapotranspiration
|
|
|
60
60
|
# @param rh_max [Float] Maximum relative humidity (%)
|
|
61
61
|
# @return [Float] Actual vapour pressure (kPa)
|
|
62
62
|
def self.avp_from_rhmin_rhmax(svp_tmin, svp_tmax, rh_min, rh_max)
|
|
63
|
-
tmp1 = svp_tmin * (rh_max / 100.0)
|
|
64
|
-
tmp2 = svp_tmax * (rh_min / 100.0)
|
|
65
|
-
return (tmp1 + tmp2) / 2.0
|
|
63
|
+
tmp1 = svp_tmin.to_f * (rh_max.to_f / 100.0)
|
|
64
|
+
tmp2 = svp_tmax.to_f * (rh_min.to_f / 100.0)
|
|
65
|
+
return (tmp1.to_f + tmp2.to_f) / 2.0
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# Estimate actual vapour pressure (*ea*) from saturation vapour pressure at
|
|
@@ -75,7 +75,7 @@ module Evapotranspiration
|
|
|
75
75
|
# @param rh_max [Float] Maximum relative humidity (%)
|
|
76
76
|
# @return [Float] Actual vapour pressure (kPa)
|
|
77
77
|
def self.avp_from_rhmax(svp_tmin, rh_max)
|
|
78
|
-
return svp_tmin * (rh_max / 100.0)
|
|
78
|
+
return svp_tmin.to_f * (rh_max.to_f / 100.0)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
# Estimate actual vapour pressure (*e*a) from saturation vapour pressure at
|
|
@@ -87,9 +87,10 @@ module Evapotranspiration
|
|
|
87
87
|
# temperature (kPa). Can be estimated using svp_from_t()
|
|
88
88
|
# @param svp_tmax [Float] Saturation vapour pressure at daily maximum
|
|
89
89
|
# temperature (kPa). Can be estimated using svp_from_t()
|
|
90
|
+
# @param rh_mean [Float] Mean relative humidity (%) (average of RH min and RH max).
|
|
90
91
|
# @return [Float] Actual vapour pressure (kPa)
|
|
91
92
|
def self.avp_from_rhmean(svp_tmin, svp_tmax, rh_mean)
|
|
92
|
-
return (rh_mean / 100.0) * ((svp_tmax + svp_tmin) / 2.0)
|
|
93
|
+
return (rh_mean.to_f / 100.0) * ((svp_tmax.to_f + svp_tmin.to_f) / 2.0)
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
# Estimate actual vapour pressure (*ea*) from dewpoint temperature.
|
|
@@ -105,7 +106,7 @@ module Evapotranspiration
|
|
|
105
106
|
# @param tdew [Float] Dewpoint temperature (deg C)
|
|
106
107
|
# @return [Float] Actual vapour pressure (kPa)
|
|
107
108
|
def self.avp_from_tdew(tdew)
|
|
108
|
-
return 0.6108 * Math.exp((17.27 * tdew) / (tdew + 237.3))
|
|
109
|
+
return 0.6108 * Math.exp((17.27 * tdew.to_f) / (tdew.to_f + 237.3))
|
|
109
110
|
end
|
|
110
111
|
|
|
111
112
|
# Estimate actual vapour pressure (*ea*) from wet and dry bulb temperature.
|
|
@@ -130,7 +131,7 @@ module Evapotranspiration
|
|
|
130
131
|
# psy_const_of_psychrometer()
|
|
131
132
|
# @return [Float] Actual vapour pressure (kPa)
|
|
132
133
|
def self.avp_from_twet_tdry(twet, tdry, svp_twet, psy_const)
|
|
133
|
-
return svp_twet - (psy_const * (tdry - twet))
|
|
134
|
+
return svp_twet.to_f - (psy_const.to_f * (tdry.to_f - twet.to_f))
|
|
134
135
|
end
|
|
135
136
|
|
|
136
137
|
# Estimate clear sky radiation from altitude and extraterrestrial radiation.
|
|
@@ -143,7 +144,7 @@ module Evapotranspiration
|
|
|
143
144
|
# estimated using et_rad()
|
|
144
145
|
# @return [Float] Clear sky radiation (MJ m-2 day-1)
|
|
145
146
|
def self.cs_rad(altitude, et_rad)
|
|
146
|
-
return (0.00002 * altitude + 0.75) * et_rad
|
|
147
|
+
return (0.00002 * altitude.to_f + 0.75) * et_rad.to_f
|
|
147
148
|
end
|
|
148
149
|
|
|
149
150
|
# Estimate mean daily temperature from the daily minimum and maximum
|
|
@@ -153,7 +154,7 @@ module Evapotranspiration
|
|
|
153
154
|
# @param tmax [Float] Maximum daily temperature (deg C)
|
|
154
155
|
# @return [Float] Mean daily temperature (deg C)
|
|
155
156
|
def self.daily_mean_t(tmin, tmax)
|
|
156
|
-
return (tmax + tmin) / 2.0
|
|
157
|
+
return (tmax.to_f + tmin.to_f) / 2.0
|
|
157
158
|
end
|
|
158
159
|
|
|
159
160
|
# Calculate daylight hours from sunset hour angle.
|
|
@@ -165,7 +166,7 @@ module Evapotranspiration
|
|
|
165
166
|
# @return [Float] Daylight hours
|
|
166
167
|
def self.daylight_hours(sha)
|
|
167
168
|
Validation.check_sunset_hour_angle_rad(sha)
|
|
168
|
-
return (24.0 / Math::PI) * sha
|
|
169
|
+
return (24.0 / Math::PI) * sha.to_f
|
|
169
170
|
end
|
|
170
171
|
|
|
171
172
|
# Estimate the slope of the saturation vapour pressure curve at a given
|
|
@@ -178,8 +179,8 @@ module Evapotranspiration
|
|
|
178
179
|
# use in Penman-Monteith
|
|
179
180
|
# @return [Float] Saturation vapour pressure (kPa degC-1)
|
|
180
181
|
def self.delta_svp(t)
|
|
181
|
-
tmp = 4098 * (0.6108 * Math.exp((17.27 * t) / (t + 237.3)))
|
|
182
|
-
return tmp / ((t + 237.3) ** 2)
|
|
182
|
+
tmp = 4098 * (0.6108 * Math.exp((17.27 * t.to_f) / (t.to_f + 237.3)))
|
|
183
|
+
return tmp.to_f / ((t.to_f + 237.3) ** 2)
|
|
183
184
|
end
|
|
184
185
|
|
|
185
186
|
# Convert energy (e.g. radiation energy) in MJ m-2 day-1 to the equivalent
|
|
@@ -194,7 +195,7 @@ module Evapotranspiration
|
|
|
194
195
|
# @param energy [Float] Energy e.g. radiation or heat flux (MJ m-2 day-1)
|
|
195
196
|
# @return [Float] Equivalent evaporation (mm day-1)
|
|
196
197
|
def self.energy2evap(energy)
|
|
197
|
-
return 0.408 * energy
|
|
198
|
+
return 0.408 * energy.to_f
|
|
198
199
|
end
|
|
199
200
|
|
|
200
201
|
# Estimate daily extraterrestrial radiation (*Ra*, 'top of the atmosphere
|
|
@@ -223,9 +224,9 @@ module Evapotranspiration
|
|
|
223
224
|
Validation.check_sunset_hour_angle_rad(sha)
|
|
224
225
|
|
|
225
226
|
tmp1 = (24.0 * 60.0) / Math::PI
|
|
226
|
-
tmp2 = sha * Math.sin(latitude) * Math.sin(sol_dec)
|
|
227
|
-
tmp3 = Math.cos(latitude) * Math.cos(sol_dec) * Math.sin(sha)
|
|
228
|
-
return tmp1 * SOLAR_CONSTANT * ird * (tmp2 + tmp3)
|
|
227
|
+
tmp2 = sha.to_f * Math.sin(latitude) * Math.sin(sol_dec.to_f)
|
|
228
|
+
tmp3 = Math.cos(latitude.to_f) * Math.cos(sol_dec.to_f) * Math.sin(sha.to_f)
|
|
229
|
+
return tmp1.to_f * SOLAR_CONSTANT * ird.to_f * (tmp2.to_f + tmp3.to_f)
|
|
229
230
|
end
|
|
230
231
|
|
|
231
232
|
# Estimate reference evapotranspiration (ETo) from a hypothetical
|
|
@@ -253,9 +254,9 @@ module Evapotranspiration
|
|
|
253
254
|
# @return [Float] Reference evapotranspiration (ETo) from a hypothetical
|
|
254
255
|
# grass reference surface (mm day-1)
|
|
255
256
|
def self.fao56_penman_monteith(net_rad, t, ws, svp, avp, delta_svp, psy, shf=0.0)
|
|
256
|
-
a1 = (0.408 * (net_rad - shf) * delta_svp / delta_svp + (psy * (1 + 0.34 * ws)))
|
|
257
|
-
a2 = (900 * ws / t * (svp - avp) * psy / (delta_svp + (psy * (1 + 0.34 * ws))))
|
|
258
|
-
return a1 + a2
|
|
257
|
+
a1 = (0.408 * (net_rad.to_f - shf.to_f) * delta_svp.to_f / delta_svp.to_f + (psy.to_f * (1 + 0.34 * ws.to_f)))
|
|
258
|
+
a2 = (900 * ws.to_f / t.to_f * (svp.to_f - avp.to_f) * psy.to_f / (delta_svp.to_f + (psy.to_f * (1 + 0.34 * ws.to_f))))
|
|
259
|
+
return a1.to_f + a2.to_f
|
|
259
260
|
end
|
|
260
261
|
|
|
261
262
|
# Estimate reference evapotranspiration over grass (ETo) using the Hargreaves
|
|
@@ -280,7 +281,7 @@ module Evapotranspiration
|
|
|
280
281
|
# Note, multiplied by 0.408 to convert extraterrestrial radiation could
|
|
281
282
|
# be given in MJ m-2 day-1 rather than as equivalent evaporation in
|
|
282
283
|
# mm day-1
|
|
283
|
-
return 0.0023 * (tmean + 17.8) * (tmax - tmin) ** 0.5 * 0.408 * et_rad
|
|
284
|
+
return 0.0023 * (tmean.to_f + 17.8) * (tmax.to_f - tmin.to_f) ** 0.5 * 0.408 * et_rad.to_f
|
|
284
285
|
end
|
|
285
286
|
|
|
286
287
|
# Calculate the inverse relative distance between earth and sun from
|
|
@@ -292,7 +293,7 @@ module Evapotranspiration
|
|
|
292
293
|
# @return [Float] Inverse relative distance between earth and the sun
|
|
293
294
|
def self.inv_rel_dist_earth_sun(day_of_year)
|
|
294
295
|
Validation.check_doy(day_of_year)
|
|
295
|
-
return 1 + (0.033 * Math.cos((2.0 * Math::PI / 365.0) * day_of_year))
|
|
296
|
+
return 1 + (0.033 * Math.cos((2.0 * Math::PI / 365.0) * day_of_year.to_f))
|
|
296
297
|
end
|
|
297
298
|
|
|
298
299
|
# Estimate mean saturation vapour pressure, *es* [kPa] from minimum and
|
|
@@ -308,16 +309,16 @@ module Evapotranspiration
|
|
|
308
309
|
# @param tmax [Float] Maximum temperature (deg C)
|
|
309
310
|
# @return [Float] Mean saturation vapour pressure (*es*) (kPa)
|
|
310
311
|
def self.mean_svp(tmin, tmax)
|
|
311
|
-
return (svp_from_t(tmin) + svp_from_t(tmax)) / 2.0
|
|
312
|
+
return (self.svp_from_t(tmin.to_f) + self.svp_from_t(tmax.to_f)) / 2.0
|
|
312
313
|
end
|
|
313
314
|
|
|
314
|
-
# Estimate monthly soil heat flux (Gmonth)
|
|
315
|
-
#
|
|
315
|
+
# Estimate monthly soil heat flux (Gmonth) from the mean air temperature of
|
|
316
|
+
# the previous and next month, assuming a grass crop.
|
|
316
317
|
#
|
|
317
|
-
# Based on equation
|
|
318
|
-
# next month is
|
|
319
|
-
# resulting heat flux can be converted to equivalent evaporation
|
|
320
|
-
# using
|
|
318
|
+
# Based on equation 43 in Allen et al (1998). If the air temperature of the
|
|
319
|
+
# next month is not known use monthly_soil_heat_flux2 instead. The
|
|
320
|
+
# resulting heat flux can be converted to equivalent evaporation [mm day-1]
|
|
321
|
+
# using energy_2_evap.
|
|
321
322
|
#
|
|
322
323
|
# @param t_month_prev [Float] Mean air temperature of the previous month
|
|
323
324
|
# (deg Celsius)
|
|
@@ -325,24 +326,24 @@ module Evapotranspiration
|
|
|
325
326
|
# (deg Celsius)
|
|
326
327
|
# @return [Float] Monthly soil heat flux (Gmonth) (MJ m-2 day-1)
|
|
327
328
|
def self.monthly_soil_heat_flux(t_month_prev, t_month_next)
|
|
328
|
-
return 0.07 * (t_month_next - t_month_prev)
|
|
329
|
+
return 0.07 * (t_month_next.to_f - t_month_prev.to_f)
|
|
329
330
|
end
|
|
330
331
|
|
|
331
332
|
# Estimate monthly soil heat flux (Gmonth) from the mean air temperature of
|
|
332
333
|
# the previous and next month, assuming a grass crop.
|
|
333
334
|
#
|
|
334
335
|
# Based on equation 44 in Allen et al (1998). If the air temperature of the
|
|
335
|
-
# next month is available, use monthly_soil_heat_flux
|
|
336
|
+
# next month is available, use monthly_soil_heat_flux instead. The
|
|
336
337
|
# resulting heat flux can be converted to equivalent evaporation [mm day-1]
|
|
337
|
-
# using
|
|
338
|
+
# using energy_2_evap.
|
|
338
339
|
#
|
|
339
340
|
# @param t_month_prev [Float] Mean air temperature of the previous month
|
|
340
341
|
# (deg Celsius)
|
|
341
|
-
# @param
|
|
342
|
+
# @param t_month_cur [Float] Mean air temperature of the current month
|
|
342
343
|
# (deg Celsius)
|
|
343
344
|
# @return [Float] Monthly soil heat flux (Gmonth) (MJ m-2 day-1)
|
|
344
345
|
def self.monthly_soil_heat_flux2(t_month_prev, t_month_cur)
|
|
345
|
-
return 0.14 * (t_month_cur - t_month_prev)
|
|
346
|
+
return 0.14 * (t_month_cur.to_f - t_month_prev.to_f)
|
|
346
347
|
end
|
|
347
348
|
|
|
348
349
|
# Calculate net incoming solar (or shortwave) radiation from gross
|
|
@@ -366,7 +367,7 @@ module Evapotranspiration
|
|
|
366
367
|
# about 0.20-0.25 (Allen et al, 1998)
|
|
367
368
|
# @return [Float] Net incoming solar (or shortwave) radiation (MJ m-2 day-1)
|
|
368
369
|
def self.net_in_sol_rad(sol_rad, albedo=0.23)
|
|
369
|
-
return (1 - albedo) * sol_rad
|
|
370
|
+
return (1 - albedo.to_f) * sol_rad.to_f
|
|
370
371
|
end
|
|
371
372
|
|
|
372
373
|
# Estimate net outgoing longwave radiation.
|
|
@@ -394,10 +395,10 @@ module Evapotranspiration
|
|
|
394
395
|
# functions with names beginning with 'avp_from'
|
|
395
396
|
# @return [Float] Net outgoing longwave radiation (MJ m-2 day-1)
|
|
396
397
|
def self.net_out_lw_rad(tmin, tmax, sol_rad, cs_rad, avp)
|
|
397
|
-
tmp1 = (STEFAN_BOLTZMANN_CONSTANT * (((tmax ** 4) + (tmin ** 4)) / 2))
|
|
398
|
-
tmp2 = (0.34 - (0.14 * Math.sqrt(avp)))
|
|
399
|
-
tmp3 = 1.35 * (sol_rad / cs_rad) - 0.35
|
|
400
|
-
return tmp1 * tmp2 * tmp3
|
|
398
|
+
tmp1 = (STEFAN_BOLTZMANN_CONSTANT * (((tmax.to_f ** 4) + (tmin.to_f ** 4)) / 2))
|
|
399
|
+
tmp2 = (0.34 - (0.14 * Math.sqrt(avp.to_f)))
|
|
400
|
+
tmp3 = 1.35 * (sol_rad.to_f / cs_rad.to_f) - 0.35
|
|
401
|
+
return tmp1.to_f * tmp2.to_f * tmp3.to_f
|
|
401
402
|
end
|
|
402
403
|
|
|
403
404
|
# Calculate daily net radiation at the crop surface, assuming a grass
|
|
@@ -415,7 +416,7 @@ module Evapotranspiration
|
|
|
415
416
|
# Can be estimated using net_out_lw_rad()
|
|
416
417
|
# @return [Float] Daily net radiation (MJ m-2 day-1)
|
|
417
418
|
def self.net_rad(ni_sw_rad, no_lw_rad)
|
|
418
|
-
return ni_sw_rad - no_lw_rad
|
|
419
|
+
return ni_sw_rad.to_f - no_lw_rad.to_f
|
|
419
420
|
end
|
|
420
421
|
|
|
421
422
|
# Calculate the psychrometric constant.
|
|
@@ -429,7 +430,7 @@ module Evapotranspiration
|
|
|
429
430
|
# using atm_pressure()
|
|
430
431
|
# @return [Float] Psychrometric constant (kPa degC-1)
|
|
431
432
|
def self.psy_const(atmos_pres)
|
|
432
|
-
return 0.000665 * atmos_pres
|
|
433
|
+
return 0.000665 * atmos_pres.to_f
|
|
433
434
|
end
|
|
434
435
|
|
|
435
436
|
# Calculate the psychrometric constant for different types of
|
|
@@ -460,7 +461,7 @@ module Evapotranspiration
|
|
|
460
461
|
raise ArgumentError.new("psychrometer should be in range 1 to 3: #{psychrometer}")
|
|
461
462
|
end
|
|
462
463
|
|
|
463
|
-
return psy_coeff * atmos_pres
|
|
464
|
+
return psy_coeff.to_f * atmos_pres.to_f
|
|
464
465
|
end
|
|
465
466
|
|
|
466
467
|
# Calculate relative humidity as the ratio of actual vapour pressure
|
|
@@ -475,7 +476,7 @@ module Evapotranspiration
|
|
|
475
476
|
# as they are the same as for *avp*). Can be estimated using svp_from_t()
|
|
476
477
|
# @return [Float] Relative humidity (%)
|
|
477
478
|
def self.rh_from_avp_svp(avp, svp)
|
|
478
|
-
return 100.0 * avp / svp
|
|
479
|
+
return 100.0 * avp.to_f / svp.to_f
|
|
479
480
|
end
|
|
480
481
|
|
|
481
482
|
# Calculate solar declination from day of the year.
|
|
@@ -486,7 +487,7 @@ module Evapotranspiration
|
|
|
486
487
|
# @return [Float] solar declination (radians)
|
|
487
488
|
def self.sol_dec(day_of_year)
|
|
488
489
|
Validation.check_doy(day_of_year)
|
|
489
|
-
return 0.409 * Math.sin(((2.0 * Math::PI / 365.0) * day_of_year - 1.39))
|
|
490
|
+
return 0.409 * Math.sin(((2.0 * Math::PI / 365.0) * day_of_year.to_f - 1.39))
|
|
490
491
|
end
|
|
491
492
|
|
|
492
493
|
# Calculate incoming solar (or shortwave) radiation, *Rs* (radiation hitting
|
|
@@ -515,7 +516,7 @@ module Evapotranspiration
|
|
|
515
516
|
|
|
516
517
|
# 0.5 and 0.25 are default values of regression constants (Angstrom values)
|
|
517
518
|
# recommended by FAO when calibrated values are unavailable.
|
|
518
|
-
return (0.5 * sunshine_hours / daylight_hours + 0.25) * et_rad
|
|
519
|
+
return (0.5 * sunshine_hours.to_f / daylight_hours.to_f + 0.25) * et_rad.to_f
|
|
519
520
|
end
|
|
520
521
|
|
|
521
522
|
# Estimate incoming solar (or shortwave) radiation, *Rs*, (radiation hitting
|
|
@@ -550,10 +551,10 @@ module Evapotranspiration
|
|
|
550
551
|
# coastal/interior locations
|
|
551
552
|
adj = coastal ? 0.19 : 0.16
|
|
552
553
|
|
|
553
|
-
sol_rad = adj * Math.sqrt(tmax - tmin) * et_rad
|
|
554
|
+
sol_rad = adj.to_f * Math.sqrt(tmax.to_f - tmin.to_f) * et_rad.to_f
|
|
554
555
|
|
|
555
556
|
# The solar radiation value is constrained by the clear sky radiation
|
|
556
|
-
return [sol_rad, cs_rad].min
|
|
557
|
+
return [sol_rad.to_f, cs_rad.to_f].min
|
|
557
558
|
end
|
|
558
559
|
|
|
559
560
|
# Estimate incoming solar (or shortwave) radiation, *Rs* (radiation hitting
|
|
@@ -573,7 +574,7 @@ module Evapotranspiration
|
|
|
573
574
|
# estimated using et_rad()
|
|
574
575
|
# @return [Float] Incoming solar (or shortwave) radiation (MJ m-2 day-1)
|
|
575
576
|
def self.sol_rad_island(et_rad)
|
|
576
|
-
return (0.7 * et_rad) - 4.0
|
|
577
|
+
return (0.7 * et_rad.to_f) - 4.0
|
|
577
578
|
end
|
|
578
579
|
|
|
579
580
|
# Calculate sunset hour angle (*Ws*) from latitude and solar
|
|
@@ -591,13 +592,13 @@ module Evapotranspiration
|
|
|
591
592
|
Validation.check_latitude_rad(latitude)
|
|
592
593
|
Validation.check_sol_dec_rad(sol_dec)
|
|
593
594
|
|
|
594
|
-
cos_sha = -Math.tan(latitude) * Math.tan(sol_dec)
|
|
595
|
+
cos_sha = -Math.tan(latitude.to_f) * Math.tan(sol_dec.to_f)
|
|
595
596
|
# If tmp is >= 1 there is no sunset, i.e. 24 hours of daylight
|
|
596
597
|
# If tmp is <= 1 there is no sunrise, i.e. 24 hours of darkness
|
|
597
598
|
# See http://www.itacanet.org/the-sun-as-a-source-of-energy/
|
|
598
599
|
# part-3-calculating-solar-angles/
|
|
599
600
|
# Domain of acos is -1 <= x <= 1 radians (this is not mentioned in FAO-56!)
|
|
600
|
-
return Math.acos([[cos_sha, -1.0].max, 1.0].min)
|
|
601
|
+
return Math.acos([[cos_sha.to_f, -1.0].max, 1.0].min)
|
|
601
602
|
end
|
|
602
603
|
|
|
603
604
|
# Estimate saturation vapour pressure (*es*) from air temperature.
|
|
@@ -607,7 +608,7 @@ module Evapotranspiration
|
|
|
607
608
|
# @param t [Float] Temperature (deg C)
|
|
608
609
|
# @return [Float] Saturation vapour pressure (kPa)
|
|
609
610
|
def self.svp_from_t(t)
|
|
610
|
-
return 0.6108 * Math.exp((17.27 * t) / (t + 237.3))
|
|
611
|
+
return 0.6108 * Math.exp((17.27 * t.to_f) / (t.to_f + 237.3))
|
|
611
612
|
end
|
|
612
613
|
|
|
613
614
|
# Convert wind speed measured at different heights above the soil
|
|
@@ -620,7 +621,7 @@ module Evapotranspiration
|
|
|
620
621
|
# @param z [Float] Height of wind measurement above ground surface (m)
|
|
621
622
|
# @return [Float] Wind speed at 2 m above the surface (m s-1)
|
|
622
623
|
def self.wind_speed_2m(ws, z)
|
|
623
|
-
return ws * (4.87 / Math.log((67.8 * z) - 5.42))
|
|
624
|
+
return ws.to_f * (4.87 / Math.log((67.8 * z.to_f) - 5.42))
|
|
624
625
|
end
|
|
625
626
|
|
|
626
627
|
end
|
|
@@ -13,7 +13,7 @@ module Evapotranspiration
|
|
|
13
13
|
|
|
14
14
|
# Sunset hour angle
|
|
15
15
|
MINSHA_RADIANS = 0.0
|
|
16
|
-
MAXSHA_RADIANS = Conversion.deg_to_rad(180)
|
|
16
|
+
MAXSHA_RADIANS = Conversion.deg_to_rad(180.0)
|
|
17
17
|
|
|
18
18
|
# Check that *hours* is in the range 1 to 24
|
|
19
19
|
def self.check_day_hours(hours, arg_name)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: evapotranspiration
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bryce Johnston
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-06-
|
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|