Esempio n. 1
0
 /// <summary>Set the crop values in the table for the specified crop name.</summary>
 private static void SetCropValues(DataTable table, SoilCrop crop, int startRow)
 {
     SetDoubleValues(table, crop.Name + " ll (mm/mm)", crop.LL, startRow);
     SetCodeValues(table, crop.Name + " llCode", crop.LLMetadata, startRow);
     SetDoubleValues(table, crop.Name + " kl (/day)", crop.KL, startRow);
     SetDoubleValues(table, crop.Name + " xf (0-1)", crop.XF, startRow);
 }
Esempio n. 2
0
        /// <summary>
        /// Return the plant available water CAPACITY. Units: mm/mm
        /// </summary>
        public double[] PAWCCrop(string CropName)
        {
            SoilCrop soilCrop = Apsim.Find(Soil, CropName) as SoilCrop;

            if (soilCrop != null)
            {
                return(Soil.CalcPAWC(Soil.Thickness,
                                     Soil.LL(CropName),
                                     Soil.DUL,
                                     Soil.XF(CropName)));
            }
            else
            {
                return(new double[0]);
            }
        }
Esempio n. 3
0
        /// <summary>Return a predicted SoilCrop for the specified crop name or null if not found.</summary>
        /// <param name="CropName">Name of the crop.</param>
        /// <returns></returns>
        private ISoilCrop PredictedCrop(string CropName)
        {
            double[] A = null;
            double B = double.NaN;
            double[] KL = null;

            if (SoilType == null)
                return null;

            if (SoilType.Equals("Black Vertosol", StringComparison.CurrentCultureIgnoreCase))
            {
                if (CropName.Equals("Cotton", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = BlackVertosol.CottonA;
                    B = BlackVertosol.CottonB;
                    KL = CottonKL;
                }
                else if (CropName.Equals("Sorghum", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = BlackVertosol.SorghumA;
                    B = BlackVertosol.SorghumB;
                    KL = SorghumKL;
                }
                else if (CropName.Equals("Wheat", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = BlackVertosol.WheatA;
                    B = BlackVertosol.WheatB;
                    KL = WheatKL;
                }
            }
            else if (SoilType.Equals("Grey Vertosol", StringComparison.CurrentCultureIgnoreCase))
            {
                if (CropName.Equals("Cotton", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.CottonA;
                    B = GreyVertosol.CottonB;
                    KL = CottonKL;
                }
                else if (CropName.Equals("Sorghum", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.SorghumA;
                    B = GreyVertosol.SorghumB;
                    KL = SorghumKL;
                }
                else if (CropName.Equals("Wheat", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.WheatA;
                    B = GreyVertosol.WheatB;
                    KL = WheatKL;
                }
                else if (CropName.Equals("Barley", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.BarleyA;
                    B = GreyVertosol.BarleyB;
                    KL = BarleyKL;
                }
                else if (CropName.Equals("Chickpea", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.ChickpeaA;
                    B = GreyVertosol.ChickpeaB;
                    KL = ChickpeaKL;
                }
                else if (CropName.Equals("Fababean", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.FababeanA;
                    B = GreyVertosol.FababeanB;
                    KL = FababeanKL;
                }
                else if (CropName.Equals("Mungbean", StringComparison.CurrentCultureIgnoreCase))
                {
                    A = GreyVertosol.MungbeanA;
                    B = GreyVertosol.MungbeanB;
                    KL = MungbeanKL;
                }
            }

            if (A == null)
                return null;

            double[] LL = PredictedLL(A, B);
            LL = Map(LL, PredictedThickness, waterNode.Thickness, MapType.Concentration, LL.Last());
            KL = Map(KL, PredictedThickness, waterNode.Thickness, MapType.Concentration, KL.Last());
            double[] XF = Map(PredictedXF, PredictedThickness, waterNode.Thickness, MapType.Concentration, PredictedXF.Last());
            string[] Metadata = StringUtilities.CreateStringArray("Estimated", waterNode.Thickness.Length);

            SoilCrop soilCrop = new SoilCrop()
            {
                LL = LL,
                LLMetadata = Metadata,
                KL = KL,
                KLMetadata = Metadata,
                XF = XF,
                XFMetadata = Metadata
            };
            return soilCrop as ISoilCrop;
        }
Esempio n. 4
0
        /// <summary>Convert a table of soils data into a list of soils.</summary>
        public static List <Soil> ToSoils(DataTable table)
        {
            var soils = new List <Soil>();

            // Loop through all blocks of rows in datatable, create a
            // soil and store soil in correct location in the AllSoils XML.
            int row = 0;

            while (row < table.Rows.Count)
            {
                // Find the end of this soil i.e. the row that has a different value for 'Name'
                // to the current row.
                int endRow = row + 1;
                while (endRow < table.Rows.Count &&
                       table.Rows[endRow]["Name"].ToString() == table.Rows[row]["Name"].ToString())
                {
                    endRow++;
                }
                int numLayers = endRow - row;

                var soil = new Soil();
                soil.Name              = table.Rows[row]["Name"].ToString();
                soil.Country           = GetStringValue(table, row, "Country");
                soil.State             = GetStringValue(table, row, "State");
                soil.Region            = GetStringValue(table, row, "Region");
                soil.NearestTown       = GetStringValue(table, row, "NearestTown");
                soil.Site              = GetStringValue(table, row, "Site");
                soil.ApsoilNumber      = GetStringValue(table, row, "APSoilNumber");
                soil.SoilType          = GetStringValue(table, row, "Texture");
                soil.LocalName         = GetStringValue(table, row, "LocalName");
                soil.ASCOrder          = GetStringValue(table, row, "ASC_Order");
                soil.ASCSubOrder       = GetStringValue(table, row, "ASC_Sub-order");
                soil.Latitude          = GetDoubleValue(table, row, "Latitude");
                soil.Longitude         = GetDoubleValue(table, row, "Longitude");
                soil.LocationAccuracy  = GetStringValue(table, row, "LocationAccuracy");
                soil.YearOfSampling    = GetStringValue(table, row, "YearOfSampling");
                soil.DataSource        = GetStringValue(table, row, "DataSource");
                soil.Comments          = GetStringValue(table, row, "Comments");
                soil.NaturalVegetation = GetStringValue(table, row, "NaturalVegetation");
                soil.RecordNumber      = GetIntegerValue(table, row, "RecordNo");

                var physical = new Physical();
                soil.Children.Add(physical);
                physical.Thickness                = MathUtilities.RemoveMissingValuesFromBottom(GetDoubleValues(table, "Thickness (mm)", row, numLayers));
                physical.BD                       = GetDoubleValues(table, "BD", row, numLayers);
                physical.BDMetadata               = GetCodeValues(table, "BDCode", row, numLayers);
                physical.SAT                      = GetDoubleValues(table, "SAT (mm/mm)", row, numLayers);
                physical.SATMetadata              = GetCodeValues(table, "SATCode", row, numLayers);
                physical.DUL                      = GetDoubleValues(table, "DUL (mm/mm)", row, numLayers);
                physical.DULMetadata              = GetCodeValues(table, "DULCode", row, numLayers);
                physical.LL15                     = GetDoubleValues(table, "LL15 (mm/mm)", row, numLayers);
                physical.LL15Metadata             = GetCodeValues(table, "LL15Code", row, numLayers);
                physical.AirDry                   = GetDoubleValues(table, "Airdry (mm/mm)", row, numLayers);
                physical.AirDryMetadata           = GetCodeValues(table, "AirdryCode", row, numLayers);
                physical.KS                       = GetDoubleValues(table, "KS (mm/day)", row, numLayers);
                physical.KSMetadata               = GetCodeValues(table, "KSCode", row, numLayers);
                physical.Rocks                    = GetDoubleValues(table, "Rocks (%)", row, numLayers);
                physical.RocksMetadata            = GetCodeValues(table, "RocksCode", row, numLayers);
                physical.Texture                  = GetStringValues(table, "Texture", row, numLayers);
                physical.TextureMetadata          = GetCodeValues(table, "TextureCode", row, numLayers);
                physical.ParticleSizeSand         = GetDoubleValues(table, "ParticleSizeSand (%)", row, numLayers);
                physical.ParticleSizeSandMetadata = GetCodeValues(table, "ParticleSizeSandCode", row, numLayers);
                physical.ParticleSizeSilt         = GetDoubleValues(table, "ParticleSizeSilt (%)", row, numLayers);
                physical.ParticleSizeSiltMetadata = GetCodeValues(table, "ParticleSizeSiltCode", row, numLayers);
                physical.ParticleSizeClay         = GetDoubleValues(table, "ParticleSizeClay (%)", row, numLayers);
                physical.ParticleSizeClayMetadata = GetCodeValues(table, "ParticleSizeClayCode", row, numLayers);

                var soilWater = new WaterBalance();
                soilWater.ResourceName = "WaterBalance";
                soil.Children.Add(soilWater);
                soilWater.Thickness   = physical.Thickness;
                soilWater.SummerU     = GetDoubleValue(table, row, "SummerU");
                soilWater.SummerCona  = GetDoubleValue(table, row, "SummerCona");
                soilWater.WinterU     = GetDoubleValue(table, row, "WinterU");
                soilWater.WinterCona  = GetDoubleValue(table, row, "WinterCona");
                soilWater.SummerDate  = GetStringValue(table, row, "SummerDate");
                soilWater.WinterDate  = GetStringValue(table, row, "WinterDate");
                soilWater.Salb        = GetDoubleValue(table, row, "Salb");
                soilWater.DiffusConst = GetDoubleValue(table, row, "DiffusConst");
                soilWater.DiffusSlope = GetDoubleValue(table, row, "DiffusSlope");
                soilWater.CN2Bare     = GetDoubleValue(table, row, "Cn2Bare");
                soilWater.CNRed       = GetDoubleValue(table, row, "CnRed");
                soilWater.CNCov       = GetDoubleValue(table, row, "CnCov");
                soilWater.SWCON       = GetDoubleValues(table, "SWCON (0-1)", row, numLayers);

                var organic = new Organic();
                soil.Children.Add(organic);
                organic.Thickness      = physical.Thickness;
                organic.FOMCNRatio     = GetDoubleValue(table, row, "RootCN");
                organic.FOM            = MathUtilities.CreateArrayOfValues(GetDoubleValue(table, row, "RootWt"), numLayers);
                organic.SoilCNRatio    = GetDoubleValues(table, "SoilCN", row, numLayers);
                organic.FBiom          = GetDoubleValues(table, "FBIOM (0-1)", row, numLayers);
                organic.FInert         = GetDoubleValues(table, "FINERT (0-1)", row, numLayers);
                organic.Carbon         = GetDoubleValues(table, "OC", row, numLayers);
                organic.CarbonMetadata = GetCodeValues(table, "OCCode", row, numLayers);

                var chemical = new Chemical();
                soil.Children.Add(chemical);
                chemical.Thickness   = physical.Thickness;
                chemical.EC          = GetDoubleValues(table, "EC (1:5 dS/m)", row, numLayers);
                chemical.ECMetadata  = GetCodeValues(table, "ECCode", row, numLayers);
                chemical.PH          = GetDoubleValues(table, "PH", row, numLayers);
                chemical.PHMetadata  = GetCodeValues(table, "PHCode", row, numLayers);
                chemical.CL          = GetDoubleValues(table, "CL (mg/kg)", row, numLayers);
                chemical.CLMetadata  = GetCodeValues(table, "CLCode", row, numLayers);
                chemical.ESP         = GetDoubleValues(table, "ESP (%)", row, numLayers);
                chemical.ESPMetadata = GetCodeValues(table, "ESPCode", row, numLayers);

                // Add in some necessary models.
                var soilTemp = new CERESSoilTemperature();
                soilTemp.Name = "Temperature";
                soil.Children.Add(soilTemp);
                var nutrient = new Nutrients.Nutrient();
                nutrient.ResourceName = "Nutrient";
                soil.Children.Add(nutrient);
                var initialWater = new InitialWater();
                soil.Children.Add(initialWater);

                // crops
                foreach (DataColumn Col in table.Columns)
                {
                    if (Col.ColumnName.ToLower().Contains(" ll"))
                    {
                        var nameBits = Col.ColumnName.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        if (nameBits.Length == 3)
                        {
                            string   cropName = nameBits[0];
                            SoilCrop crop     = new SoilCrop();
                            crop.Name       = cropName + "Soil";
                            crop.LL         = GetDoubleValues(table, cropName + " ll (mm/mm)", row, numLayers);
                            crop.LLMetadata = GetCodeValues(table, cropName + " llCode", row, numLayers);
                            crop.KL         = GetDoubleValues(table, cropName + " kl (/day)", row, numLayers);
                            crop.XF         = GetDoubleValues(table, cropName + " xf (0-1)", row, numLayers);
                            if (MathUtilities.ValuesInArray(crop.LL) ||
                                MathUtilities.ValuesInArray(crop.KL))
                            {
                                physical.Children.Add(crop);
                            }
                        }
                    }
                }

                soils.Add(soil);

                row += numLayers;
            }

            return(soils);
        }
Esempio n. 5
0
 private void OnSimulationCommencing(object sender, EventArgs e)
 {
     soilCrop = this.Soil.Crop(this.Plant.Name) as SoilCrop;
     if (soilCrop == null)
         throw new ApsimXException(this, "Cannot find a soil crop parameterisation for " + Name);
     Clear();
 }