/// <summary>Adds a irrigation operation.</summary> /// <param name="application">The application.</param> public void AddIrrigateOperation(Irrigate application) { string action = "Irrigation apply amount = " + application.Amount.ToString("F0") + " (mm)" + "efficiency = " + application.Efficiency.ToString("F2") + "(0-1)"; AddOperation(application.Date, action, application.IsEveryYear); }
/// <summary>Adds a irrigation operation.</summary> /// <param name="application">The application.</param> public void AddIrrigateOperation(Irrigate application) { string action = "[Irrigation].Apply(amount: " + application.Amount.ToString("F0") + ",efficiency: " + application.Efficiency.ToString("F2") + ")"; AddOperation(application.Date, action); }
/// <summary>Converts the paddock XML.</summary> /// <param name="paddock">The paddock.</param> /// <exception cref="System.Exception">Bad paddock name: + name</exception> private static Paddock CreateSimulationSpec(XmlNode paddock, string baseFolder) { Paddock simulation = new Paddock(); string name = XmlUtilities.NameAttr(paddock); string delimiter = "^"; int posCaret = name.IndexOf(delimiter); if (posCaret == -1) { throw new Exception("Bad paddock name: " + name); } string remainder = StringUtilities.SplitOffAfterDelimiter(ref name, delimiter); string growerName; string paddockName = StringUtilities.SplitOffAfterDelimiter(ref remainder, delimiter); if (paddockName == string.Empty) { growerName = name; paddockName = remainder; } else { growerName = remainder; } // Give the paddock a name. string fullName = string.Format("{0}^{1}^{2}", GetDate(paddock, "SowDateFull").Year, growerName, paddockName); simulation.Name = fullName; // Set the report date. simulation.NowDate = GetDate(paddock.ParentNode, "TodayDateFull"); if (simulation.NowDate == DateTime.MinValue) { simulation.NowDate = DateTime.Now; } // Store any rainfall data in the simulation. string rainfallSource = GetString(paddock, "RainfallSource"); if (rainfallSource != "Weather station") { string rainFileName = GetString(paddock, "RainfallFilename"); if (rainFileName != string.Empty) { string fullFileName = Path.Combine(baseFolder, rainFileName); if (!File.Exists(fullFileName)) { throw new Exception("Cannot find file: " + fullFileName); } simulation.ObservedData = ApsimTextFile.ToTable(fullFileName); simulation.ObservedData.TableName = rainfallSource; if (simulation.ObservedData.Rows.Count == 0) { simulation.ObservedData = null; } } } // Set the reset dates simulation.SoilWaterSampleDate = GetDate(paddock, "ResetDateFull"); simulation.SoilNitrogenSampleDate = GetDate(paddock, "SoilNitrogenSampleDateFull"); simulation.StationNumber = GetInteger(paddock, "StationNumber"); simulation.StationName = GetString(paddock, "StationName"); // Create a sowing management Sow sowing = new Sow(); simulation.Management.Add(sowing); sowing.Date = GetDate(paddock, "SowDateFull"); sowing.EmergenceDate = GetDate(paddock, "EmergenceDateFull"); sowing.Crop = GetString(paddock, "Crop"); sowing.Cultivar = GetString(paddock, "Cultivar"); sowing.SkipRow = GetString(paddock, "SkipRow"); sowing.SowingDensity = GetInteger(paddock, "SowingDensity"); sowing.MaxRootDepth = GetInteger(paddock, "MaxRootDepth") * 10; // cm to mm sowing.BedWidth = GetInteger(paddock, "BedWidth"); sowing.BedRowSpacing = GetDouble(paddock, "BedRowSpacing"); // Make sure we have a stubbletype simulation.StubbleType = GetString(paddock, "StubbleType"); if (simulation.StubbleType == string.Empty || simulation.StubbleType == "None") { simulation.StubbleType = "Wheat"; } simulation.StubbleMass = GetDouble(paddock, "StubbleMass"); simulation.Slope = GetDouble(paddock, "Slope"); simulation.SlopeLength = GetDouble(paddock, "SlopeLength"); simulation.UseEC = GetBoolean(paddock, "UseEC"); // Fertilise nodes. List <XmlNode> fertiliserNodes = XmlUtilities.ChildNodes(paddock, "Fertilise"); for (int f = 0; f < fertiliserNodes.Count; f++) { Fertilise fertilise = new Fertilise(); simulation.Management.Add(fertilise); fertilise.Date = GetDate(fertiliserNodes[f], "FertDateFull"); fertilise.Amount = GetDouble(fertiliserNodes[f], "FertAmount"); } // Irrigate nodes. List <XmlNode> irrigateNodes = XmlUtilities.ChildNodes(paddock, "Irrigate"); for (int i = 0; i < irrigateNodes.Count; i++) { Irrigate irrigate = new Irrigate(); simulation.Management.Add(irrigate); irrigate.Date = GetDate(irrigateNodes[i], "IrrigateDateFull"); irrigate.Amount = GetDouble(irrigateNodes[i], "IrrigateAmount"); irrigate.Efficiency = GetDouble(irrigateNodes[i], "IrrigateEfficiency"); } // Tillage nodes. foreach (XmlNode tillageNode in XmlUtilities.ChildNodes(paddock, "Tillage")) { Tillage tillage = new Tillage(); simulation.Management.Add(tillage); tillage.Date = GetDate(tillageNode, "TillageDateFull"); string disturbance = GetString(tillageNode, "Disturbance"); if (disturbance == "Low") { tillage.Disturbance = Tillage.DisturbanceEnum.Low; } else if (disturbance == "Medium") { tillage.Disturbance = Tillage.DisturbanceEnum.Medium; } else { tillage.Disturbance = Tillage.DisturbanceEnum.High; } } // Stubble removed nodes. foreach (XmlNode stubbleRemovedNode in XmlUtilities.ChildNodes(paddock, "StubbleRemoved")) { StubbleRemoved stubbleRemoved = new StubbleRemoved(); simulation.Management.Add(stubbleRemoved); stubbleRemoved.Date = GetDate(stubbleRemovedNode, "StubbleRemovedDateFull"); stubbleRemoved.Percent = GetDouble(stubbleRemovedNode, "StubbleRemovedAmount"); } // Look for a soil node. XmlNode soilNode = XmlUtilities.FindByType(paddock, "Soil"); if (soilNode != null) { string testValue = XmlUtilities.Value(soilNode, "Water/Layer/Thickness"); if (testValue != string.Empty) { // old format. soilNode = ConvertSoilNode.Upgrade(soilNode); } } // Fix up soil sample variables. Sample sample1 = new Sample { Name = "Sample1", Thickness = GetArray(paddock, "Sample1Thickness"), SW = GetArray(paddock, "SW") }; if (sample1.SW == null) { // Really old way of doing samples - they are stored under soil. List <XmlNode> sampleNodes = XmlUtilities.ChildNodes(soilNode, "Sample"); if (sampleNodes.Count > 0) { sample1 = XmlUtilities.Deserialise(sampleNodes[0], typeof(Sample)) as Sample; } } else { sample1.NO3 = GetArray(paddock, "NO3"); sample1.NH4 = GetArray(paddock, "NH4"); } Sample sample2 = null; double[] sample2Thickness = GetArray(paddock, "Sample2Thickness"); if (sample2Thickness == null) { // Really old way of doing samples - they are stored under soil. List <XmlNode> sampleNodes = XmlUtilities.ChildNodes(soilNode, "Sample"); if (sampleNodes.Count > 1) { sample2 = XmlUtilities.Deserialise(sampleNodes[1], typeof(Sample)) as Sample; } } else { sample2 = sample1; if (!MathUtilities.AreEqual(sample2Thickness, sample1.Thickness)) { sample2 = new Sample { Name = "Sample2" }; } sample2.OC = GetArray(paddock, "OC"); sample2.EC = GetArray(paddock, "EC"); sample2.PH = GetArray(paddock, "PH"); sample2.CL = GetArray(paddock, "CL"); sample2.OCUnits = SoilOrganicMatter.OCUnitsEnum.WalkleyBlack; sample2.PHUnits = Analysis.PHUnitsEnum.CaCl2; } // Make sure we have NH4 values. if (sample1.NH4 == null && sample1.NO3 != null) { string[] defaultValues = StringUtilities.CreateStringArray("0.1", sample1.NO3.Length); sample1.NH4 = MathUtilities.StringsToDoubles(defaultValues); } RemoveNullFieldsFromSample(sample1); if (sample2 != null) { RemoveNullFieldsFromSample(sample2); } // Fix up <WaterFormat> string waterFormatString = GetString(paddock, "WaterFormat"); if (waterFormatString.Contains("Gravimetric")) { sample1.SWUnits = Sample.SWUnitsEnum.Gravimetric; } else { sample1.SWUnits = Sample.SWUnitsEnum.Volumetric; } if (MathUtilities.ValuesInArray(sample1.Thickness)) { simulation.Samples.Add(sample1); } if (sample2 != null && MathUtilities.ValuesInArray(sample2.Thickness) && sample2 != sample1) { simulation.Samples.Add(sample2); } // Check for InitTotalWater & InitTotalNitrogen simulation.InitTotalWater = GetDouble(paddock, "InitTotalWater"); simulation.InitTotalNitrogen = GetDouble(paddock, "InitTotalNitrogen"); // Check to see if we need to convert the soil structure. simulation.SoilPath = GetString(paddock, "SoilName"); if (soilNode != null) { // See if there is a 'SWUnits' value. If found then copy it into // <WaterFormat> string waterFormat = XmlUtilities.Value(paddock, "WaterFormat"); if (waterFormat == string.Empty) { int sampleNumber = 0; foreach (XmlNode soilSample in XmlUtilities.ChildNodes(soilNode, "Sample")) { string swUnits = XmlUtilities.Value(soilSample, "SWUnits"); if (swUnits != string.Empty) { XmlUtilities.SetValue(paddock, "WaterFormat", swUnits); } // Also make sure we don't have 2 samples with the same name. string sampleName = "Sample" + (sampleNumber + 1).ToString(); XmlUtilities.SetAttribute(soilSample, "name", sampleName); sampleNumber++; } } simulation.Soil = SoilUtilities.FromXML(soilNode.OuterXml); if (simulation.Samples != null) { simulation.Soil.Samples = simulation.Samples; } } return(simulation); }
/// <summary>Adds a irrigation operation.</summary> /// <param name="application">The application.</param> public void AddIrrigateOperation(Irrigate application) { if (application.Scenario) AddOperation(application.Date, "act_mods ScenarioOperation"); string action = "Irrigation apply amount = " + application.Amount.ToString("F0") + " (mm)" + "efficiency = " + application.Efficiency.ToString("F2") + "(0-1)"; AddOperation(application.Date, action); }
/// <summary>Converts the paddock XML.</summary> /// <param name="paddock">The paddock.</param> /// <exception cref="System.Exception">Bad paddock name: + name</exception> private static Paddock CreateSimulationSpec(XmlNode paddock, string baseFolder) { Paddock simulation = new Paddock(); string name = XmlUtilities.NameAttr(paddock); string delimiter = "^"; int posCaret = name.IndexOf(delimiter); if (posCaret == -1) throw new Exception("Bad paddock name: " + name); string remainder = StringUtilities.SplitOffAfterDelimiter(ref name, delimiter); string growerName; string paddockName = StringUtilities.SplitOffAfterDelimiter(ref remainder, delimiter); if (paddockName == string.Empty) { growerName = name; paddockName = remainder; } else growerName = remainder; simulation.StartSeasonDate = GetDate(paddock, "StartSeasonDateFull"); // Give the paddock a name. string fullName = string.Format("{0}^{1}^{2}", simulation.StartSeasonDate.Year, growerName, paddockName); simulation.Name = fullName; // Set the report date. simulation.NowDate = GetDate(paddock.ParentNode, "TodayDateFull"); if (simulation.NowDate == DateTime.MinValue) simulation.NowDate = DateTime.Now; // Store any rainfall data in the simulation. simulation.RainfallSource = GetString(paddock, "RainfallSource"); if (simulation.RainfallSource != "Weather station") { string rainFileName = GetString(paddock, "RainfallFilename"); if (rainFileName != string.Empty) { string fullFileName = Path.Combine(baseFolder, rainFileName); if (!File.Exists(fullFileName)) throw new Exception("Cannot find file: " + fullFileName); simulation.ObservedData = ApsimTextFile.ToTable(fullFileName); if (simulation.ObservedData.Rows.Count == 0) simulation.ObservedData = null; } } // Set the reset dates simulation.SoilWaterSampleDate = GetDate(paddock, "ResetDateFull"); simulation.SoilNitrogenSampleDate = GetDate(paddock, "SoilNitrogenSampleDateFull"); simulation.StationNumber = GetInteger(paddock, "StationNumber"); simulation.StationName = GetString(paddock, "StationName"); // Create a sowing management Sow sowing = new Sow(); simulation.Management.Add(sowing); sowing.Date = GetDate(paddock, "SowDateFull"); sowing.EmergenceDate = GetDate(paddock, "EmergenceDateFull"); sowing.Crop = GetString(paddock, "Crop"); sowing.Cultivar = GetString(paddock, "Cultivar"); sowing.SkipRow = GetString(paddock, "SkipRow"); sowing.SowingDensity = GetInteger(paddock, "SowingDensity"); sowing.MaxRootDepth = GetInteger(paddock, "MaxRootDepth") * 10; // cm to mm sowing.BedWidth = GetInteger(paddock, "BedWidth"); sowing.BedRowSpacing = GetDouble(paddock, "BedRowSpacing"); // Make sure we have a stubbletype simulation.StubbleType = GetString(paddock, "StubbleType"); if (simulation.StubbleType == string.Empty || simulation.StubbleType == "None") simulation.StubbleType = "Wheat"; simulation.StubbleMass = GetDouble(paddock, "StubbleMass"); simulation.Slope = GetDouble(paddock, "Slope"); simulation.SlopeLength = GetDouble(paddock, "SlopeLength"); simulation.UseEC = GetBoolean(paddock, "UseEC"); // Fertilise nodes. List<XmlNode> fertiliserNodes = XmlUtilities.ChildNodes(paddock, "Fertilise"); for (int f = 0; f < fertiliserNodes.Count; f++) { Fertilise fertilise = new Fertilise(); simulation.Management.Add(fertilise); fertilise.Date = GetDate(fertiliserNodes[f], "FertDateFull"); fertilise.Amount = GetDouble(fertiliserNodes[f], "FertAmount"); fertilise.Scenario = GetBoolean(fertiliserNodes[f], "Scenario"); } // Irrigate nodes. List<XmlNode> irrigateNodes = XmlUtilities.ChildNodes(paddock, "Irrigate"); for (int i = 0; i < irrigateNodes.Count; i++) { Irrigate irrigate = new Irrigate(); simulation.Management.Add(irrigate); irrigate.Date = GetDate(irrigateNodes[i], "IrrigateDateFull"); irrigate.Amount = GetDouble(irrigateNodes[i], "IrrigateAmount"); irrigate.Efficiency = GetDouble(irrigateNodes[i], "IrrigateEfficiency"); irrigate.Scenario = GetBoolean(irrigateNodes[i], "Scenario"); } // Tillage nodes. foreach (XmlNode tillageNode in XmlUtilities.ChildNodes(paddock, "Tillage")) { Tillage tillage = new Tillage(); simulation.Management.Add(tillage); tillage.Date = GetDate(tillageNode, "TillageDateFull"); string disturbance = GetString(tillageNode, "Disturbance"); if (disturbance == "Low") tillage.Disturbance = Tillage.DisturbanceEnum.Low; else if (disturbance == "Medium") tillage.Disturbance = Tillage.DisturbanceEnum.Medium; else tillage.Disturbance = Tillage.DisturbanceEnum.High; tillage.Scenario = GetBoolean(tillageNode, "Scenario"); } // Stubble removed nodes. foreach (XmlNode stubbleRemovedNode in XmlUtilities.ChildNodes(paddock, "StubbleRemoved")) { StubbleRemoved stubbleRemoved = new StubbleRemoved(); simulation.Management.Add(stubbleRemoved); stubbleRemoved.Date = GetDate(stubbleRemovedNode, "StubbleRemovedDateFull"); stubbleRemoved.Percent = GetDouble(stubbleRemovedNode, "StubbleRemovedAmount"); } // Look for a soil node. XmlNode soilNode = XmlUtilities.FindByType(paddock, "Soil"); if (soilNode != null) { string testValue = XmlUtilities.Value(soilNode, "Water/Layer/Thickness"); if (testValue != string.Empty) { // old format. soilNode = ConvertSoilNode.Upgrade(soilNode); } } // Fix up soil sample variables. Sample sample1 = new Sample(); sample1.Name = "Sample1"; sample1.Thickness = GetArray(paddock, "Sample1Thickness"); sample1.SW = GetArray(paddock, "SW"); if (sample1.SW == null) { // Really old way of doing samples - they are stored under soil. List<XmlNode> sampleNodes = XmlUtilities.ChildNodes(soilNode, "Sample"); if (sampleNodes.Count > 0) sample1 = XmlUtilities.Deserialise(sampleNodes[0], typeof(Sample)) as Sample; } else { sample1.NO3 = GetArray(paddock, "NO3"); sample1.NH4 = GetArray(paddock, "NH4"); } Sample sample2 = null; double[] sample2Thickness = GetArray(paddock, "Sample2Thickness"); if (sample2Thickness == null) { // Really old way of doing samples - they are stored under soil. List<XmlNode> sampleNodes = XmlUtilities.ChildNodes(soilNode, "Sample"); if (sampleNodes.Count > 1) sample2 = XmlUtilities.Deserialise(sampleNodes[1], typeof(Sample)) as Sample; } else { sample2 = sample1; if (!MathUtilities.AreEqual(sample2Thickness, sample1.Thickness)) { sample2 = new Sample(); sample2.Name = "Sample2"; } sample2.OC = GetArray(paddock, "OC"); sample2.EC = GetArray(paddock, "EC"); sample2.PH = GetArray(paddock, "PH"); sample2.CL = GetArray(paddock, "CL"); sample2.OCUnits = SoilOrganicMatter.OCUnitsEnum.WalkleyBlack; sample2.PHUnits = Analysis.PHUnitsEnum.CaCl2; } // Make sure we have NH4 values. if (sample1.NH4 == null && sample1.NO3 != null) { string[] defaultValues = StringUtilities.CreateStringArray("0.1", sample1.NO3.Length); sample1.NH4 = MathUtilities.StringsToDoubles(defaultValues); } RemoveNullFieldsFromSample(sample1); if (sample2 != null) RemoveNullFieldsFromSample(sample2); // Fix up <WaterFormat> string waterFormatString = GetString(paddock, "WaterFormat"); if (waterFormatString.Contains("Gravimetric")) sample1.SWUnits = Sample.SWUnitsEnum.Gravimetric; else sample1.SWUnits = Sample.SWUnitsEnum.Volumetric; if (MathUtilities.ValuesInArray(sample1.Thickness)) simulation.Samples.Add(sample1); if (sample2 != null && MathUtilities.ValuesInArray(sample2.Thickness) && sample2 != sample1) simulation.Samples.Add(sample2); // Check for InitTotalWater & InitTotalNitrogen simulation.InitTotalWater = GetDouble(paddock, "InitTotalWater"); simulation.InitTotalNitrogen = GetDouble(paddock, "InitTotalNitrogen"); // Check to see if we need to convert the soil structure. simulation.SoilPath = GetString(paddock, "SoilName"); if (soilNode != null) { // See if there is a 'SWUnits' value. If found then copy it into // <WaterFormat> string waterFormat = XmlUtilities.Value(paddock, "WaterFormat"); if (waterFormat == string.Empty) { int sampleNumber = 0; foreach (XmlNode soilSample in XmlUtilities.ChildNodes(soilNode, "Sample")) { string swUnits = XmlUtilities.Value(soilSample, "SWUnits"); if (swUnits != string.Empty) XmlUtilities.SetValue(paddock, "WaterFormat", swUnits); // Also make sure we don't have 2 samples with the same name. string sampleName = "Sample" + (sampleNumber + 1).ToString(); XmlUtilities.SetAttribute(soilSample, "name", sampleName); sampleNumber++; } } simulation.Soil = SoilUtilities.FromXML(soilNode.OuterXml); if (simulation.Samples != null) simulation.Soil.Samples = simulation.Samples; } return simulation; }