//------------------------------------------------------------------------------------------------ private void CalcSVP() { // Calculates hourlySVP at the air temperature in hPa hourlySVP = new List <double>(); for (int i = 0; i < 24; i++) { hourlySVP.Add(MetUtilities.svp(hourlyTemp[i])); } }
private void OnDoWeather(object sender, EventArgs e) { if (this.doSeek) { if (!this.OpenDataFile()) { throw new ApsimXException(this, "Cannot find weather file '" + this.FileName + "'"); } this.doSeek = false; this.reader.SeekToDate(this.clock.Today); } object[] values = this.reader.GetNextLineOfData(); if (this.clock.Today != this.reader.GetDateFromValues(values)) { throw new Exception("Non consecutive dates found in file: " + this.FileName); } this.todaysMetData.Today = this.clock.Today; this.todaysMetData.Radn = Convert.ToSingle(values[this.radiationIndex]); this.todaysMetData.Maxt = Convert.ToSingle(values[this.maximumTemperatureIndex]); this.todaysMetData.Mint = Convert.ToSingle(values[this.minimumTemperatureIndex]); this.todaysMetData.Rain = Convert.ToSingle(values[this.rainIndex]); if (this.vapourPressureIndex == -1) { // If VP is not present in the weather file assign a defalt value this.todaysMetData.VP = Math.Max(0, MetUtilities.svp(this.MetData.Mint)); } else { this.todaysMetData.VP = Convert.ToSingle(values[this.vapourPressureIndex]); } if (this.windIndex == -1) { // If Wind is not present in the weather file assign a defalt value this.todaysMetData.Wind = 3.0; } else { this.todaysMetData.Wind = Convert.ToSingle(values[this.windIndex]); } if (this.PreparingNewWeatherData != null) { this.PreparingNewWeatherData.Invoke(this, new EventArgs()); } if (this.NewWeatherDataAvailable != null) { this.NewWeatherDataAvailable.Invoke(this, new EventArgs()); } }
/// <summary>Gets the value.</summary> /// <value>The value.</value> public double Value(int arrayIndex = -1) { double VPDmint = MetUtilities.svp((float)MetData.MinT) - MetData.VP; VPDmint = Math.Max(VPDmint, 0.0); double VPDmaxt = MetUtilities.svp((float)MetData.MaxT) - MetData.VP; VPDmaxt = Math.Max(VPDmaxt, 0.0); return(MaximumVPDWeight * VPDmaxt + (1 - MaximumVPDWeight) * VPDmint); }
//------------------------------------------------------------------------------------------------ private void CalcVPD() { // Calculates hourlyVPD at the air temperature in kPa hourlyVPD = new List <double>(); minVPD = -1; for (int i = 0; i < 24; i++) { double vpd = 0.1 * (MetUtilities.svp(hourlyTemp[i]) - MetUtilities.svp(Weather.MinT)); hourlyVPD.Add(vpd); if (vpd > 0 && minVPD < 0) { minVPD = vpd; } } MeanDayVPD = hourlyVPD.Where(v => v > 0).Average(); MaxHrVPD = hourlyVPD.Max(); }
private void OnDoWeather(object sender, EventArgs e) { if (this.doSeek) { if (!this.OpenDataFile()) { throw new ApsimXException(this, "Cannot find weather file '" + this.FileName + "'"); } this.doSeek = false; this.reader.SeekToDate(this.clock.Today); } object[] values = this.reader.GetNextLineOfData(); if (this.clock.Today != this.reader.GetDateFromValues(values)) { throw new Exception("Non consecutive dates found in file: " + this.FileName + ". Another posibility is that you have two clock objects in your simulation, there should only be one"); } this.todaysMetData.Today = this.clock.Today; if (this.radiationIndex != -1) { this.todaysMetData.Radn = Convert.ToSingle(values[this.radiationIndex]); } else { this.todaysMetData.Radn = this.reader.ConstantAsDouble("radn"); } if (this.maximumTemperatureIndex != -1) { this.todaysMetData.Maxt = Convert.ToSingle(values[this.maximumTemperatureIndex]); } else { this.todaysMetData.Maxt = this.reader.ConstantAsDouble("maxt"); } if (this.minimumTemperatureIndex != -1) { this.todaysMetData.Mint = Convert.ToSingle(values[this.minimumTemperatureIndex]); } else { this.todaysMetData.Mint = this.reader.ConstantAsDouble("mint"); } if (this.rainIndex != -1) { this.todaysMetData.Rain = Convert.ToSingle(values[this.rainIndex]); } else { this.todaysMetData.Rain = this.reader.ConstantAsDouble("rain"); } if (this.evaporationIndex == -1) { // If Evap is not present in the weather file assign a default value this.todaysMetData.PanEvap = double.NaN; } else { this.todaysMetData.PanEvap = Convert.ToSingle(values[this.evaporationIndex]); } if (this.rainfallHoursIndex == -1) { // If Evap is not present in the weather file assign a default value this.todaysMetData.RainfallHours = double.NaN; } else { this.todaysMetData.RainfallHours = Convert.ToSingle(values[this.rainfallHoursIndex]); } if (this.vapourPressureIndex == -1) { // If VP is not present in the weather file assign a defalt value this.todaysMetData.VP = Math.Max(0, MetUtilities.svp(this.MetData.Mint)); } else { this.todaysMetData.VP = Convert.ToSingle(values[this.vapourPressureIndex]); } if (this.windIndex == -1) { // If Wind is not present in the weather file assign a default value this.todaysMetData.Wind = 3.0; } else { this.todaysMetData.Wind = Convert.ToSingle(values[this.windIndex]); } if (this.PreparingNewWeatherData != null) { this.PreparingNewWeatherData.Invoke(this, new EventArgs()); } }
private void OnDoWeather(object sender, EventArgs e) { if (this.doSeek) { if (!this.OpenDataFile()) { throw new ApsimXException(this, "Cannot find weather file '" + this.FileName + "'"); } this.doSeek = false; this.reader.SeekToDate(this.clock.Today); } object[] values = this.reader.GetNextLineOfData(); if (this.clock.Today != this.reader.GetDateFromValues(values)) { throw new Exception("Non consecutive dates found in file: " + this.FileName + ". Another posibility is that you have two clock objects in your simulation, there should only be one"); } if (this.radiationIndex != -1) { this.Radn = Convert.ToSingle(values[this.radiationIndex], CultureInfo.InvariantCulture); } else { this.Radn = this.reader.ConstantAsDouble("radn"); } if (this.maximumTemperatureIndex != -1) { this.MaxT = Convert.ToSingle(values[this.maximumTemperatureIndex], CultureInfo.InvariantCulture); } else { this.MaxT = this.reader.ConstantAsDouble("maxt"); } if (this.minimumTemperatureIndex != -1) { this.MinT = Convert.ToSingle(values[this.minimumTemperatureIndex], CultureInfo.InvariantCulture); } else { this.MinT = this.reader.ConstantAsDouble("mint"); } if (this.rainIndex != -1) { this.Rain = Convert.ToSingle(values[this.rainIndex], CultureInfo.InvariantCulture); } else { this.Rain = this.reader.ConstantAsDouble("rain"); } if (this.evaporationIndex == -1) { this.PanEvap = double.NaN; } else { this.PanEvap = Convert.ToSingle(values[this.evaporationIndex], CultureInfo.InvariantCulture); } if (this.rainfallHoursIndex == -1) { this.RainfallHours = double.NaN; } else { this.RainfallHours = Convert.ToSingle(values[this.rainfallHoursIndex], CultureInfo.InvariantCulture); } if (this.vapourPressureIndex == -1) { this.VP = Math.Max(0, MetUtilities.svp(this.MinT)); } else { this.VP = Convert.ToSingle(values[this.vapourPressureIndex], CultureInfo.InvariantCulture); } if (this.windIndex == -1) { this.Wind = 3.0; } else { this.Wind = Convert.ToSingle(values[this.windIndex], CultureInfo.InvariantCulture); } if (this.DiffuseFractionIndex == -1) { this.DiffuseFraction = -1; } else { this.DiffuseFraction = Convert.ToSingle(values[this.DiffuseFractionIndex], CultureInfo.InvariantCulture); } if (this.dayLengthIndex == -1) // Daylength is not a column - check for a constant { if (this.reader.Constant("daylength") != null) { this.DayLength = this.reader.ConstantAsDouble("daylength"); } else { this.DayLength = -1; } } else { this.DayLength = Convert.ToSingle(values[this.dayLengthIndex], CultureInfo.InvariantCulture); } if (this.PreparingNewWeatherData != null) { this.PreparingNewWeatherData.Invoke(this, new EventArgs()); } if (clock.Today.DayOfYear == WinterSolsticeDOY) { DaysSinceWinterSolstice = 0; } else { DaysSinceWinterSolstice += 1; } }
/// <summary>Method to read one days met data in from file</summary> /// <param name="date">the date to read met data</param> private DailyMetDataFromFile GetMetData(DateTime date) { if (this.doSeek) { if (!this.OpenDataFile()) { throw new ApsimXException(this, "Cannot find weather file '" + this.FileName + "'"); } this.doSeek = false; this.reader.SeekToDate(date); } object[] values; DailyMetDataFromFile readMetData = new DailyMetDataFromFile(); try { values = this.reader.GetNextLineOfData(); } catch (IndexOutOfRangeException err) { throw new Exception($"Unable to retrieve weather data on {date.ToString("yyy-MM-dd")} in file {FileName}", err); } if (date != this.reader.GetDateFromValues(values)) { throw new Exception("Non consecutive dates found in file: " + this.FileName + ". Another posibility is that you have two clock objects in your simulation, there should only be one"); } if (this.radiationIndex != -1) { readMetData.Radn = Convert.ToSingle(values[this.radiationIndex], CultureInfo.InvariantCulture); } else { readMetData.Radn = this.reader.ConstantAsDouble("radn"); } if (this.maximumTemperatureIndex != -1) { readMetData.MaxT = Convert.ToSingle(values[this.maximumTemperatureIndex], CultureInfo.InvariantCulture); } else { readMetData.MaxT = this.reader.ConstantAsDouble("maxt"); } if (this.minimumTemperatureIndex != -1) { readMetData.MinT = Convert.ToSingle(values[this.minimumTemperatureIndex], CultureInfo.InvariantCulture); } else { readMetData.MinT = this.reader.ConstantAsDouble("mint"); } if (this.rainIndex != -1) { readMetData.Rain = Convert.ToSingle(values[this.rainIndex], CultureInfo.InvariantCulture); } else { readMetData.Rain = this.reader.ConstantAsDouble("rain"); } if (this.evaporationIndex == -1) { readMetData.PanEvap = double.NaN; } else { readMetData.PanEvap = Convert.ToSingle(values[this.evaporationIndex], CultureInfo.InvariantCulture); } if (this.rainfallHoursIndex == -1) { readMetData.RainfallHours = double.NaN; } else { readMetData.RainfallHours = Convert.ToSingle(values[this.rainfallHoursIndex], CultureInfo.InvariantCulture); } if (this.vapourPressureIndex == -1) { readMetData.VP = Math.Max(0, MetUtilities.svp(readMetData.MinT)); } else { readMetData.VP = Convert.ToSingle(values[this.vapourPressureIndex], CultureInfo.InvariantCulture); } if (this.windIndex == -1) { readMetData.Wind = 3.0; } else { readMetData.Wind = Convert.ToSingle(values[this.windIndex], CultureInfo.InvariantCulture); } if (this.DiffuseFractionIndex == -1) { readMetData.DiffuseFraction = -1; } else { readMetData.DiffuseFraction = Convert.ToSingle(values[this.DiffuseFractionIndex], CultureInfo.InvariantCulture); } if (this.dayLengthIndex == -1) // Daylength is not a column - check for a constant { if (this.reader.Constant("daylength") != null) { readMetData.DayLength = this.reader.ConstantAsDouble("daylength"); } else { readMetData.DayLength = -1; } } else { readMetData.DayLength = Convert.ToSingle(values[this.dayLengthIndex], CultureInfo.InvariantCulture); } return(readMetData); }
/// <summary>Method to read one days met data in from file</summary> /// <param name="date">the date to read met data</param> private DailyMetDataFromFile GetMetData(DateTime date) { if (this.doSeek) { if (!this.OpenDataFile()) { throw new ApsimXException(this, "Cannot find weather file '" + this.FileName + "'"); } this.doSeek = false; this.reader.SeekToDate(date); } object[] values; DailyMetDataFromFile readMetData = new DailyMetDataFromFile(); try { values = this.reader.GetNextLineOfData(); } catch (IndexOutOfRangeException err) { throw new Exception($"Unable to retrieve weather data on {date.ToString("yyy-MM-dd")} in file {FileName}", err); } if (date != this.reader.GetDateFromValues(values)) { throw new Exception("Non consecutive dates found in file: " + this.FileName + ". Another posibility is that you have two clock objects in your simulation, there should only be one"); } if (this.radiationIndex != -1) { readMetData.Radn = Convert.ToSingle(values[this.radiationIndex], CultureInfo.InvariantCulture); } else { readMetData.Radn = this.reader.ConstantAsDouble("radn"); } if (this.maximumTemperatureIndex != -1) { readMetData.MaxT = Convert.ToSingle(values[this.maximumTemperatureIndex], CultureInfo.InvariantCulture); } else { readMetData.MaxT = this.reader.ConstantAsDouble("maxt"); } if (this.minimumTemperatureIndex != -1) { readMetData.MinT = Convert.ToSingle(values[this.minimumTemperatureIndex], CultureInfo.InvariantCulture); } else { readMetData.MinT = this.reader.ConstantAsDouble("mint"); } if (this.rainIndex != -1) { readMetData.Rain = Convert.ToSingle(values[this.rainIndex], CultureInfo.InvariantCulture); } else { readMetData.Rain = this.reader.ConstantAsDouble("rain"); } if (this.evaporationIndex == -1) { readMetData.PanEvap = double.NaN; } else { readMetData.PanEvap = Convert.ToSingle(values[this.evaporationIndex], CultureInfo.InvariantCulture); } if (this.rainfallHoursIndex == -1) { readMetData.RainfallHours = double.NaN; } else { readMetData.RainfallHours = Convert.ToSingle(values[this.rainfallHoursIndex], CultureInfo.InvariantCulture); } if (this.vapourPressureIndex == -1) { readMetData.VP = Math.Max(0, MetUtilities.svp(readMetData.MinT)); } else { readMetData.VP = Convert.ToSingle(values[this.vapourPressureIndex], CultureInfo.InvariantCulture); } if (this.windIndex == -1) { readMetData.Wind = 3.0; } else { readMetData.Wind = Convert.ToSingle(values[this.windIndex], CultureInfo.InvariantCulture); } if (this.DiffuseFractionIndex == -1) { // Estimate Diffuse Fraction using the Approach of Bristow and Campbell double Qmax = MetUtilities.QMax(clock.Today.DayOfYear + 1, Latitude, MetUtilities.Taz, MetUtilities.Alpha, 0.0); // Radiation for clear and dry sky (ie low humidity) double Q0 = MetUtilities.Q0(clock.Today.DayOfYear + 1, Latitude); double B = Qmax / Q0; double Tt = MathUtilities.Bound(readMetData.Radn / Q0, 0, 1); if (Tt > B) { Tt = B; } readMetData.DiffuseFraction = (1 - Math.Exp(0.6 * (1 - B / Tt) / (B - 0.4))); if (Tt > 0.5 && readMetData.DiffuseFraction < 0.1) { readMetData.DiffuseFraction = 0.1; } } else { readMetData.DiffuseFraction = Convert.ToSingle(values[this.DiffuseFractionIndex], CultureInfo.InvariantCulture); } if (this.dayLengthIndex == -1) // Daylength is not a column - check for a constant { if (this.reader.Constant("daylength") != null) { readMetData.DayLength = this.reader.ConstantAsDouble("daylength"); } else { readMetData.DayLength = -1; } } else { readMetData.DayLength = Convert.ToSingle(values[this.dayLengthIndex], CultureInfo.InvariantCulture); } return(readMetData); }
private void OnDoWeather(object sender, EventArgs e) { if (this.doSeek) { if (!this.OpenDataFile()) { throw new ApsimXException(this, "Cannot find weather file '" + this.FileName + "'"); } this.doSeek = false; this.reader.SeekToDate(this.clock.Today); } object[] values; try { values = this.reader.GetNextLineOfData(); } catch (IndexOutOfRangeException err) { throw new Exception($"Unable to retrieve weather data on {clock.Today.ToString("yyy-MM-dd")} in file {FileName}", err); } if (this.clock.Today != this.reader.GetDateFromValues(values)) { throw new Exception("Non consecutive dates found in file: " + this.FileName + ". Another posibility is that you have two clock objects in your simulation, there should only be one"); } if (this.radiationIndex != -1) { this.Radn = Convert.ToSingle(values[this.radiationIndex], CultureInfo.InvariantCulture); } else { this.Radn = this.reader.ConstantAsDouble("radn"); } if (this.maximumTemperatureIndex != -1) { this.MaxT = Convert.ToSingle(values[this.maximumTemperatureIndex], CultureInfo.InvariantCulture); } else { this.MaxT = this.reader.ConstantAsDouble("maxt"); } if (this.minimumTemperatureIndex != -1) { this.MinT = Convert.ToSingle(values[this.minimumTemperatureIndex], CultureInfo.InvariantCulture); } else { this.MinT = this.reader.ConstantAsDouble("mint"); } if (this.rainIndex != -1) { this.Rain = Convert.ToSingle(values[this.rainIndex], CultureInfo.InvariantCulture); } else { this.Rain = this.reader.ConstantAsDouble("rain"); } if (this.evaporationIndex == -1) { this.PanEvap = double.NaN; } else { this.PanEvap = Convert.ToSingle(values[this.evaporationIndex], CultureInfo.InvariantCulture); } if (this.rainfallHoursIndex == -1) { this.RainfallHours = double.NaN; } else { this.RainfallHours = Convert.ToSingle(values[this.rainfallHoursIndex], CultureInfo.InvariantCulture); } if (this.vapourPressureIndex == -1) { this.VP = Math.Max(0, MetUtilities.svp(this.MinT)); } else { this.VP = Convert.ToSingle(values[this.vapourPressureIndex], CultureInfo.InvariantCulture); } if (this.windIndex == -1) { this.Wind = 3.0; } else { this.Wind = Convert.ToSingle(values[this.windIndex], CultureInfo.InvariantCulture); } if (this.DiffuseFractionIndex == -1) { this.DiffuseFraction = -1; } else { this.DiffuseFraction = Convert.ToSingle(values[this.DiffuseFractionIndex], CultureInfo.InvariantCulture); } if (this.dayLengthIndex == -1) // Daylength is not a column - check for a constant { if (this.reader.Constant("daylength") != null) { this.DayLength = this.reader.ConstantAsDouble("daylength"); } else { this.DayLength = -1; } } else { this.DayLength = Convert.ToSingle(values[this.dayLengthIndex], CultureInfo.InvariantCulture); } if (this.PreparingNewWeatherData != null) { this.PreparingNewWeatherData.Invoke(this, new EventArgs()); } if (First) { //StartDAWS = met.DaysSinceWinterSolstice; if (clock.Today.DayOfYear < WinterSolsticeDOY) { if (DateTime.IsLeapYear(clock.Today.Year)) { DaysSinceWinterSolstice = 366 - WinterSolsticeDOY + clock.Today.DayOfYear - 1; //minus 1 as we set the first day as zero } else { DaysSinceWinterSolstice = 365 - WinterSolsticeDOY + clock.Today.DayOfYear - 1; } } else { DaysSinceWinterSolstice = clock.Today.DayOfYear - WinterSolsticeDOY; } First = false; } if (clock.Today.DayOfYear == WinterSolsticeDOY & First == false) { DaysSinceWinterSolstice = 0; } else { DaysSinceWinterSolstice += 1; } Qmax = MetUtilities.QMax(clock.Today.DayOfYear + 1, Latitude, MetUtilities.Taz, MetUtilities.Alpha, VP); }