public List <double> GetMonthlyAvgEvapotranspiration() { return(Evapotranspiration.Select(x => x / (((double)Counts[Evapotranspiration.IndexOf(x)]) / 365.25 * 12.0)).ToList()); }
public double GetAnnualAvgEvapotranspiration() { return(Evapotranspiration.Sum() / ((float)Counts.Sum() / 365.25)); }
//public Evapotranspiration Calculate(string wundergroundKey, DateTime inputDate, string pws, double canopyReflectionCoefficient) public Evapotranspiration Calculate(string wundergroundKey, DateTime inputDate, string pws, double canopyReflectionCoefficient) { var url = "http://api.wunderground.com/api/" + wundergroundKey + "/conditions/history_" + inputDate.ToString("yyyyMMdd") + "/q/pws:" + pws + ".json"; var wc = new WebClient(); string json = wc.DownloadString(url); var serializer = new JavaScriptSerializer(); dynamic obj = serializer.DeserializeObject(json); var maxTempF = ParseDouble(obj["history"]["dailysummary"][0]["maxtempi"]); var minTempF = ParseDouble(obj["history"]["dailysummary"][0]["mintempi"]); var solarRadiationReadings = new List <double>(); var observationsArray = (object[])obj["history"]["observations"]; for (var i = observationsArray.Length - 1; i >= 0; i--) { var observations = (Dictionary <string, object>)observationsArray[i]; var solarRadiationReading = ParseDouble(observations["solarradiation"].ToString()); solarRadiationReadings.Add(solarRadiationReading); } var meanSolarRadiationW = solarRadiationReadings.Average(); var avgWindSpeedMPH = ParseDouble(obj["history"]["dailysummary"][0]["meanwindspdi"]); var elevationFt = ParseDouble(obj["current_observation"]["display_location"]["elevation"]) * 3.28084; var maxHumidity = ParseDouble(obj["history"]["dailysummary"][0]["maxhumidity"]); var minHumidity = ParseDouble(obj["history"]["dailysummary"][0]["minhumidity"]); var latitudeDegrees = ParseDouble(obj["current_observation"]["display_location"]["latitude"]); var longitudeDegrees = ParseDouble(obj["current_observation"]["display_location"]["longitude"]); var maxTempC = FtoC(maxTempF); var minTempC = FtoC(minTempF); var elevationM = FttoM(elevationFt); var julianDay = inputDate.DayOfYear; // step 1, mean daily air temperature C var meanDailyAirTemperatureC = new List <double> { maxTempC, minTempC }.Average(); // step 2, mean solar radiation MJ var meanSolarRadiationMJ = MJtoW(meanSolarRadiationW); // step 3, avg wind speed Ms at 2m var avgWindSpeedMs = MPHtoMs(avgWindSpeedMPH); // step 4, slope of saturation vapor pressure curve var saturationVaporPressureCurveSlope = saturationVaporPressureCurveSlopeFn(meanDailyAirTemperatureC); // step 5, atmospheric pressure var atmosphericPressue = atmosphericPressueFn(elevationM); // step 6, psycometric constant var psychrometricConstant = psychrometricConstantFn(atmosphericPressue); // step 7, delta term (DT) var deltaTerm = deltaTermFn(saturationVaporPressureCurveSlope, psychrometricConstant, avgWindSpeedMs); // step 8, psi term (PT) var psiTerm = psiTermFn(saturationVaporPressureCurveSlope, psychrometricConstant, avgWindSpeedMs); // step 9, temperature term (TT) var temperatureTerm = temperatureTermFn(meanDailyAirTemperatureC, avgWindSpeedMs); // step 10, mean saturation vapor pressure curve var saturationVaporPressureMean = new List <double> { saturationVaporFn(maxTempC), saturationVaporFn(minTempC) }.Average(); // step 11, actual vapor pressure var saturationVaporPressureActual = saturationVaporPressureActualFn(minTempC, maxTempC, minHumidity, maxHumidity); // step 11.1, vapor pressure deficit var saturationVaporPressureDeficit = saturationVaporPressureMean - saturationVaporPressureActual; // step 12.1 relative sun earth difference var relativeEarthSunDifference = relativeEarthSunDifferenceFn(julianDay); // step 12.2 relative sun earth difference var solarDeclination = solarDeclinationFn(julianDay); // step 13 latitude radians var latitudeRadians = DEGtoRAD(latitudeDegrees); // step 14 sunset hour angle var sunsetHourAngle = sunsetHourAngleFn(latitudeRadians, solarDeclination); // step 15 extraterrestrial radiation var extraterrestrialRadiation = extraterrestrialRadiationFn(relativeEarthSunDifference, sunsetHourAngle, latitudeRadians, solarDeclination); // step 16 clear sky solar radiation var clearSkySolarRadiation = clearSkySolarRadiationFn(elevationM, extraterrestrialRadiation); // step 17 clear sky solar radiation var netSolarRadiation = (1 - canopyReflectionCoefficient) * meanSolarRadiationMJ; // step 18 Net outgoing long wave solar radiation var netOutgoingLongWaveSolarRadiation = netOutgoingLongWaveSolarRadiationFn(minTempC, maxTempC, saturationVaporPressureActual, meanSolarRadiationMJ, clearSkySolarRadiation); // step 19 net radiation var netRadiation = netSolarRadiation - netOutgoingLongWaveSolarRadiation; // step 19.1 net radiation ng in mm var netRadiationMM = netRadiation * 0.408; // step FS1 radiation term var radiationTerm = deltaTerm * netRadiationMM; // step FS2 wind term var windTerm = psiTerm * temperatureTerm * (saturationVaporPressureMean - saturationVaporPressureActual); // step Final, evapotranspiration value var evapotranspirationMM = radiationTerm + windTerm; var evapotranspirationIN = evapotranspirationMM * 0.0393701; var evapoObject = new Evapotranspiration { AvgDailyAirTemperatureC = meanDailyAirTemperatureC, AvgSolarRadiationMJ = meanSolarRadiationMJ, AvgWindSpeedMs = avgWindSpeedMs, SaturationVaporPressureCurveSlope = saturationVaporPressureCurveSlope, AtmosphericPressue = atmosphericPressue, PsychrometricConstant = psychrometricConstant, DeltaTerm = deltaTerm, PsiTerm = psiTerm, TemperatureTerm = temperatureTerm, SaturationVaporPressureAvg = saturationVaporPressureMean, SaturationVaporPressureActual = saturationVaporPressureActual, SaturationVaporPressureDeficit = saturationVaporPressureDeficit, RelativeEarthSunDifference = relativeEarthSunDifference, SolarDeclination = solarDeclination, LatitudeRadians = latitudeRadians, SunsetHourAngle = sunsetHourAngle, ExtraterrestrialRadiation = extraterrestrialRadiation, ClearSkySolarRadiation = clearSkySolarRadiation, NetSolarRadiation = netSolarRadiation, NetOutgoingLongWaveSolarRadiation = netOutgoingLongWaveSolarRadiation, NetRadiation = netRadiation, NetRadiationMM = netRadiationMM, RadiationTerm = radiationTerm, WindTerm = windTerm, EvapotranspirationIN = evapotranspirationIN, EvapotranspirationMM = evapotranspirationMM }; return(evapoObject); }