-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpenmanmonteith.php
544 lines (480 loc) · 20.5 KB
/
penmanmonteith.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<?php
/*
* Summary:
* A PHP implementation of the United Nations Food and Agriculture Organization (FAO)
* Penman-Monteith evapotranspiration equation.
*
* For more information see:
* 1) http://en.wikipedia.org/wiki/Penman%E2%80%93Monteith_equation
* 2) http://www.fao.org/docrep/X0490E/x0490e00.htm
* 3) http://www.fao.org/nr/water/eto.html
*
* Description:
* Calculates estimated evapotranspiration from a surface using meteorological data.
* Requires, elevation, latitude, min and max temperature, min and max humidity and windspeed.
* A 24 hour calculation period is assumed.
*
* License:
* Copyright 2009 Allan Glen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class PenmanMonteith
{
// The elevation of the weather station
public $elevationFeet = 0;
// The latitude of the weather station in degrees
public $latitude = 0;
// The albedo of the surface. The default albedo (0.23) is based on a reference crop of 0.12 meters
// and is commonly used for short grass surfaces
public $albedo = 0.23;
// Solar radiation factor for overcast and cloudy
private $fractionOfRadiationOvercast = 0.25;
private $fractionOfRadiationClear = 0.5;
/*
* Description:
* Calculate the evapotranspiration for a 24 hour period.
*
* Parameters:
* $temperatureMinF - Minimum temperature in farenheit
* $temperatureMaxF - Maximum temperature in farenheit
* $relativeHumidityMin - Minimum relative humidity (percent)
* $relativeHumidityMax - Maximum relative humidity (percent)
* $windspeedMilesPerHour - Wind speed in miles per hour
*
* Returns:
* Estimated evapotranspiration in inches rounded to 3 decimal places.
*/
public function calculateEvapotranspiration($temperatureMinF,$temperatureMaxF,$relativeHumidityMin,
$relativeHumidityMax, $windspeedMilesPerHour) {
// Get the day of the year
$dayOfYear = $this->dayOfYear();
// Convert input values to metric
$elevationMeters = $this->feetToMeters($this->elevationFeet);
$temperatureMinC = $this->farenheitToCelcius($temperatureMinF);
$temperatureMaxC = $this->farenheitToCelcius($temperatureMaxF);
$temperatureMeanC = $this->mean($temperatureMinC,$temperatureMaxC);
$windspeedMetersPerSecond = $this->milesPerHourToMetersPerSecond($windspeedMilesPerHour);
// Calculate meteorological parameters for Penman-Monteith equation
$atmosphericPressure = $this->atmosphericPressure($elevationMeters);
$psychrometricConstant = $this->psychrometricConstant($atmosphericPressure);
$saturationVapourPressureMin = $this->saturationVapourPressure($temperatureMinC);
$saturationVapourPressureMax = $this->saturationVapourPressure($temperatureMaxC);
$saturationVapourPressureMean = $this->mean($saturationVapourPressureMin,$saturationVapourPressureMax);
$slopeOfSaturationVapourPressureCurve = $this->slopeOfSaturationVapourPressureCurve($saturationVapourPressureMean);
$actualVapourPressure = $this->actualVapourPressure($saturationVapourPressureMin,
$saturationVapourPressureMax,
$relativeHumidityMin,
$relativeHumidityMax);
$vapourPressureDeficit = $this->vapourPressureDeficit($saturationVapourPressureMin,
$saturationVapourPressureMax,
$actualVapourPressure);
// Calculate solar radiation paramters for Penman-Monteith equation
$inverseRelativeDistanceEarthSun = $this->inverseRelativeDistanceEarthSun($dayOfYear);
$solarDeclination = $this->solarDeclination($dayOfYear);
$sunsetHourAngle = $this->sunsetHourAngle($this->latitude,$solarDeclination);
$extraterrestrialRadiationDaily = $this->extraterrestrialRadiationDaily($inverseRelativeDistanceEarthSun,
$sunsetHourAngle,
$this->latitude,
$solarDeclination);
$daylightHours = $this->daylightHours($sunsetHourAngle);
$clearSkySolarRadiation = $this->solarRadiation($daylightHours,$daylightHours,
$extraterrestrialRadiationDaily);
// Note: Clear sky is assumed for the purposes of this estimate as actual sunshine hours are not typically available
// The difference is not significant as changes in direct sunlight typically result in lower temperatures and
// higher humidity.
$actualSunshineHours = $daylightHours;
$incomingSolarRadiation = $this->solarRadiation($actualSunshineHours,$daylightHours,
$extraterrestrialRadiationDaily);
$netSolarRadiation = $this->netSolarRadiation($this->albedo,$incomingSolarRadiation);
$netLongwaveRadiation = $this->netLongwaveRadiation($temperatureMinC,
$temperatureMaxC,
$actualVapourPressure,
$incomingSolarRadiation,
$clearSkySolarRadiation);
$netRadiation = $this->netRadiation($netSolarRadiation,$netLongwaveRadiation);
// Calculation the evapotranspiration (metric)
$evapotranspirationMm = $this->penmanMoneteithEvapotranspiration($slopeOfSaturationVapourPressureCurve,
$netRadiation,
$psychrometricConstant,
$temperatureMeanC,
$windspeedMetersPerSecond,
$vapourPressureDeficit);
// Convert evapotranpiration to inches
$evapotranspirationIn = $this->mmToIn($evapotranspirationMm);
return round($evapotranspirationIn,3);
}
/*
* Description:
* Calculate the estimated evapotranspiration in millimeters for a 24 hour period.
*
* Parameters:
* $slopeOfSaturationVapourPressureCurve - Slope of the saturation vapour pressure curve
* $netRadiation - Net radiation for the 24 hour period
* $psychrometricConstant - The psychrometric constant
* $temperatureMeanC - Mean daily temperature in celcius
* $windspeedMetersPerSecond - Wind speed in meters per second
* $vapourPressureDeficit - Vapour pressure defecit
*
* Returns:
* Estimated evapotranspiration in millimeters.
*/
private function penmanMoneteithEvapotranspiration($slopeOfSaturationVapourPressureCurve,
$netRadiation,
$psychrometricConstant,
$temperatureMeanC,
$windspeedMetersPerSecond,
$vapourPressureDeficit) {
$numerator = (0.408 * $slopeOfSaturationVapourPressureCurve * $netRadiation) +
($psychrometricConstant * (900 / ($temperatureMeanC + 273)) * $windspeedMetersPerSecond * $vapourPressureDeficit);
$denominator = $slopeOfSaturationVapourPressureCurve + ($psychrometricConstant * (1 + (0.34 * $windspeedMetersPerSecond)));
return $numerator / $denominator;
}
/*
* Description:
* Convert farenheit to celcius.
*
* Parameters:
* $farenheit - Temperature in farenheit
*
* Returns:
* Temperature in celcius.
*/
private function farenheitToCelcius($farenheit) {
return ($farenheit - 32) * (5/9);
}
/*
* Description:
* Convert celcius to kelvin.
*
* Parameters:
* $celcius - Temperature in celcius
*
* Returns:
* Temperature in kelvin.
*/
private function celciusToKelvin($celcius) {
return $celcius + 273.16;
}
/*
* Description:
* Convert feet to meters.
*
* Parameters:
* $feet - Distance in feet
*
* Returns:
* Distance in meters.
*/
private function feetToMeters($feet) {
return $feet * 0.3048;
}
/*
* Description:
* Convert miles per hour to meters per second.
*
* Parameters:
* $milesPerHour - Miles per hours
*
* Returns:
* Speed in meters per second.
*/
private function milesPerHourToMetersPerSecond($milesPerHour) {
return $milesPerHour * 0.44704;
}
/*
* Description:
* Convert millimeters to inches.
*
* Parameters:
* $mm - Millimeters
*
* Returns:
* Distance in inches.
*/
private function mmToIn($mm) {
return $mm * 0.0393700787;
}
/*
* Description:
* Returns the current day of the year based on the system clock.
*
* Returns:
* Day of the year where 1 is the first day of the year.
*/
private function dayOfYear() {
return date("z") + 1;
}
/*
* Description:
* Calculates the estimated atmospheric pressure at a specific elevation based on the ideal gas law at 20 degrees C.
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#atmospheric parameters
*
* Parameters:
* $elevationMeters - Elevation in meters
*
* Returns:
* Atmospheric pressure (kPa)
*/
// Atmospheric pressure (P)
private function atmosphericPressure($elevationMeters) {
return 101.3 * pow(((293 - (0.0065 * $elevationMeters))/293),5.26);
}
/*
* Description:
* Calculates the psychrometric constant atmospheric pressure at a specific elevation based on the ideal gas law at 20 degrees C.
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#psychrometric constant (g)
*
* Parameters:
* $atmosphericPressure - Atmospheric pressure in kPa
*
* Returns:
* Psychrometric constant (kPa °C-1)
*/
private function psychrometricConstant($atmosphericPressure)
{
return 0.000665 * $atmosphericPressure;
}
/*
* Description:
* Calculates the saturation vapour pressure at a specified temperature
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#air humidity
*
* Parameters:
* $temperatureC - Temperature in celcius
*
* Returns:
* Saturation vapour pressure (kPa)
*/
private function saturationVapourPressure($temperatureC) {
return 0.6108 * exp((17.27 * $temperatureC) / ($temperatureC + 237.3));
}
/*
* Description:
* Calculate the mean (average) of two values)
*
* Parameters:
* $value1 - The first value
* $value2 - The second value
*
* Returns:
* The mean of the two parameters
*/
private function mean($value1, $value2) {
return ($value1 + $value2) / 2;
}
/*
* Description:
* Calculates the slope of the saturation vapour pressure curve at a specified temperature
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#air humidity
*
* Parameters:
* $temperatureC - Temperature in celcius
*
* Returns:
* Slope of the saturation vapour pressure curve (kPa °C-1)
*/
private function slopeOfSaturationVapourPressureCurve($temperatureC) {
return (4098 * $this->saturationVapourPressure($temperatureC)) / pow(($temperatureC + 237.3),2);
}
/*
* Description:
* Calculates the actual vapour pressure
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#air humidity
*
* Parameters:
* $saturationVapourPressureMin - Minimum saturation vapour pressure (kPa)
* $saturationVapourPressureMax - Maximum saturation vapour pressure (kPa)
* $relativeHumidityMin - Minimum relative humidity (%)
* $relativeHumidityMax - Masimum relative humidity (%)
*
* Returns:
* Actual vapour pressure (kPa)
*/
private function actualVapourPressure($saturationVapourPressureMin,$saturationVapourPressureMax,
$relativeHumidityMin,$relativeHumidityMax) {
return $this->mean($saturationVapourPressureMin * ($relativeHumidityMax / 100),
$saturationVapourPressureMax * ($relativeHumidityMin / 100));
}
/*
* Description:
* Calculates the vapour pressure deficit
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#air humidity
*
* Parameters:
* $saturationVapourPressureMin - Minimum saturation vapour pressure (kPa)
* $saturationVapourPressureMax - Maximum saturation vapour pressure (kPa)
* $actualVapourPressure - Actual vapour pressure (kPa)
*
* Returns:
* Vapour pressure deficit (kPa)
*/
private function vapourPressureDeficit($saturationVapourPressureMin,$saturationVapourPressureMax,
$actualVapourPressure) {
return $this->mean($saturationVapourPressureMin,$saturationVapourPressureMax) - $actualVapourPressure;
}
/*
* Description:
* Calculates the daily extraterrestrial radiation at a specific latitude at a specific time of year
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $inverseRelativeDistanceEarthSun - Inverse relative distance Earth-Sun
* $sunsetHourAngle - Sunset hour angle (radians)
* $latitude - Latitude (degrees)
* $solarDeclination - Solar declination (radians)
*
* Returns:
* Extraterrestrial radiation (MJ m-2 day-1)
*/
private function extraterrestrialRadiationDaily($inverseRelativeDistanceEarthSun, $sunsetHourAngle, $latitude, $solarDeclination) {
$solarConstant = 0.0820;
$angleCalculation = ($sunsetHourAngle * sin(deg2rad($latitude)) * sin($solarDeclination)) +
(cos(deg2rad($latitude)) * cos($solarDeclination) * sin($sunsetHourAngle));
return ((24 * 60) / pi()) * $solarConstant * $inverseRelativeDistanceEarthSun * ( $angleCalculation );
}
/*
* Description:
* Calculates the inverse relative distance earth-sun based on the day of the year.
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $dayOfYear - Day of the year where 1 is the first day of the year
*
* Returns:
* Inverse relative distance earth-sun (radians)
*/
private function inverseRelativeDistanceEarthSun($dayOfYear) {
return 1 + (0.033 * cos(((2 * pi()) / 365) * $dayOfYear));
}
/*
* Description:
* Calculates the solar declination based on the day of the year.
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $dayOfYear - Day of the year where 1 is the first day of the year
*
* Returns:
* Solar declination (radians)
*/
private function solarDeclination($dayOfYear) {
return 0.409 * sin((((2 * pi())/365)*$dayOfYear)-1.39);
}
/*
* Description:
* Calculates the sunset hour angle based on the latitude and the solar declination
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $latitude - Latitude (degrees)
* $solarDeclination - Solar declination (radians)
*
* Returns:
* Sunset hour angle (radians)
*/
private function sunsetHourAngle($latitude,$solarDeclination) {
return acos(-tan(deg2rad($latitude)) * tan($solarDeclination));
}
/*
* Description:
* Calculates the daylight hours given the sunset hour angle
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $sunsetHourAngle - Sunset hour angle (radians)
*
* Returns:
* Daylight hours
*/
private function daylightHours($sunsetHourAngle) {
return (24 / pi()) * $sunsetHourAngle;
}
/*
* Description:
* Calculates the solar radiation
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $sunshineHoursActual - Actual sunshine hours
* $sunshineHoursMax - Maximum sunshine hours
* $extraterrestrialRadiationDaily - Daily extraterrestrial radiation (MJ m-2 day-1)
*
* Returns:
* Daylight hours
*/
private function solarRadiation($sunshineHoursActual,$sunshineHoursMax,$extraterrestrialRadiationDaily) {
$fractionOfRadiationOvercast = $this->fractionOfRadiationOvercast;
$fractionOfRadiationClear = $this->fractionOfRadiationClear;
return ($fractionOfRadiationOvercast + ($fractionOfRadiationClear*($sunshineHoursActual / $sunshineHoursMax))) *
$extraterrestrialRadiationDaily;
}
/*
* Description:
* Calculates the net solar radiation
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $albedo - Albedo of the surface
* $incomingSolarRadiation - Incoming solar radiation (MJ m-2 day-1)
*
* Returns:
* Net solar radiation (MJ m-2 day-1)
*/
private function netSolarRadiation($albedo,$incomingSolarRadiation) {
return (1 - $albedo) * $incomingSolarRadiation;
}
/*
* Description:
* Calculates the net longwave radiation
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $temperatureMinC - Minimum temperature (C)
* $temperatureMaxC - Maximum temperature (C)
* $actualVapourPressure - Actual vapour pressure (kPa)
* $incomingSolarRadiation - Incoming solar radiation (MJ m-2 day-1)
* $clearSkySolarRadiation - Clear sky solar radiation (MJ m-2 day-1)
*
* Returns:
* Net longwave radiation (MJ m-2 day-1)
*/
private function netLongwaveRadiation($temperatureMinC,$temperatureMaxC,$actualVapourPressure,$incomingSolarRadiation,$clearSkySolarRadiation) {
// Convert temperature to kelvin
$temperatureMinK = $this->celciusToKelvin($temperatureMinC);
$temperatureMaxK = $this->celciusToKelvin($temperatureMaxC);
// Calculate the average temperature to the 4th power
$temperatureAvgFourthPower = (pow($temperatureMinK,4) + pow($temperatureMaxK,4)) / 2;
// Calculate the relative shortwave radiation
$relativeShortwaveRadiation = $incomingSolarRadiation / $clearSkySolarRadiation;
// Calculate the net longwave radiation
return 0.000000004903 * $temperatureAvgFourthPower *
(0.34 - (0.14 * sqrt($actualVapourPressure))) * ((1.35 * $relativeShortwaveRadiation) - 0.35);
}
/*
* Description:
* Calculates the net radiation
* See http://www.fao.org/docrep/X0490E/x0490e07.htm#radiation
*
* Parameters:
* $netSolarRadiation - Net solar radiation (MJ m-2 day-1)
* $netLongwaveRadiation - Net longwave radiation (MJ m-2 day-1)
*
* Returns:
* Net radiation (MJ m-2 day-1)
*/
private function netRadiation($netSolarRadiation,$netLongwaveRadiation) {
return $netSolarRadiation - $netLongwaveRadiation;
}
}
?>