public HowLeakyOutputs(BrowserDate startDate, BrowserDate endDate) { StartDate = new BrowserDate(startDate); EndDate = new BrowserDate(endDate); TimeSeries = new List <HowLeakyOutputTimeseriesActive>(); // Definitions=new List<HowLeakyOutputDefinition>(); }
internal bool IsDateInWindow(BrowserDate date, DayMonthData startWindow, DayMonthData endWindow) { try { int currYear = date.Year; if (doesDateOverlapYear(startWindow, endWindow) == false) { var _startWindow = new BrowserDate(currYear, startWindow.Month, startWindow.Day); var _endWindow = new BrowserDate(currYear, endWindow.Month, endWindow.Day); return(date.IsBetween(_startWindow, _endWindow)); } else { var _startWindow = new BrowserDate(currYear, startWindow.Month, startWindow.Day); if (_startWindow.DateInt > date.DateInt) { _startWindow = new BrowserDate(currYear - 1, startWindow.Month, startWindow.Day); var _endWindow = new BrowserDate(currYear, endWindow.Month, endWindow.Day); return(date.IsBetween(_startWindow, _endWindow)); } else { var _endWindow = new BrowserDate(currYear + 1, endWindow.Month, endWindow.Day); return(date.IsBetween(_startWindow, _endWindow)); } } return(false); } catch (Exception ex) { throw ErrorLogger.CreateException(ex); } // return false; }
public HowLeakyOutputTimeSeries(string name, string color, int?index, BrowserDate start, BrowserDate end, List <double> values, bool canAccomulate) { Name = name; StartDate = new BrowserDate(start); EndDate = new BrowserDate(end); Index = index; ColorValue = color; DailyValues = values.Select(x => (double?)x).ToList(); CanAccumulate = canAccomulate; }
public HowLeakyOutputTimeSeries(int?simindex, string name, BrowserDate start, BrowserDate end, int count, bool canAccumulate) { SimulationIndex = simindex; Name = name; StartDate = new BrowserDate(start); EndDate = new BrowserDate(end); Index = null; Initialise(count); CanAccumulate = canAccumulate; }
public TimeSeriesViewModel(string name, BrowserDate start, BrowserDate end) { SimIndex = -1; Name = name; StartDate = new BrowserDate(start); EndDate = new BrowserDate(end); var count = end.DateInt - start.DateInt + 1; Values = new List <double>(new double[count]); }
public TimeSeriesViewModel(int simindex, string name, BrowserDate start, BrowserDate end) { SimIndex = simindex; Name = name; StartDate = start; EndDate = end; var count = end.DateInt - start.DateInt + 1; Values = new List <double>(new double[count]); }
//public HowLeakyOutputTimeseries(HowLeakyOutputDefinition outputtype, int? index, Action<HowLeakyOutputTimeseries> action) //{ // // Action=action; // Index=index; //} public HowLeakyOutputTimeseriesActive(HowLeakyOutputDefinition outputtype, BrowserDate start, BrowserDate end) : base() { Name = outputtype.DisplayName;//$"{outputtype.DisplayName}"; StartDate = new BrowserDate(start); EndDate = new BrowserDate(end); OutputDefn = outputtype; Index = outputtype.VectorIndex; ColorValue = outputtype.ColorValue; DailyValues = new List <double?>(new double?[EndDate.DateInt - StartDate.DateInt + 1]); CanAccumulate = outputtype.CanAccumulate; }
public double RainOnDay(BrowserDate date) { try { int index = date.DateInt - InputModel.StartDate.DateInt;//(day - InputModel.StartDate.Value).Days; if (index > 0 && index <= InputModel.Rain.Count - 1) { return(InputModel.Rain[index]); } } catch (Exception ex) { throw ErrorLogger.CreateException(ex); } return(0); }
/// <summary> /// /// </summary> /// <param name="today"></param> /// <returns></returns> public override bool HasCropBeenAbsentForSufficientYears(BrowserDate today) { try { if (InputModel.PlantingRulesOptions != (int)EPlantingRules.PlantFromSequenceFile && InputModel.RotationFormat != UNCONTROLLED) { if (LastHarvestDate != null) { int months_since_last_sow = today.MonthsFrom(LastHarvestDate);//DateUtilities.MonthsBetween(today, LastHarvestDate); return(months_since_last_sow >= InputModel.RestPeriodAfterChangingCrops); } } } catch (Exception ex) { throw ErrorLogger.CreateException(ex); } return(true); }
static public List <TimeSeriesViewModel> ReadOutputs(string path) { try { if (File.Exists(path)) { var list = new List <TimeSeriesViewModel>(); using (FileStream fileStream = new FileStream(path, FileMode.Open)) // destiny file directory. { using (BinaryReader binaryReader = new BinaryReader(fileStream)) { binaryReader.BaseStream.Position = 0; var simindex = binaryReader.ReadInt32(); var timeseriescount = binaryReader.ReadInt32(); var start = new BrowserDate(binaryReader.ReadInt32()); var end = new BrowserDate(binaryReader.ReadInt32()); var datacount = end.DateInt - start.DateInt + 1; var outputs = new HowLeakyOutputs(start, end); var timeserieslist = outputs.TimeSeries; for (var index1 = 0; index1 < timeseriescount; ++index1) { var name = binaryReader.ReadString(); var vm = new TimeSeriesViewModel(simindex, name, start, end); for (var i = 0; i < datacount; ++i) { vm.Values[i] = binaryReader.ReadDouble(); } list.Add(vm); } } } return(list); } } catch (Exception ex) { throw ErrorLogger.CreateException(ex); } return(new List <TimeSeriesViewModel>()); }
public List <double?> MonthlyValues() { var monthlyValues = new List <double?>(); var lastDate = StartDate; double?sum = null; int count = 0; for (var i = 0; i < DailyValues.Count; ++i) { var date = StartDate.AddDays(i); if (date.Month == lastDate.Month) { ++count; if (DailyValues[i] != null) { if (sum != null) { sum += (double)DailyValues[i]; } else { sum = (double)DailyValues[i]; } } } else { UpdateValues(monthlyValues, sum, count); count = 1; sum = DailyValues[i]; lastDate = new BrowserDate(date); } } if (sum != null) { UpdateValues(monthlyValues, sum, count); } return(monthlyValues); }
public virtual bool HasCropBeenAbsentForSufficientYears(BrowserDate today) { return(true); }
public bool LoadInputs(HowLeakyInputsModel model) { try { SimulationName = model.Name; Modules = new List <_CustomHowLeakyEngineModule>(); if (model.Climate != null) { ClimateModule = new HowLeakyEngineModule_Climate(this, model.Climate); Modules.Add(ClimateModule); } if (model.Soil != null) { SoilModule = new HowLeakyEngineModule_Soil(this, model.Soil); Modules.Add(SoilModule); } if (model.Crops != null) { VegetationModules = new List <_CustomHowLeakyEngine_VegModule>(); foreach (var crop in model.Crops) { if (crop.IsLAI()) { VegetationModules.Add(new HowLeakyEngineModule_LAIVeg(this, (HowLeakyInputs_LAIVeg)crop)); } else { VegetationModules.Add(new HowLeakyEngineModule_CoverVeg(this, (HowLeakyInputs_CoverVeg)crop)); } } Modules.AddRange(VegetationModules); } if (model.Tillage != null) { TillageModules = new List <HowLeakyEngineModule_Tillage>(); foreach (var till in model.Tillage) { TillageModules.Add(new HowLeakyEngineModule_Tillage(this, till)); } Modules.AddRange(TillageModules); } if (model.Pesticides != null) { PesticideModules = new List <HowLeakyEngineModule_Pesticide>(); foreach (var pest in model.Pesticides) { PesticideModules.Add(new HowLeakyEngineModule_Pesticide(this, pest)); } Modules.AddRange(PesticideModules); } if (model.Irrigation != null) { IrrigationModule = new HowLeakyEngineModule_Irrigation(this, model.Irrigation); Modules.Add(IrrigationModule); } if (model.Phosphorus != null) { PhosphorusModule = new HowLeakyEngineModule_Phosphorus(this, model.Phosphorus); Modules.Add(PhosphorusModule); } if (model.Solutes != null) { SolutesModule = new HowLeakyEngineModule_Solutes(this, model.Solutes); Modules.Add(SolutesModule); } if (model.Nitrate != null) { NitrateModule = new HowLeakyEngineModule_Nitrate(this, model.Nitrate); Modules.Add(NitrateModule); } StartDate = model.StartDate; EndDate = model.EndDate; if (ClimateModule != null && ClimateModule.InputModel != null) { if (StartDate == null || StartDate.DateInt < ClimateModule.InputModel.StartDate.DateInt) { StartDate = new BrowserDate(ClimateModule.InputModel.StartDate); } if (EndDate == null || EndDate.DateInt > ClimateModule.InputModel.EndDate.DateInt) { EndDate = new BrowserDate(ClimateModule.InputModel.EndDate); } } if (StartDate != null) { TodaysDate = new BrowserDate(StartDate); } if (ClimateModule == null) { throw new Exception("Climate Module could not be loaded"); } if (SoilModule == null) { throw new Exception("Soil Module could not be loaded"); } else if (VegetationModules == null || VegetationModules.Count == 0) { throw new Exception("Vegetation Modules could not be loaded"); } //ResetResidueMassDay=model.ResetResidueMassDay; //ResetResidueMassMonth=model.ResetResidueMassMonth; //ResetResidueMassValue=model.ResetResidueMassValue; //ResetSoilWaterAtDate=model.ResetSoilWaterAtDefinedDate; //ResetSoilWaterDay=model.ResetSoilWaterDay; //ResetSoilWaterMonth=model.ResetSoilWaterMonth; // ResetValueForSWAtPlanting=model.ResetSoilWaterValue; //ResetValueForSWAtPlanting=model.ResetSoilWaterValue; //ResetSoilWaterAtPlanting=model.ResetSoilWaterAtPlanting; //public bool CalculateLateralFlow{get;set;} //public bool IgnoreCropDepth{get;set;} //public bool UsePERFECTDryMatterFn{get;set;} //public bool UsePERFECTGroundCoverFn{get;set;} //public bool UsePERFECTSoilEvapFn{get;set;} //public bool UsePERFECTLeafAreaFn{get;set;} //public bool UsePERFECTResidueFn{get;set;} //public bool UsePERFECTUSLELSFactor{get;set;} //public bool UsePERFECTCNFn{get;set;} //public double PAWCStart{get;set;} //public int EvaporationOptions{get;set;} ClimateModule.InputModel.PanEvapMultiplier = model.EPanMultiplier; ClimateModule.InputModel.RainfallMultiplier = model.RainfallMultiplier; return(ClimateModule != null && SoilModule != null && VegetationModules != null && VegetationModules.Count > 0); } catch (Exception ex) { throw ErrorLogger.CreateException(ex); } // return false; }
private int LoadExtendedFromFileAtIndex(int startindex, string filename) { try { var datetext = ""; float tmax; float tmin; float rain; float pan; float solarrad; float vp; float rhmax; float rhmin; float fao56; int index = startindex; string line; bool foundstart = false; if (startindex <= 0) { CreateTimeSeries(9); } var MaxTempValues = TimeSeries[0]; var MinTempValues = TimeSeries[1]; var RainfallValues = TimeSeries[2]; var PanEvapValues = TimeSeries[3]; var SolarRadValues = TimeSeries[4]; var VPValues = TimeSeries[5]; var RHMaxValues = TimeSeries[6]; var RHMinValues = TimeSeries[7]; var FAO56Values = TimeSeries[8]; //DateTime date; using (StreamReader infile = new StreamReader(filename)) { while ((line = infile.ReadLine()) != null) { if (foundstart) { if (index >= startindex) { String[] dellist = line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (dellist.Length == 18) { //" * Patched Point data for station: 41023 DALBY POST OFFICE Lat: -27.18 Long: 151.26" //Date Day Date2 T.Max Smx T.Min Smn Rain Srn Evap Sev Radn Ssl VP Svp RHmaxT RHminT FAO56 //(yyyymmdd) () (ddmmyyyy) (oC) () (oC) () (mm) () (mm) () (MJ/m2) () (hPa) () (%) (%) (mm) // (0) (1) (2) (*3*) (4) (*5*) (6) (*7*) (8) (*9*) (10)(*11*) (12)(*13*)(14)(*15*) (*16*) (*17*) datetext = dellist[0]; if (StartDate == null) { StartDate = new BrowserDate(datetext, "yyyyMMdd"); } tmax = Convert.ToSingle(dellist[3]); tmin = Convert.ToSingle(dellist[5]); rain = Convert.ToSingle(dellist[7]); pan = Convert.ToSingle(dellist[9]); solarrad = Convert.ToSingle(dellist[11]); vp = Convert.ToSingle(dellist[13]); rhmax = Convert.ToSingle(dellist[15]); rhmin = Convert.ToSingle(dellist[16]); fao56 = Convert.ToSingle(dellist[17]); MaxTempValues.Add(tmax); MinTempValues.Add(tmin); RainfallValues.Add(rain); PanEvapValues.Add(pan); SolarRadValues.Add(solarrad); VPValues.Add(vp); RHMaxValues.Add(rhmax); RHMinValues.Add(rhmin); FAO56Values.Add(fao56); ++index; } } } else if (line.Contains("yyyymmdd") && line.Contains("ddmmyyyy")) { foundstart = true; } } //infile.Close(); shouldn't need to close when using a "using"! } if (foundstart) { EndDate = new BrowserDate(datetext, "yyyyMMdd"); --index; return(index); } } catch (Exception) { } return(-1); }
private int LoadStandardFromFileAtIndex(int startindex, string filename) { try { var datetext = ""; float tmax; float tmin; float rain; float pan; float solarrad; int index = startindex; string line; bool foundstart = false; if (startindex <= 0) { CreateTimeSeries(5); } var MaxTempValues = TimeSeries[0]; var MinTempValues = TimeSeries[1]; var RainfallValues = TimeSeries[2]; var PanEvapValues = TimeSeries[3]; var SolarRadValues = TimeSeries[4]; //DateTime date; using (StreamReader infile = new StreamReader(filename)) { while ((line = infile.ReadLine()) != null) { if (foundstart) { if (index >= startindex) { String[] dellist = line.Split(new[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries); if (dellist.Length == 8) { datetext = dellist[0]; if (StartDate == null) { StartDate = new BrowserDate(datetext, "yyyyMMdd"); } tmax = Convert.ToSingle(dellist[2]); tmin = Convert.ToSingle(dellist[3]); rain = Convert.ToSingle(dellist[4]); pan = Convert.ToSingle(dellist[5]); solarrad = Convert.ToSingle(dellist[6]); MaxTempValues.Add(tmax); MinTempValues.Add(tmin); RainfallValues.Add(rain); PanEvapValues.Add(pan); SolarRadValues.Add(solarrad); ++index; } } } else if (line.Contains("date") && line.Contains("jday")) { foundstart = true; } } //infile.Close(); shouldn't need to close when using a "using"! } if (foundstart) { EndDate = new BrowserDate(datetext, "yyyyMMdd"); --index; return(index); } } catch (Exception) { } return(-1); }